mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-01-18 18:56:28 +00:00
Merge branch '3891-mutable-http-protocol-part-2' into 3893-mutable-http-protocol-part-3
This commit is contained in:
commit
17fc9d0064
@ -350,8 +350,10 @@ Because of the simple types used throughout
|
||||
and the equivalence described in `RFC 7049`_
|
||||
these examples should be representative regardless of which of these two encodings is chosen.
|
||||
|
||||
The one exception is sets.
|
||||
For CBOR messages, any sequence that is semantically a set (i.e. no repeated values allowed, order doesn't matter, and elements are hashable in Python) should be sent as a set.
|
||||
Tag 6.258 is used to indicate sets in CBOR; see `the CBOR registry <https://www.iana.org/assignments/cbor-tags/cbor-tags.xhtml>`_ for more details.
|
||||
Sets will be represented as JSON lists in examples because JSON doesn't support sets.
|
||||
|
||||
HTTP Design
|
||||
~~~~~~~~~~~
|
||||
@ -739,7 +741,7 @@ Reading
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
|
||||
Retrieve a set indicating all shares available for the indicated storage index.
|
||||
For example::
|
||||
For example (this is shown as list, since it will be list for JSON, but will be set for CBOR)::
|
||||
|
||||
[1, 5]
|
||||
|
||||
|
@ -658,12 +658,9 @@ class HTTPServer(object):
|
||||
"/v1/mutable/<storage_index:storage_index>/shares",
|
||||
methods=["GET"],
|
||||
)
|
||||
def list_mutable_shares(self, request, authorization, storage_index):
|
||||
def enumerate_mutable_shares(self, request, authorization, storage_index):
|
||||
"""List mutable shares for a storage index."""
|
||||
try:
|
||||
shares = self._storage_server.list_mutable_shares(storage_index)
|
||||
except KeyError:
|
||||
raise _HTTPError(http.NOT_FOUND)
|
||||
shares = self._storage_server.enumerate_mutable_shares(storage_index)
|
||||
return self._send_encoded(request, shares)
|
||||
|
||||
@_authorized_route(
|
||||
|
@ -690,16 +690,13 @@ class StorageServer(service.MultiService):
|
||||
self)
|
||||
return share
|
||||
|
||||
def list_mutable_shares(self, storage_index) -> set[int]:
|
||||
"""List all share numbers for the given mutable.
|
||||
|
||||
Raises ``KeyError`` if the storage index is not known.
|
||||
"""
|
||||
def enumerate_mutable_shares(self, storage_index: bytes) -> set[int]:
|
||||
"""Return all share numbers for the given mutable."""
|
||||
si_dir = storage_index_to_dir(storage_index)
|
||||
# shares exist if there is a file for them
|
||||
bucketdir = os.path.join(self.sharedir, si_dir)
|
||||
if not os.path.isdir(bucketdir):
|
||||
raise KeyError("Not found")
|
||||
return set()
|
||||
result = set()
|
||||
for sharenum_s in os.listdir(bucketdir):
|
||||
try:
|
||||
|
@ -854,6 +854,22 @@ class IStorageServerMutableAPIsTestsMixin(object):
|
||||
{0: [b"abcdefg"], 1: [b"0123456"], 2: [b"9876543"]},
|
||||
)
|
||||
|
||||
@inlineCallbacks
|
||||
def test_slot_readv_unknown_storage_index(self):
|
||||
"""
|
||||
With unknown storage index, ``IStorageServer.slot_readv()`` TODO.
|
||||
"""
|
||||
storage_index = new_storage_index()
|
||||
reads = yield self.storage_client.slot_readv(
|
||||
storage_index,
|
||||
shares=[],
|
||||
readv=[(0, 7)],
|
||||
)
|
||||
self.assertEqual(
|
||||
reads,
|
||||
{},
|
||||
)
|
||||
|
||||
@inlineCallbacks
|
||||
def create_slot(self):
|
||||
"""Create a slot with sharenum 0."""
|
||||
|
@ -1315,29 +1315,29 @@ class MutableServer(unittest.TestCase):
|
||||
self.failUnless(isinstance(readv_data, dict))
|
||||
self.failUnlessEqual(len(readv_data), 0)
|
||||
|
||||
def test_list_mutable_shares(self):
|
||||
def test_enumerate_mutable_shares(self):
|
||||
"""
|
||||
``StorageServer.list_mutable_shares()`` returns a set of share numbers
|
||||
for the given storage index, or raises ``KeyError`` if it does not exist at all.
|
||||
``StorageServer.enumerate_mutable_shares()`` returns a set of share
|
||||
numbers for the given storage index, or an empty set if it does not
|
||||
exist at all.
|
||||
"""
|
||||
ss = self.create("test_list_mutable_shares")
|
||||
ss = self.create("test_enumerate_mutable_shares")
|
||||
|
||||
# Initially, nothing exists:
|
||||
with self.assertRaises(KeyError):
|
||||
ss.list_mutable_shares(b"si1")
|
||||
empty = ss.enumerate_mutable_shares(b"si1")
|
||||
|
||||
self.allocate(ss, b"si1", b"we1", b"le1", [0, 1, 4, 2], 12)
|
||||
shares0_1_2_4 = ss.list_mutable_shares(b"si1")
|
||||
shares0_1_2_4 = ss.enumerate_mutable_shares(b"si1")
|
||||
|
||||
# Remove share 2, by setting size to 0:
|
||||
secrets = (self.write_enabler(b"we1"),
|
||||
self.renew_secret(b"le1"),
|
||||
self.cancel_secret(b"le1"))
|
||||
ss.slot_testv_and_readv_and_writev(b"si1", secrets, {2: ([], [], 0)}, [])
|
||||
shares0_1_4 = ss.list_mutable_shares(b"si1")
|
||||
shares0_1_4 = ss.enumerate_mutable_shares(b"si1")
|
||||
self.assertEqual(
|
||||
(shares0_1_2_4, shares0_1_4),
|
||||
({0, 1, 2, 4}, {0, 1, 4})
|
||||
(empty, shares0_1_2_4, shares0_1_4),
|
||||
(set(), {0, 1, 2, 4}, {0, 1, 4})
|
||||
)
|
||||
|
||||
def test_bad_magic(self):
|
||||
|
Loading…
Reference in New Issue
Block a user