]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
mutable slots: add some test coverage for lease-addition
authorBrian Warner <warner@lothar.com>
Wed, 31 Oct 2007 07:38:30 +0000 (00:38 -0700)
committerBrian Warner <warner@lothar.com>
Wed, 31 Oct 2007 07:38:30 +0000 (00:38 -0700)
src/allmydata/storage.py
src/allmydata/test/test_storage.py

index dcd1155485b046ee3bb9a5f44dea332302beabae..8c83079b0e9370302bb8a0cef535db62f6a54fe3 100644 (file)
@@ -397,13 +397,13 @@ class MutableShareFile(Referenceable):
         elif (lease_number-4) < num_extra_leases:
             offset = (extra_lease_offset
                       + 4
-                      + (lease_number-4)*self.LEASE_NUMBER)
+                      + (lease_number-4)*self.LEASE_SIZE)
         else:
             # must add an extra lease record
             self._write_num_extra_leases(f, num_extra_leases+1)
             offset = (extra_lease_offset
                       + 4
-                      + (lease_number-4)*self.LEASE_NUMBER)
+                      + (lease_number-4)*self.LEASE_SIZE)
         f.seek(offset)
         assert f.tell() == offset
         f.write(struct.pack(">LL32s32s32s",
@@ -419,7 +419,7 @@ class MutableShareFile(Referenceable):
         elif (lease_number-4) < num_extra_leases:
             offset = (extra_lease_offset
                       + 4
-                      + (lease_number-4)*self.LEASE_NUMBER)
+                      + (lease_number-4)*self.LEASE_SIZE)
         else:
             raise IndexError("No such lease number %d" % lease_number)
         f.seek(offset)
index 1bb7ae7b89a7135257a37e7cfbba722e661ed14a..b81ab11e49c45eb9487c096fc8d1d4c0dc576782 100644 (file)
@@ -466,10 +466,10 @@ class MutableServer(unittest.TestCase):
     def write_enabler(self, we_tag):
         return hashutil.tagged_hash("we_blah", we_tag)
 
-    def allocate(self, ss, storage_index, we_tag, sharenums, size):
+    def allocate(self, ss, storage_index, we_tag, lease_tag, sharenums, size):
         write_enabler = self.write_enabler(we_tag)
-        renew_secret = hashutil.tagged_hash("blah", "%d" % self._secret.next())
-        cancel_secret = hashutil.tagged_hash("blah", "%d" % self._secret.next())
+        renew_secret = hashutil.tagged_hash("blah", str(lease_tag))
+        cancel_secret = hashutil.tagged_hash("blah", str(lease_tag))
         return ss.remote_allocate_mutable_slot(storage_index,
                                                write_enabler,
                                                renew_secret, cancel_secret,
@@ -477,7 +477,8 @@ class MutableServer(unittest.TestCase):
 
     def test_allocate(self):
         ss = self.create("test_allocate")
-        shares = self.allocate(ss, "si1", "we1", set([0,1,2]), 100)
+        shares = self.allocate(ss, "si1", "we1", self._secret.next(),
+                               set([0,1,2]), 100)
         self.failUnlessEqual(len(shares), 3)
         self.failUnlessEqual(set(shares.keys()), set([0,1,2]))
         shares2 = ss.remote_get_mutable_slot("si1")
@@ -527,7 +528,8 @@ class MutableServer(unittest.TestCase):
         # test operators, the data we're comparing is '11111' in all cases.
         # test both fail+pass, reset data after each one.
         ss = self.create("test_operators")
-        shares = self.allocate(ss, "si1", "we1", set([0,1,2]), 100)
+        shares = self.allocate(ss, "si1", "we1", self._secret.next(),
+                               set([0,1,2]), 100)
         s0 = shares[0]
         WE = self.write_enabler("we1")
         data = "".join([ ("%d" % i) * 10 for i in range(10) ])
@@ -678,3 +680,37 @@ class MutableServer(unittest.TestCase):
         self.failUnlessEqual(answer, (False, ["11111"]))
         self.failUnlessEqual(s0.remote_read(0, 100), data)
         s0.remote_testv_and_writev(WE, [], [(0,data)], None)
+
+    def test_leases(self):
+        ss = self.create("test_leases")
+        secret = 14
+        shares = self.allocate(ss, "si1", "we1", secret, set([0,1,2]), 100)
+        s0 = shares[0]
+        WE = self.write_enabler("we1")
+        data = "".join([ ("%d" % i) * 10 for i in range(10) ])
+        answer = s0.remote_testv_and_writev(WE,
+                                            [],
+                                            [(0, data),],
+                                            new_length=None)
+
+        # re-allocate the slots and use the same secrets, that should update
+        # the lease
+        shares2 = self.allocate(ss, "si1", "we1", secret, set([0,1,2]), 100)
+
+        # now allocate them with a bunch of different secrets, to trigger the
+        # extended lease code
+        shares2 = self.allocate(ss, "si1", "we1", secret+1, set([0,1,2]), 100)
+        shares2 = self.allocate(ss, "si1", "we1", secret+2, set([0,1,2]), 100)
+        shares2 = self.allocate(ss, "si1", "we1", secret+3, set([0,1,2]), 100)
+        shares2 = self.allocate(ss, "si1", "we1", secret+4, set([0,1,2]), 100)
+        shares2 = self.allocate(ss, "si1", "we1", secret+5, set([0,1,2]), 100)
+
+        # and write enough data to expand the container, forcing the server
+        # to move the leases
+        answer = s0.remote_testv_and_writev(WE,
+                                            [],
+                                            [(0, data),],
+                                            new_length=200)
+
+        # TODO: read back the leases, make sure they're still intact. We need
+        # a renew_lease() call for this.