mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-06-22 08:50:07 +00:00
storage.py: more test coverage, make sure leases survive resizing
This commit is contained in:
@ -447,7 +447,7 @@ class MutableShareFile(Referenceable):
|
|||||||
return i
|
return i
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def enumerate_leases(self, f):
|
def _enumerate_leases(self, f):
|
||||||
"""Yields (leasenum, (ownerid, expiration_time, renew_secret,
|
"""Yields (leasenum, (ownerid, expiration_time, renew_secret,
|
||||||
cancel_secret, accepting_nodeid)) for all leases."""
|
cancel_secret, accepting_nodeid)) for all leases."""
|
||||||
for i in range(self._get_num_lease_slots(f)):
|
for i in range(self._get_num_lease_slots(f)):
|
||||||
@ -458,6 +458,12 @@ class MutableShareFile(Referenceable):
|
|||||||
except IndexError:
|
except IndexError:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def debug_enumerate_leases(self):
|
||||||
|
f = open(self.home, 'rb')
|
||||||
|
leases = list(self._enumerate_leases(f))
|
||||||
|
f.close()
|
||||||
|
return leases
|
||||||
|
|
||||||
def add_lease(self, lease_info):
|
def add_lease(self, lease_info):
|
||||||
f = open(self.home, 'rb+')
|
f = open(self.home, 'rb+')
|
||||||
num_lease_slots = self._get_num_lease_slots(f)
|
num_lease_slots = self._get_num_lease_slots(f)
|
||||||
@ -471,7 +477,7 @@ class MutableShareFile(Referenceable):
|
|||||||
def renew_lease(self, renew_secret, new_expire_time):
|
def renew_lease(self, renew_secret, new_expire_time):
|
||||||
accepting_nodeids = set()
|
accepting_nodeids = set()
|
||||||
f = open(self.home, 'rb+')
|
f = open(self.home, 'rb+')
|
||||||
for (leasenum,(oid,et,rs,cs,anid)) in self.enumerate_leases(f):
|
for (leasenum,(oid,et,rs,cs,anid)) in self._enumerate_leases(f):
|
||||||
if rs == renew_secret:
|
if rs == renew_secret:
|
||||||
# yup. See if we need to update the owner time.
|
# yup. See if we need to update the owner time.
|
||||||
if new_expire_time > et:
|
if new_expire_time > et:
|
||||||
@ -510,7 +516,7 @@ class MutableShareFile(Referenceable):
|
|||||||
blank = "\x00"*32
|
blank = "\x00"*32
|
||||||
blank_lease = (0, 0, blank, blank, blank)
|
blank_lease = (0, 0, blank, blank, blank)
|
||||||
f = open(self.home, 'rb+')
|
f = open(self.home, 'rb+')
|
||||||
for (leasenum,(oid,et,rs,cs,anid)) in self.enumerate_leases(f):
|
for (leasenum,(oid,et,rs,cs,anid)) in self._enumerate_leases(f):
|
||||||
accepting_nodeids.add(anid)
|
accepting_nodeids.add(anid)
|
||||||
if cs == cancel_secret:
|
if cs == cancel_secret:
|
||||||
self._write_lease_record(f, leasenum, blank_lease)
|
self._write_lease_record(f, leasenum, blank_lease)
|
||||||
|
@ -724,6 +724,9 @@ class MutableServer(unittest.TestCase):
|
|||||||
# cancel one of them
|
# cancel one of them
|
||||||
ss.remote_cancel_lease("si1", self.cancel_secret(secret+5))
|
ss.remote_cancel_lease("si1", self.cancel_secret(secret+5))
|
||||||
|
|
||||||
|
all_leases = s0.debug_enumerate_leases()
|
||||||
|
self.failUnlessEqual(len(all_leases), 5)
|
||||||
|
|
||||||
# and write enough data to expand the container, forcing the server
|
# and write enough data to expand the container, forcing the server
|
||||||
# to move the leases
|
# to move the leases
|
||||||
answer = s0.remote_testv_and_writev(WE,
|
answer = s0.remote_testv_and_writev(WE,
|
||||||
@ -731,8 +734,9 @@ class MutableServer(unittest.TestCase):
|
|||||||
[(0, data),],
|
[(0, data),],
|
||||||
new_length=200)
|
new_length=200)
|
||||||
|
|
||||||
# TODO: read back the leases, make sure they're still intact. We need
|
# read back the leases, make sure they're still intact.
|
||||||
# a renew_lease() call for this.
|
self.failUnlessEqual(all_leases, s0.debug_enumerate_leases())
|
||||||
|
|
||||||
ss.remote_renew_lease("si1", self.renew_secret(secret))
|
ss.remote_renew_lease("si1", self.renew_secret(secret))
|
||||||
ss.remote_renew_lease("si1", self.renew_secret(secret+1))
|
ss.remote_renew_lease("si1", self.renew_secret(secret+1))
|
||||||
ss.remote_renew_lease("si1", self.renew_secret(secret+2))
|
ss.remote_renew_lease("si1", self.renew_secret(secret+2))
|
||||||
@ -751,14 +755,29 @@ class MutableServer(unittest.TestCase):
|
|||||||
ss.remote_cancel_lease, "si1",
|
ss.remote_cancel_lease, "si1",
|
||||||
self.cancel_secret(secret+20))
|
self.cancel_secret(secret+20))
|
||||||
|
|
||||||
|
self.failUnlessEqual(all_leases, s0.debug_enumerate_leases())
|
||||||
|
answer = s0.remote_testv_and_writev(WE,
|
||||||
|
[],
|
||||||
|
[(200, "make me bigger"),],
|
||||||
|
new_length=None)
|
||||||
|
self.failUnlessEqual(all_leases, s0.debug_enumerate_leases())
|
||||||
|
|
||||||
|
answer = s0.remote_testv_and_writev(WE,
|
||||||
|
[],
|
||||||
|
[(500, "make me really bigger"),],
|
||||||
|
new_length=None)
|
||||||
|
self.failUnlessEqual(all_leases, s0.debug_enumerate_leases())
|
||||||
|
|
||||||
# now cancel them all
|
# now cancel them all
|
||||||
ss.remote_cancel_lease("si1", self.cancel_secret(secret))
|
ss.remote_cancel_lease("si1", self.cancel_secret(secret))
|
||||||
ss.remote_cancel_lease("si1", self.cancel_secret(secret+1))
|
ss.remote_cancel_lease("si1", self.cancel_secret(secret+1))
|
||||||
ss.remote_cancel_lease("si1", self.cancel_secret(secret+2))
|
ss.remote_cancel_lease("si1", self.cancel_secret(secret+2))
|
||||||
ss.remote_cancel_lease("si1", self.cancel_secret(secret+3))
|
ss.remote_cancel_lease("si1", self.cancel_secret(secret+3))
|
||||||
# slot should still be there
|
# the slot should still be there
|
||||||
shares3 = ss.remote_get_mutable_slot("si1")
|
shares3 = ss.remote_get_mutable_slot("si1")
|
||||||
self.failUnlessEqual(len(shares3), 3)
|
self.failUnlessEqual(len(shares3), 3)
|
||||||
|
self.failUnlessEqual(len(s0.debug_enumerate_leases()), 1)
|
||||||
|
|
||||||
ss.remote_cancel_lease("si1", self.cancel_secret(secret+4))
|
ss.remote_cancel_lease("si1", self.cancel_secret(secret+4))
|
||||||
# now the slot should be gone
|
# now the slot should be gone
|
||||||
self.failUnlessEqual(ss.remote_get_mutable_slot("si1"), {})
|
self.failUnlessEqual(ss.remote_get_mutable_slot("si1"), {})
|
||||||
|
Reference in New Issue
Block a user