From: Brian Warner Date: Wed, 7 Nov 2007 01:53:34 +0000 (-0700) Subject: mutable: fix use of storage API X-Git-Url: https://git.rkrishnan.org/components/com_hotproperty/%22doc.html/...?a=commitdiff_plain;h=7e43c7b5f91e5611a14431174da042c8bc4b2a97;p=tahoe-lafs%2Ftahoe-lafs.git mutable: fix use of storage API --- diff --git a/src/allmydata/interfaces.py b/src/allmydata/interfaces.py index d4cf522f..171d2da4 100644 --- a/src/allmydata/interfaces.py +++ b/src/allmydata/interfaces.py @@ -181,12 +181,15 @@ class RIStorageServer(RemoteInterface): Each share can have a separate test vector (i.e. a list of comparisons to perform). If all vectors for all shares pass, then all writes for all shares are recorded. Each comparison is a 4-tuple of - (offset, length, operator, specimen), which effectively does a - read(offset, length) and then compares the result against the - specimen using the given equality/inequality operator. Reads from the - end of the container are truncated, and missing shares behave like - empty ones, so to assert that a share doesn't exist (for use when - creating a new share), use (0, 1, 'eq', ''). + (offset, length, operator, specimen), which effectively does a bool( + (read(offset, length)) OPERATOR specimen ) and only performs the + write if all these evaluate to True. Basic test-and-set uses 'eq'. + Write-if-newer uses a seqnum and (offset, length, 'lt', specimen). + Write-if-same-or-newer uses 'le'. + + Reads from the end of the container are truncated, and missing shares + behave like empty ones, so to assert that a share doesn't exist (for + use when creating a new share), use (0, 1, 'eq', ''). The write vector will be applied to the given share, expanding it if necessary. A write vector applied to a share number that did not diff --git a/src/allmydata/mutable.py b/src/allmydata/mutable.py index e207de59..c7baca4e 100644 --- a/src/allmydata/mutable.py +++ b/src/allmydata/mutable.py @@ -272,7 +272,8 @@ class Retrieve: peer_storage_servers[peerid] = ss return ss d.addCallback(_got_storageserver) - d.addCallback(lambda ss: ss.callRemote("readv_slots", [(0, readsize)])) + d.addCallback(lambda ss: ss.callRemote("slot_readv", storage_index, + [], [(0, readsize)])) d.addCallback(self._got_results, peerid, readsize) d.addErrback(self._query_failed, peerid, (conn, storage_index, peer_storage_servers)) @@ -676,7 +677,8 @@ class Publish: peer_storage_servers = {} dl = [] for (permutedid, peerid, conn) in partial_peerlist: - d = self._do_query(conn, peerid, peer_storage_servers) + d = self._do_query(conn, peerid, peer_storage_servers, + storage_index) d.addCallback(self._got_query_results, peerid, permutedid, reachable_peers, current_share_peers) @@ -688,11 +690,11 @@ class Publish: # TODO: add an errback to, probably to ignore that peer return d - def _do_query(self, conn, peerid, peer_storage_servers): + def _do_query(self, conn, peerid, peer_storage_servers, storage_index): d = conn.callRemote("get_service", "storageserver") def _got_storageserver(ss): peer_storage_servers[peerid] = ss - return ss.callRemote("readv_slots", [(0, 2000)]) + return ss.callRemote("slot_readv", storage_index, [], [(0, 2000)]) d.addCallback(_got_storageserver) return d @@ -770,7 +772,7 @@ class Publish: for shnum, peers in target_map.items(): for (peerid, old_seqnum, old_root_hash) in peers: - testv = [(0, len(my_checkstring), "ge", my_checkstring)] + testv = [(0, len(my_checkstring), "le", my_checkstring)] new_share = self._new_shares[shnum] writev = [(0, new_share)] if peerid not in peer_messages: diff --git a/src/allmydata/test/test_mutable.py b/src/allmydata/test/test_mutable.py index d488448d..8665be8d 100644 --- a/src/allmydata/test/test_mutable.py +++ b/src/allmydata/test/test_mutable.py @@ -64,7 +64,7 @@ class FakeFilenode(mutable.MutableFileNode): return "fake readonly" class FakePublish(mutable.Publish): - def _do_query(self, conn, peerid, peer_storage_servers): + def _do_query(self, conn, peerid, peer_storage_servers, storage_index): assert conn[0] == peerid shares = self._peers[peerid] return defer.succeed(shares)