Conflicting writes.

This commit is contained in:
Itamar Turner-Trauring 2022-02-09 12:41:32 -05:00
parent 8c739343f3
commit faacde4e32
2 changed files with 31 additions and 6 deletions

View File

@ -31,7 +31,7 @@ from cbor2 import dumps, loads
from .server import StorageServer
from .http_common import swissnum_auth_header, Secrets
from .common import si_a2b
from .immutable import BucketWriter
from .immutable import BucketWriter, ConflictingWriteError
from ..util.hashutil import timing_safe_compare
from ..util.base32 import rfc3548_alphabet
@ -253,9 +253,11 @@ class HTTPServer(object):
request.setResponseCode(http.NOT_FOUND)
return b""
try:
finished = bucket.write(offset, data)
# TODO if raises ConflictingWriteError, return HTTP CONFLICT code.
except ConflictingWriteError:
request.setResponseCode(http.CONFLICT)
return b""
if finished:
bucket.close()

View File

@ -626,9 +626,32 @@ class ImmutableHTTPAPITests(SyncTestCase):
"""
If an uploaded chunk conflicts with an already uploaded chunk, a
CONFLICT error is returned.
TBD in https://tahoe-lafs.org/trac/tahoe-lafs/ticket/3860
"""
(upload_secret, _, storage_index, created) = self.create_upload({1}, 100)
# Write:
result_of(
self.im_client.write_share_chunk(
storage_index,
1,
upload_secret,
0,
b"0" * 10,
)
)
# Conflicting write:
with self.assertRaises(ClientException) as e:
result_of(
self.im_client.write_share_chunk(
storage_index,
1,
upload_secret,
0,
b"0123456789",
)
)
self.assertEqual(e.exception.code, http.NOT_FOUND)
def test_read_of_wrong_storage_index_fails(self):
"""