mirror of
https://github.com/trapexit/mergerfs.git
synced 2026-12-02 04:46:41 -05:00
fix: report a short write when ENOSPC recovery fails after a prefix
- 78a67fd0 kept the bytes written before ENOSPC when the move worked.
When it didn't (moveonenospc off, no branch to move to, the move or
the retry failing, or a non-ENOSPC error), write still returned the
error and dropped the count, though those bytes were on disk. An
O_APPEND writer that retried the whole buffer duplicated them.
- Return the bytes written as a short write whenever some reached the
file, as a local filesystem does. A write that wrote nothing still
returns the error.
- TEST_movefile_enospc checks it with moveonenospc=false and a write
bigger than the space left. Document it in moveonenospc.md.
This commit is contained in:
parent
0091523ce5
commit
072b07b6d5
3 changed files with 54 additions and 11 deletions
|
|
@ -110,6 +110,35 @@ def test_partial_append():
|
|||
return check_relocated(branches, pool, initial + payload)
|
||||
|
||||
|
||||
def test_partial_without_move():
|
||||
with enospc_pool("minfreespace=0,cache.files=full,cache.writeback=false,moveonenospc=false") as (
|
||||
branches, pool, initial,
|
||||
):
|
||||
# Only one block fits. The bytes written before ENOSPC stay on
|
||||
# disk, so the write must report them as a short write, not
|
||||
# fail: a caller that retries the whole buffer would append
|
||||
# them twice.
|
||||
block_size = len(initial)
|
||||
payload = bytes(range(256)) * (block_size // 64)
|
||||
fd = os.open(os.path.join(pool, "target"), os.O_WRONLY | os.O_APPEND)
|
||||
try:
|
||||
try:
|
||||
written = os.write(fd, payload)
|
||||
except OSError as e:
|
||||
return fail(f"append failed with {e.strerror} after writing a prefix")
|
||||
finally:
|
||||
os.close(fd)
|
||||
if not 0 < written < len(payload):
|
||||
return fail(f"append returned {written}, expected a short write")
|
||||
with open(os.path.join(branches["source"], "target"), "rb") as stream:
|
||||
actual = stream.read()
|
||||
if actual != initial + payload[:written]:
|
||||
return fail(f"source holds {len(actual)} bytes, expected {len(initial) + written}")
|
||||
if holders(branches) != ["source"]:
|
||||
return fail(f"target on {holders(branches)}, expected only source")
|
||||
return 0
|
||||
|
||||
|
||||
def test_second_relocation():
|
||||
# lfs over branches with at least minfreespace free picks `middle`
|
||||
# first; once it fills too only `destination` is left. The same open
|
||||
|
|
@ -142,7 +171,7 @@ def test_second_relocation():
|
|||
return check_relocated(branches, pool, bytes(expected))
|
||||
|
||||
|
||||
TESTS = (test_partial_append, test_second_relocation)
|
||||
TESTS = (test_partial_append, test_partial_without_move, test_second_relocation)
|
||||
|
||||
|
||||
def main():
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue