juicedata / juicefs

JuiceFS is a distributed POSIX file system built on top of Redis and S3.
https://juicefs.com
Apache License 2.0
10.66k stars 930 forks source link

nlink incorrect when dump with --skip-trash #4624

Open zhoucheng361 opened 6 months ago

zhoucheng361 commented 6 months ago

What happened:


./juicefs format tikv://localhost:2379/test myjfs --trash-days $trash_days --enable-acl
./juicefs mount -d tikv://localhost:2379/test /jfs --enable-xattr
 SEED=$SEED LOG_LEVEL=WARNING MAX_EXAMPLE=30 STEP_COUNT=20 PROFILE=generate ROOT_DIR1=/jfs/fsrand
ROOT_DIR2=/tmp/fsrand python3 .github/scripts/hypo/fsrand2.py || true
./juicefs dump  tikv://localhost:2379/test dump.json --skip-trash
rm -rf test2.db
./juicefs load sqlite3://test2.db dump.json
./juicefs dump sqlite3://test2.db dump2.json --skip-trash

diff dump.json dump2.json
--- dump.json.bak   2024-04-01 15:03:43.232752299 +0800
+++ dump2.json.bak  2024-04-01 15:03:43.232752299 +0800
@@ -152,7 +152,7 @@
             }
           },
           "fnnw": {
-            "attr": {"inode":0,"type":"regular","mode":440,"uid":0,"gid":0,"atime":1711954992,"mtime":1711954992,"ctime":1711954997,"atimensec":743978721,"mtimensec":746723565,"ctimensec":474743498,"nlink":5,"length":4},
+            "attr": {"inode":0,"type":"regular","mode":440,"uid":0,"gid":0,"atime":1711954992,"mtime":1711954992,"ctime":1711954997,"atimensec":743978721,"mtimensec":746723565,"ctimensec":474743498,"nlink":3,"length":4},
             "posix_acl_access": {"owner":6,"group":0,"other":0,"mask":7,"users":[{"id":0,"perm":2},{"id":1005,"perm":7},{"id":1006,"perm":0},{"id":1007,"perm":7}],"groups":[{"id":0,"perm":6},{"id":1005,"perm":7},{"id":1006,"perm":0},{"id":1007,"perm":7},{"id":1009,"perm":2},{"id":1010,"perm":1},{"id":1011,"perm":1}]},
             "chunks": [{"index":0,"slices":[{"id":54,"size":4,"len":4}]}]
           },
@@ -216,7 +216,7 @@
             "chunks": [{"index":0,"slices":[{"id":48,"size":5,"len":5}]}]
           },
           "inla": {
-            "attr": {"inode":0,"type":"regular","mode":440,"uid":0,"gid":0,"atime":1711954993,"mtime":1711954993,"ctime":1711954997,"atimensec":490562418,"mtimensec":493838365,"ctimensec":499122371,"nlink":2,"length":8},
+            "attr": {"inode":0,"type":"regular","mode":440,"uid":0,"gid":0,"atime":1711954993,"mtime":1711954993,"ctime":1711954997,"atimensec":490562418,"mtimensec":493838365,"ctimensec":499122371,"nlink":1,"length":8},
             "posix_acl_access": {"owner":6,"group":0,"other":0,"mask":7,"users":[{"id":0,"perm":2},{"id":1005,"perm":7},{"id":1006,"perm":0},{"id":1007,"perm":7}],"groups":[{"id":0,"perm":6},{"id":1005,"perm":7},{"id":1006,"perm":0},{"id":1007,"perm":7},{"id":1009,"perm":2},{"id":1010,"perm":1},{"id":1011,"perm":1}]},
             "chunks": [{"index":0,"slices":[{"id":55,"size":8,"len":8}]}]
           },
@@ -385,7 +385,7 @@
             }
           },
           "pjad": {
-            "attr": {"inode":0,"type":"regular","mode":440,"uid":0,"gid":0,"atime":1711954992,"mtime":1711954992,"ctime":1711954997,"atimensec":743978721,"mtimensec":746723565,"ctimensec":474743498,"nlink":5,"length":4},
+            "attr": {"inode":0,"type":"regular","mode":440,"uid":0,"gid":0,"atime":1711954992,"mtime":1711954992,"ctime":1711954997,"atimensec":743978721,"mtimensec":746723565,"ctimensec":474743498,"nlink":3,"length":4},
             "posix_acl_access": {"owner":6,"group":0,"other":0,"mask":7,"users":[{"id":0,"perm":2},{"id":1005,"perm":7},{"id":1006,"perm":0},{"id":1007,"perm":7}],"groups":[{"id":0,"perm":6},{"id":1005,"perm":7},{"id":1006,"perm":0},{"id":1007,"perm":7},{"id":1009,"perm":2},{"id":1010,"perm":1},{"id":1011,"perm":1}]},
             "chunks": [{"index":0,"slices":[{"id":54,"size":4,"len":4}]}]
           },
@@ -749,7 +749,7 @@
             }
           },
           "ynyc": {
-            "attr": {"inode":0,"type":"regular","mode":440,"uid":0,"gid":0,"atime":1711954992,"mtime":1711954992,"ctime":1711954997,"atimensec":743978721,"mtimensec":746723565,"ctimensec":474743498,"nlink":5,"length":4},
+            "attr": {"inode":0,"type":"regular","mode":440,"uid":0,"gid":0,"atime":1711954992,"mtime":1711954992,"ctime":1711954997,"atimensec":743978721,"mtimensec":746723565,"ctimensec":474743498,"nlink":3,"length":4},
             "posix_acl_access": {"owner":6,"group":0,"other":0,"mask":7,"users":[{"id":0,"perm":2},{"id":1005,"perm":7},{"id":1006,"perm":0},{"id":1007,"perm":7}],"groups":[{"id":0,"perm":6},{"id":1005,"perm":7},{"id":1006,"perm":0},{"id":1007,"perm":7},{"id":1009,"perm":2},{"id":1010,"perm":1},{"id":1011,"perm":1}]},
             "chunks": [{"index":0,"slices":[{"id":54,"size":4,"len":4}]}]
           },

What you expected to happen:

How to reproduce it (as minimally and precisely as possible):

Anything else we need to know?

Environment:

zhijian-pro commented 6 months ago

A certain file has 4 hard links, of which 2 have been deleted and moved to the trash. At this time, its nlink is 5. When using dump --skip-trash, the nlink in the resulting JSON file is also 5. However, during loading, the nlink was recalculated and after loading it became 3.