juicedata / juicefs

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

setxattr failed with special name. #4803

Open zhoucheng361 opened 5 months ago

zhoucheng361 commented 5 months ago

What happened:

reproduce:
root@bench-01:~/juicefs# cat .github/scripts/hypo/fs_test.py
    def test_xattr(self):
        state = JuicefsMachine()
        v1 = state.init_folders()
        v19 = state.create_file(content=b'\xb5y', file_name='wums', mode='x', parent=v1, umask=16, user='root')
        v29 = state.set_xattr(file=v19, flag=2, name='R', user='root', value=b'(9')
        state.set_xattr(file=v19, flag=2, name='\x8ar', user='root', value=b'E$\xfe')
        state.teardown()

log:
root@bench-01:~/juicefs# python3 .github/scripts/hypo/fs_test.py -k test_xattr
setup_logger ./fs1.log
setup_logger ./fs2.log
__init__
duration is 0.02861332893371582
2024-04-28 17:12:52,627 - INFO - do_create_file /tmp/fsrand/wums with mode x succeed
2024-04-28 17:12:52,641 - INFO - do_create_file /tmp/jfs/fsrand/wums with mode x succeed
2024-04-28 17:12:52,642 - INFO - do_set_xattr /tmp/fsrand/wums user.R b'(9' 2 succeed
2024-04-28 17:12:52,644 - INFO - do_set_xattr /tmp/jfs/fsrand/wums user.R b'(9' 2 succeed
2024-04-28 17:12:52,645 - INFO - do_set_xattr /tmp/fsrand/wums user.Šr b'E$\xfe' 2 succeed
2024-04-28 17:12:52,646 - INFO - do_set_xattr /tmp/jfs/fsrand/wums {'name': '\x8ar', 'value': b'E$\xfe', 'flag': 2, 'user': 'root'} failed: [Errno 17] File exists: b'/tmp/jfs/fsrand/wums'
F
======================================================================
FAIL: test_xattr (__main__.TestFsrand2)
----------------------------------------------------------------------
Traceback (most recent call last):
  File ".github/scripts/hypo/fs_test.py", line 61, in test_xattr
    state.set_xattr(file=v19, flag=2, name='\x8ar', user='root', value=b'E$\xfe')
  File "/root/juicefs/.github/scripts/hypo/fs.py", line 346, in set_xattr
    file = Files.filter(lambda x: x != multiple()),
  File "/root/hypothesis/hypothesis-python/src/hypothesis/stateful.py", line 681, in rule_wrapper
    return f(*args, **kwargs)
  File "/root/juicefs/.github/scripts/hypo/fs.py", line 346, in set_xattr
    file = Files.filter(lambda x: x != multiple()),
  File "/root/hypothesis/hypothesis-python/src/hypothesis/stateful.py", line 802, in precondition_wrapper
    return f(*args, **kwargs)
  File "/root/juicefs/.github/scripts/hypo/fs.py", line 357, in set_xattr
    assert self.equal(result1, result2), f'\033[31mset_xattr:\nresult1 is {result1}\nresult2 is {result2}\033[0m'
AssertionError: set_xattr:
result1 is (b'E$\xfe',)
result2 is [Errno 17] File exists: b'/tmp/jfs/fsrand/wums'

What you expected to happen:

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

Anything else we need to know?

Environment:

jiefenghuang commented 5 months ago

TBD: It's strange that the ORM library converts this special character, causing "R" and "\x8ar" to be judged as equal. "\x8a" is also not a special escape character in MySQL.

davies commented 4 months ago

FoldEqual?Maybe we should store the xattr names as binary in SQL database.

jiefenghuang commented 4 months ago

FoldEqual?Maybe we should store the xattr names as binary in SQL database.

It doesn’t seem to be a problem with FoldEqual. Storing xattr name as binary seems better, but it seems handling compatibility with older versions of metadata could be challenging.