[Zodb-checkins] SVN: ZODB/trunk/src/ZODB/ Added support for copying to blob cache when renaming fails to the

Jim Fulton jim at zope.com
Sun Jun 10 14:25:10 EDT 2007


Log message for revision 76585:
  Added support for copying to blob cache when renaming fails to the
  savepoint storage.
  
  Also added a test for the normal blob case.
  

Changed:
  U   ZODB/trunk/src/ZODB/Connection.py
  U   ZODB/trunk/src/ZODB/tests/testblob.py

-=-
Modified: ZODB/trunk/src/ZODB/Connection.py
===================================================================
--- ZODB/trunk/src/ZODB/Connection.py	2007-06-10 18:25:06 UTC (rev 76584)
+++ ZODB/trunk/src/ZODB/Connection.py	2007-06-10 18:25:09 UTC (rev 76585)
@@ -30,7 +30,7 @@
 from persistent.interfaces import IPersistentDataManager
 from ZODB.interfaces import IConnection
 from ZODB.interfaces import IBlobStorage
-from ZODB.blob import Blob
+from ZODB.blob import Blob, rename_or_copy_blob
 from transaction.interfaces import ISavepointDataManager
 from transaction.interfaces import IDataManagerSavepoint
 from transaction.interfaces import ISynchronizer
@@ -1245,7 +1245,7 @@
             os.makedirs(targetpath, 0700)
 
         targetname = self._getCleanFilename(oid, serial)
-        utils.rename_or_copy(blobfilename, targetname)
+        rename_or_copy_blob(blobfilename, targetname)
 
     def loadBlob(self, oid, serial):
         """Return the filename where the blob file can be found.

Modified: ZODB/trunk/src/ZODB/tests/testblob.py
===================================================================
--- ZODB/trunk/src/ZODB/tests/testblob.py	2007-06-10 18:25:06 UTC (rev 76584)
+++ ZODB/trunk/src/ZODB/tests/testblob.py	2007-06-10 18:25:09 UTC (rev 76585)
@@ -278,6 +278,66 @@
     False
     """
 
+def commit_from_wrong_partition():
+    """
+    It should be possible to commit changes even when a blob is on a
+    different partition.
+
+    We can simulare this by temporarily breaking os.rename. :)
+
+    >>> def fail(*args):
+    ...     raise OSError
+
+    >>> os_rename = os.rename
+    >>> os.rename = fail
+
+    >>> import logging, sys
+    >>> logger = logging.getLogger('ZODB.blob.copied')
+    >>> handler = logging.StreamHandler(sys.stdout)
+    >>> logger.propagate = False
+    >>> logger.setLevel(logging.DEBUG)
+    >>> logger.addHandler(handler)
+
+    >>> import transaction
+    >>> from ZODB.MappingStorage import MappingStorage
+    >>> from ZODB.blob import BlobStorage
+    >>> from ZODB.DB import DB
+    >>> from tempfile import mkdtemp
+    >>> base_storage = MappingStorage("test")
+    >>> blob_dir = mkdtemp()
+    >>> blob_storage = BlobStorage(blob_dir, base_storage)
+    >>> database = DB(blob_storage)
+    >>> connection = database.open()
+    >>> root = connection.root()
+    >>> from ZODB.blob import Blob
+    >>> root['blob'] = Blob()
+    >>> root['blob'].open('w').write('test')
+    >>> transaction.commit() # doctest: +ELLIPSIS
+    Copied blob file ...
+
+    >>> root['blob'].open().read()
+    'test'
+
+Works with savepoints too:
+
+    >>> root['blob2'] = Blob()
+    >>> root['blob2'].open('w').write('test2')
+    >>> _ = transaction.savepoint() # doctest: +ELLIPSIS
+    Copied blob file ...
+
+    >>> transaction.commit() # doctest: +ELLIPSIS
+    Copied blob file ...
+    
+    >>> root['blob2'].open().read()
+    'test2'
+    
+    >>> os.rename = os_rename
+    >>> logger.propagate = True
+    >>> logger.setLevel(0)
+    >>> logger.removeHandler(handler)
+
+    """
+
 def test_suite():
     suite = unittest.TestSuite()
     suite.addTest(unittest.makeSuite(ZODBBlobConfigTest))



More information about the Zodb-checkins mailing list