]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
add simple metadata (a single string) to the storage protocol
authorBrian Warner <warner@allmydata.com>
Mon, 15 Jan 2007 21:01:22 +0000 (14:01 -0700)
committerBrian Warner <warner@allmydata.com>
Mon, 15 Jan 2007 21:01:22 +0000 (14:01 -0700)
src/allmydata/bucketstore.py
src/allmydata/interfaces.py
src/allmydata/test/test_storage.py

index e3e1b6752907484d47b69de7747b137913358d74..08ea9dc96661d72afc796249e6daeb0c02fa2e9c 100644 (file)
@@ -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
index b9d35ed3b1063bf595d758ea47a932f28e12feba..396a75d24bec7b0474b7cff469a52f7f883039bf 100644 (file)
@@ -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
 
index 6e7b57d1a2231397c861e0890c3e15663fe01329..dcc4035e3fb87ac21582098918d488823164972d 100644 (file)
@@ -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)