[Checkins] SVN: relstorage/branches/postgres_blob_oid/relstorage/ Truncate the temporary blob chunk table on commit.

Martijn Pieters mj at zopatista.com
Wed Jun 15 05:21:54 EDT 2011


Log message for revision 121943:
  Truncate the temporary blob chunk table on commit.
  
  We drop it when opening the store again. This way we get to reap any orphaned oids still listed in that table through the BEFORE DELETE trigger.

Changed:
  U   relstorage/branches/postgres_blob_oid/relstorage/adapters/mover.py
  U   relstorage/branches/postgres_blob_oid/relstorage/tests/blob/testblob.py

-=-
Modified: relstorage/branches/postgres_blob_oid/relstorage/adapters/mover.py
===================================================================
--- relstorage/branches/postgres_blob_oid/relstorage/adapters/mover.py	2011-06-15 08:01:28 UTC (rev 121942)
+++ relstorage/branches/postgres_blob_oid/relstorage/adapters/mover.py	2011-06-15 09:21:54 UTC (rev 121943)
@@ -389,11 +389,12 @@
         ) ON COMMIT DROP;
         CREATE UNIQUE INDEX temp_store_zoid ON temp_store (zoid);
 
+        DROP TABLE IF EXISTS temp_blob_chunk;
         CREATE TEMPORARY TABLE temp_blob_chunk (
             zoid        BIGINT NOT NULL,
             chunk_num   BIGINT NOT NULL,
             chunk       OID
-        ) ON COMMIT DROP;
+        ) ON COMMIT DELETE ROWS;
         CREATE UNIQUE INDEX temp_blob_chunk_key
             ON temp_blob_chunk (zoid, chunk_num);
         -- Trigger to clean out oids that did not get copied to blob_chunk

Modified: relstorage/branches/postgres_blob_oid/relstorage/tests/blob/testblob.py
===================================================================
--- relstorage/branches/postgres_blob_oid/relstorage/tests/blob/testblob.py	2011-06-15 08:01:28 UTC (rev 121942)
+++ relstorage/branches/postgres_blob_oid/relstorage/tests/blob/testblob.py	2011-06-15 09:21:54 UTC (rev 121943)
@@ -17,6 +17,7 @@
 from zope.testing import doctest
 
 import atexit
+import collections
 import os
 import random
 import re
@@ -34,6 +35,12 @@
 import ZODB.tests.util
 import zope.testing.renormalizing
 
+try:
+    from hashlib import md5
+except ImportError:
+    from md5 import new as md5
+
+
 def new_time():
     """Create a _new_ time stamp.
 
@@ -49,6 +56,38 @@
     return new_time
 
 
+def random_file(size, filename):
+    """Create a random data file of at least the given size.
+
+    See http://jessenoller.com/2008/05/30/making-re-creatable-random-data-files-really-fast-in-python/
+    for the technique used.
+
+    Returns the md5 sum of the file contents for easy comparison.
+
+    """
+    def fdata():
+        seed = "1092384956781341341234656953214543219"
+        # Just use the this module as the source of our data
+        words = open(__file__, "r").read().replace("\n", '').split()
+        a = collections.deque(words)
+        b = collections.deque(seed)
+        while True:
+            yield ' '.join(list(a)[0:1024])
+            a.rotate(int(b[0]))
+            b.rotate(1)
+    datagen = fdata()
+    output = open(filename, 'wb')
+    bytes = 0
+    md5sum = md5()
+    while bytes < size:
+        data = datagen.next()
+        md5sum.update(data)
+        output.write(data)
+        bytes += len(data)
+    output.close()
+    return md5sum.hexdigest()
+
+
 class BlobTestBase(ZODB.tests.StorageTestBase.StorageTestBase):
 
     def setUp(self):



More information about the checkins mailing list