mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-06-22 08:50:07 +00:00
storage: handle simultanous uploads: add a lease for the pre-empted client
This commit is contained in:
@ -157,7 +157,6 @@ class BucketWriter(Referenceable):
|
|||||||
self.incominghome = incominghome
|
self.incominghome = incominghome
|
||||||
self.finalhome = finalhome
|
self.finalhome = finalhome
|
||||||
self._size = size
|
self._size = size
|
||||||
self._lease_info = lease_info
|
|
||||||
self.closed = False
|
self.closed = False
|
||||||
self.throw_out_all_data = False
|
self.throw_out_all_data = False
|
||||||
# touch the file, so later callers will see that we're working on it.
|
# touch the file, so later callers will see that we're working on it.
|
||||||
@ -167,6 +166,9 @@ class BucketWriter(Referenceable):
|
|||||||
f.write(struct.pack(">LLL", 1, size, 0))
|
f.write(struct.pack(">LLL", 1, size, 0))
|
||||||
f.close()
|
f.close()
|
||||||
self._sharefile = ShareFile(self.incominghome)
|
self._sharefile = ShareFile(self.incominghome)
|
||||||
|
# also, add our lease to the file now, so that other ones can be
|
||||||
|
# added by simultaneous uploaders
|
||||||
|
self._sharefile.add_lease(lease_info)
|
||||||
|
|
||||||
def allocated_size(self):
|
def allocated_size(self):
|
||||||
return self._size
|
return self._size
|
||||||
@ -179,7 +181,6 @@ class BucketWriter(Referenceable):
|
|||||||
|
|
||||||
def remote_close(self):
|
def remote_close(self):
|
||||||
precondition(not self.closed)
|
precondition(not self.closed)
|
||||||
self._sharefile.add_lease(self._lease_info)
|
|
||||||
fileutil.rename(self.incominghome, self.finalhome)
|
fileutil.rename(self.incominghome, self.finalhome)
|
||||||
self._sharefile = None
|
self._sharefile = None
|
||||||
self.closed = True
|
self.closed = True
|
||||||
@ -256,10 +257,10 @@ class StorageServer(service.MultiService, Referenceable):
|
|||||||
finalhome = os.path.join(self.sharedir, si_s, "%d" % shnum)
|
finalhome = os.path.join(self.sharedir, si_s, "%d" % shnum)
|
||||||
if os.path.exists(incominghome) or os.path.exists(finalhome):
|
if os.path.exists(incominghome) or os.path.exists(finalhome):
|
||||||
alreadygot.add(shnum)
|
alreadygot.add(shnum)
|
||||||
# add a lease
|
# add a lease for the client whose upload was pre-empted
|
||||||
if os.path.exists(incominghome):
|
if os.path.exists(incominghome):
|
||||||
# TODO: add a lease to the still-in-construction share
|
# the lease gets added to the still-in-construction share
|
||||||
pass
|
sf = ShareFile(incominghome)
|
||||||
else:
|
else:
|
||||||
sf = ShareFile(finalhome)
|
sf = ShareFile(finalhome)
|
||||||
sf.add_lease(lease_info)
|
sf.add_lease(lease_info)
|
||||||
|
@ -406,3 +406,23 @@ class Server(unittest.TestCase):
|
|||||||
leases = list(ss.get_leases("si1"))
|
leases = list(ss.get_leases("si1"))
|
||||||
self.failUnlessEqual(len(leases), 0)
|
self.failUnlessEqual(len(leases), 0)
|
||||||
|
|
||||||
|
|
||||||
|
# test overlapping uploads
|
||||||
|
rs3,cs3 = (hashutil.tagged_hash("blah", "%d" % self._secret.next()),
|
||||||
|
hashutil.tagged_hash("blah", "%d" % self._secret.next()))
|
||||||
|
rs4,cs4 = (hashutil.tagged_hash("blah", "%d" % self._secret.next()),
|
||||||
|
hashutil.tagged_hash("blah", "%d" % self._secret.next()))
|
||||||
|
already,writers = ss.remote_allocate_buckets("si3", rs3, cs3,
|
||||||
|
sharenums, size, canary)
|
||||||
|
self.failUnlessEqual(len(already), 0)
|
||||||
|
self.failUnlessEqual(len(writers), 5)
|
||||||
|
already2,writers2 = ss.remote_allocate_buckets("si3", rs4, cs4,
|
||||||
|
sharenums, size, canary)
|
||||||
|
self.failUnlessEqual(len(already2), 5)
|
||||||
|
self.failUnlessEqual(len(writers2), 0)
|
||||||
|
for wb in writers.values():
|
||||||
|
wb.remote_close()
|
||||||
|
|
||||||
|
leases = list(ss.get_leases("si3"))
|
||||||
|
self.failUnlessEqual(len(leases), 2)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user