[Checkins] SVN: gocept.zeoraid/trunk/src/gocept/zeoraid/ made
loadBlob use ZEORaid's blob cache
Thomas Lotze
tl at gocept.com
Mon Apr 28 09:53:35 EDT 2008
Log message for revision 85801:
made loadBlob use ZEORaid's blob cache
Changed:
U gocept.zeoraid/trunk/src/gocept/zeoraid/storage.py
U gocept.zeoraid/trunk/src/gocept/zeoraid/tests/test_basics.py
-=-
Modified: gocept.zeoraid/trunk/src/gocept/zeoraid/storage.py
===================================================================
--- gocept.zeoraid/trunk/src/gocept/zeoraid/storage.py 2008-04-28 13:51:16 UTC (rev 85800)
+++ gocept.zeoraid/trunk/src/gocept/zeoraid/storage.py 2008-04-28 13:53:33 UTC (rev 85801)
@@ -72,6 +72,8 @@
ZEO.interfaces.IServeable,
)
+ blob_fshelper = None
+
closed = False
_transaction = None
@@ -390,8 +392,60 @@
def loadBlob(self, oid, serial):
"""Return the filename of the Blob data for this OID and serial."""
- return self._apply_single_storage('loadBlob', (oid, serial))
+ # XXX needs some refactoring
+ blob_filename = self.blob_fshelper.getBlobFilename(oid, serial)
+ if os.path.exists(blob_filename):
+ return blob_filename
+ backend_filename = self._apply_single_storage('loadBlob',
+ (oid, serial))
+ lock_filename = blob_filename + '.lock'
+ self.blob_fshelper.createPathForOID(oid)
+ try:
+ lock = ZODB.lock_file.LockFile(lock_filename)
+ except ZODB.lock_file.LockError:
+ while True:
+ time.sleep(0.1)
+ try:
+ lock = ZODB.lock_file.LockFile(lock_filename)
+ except ZODB.lock_file.LockError:
+ pass
+ else:
+ # We have the lock. We should be able to get the file now.
+ lock.close()
+ try:
+ os.remove(lock_filename)
+ except OSError:
+ pass
+ break
+
+ if os.path.exists(blob_filename):
+ return blob_filename
+
+ return None # XXX see ClientStorage
+
+ try:
+ try:
+ os.link(backend_filename, blob_filename)
+ except OSError:
+ ZODB.blob.copied("Copied blob file %r to %r.",
+ backend_filename, blob_filename)
+ file1 = open(backend_filename, 'rb')
+ file2 = open(blob_filename, 'wb')
+ try:
+ ZODB.utils.cp(file1, file2)
+ finally:
+ file1.close()
+ file2.close()
+ finally:
+ lock.close()
+ try:
+ os.remove(lock_filename)
+ except OSError:
+ pass
+
+ return blob_filename
+
def temporaryDirectory(self):
"""Return a directory that should be used for uncommitted blob data.
"""
Modified: gocept.zeoraid/trunk/src/gocept/zeoraid/tests/test_basics.py
===================================================================
--- gocept.zeoraid/trunk/src/gocept/zeoraid/tests/test_basics.py 2008-04-28 13:51:16 UTC (rev 85800)
+++ gocept.zeoraid/trunk/src/gocept/zeoraid/tests/test_basics.py 2008-04-28 13:53:33 UTC (rev 85801)
@@ -160,8 +160,10 @@
blob_dir=blob_dir,
min_disconnect_poll=0.5, wait=1,
wait_timeout=60))
- self._storage = gocept.zeoraid.storage.RAIDStorage('teststorage',
- self._storages)
+ blob_dir = tempfile.mkdtemp()
+ self._blob_dirs.append(blob_dir)
+ self._storage = gocept.zeoraid.storage.RAIDStorage(
+ 'teststorage', self._storages, blob_dir=blob_dir)
def tearDown(self):
self._storage.close()
@@ -672,6 +674,9 @@
oid, self._storage.lastTransaction())
self.assertEquals('I am a happy blob.',
open(stored_file_name, 'r').read())
+ expected = self._storage.blob_fshelper.getBlobFilename(
+ oid, self._storage.lastTransaction())
+ self.assertEquals(expected, stored_file_name)
def test_storeBlob_degrading1(self):
oid = self._storage.new_oid()
More information about the Checkins
mailing list