[Checkins] SVN: relstorage/trunk/ Merged pieces of the packless branch:
Shane Hathaway
shane at hathawaymix.org
Tue Sep 22 16:23:40 EDT 2009
Log message for revision 104438:
Merged pieces of the packless branch:
- PostgreSQL: use the documented ALTER SEQUENCE RESTART WITH
statement instead of ALTER SEQUENCE START WITH.
- Moved MD5 sum computation to the adapters so they can choose not
to use MD5.
- Changed loadSerial to load from the store connection only if the
load connection can not provide the object requested.
Changed:
U relstorage/trunk/CHANGES.txt
U relstorage/trunk/relstorage/adapters/common.py
U relstorage/trunk/relstorage/adapters/mysql.py
U relstorage/trunk/relstorage/adapters/oracle.py
U relstorage/trunk/relstorage/adapters/postgresql.py
U relstorage/trunk/relstorage/relstorage.py
-=-
Modified: relstorage/trunk/CHANGES.txt
===================================================================
--- relstorage/trunk/CHANGES.txt 2009-09-22 20:22:30 UTC (rev 104437)
+++ relstorage/trunk/CHANGES.txt 2009-09-22 20:23:39 UTC (rev 104438)
@@ -2,9 +2,15 @@
Unreleased
----------
-- ...
+- PostgreSQL: use the documented ALTER SEQUENCE RESTART WITH
+ statement instead of ALTER SEQUENCE START WITH.
+- Moved MD5 sum computation to the adapters so they can choose not
+ to use MD5.
+- Changed loadSerial to load from the store connection only if the
+ load connection can not provide the object requested.
+
1.3.0b1 (2009-09-04)
--------------------
Modified: relstorage/trunk/relstorage/adapters/common.py
===================================================================
--- relstorage/trunk/relstorage/adapters/common.py 2009-09-22 20:22:30 UTC (rev 104437)
+++ relstorage/trunk/relstorage/adapters/common.py 2009-09-22 20:23:39 UTC (rev 104438)
@@ -18,6 +18,12 @@
import logging
import time
+try:
+ from hashlib import md5
+except ImportError:
+ from md5 import new as md5
+
+
log = logging.getLogger("relstorage.adapters.common")
verify_sane_database = False
@@ -954,18 +960,30 @@
return None, new_polled_tid
# Get the list of changed OIDs and return it.
- stmt = """
- SELECT zoid
- FROM current_object
- WHERE tid > %(tid)s
- """
if ignore_tid is None:
+ stmt = """
+ SELECT zoid
+ FROM current_object
+ WHERE tid > %(tid)s
+ """
cursor.execute(intern(stmt % self._script_vars),
{'tid': prev_polled_tid})
else:
- stmt += " AND tid != %(self_tid)s"
+ stmt = """
+ SELECT zoid
+ FROM current_object
+ WHERE tid > %(tid)s
+ AND tid != %(self_tid)s
+ """
cursor.execute(intern(stmt % self._script_vars),
{'tid': prev_polled_tid, 'self_tid': ignore_tid})
oids = [oid for (oid,) in cursor]
return oids, new_polled_tid
+
+ def md5sum(self, data):
+ if data is not None:
+ return md5(data).hexdigest()
+ else:
+ # George Bailey object
+ return None
Modified: relstorage/trunk/relstorage/adapters/mysql.py
===================================================================
--- relstorage/trunk/relstorage/adapters/mysql.py 2009-09-22 20:22:30 UTC (rev 104437)
+++ relstorage/trunk/relstorage/adapters/mysql.py 2009-09-22 20:23:39 UTC (rev 104438)
@@ -467,16 +467,18 @@
except disconnected_exceptions, e:
raise StorageError(e)
- def store_temp(self, cursor, oid, prev_tid, md5sum, data):
+ def store_temp(self, cursor, oid, prev_tid, data):
"""Store an object in the temporary table."""
+ md5sum = self.md5sum(data)
stmt = """
REPLACE INTO temp_store (zoid, prev_tid, md5, state)
VALUES (%s, %s, %s, %s)
"""
cursor.execute(stmt, (oid, prev_tid, md5sum, MySQLdb.Binary(data)))
- def replace_temp(self, cursor, oid, prev_tid, md5sum, data):
+ def replace_temp(self, cursor, oid, prev_tid, data):
"""Replace an object in the temporary table."""
+ md5sum = self.md5sum(data)
stmt = """
UPDATE temp_store SET
prev_tid = %s,
@@ -486,11 +488,12 @@
"""
cursor.execute(stmt, (prev_tid, md5sum, MySQLdb.Binary(data), oid))
- def restore(self, cursor, oid, tid, md5sum, data):
+ def restore(self, cursor, oid, tid, data):
"""Store an object directly, without conflict detection.
Used for copying transactions into this database.
"""
+ md5sum = self.md5sum(data)
stmt = """
INSERT INTO object_state (zoid, tid, prev_tid, md5, state)
VALUES (%s, %s,
Modified: relstorage/trunk/relstorage/adapters/oracle.py
===================================================================
--- relstorage/trunk/relstorage/adapters/oracle.py 2009-09-22 20:22:30 UTC (rev 104437)
+++ relstorage/trunk/relstorage/adapters/oracle.py 2009-09-22 20:23:39 UTC (rev 104438)
@@ -538,8 +538,9 @@
except disconnected_exceptions, e:
raise StorageError(e)
- def store_temp(self, cursor, oid, prev_tid, md5sum, data):
+ def store_temp(self, cursor, oid, prev_tid, data):
"""Store an object in the temporary table."""
+ md5sum = self.md5sum(data)
cursor.execute("DELETE FROM temp_store WHERE zoid = :oid", oid=oid)
if len(data) <= 2000:
# Send data inline for speed. Oracle docs say maximum size
@@ -561,8 +562,9 @@
cursor.execute(stmt, oid=oid, prev_tid=prev_tid,
md5sum=md5sum, blobdata=data)
- def replace_temp(self, cursor, oid, prev_tid, md5sum, data):
+ def replace_temp(self, cursor, oid, prev_tid, data):
"""Replace an object in the temporary table."""
+ md5sum = self.md5sum(data)
cursor.setinputsizes(data=cx_Oracle.BLOB)
stmt = """
UPDATE temp_store SET
@@ -574,11 +576,12 @@
cursor.execute(stmt, oid=oid, prev_tid=prev_tid,
md5sum=md5sum, data=cx_Oracle.Binary(data))
- def restore(self, cursor, oid, tid, md5sum, data):
+ def restore(self, cursor, oid, tid, data):
"""Store an object directly, without conflict detection.
Used for copying transactions into this database.
"""
+ md5sum = self.md5sum(data)
cursor.setinputsizes(data=cx_Oracle.BLOB)
stmt = """
INSERT INTO object_state (zoid, tid, prev_tid, md5, state)
Modified: relstorage/trunk/relstorage/adapters/postgresql.py
===================================================================
--- relstorage/trunk/relstorage/adapters/postgresql.py 2009-09-22 20:22:30 UTC (rev 104437)
+++ relstorage/trunk/relstorage/adapters/postgresql.py 2009-09-22 20:23:39 UTC (rev 104438)
@@ -167,7 +167,7 @@
-- Create a special transaction to represent object creation.
INSERT INTO transaction (tid, username, description) VALUES
(0, 'system', 'special transaction for object creation');
- ALTER SEQUENCE zoid_seq START WITH 1;
+ ALTER SEQUENCE zoid_seq RESTART WITH 1;
""")
self._open_and_call(callback)
@@ -398,8 +398,9 @@
except disconnected_exceptions, e:
raise StorageError(e)
- def store_temp(self, cursor, oid, prev_tid, md5sum, data):
+ def store_temp(self, cursor, oid, prev_tid, data):
"""Store an object in the temporary table."""
+ md5sum = self.md5sum(data)
stmt = """
DELETE FROM temp_store WHERE zoid = %s;
INSERT INTO temp_store (zoid, prev_tid, md5, state)
@@ -407,8 +408,9 @@
"""
cursor.execute(stmt, (oid, oid, prev_tid, md5sum, encodestring(data)))
- def replace_temp(self, cursor, oid, prev_tid, md5sum, data):
+ def replace_temp(self, cursor, oid, prev_tid, data):
"""Replace an object in the temporary table."""
+ md5sum = self.md5sum(data)
stmt = """
UPDATE temp_store SET
prev_tid = %s,
@@ -418,11 +420,12 @@
"""
cursor.execute(stmt, (prev_tid, md5sum, encodestring(data), oid))
- def restore(self, cursor, oid, tid, md5sum, data):
+ def restore(self, cursor, oid, tid, data):
"""Store an object directly, without conflict detection.
Used for copying transactions into this database.
"""
+ md5sum = self.md5sum(data)
stmt = """
INSERT INTO object_state (zoid, tid, prev_tid, md5, state)
VALUES (%s, %s,
Modified: relstorage/trunk/relstorage/relstorage.py
===================================================================
--- relstorage/trunk/relstorage/relstorage.py 2009-09-22 20:22:30 UTC (rev 104437)
+++ relstorage/trunk/relstorage/relstorage.py 2009-09-22 20:23:39 UTC (rev 104438)
@@ -58,12 +58,6 @@
if hasattr(ZODB.interfaces, name):
_relstorage_interfaces.append(getattr(ZODB.interfaces, name))
-try:
- from hashlib import md5
-except ImportError:
- from md5 import new as md5
-
-
log = logging.getLogger("relstorage")
# Set the RELSTORAGE_ABORT_EARLY environment variable when debugging
@@ -412,15 +406,15 @@
self._lock_acquire()
try:
- if self._store_cursor is not None:
+ if not self._load_transaction_open:
+ self._restart_load()
+ state = self._adapter.load_revision(
+ self._load_cursor, oid_int, tid_int)
+ if state is None and self._store_cursor is not None:
# Allow loading data from later transactions
# for conflict resolution.
- cursor = self._store_cursor
- else:
- if not self._load_transaction_open:
- self._restart_load()
- cursor = self._load_cursor
- state = self._adapter.load_revision(cursor, oid_int, tid_int)
+ state = self._adapter.load_revision(
+ self._store_cursor, oid_int, tid_int)
finally:
self._lock_release()
@@ -481,7 +475,6 @@
# attempting to store objects after the vote phase has finished.
# That should not happen, should it?
assert self._prepared_txn is None
- md5sum = md5(data).hexdigest()
adapter = self._adapter
cursor = self._store_cursor
@@ -496,7 +489,7 @@
try:
self._max_stored_oid = max(self._max_stored_oid, oid_int)
# save the data in a temporary table
- adapter.store_temp(cursor, oid_int, prev_tid_int, md5sum, data)
+ adapter.store_temp(cursor, oid_int, prev_tid_int, data)
return None
finally:
self._lock_release()
@@ -515,11 +508,6 @@
assert self._tid is not None
assert self._prepared_txn is None
- if data is not None:
- md5sum = md5(data).hexdigest()
- else:
- # George Bailey object
- md5sum = None
adapter = self._adapter
cursor = self._store_cursor
@@ -530,8 +518,8 @@
self._lock_acquire()
try:
self._max_stored_oid = max(self._max_stored_oid, oid_int)
- # save the data. Note that md5sum and data can be None.
- adapter.restore(cursor, oid_int, tid_int, md5sum, data)
+ # save the data. Note that data can be None.
+ adapter.restore(cursor, oid_int, tid_int, data)
finally:
self._lock_release()
@@ -648,9 +636,8 @@
else:
# resolved
data = rdata
- md5sum = md5(data).hexdigest()
self._adapter.replace_temp(
- cursor, oid_int, prev_tid_int, md5sum, data)
+ cursor, oid_int, prev_tid_int, data)
resolved.add(oid)
# Move the new states into the permanent table
@@ -993,6 +980,7 @@
finally:
lock_conn.rollback()
adapter.close(lock_conn, lock_cursor)
+ self.sync()
def _after_pack(self, oid_int, tid_int):
"""Called after an object state has been removed by packing.
More information about the checkins
mailing list