From: Brian Warner Date: Mon, 15 Jan 2007 21:01:22 +0000 (-0700) Subject: add simple metadata (a single string) to the storage protocol X-Git-Tag: tahoe_v0.1.0-0-UNSTABLE~375 X-Git-Url: https://git.rkrishnan.org/(%5B%5E?a=commitdiff_plain;h=78a9e815c5ae425fd071d42296c0adf11ff3a741;p=tahoe-lafs%2Ftahoe-lafs.git add simple metadata (a single string) to the storage protocol --- diff --git a/src/allmydata/bucketstore.py b/src/allmydata/bucketstore.py index e3e1b675..08ea9dc9 100644 --- a/src/allmydata/bucketstore.py +++ b/src/allmydata/bucketstore.py @@ -62,6 +62,9 @@ class Lease(Referenceable): def remote_write(self, data): self._bucket.write(data) + def remote_set_metadata(self, metadata): + self._bucket.set_metadata(metadata) + def remote_close(self): self._bucket.close() @@ -93,6 +96,7 @@ class WriteBucket(Bucket): precondition(not os.path.exists(bucket_dir)) os.mkdir(bucket_dir) + self._open = True self._size = size self._data = file(os.path.join(self._bucket_dir, 'data'), 'wb') self._bytes_written = 0 @@ -103,15 +107,21 @@ class WriteBucket(Bucket): self._write_attr('leases', leaser) def write(self, data): + precondition(self._open) precondition(len(data) + self._bytes_written <= self._size) self._data.write(data) self._data.flush() self._bytes_written += len(data) + def set_metadata(self, metadata): + precondition(self._open) + self._write_attr('metadata', metadata) + def close(self): precondition(self._bytes_written == self._size) self._data.close() self._write_attr('closed', '') + self._open = False def is_complete(self): complete = Bucket.is_complete(self) @@ -132,3 +142,7 @@ class ReadBucket(Bucket, Referenceable): def read(self): return self._read_attr('data') remote_read = read + + def get_metadata(self): + return self._read_attr('metadata') + remote_get_metadata = get_metadata diff --git a/src/allmydata/interfaces.py b/src/allmydata/interfaces.py index b9d35ed3..396a75d2 100644 --- a/src/allmydata/interfaces.py +++ b/src/allmydata/interfaces.py @@ -1,6 +1,6 @@ from zope.interface import Interface -from foolscap.schema import StringConstraint, ListOf, TupleOf, Any, Nothing +from foolscap.schema import StringConstraint, ListOf, TupleOf, Any from foolscap import RemoteInterface Nodeid = StringConstraint(20) # binary format 20-byte SHA1 hash @@ -24,9 +24,9 @@ class RIClient(RemoteInterface): def get_service(name=str): return Referenceable_ def add_peers(new_peers=ListOf(TupleOf(Nodeid, PBURL), maxLength=100)): - return Nothing() + return None def lost_peers(lost_peers=ListOf(Nodeid)): - return Nothing() + return None class RIStorageServer(RemoteInterface): def allocate_bucket(verifierid=Verifierid, bucket_num=int, size=int, @@ -38,15 +38,18 @@ class RIStorageServer(RemoteInterface): class RIBucketWriter(RemoteInterface): def write(data=ShareData): - return Nothing() - + return None + def set_metadata(metadata=str): + return None def close(): - return Nothing() + return None class RIBucketReader(RemoteInterface): def read(): return ShareData + def get_metadata(): + return str class RIMutableDirectoryNode(RemoteInterface): @@ -63,10 +66,10 @@ class RIMutableDirectoryNode(RemoteInterface): return RIMutableDirectoryNode_ def add_file(name=str, data=Verifierid): - return Nothing() + return None def remove(name=str): - return Nothing() + return None # need more to move directories diff --git a/src/allmydata/test/test_storage.py b/src/allmydata/test/test_storage.py index 6e7b57d1..dcc4035e 100644 --- a/src/allmydata/test/test_storage.py +++ b/src/allmydata/test/test_storage.py @@ -49,6 +49,8 @@ class StorageTest(unittest.TestCase): def write_to_bucket(bucket): def write_some(junk, bytes): return bucket.callRemote('write', data=bytes) + def set_metadata(junk, metadata): + return bucket.callRemote('set_metadata', metadata) def finalise(junk): return bucket.callRemote('close') off1 = len(data) / 2 @@ -56,6 +58,7 @@ class StorageTest(unittest.TestCase): d = defer.succeed(None) d.addCallback(write_some, data[:off1]) d.addCallback(write_some, data[off1:off2]) + d.addCallback(set_metadata, "metadata") d.addCallback(write_some, data[off2:]) d.addCallback(finalise) return d @@ -79,6 +82,11 @@ class StorageTest(unittest.TestCase): self.failUnlessEqual(bytes_read, data) d = bucket.callRemote('read') d.addCallback(check_data) + + def check_metadata(metadata): + self.failUnlessEqual(metadata, 'metadata') + d.addCallback(lambda res: bucket.callRemote('get_metadata')) + d.addCallback(check_metadata) return d rssd.addCallback(read_buckets)