Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update of #18 #48

Merged
merged 2 commits into from
Jun 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,19 @@
as a destination, not just RelStorages.

- zodbconvert: The ``--incremental`` option is supported with a
RelStorage as a destination. See `PR 22`. With contributions by
RelStorage as a destination. See `PR 22`_. With contributions by
Sylvain Viollon, Mauro Amico, and Peter Jacobs. Originally reported
by Jan-Wijbrand Kolman.

.. _`PR 22`: https://github.com/zodb/relstorage/pull/22


- Raise a specific exception when acquiring the commit or pack locks
fails. See `PR 18`_.

.. _`PR 18`: https://github.com/zodb/relstorage/pull/18/


1.6.0b3 (2014-12-08)
--------------------

Expand Down
11 changes: 9 additions & 2 deletions relstorage/adapters/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
##############################################################################
"""Interfaces provided by RelStorage database adapters"""

from ZODB.POSException import StorageError
from zope.interface import Attribute
from zope.interface import Interface

Expand Down Expand Up @@ -162,7 +163,7 @@ def hold_commit_lock(cursor, ensure_current=False, nowait=False):
If ensure_current is True, other tables may be locked as well, to
ensure the most current data is available.

May raise StorageError if the lock can not be acquired before
May raise UnableToAcquireCommitLockError if the lock can not be acquired before
some timeout.

With nowait set to True, only try to obtain the lock without waiting
Expand All @@ -176,7 +177,7 @@ def release_commit_lock(cursor):
def hold_pack_lock(cursor):
"""Try to acquire the pack lock.

Raise StorageError if packing or undo is already in progress.
Raise UnableToAcquirePackUndoLockError if packing or undo is already in progress.
"""

def release_pack_lock(cursor):
Expand Down Expand Up @@ -470,3 +471,9 @@ def abort(conn, cursor, txn=None):

class ReplicaClosedException(Exception):
"""The connection to the replica has been closed"""

class UnableToAcquireCommitLockError(StorageError):
"""The commit lock cannot be acquired."""

class UnableToAcquirePackUndoLockError(StorageError):
"""A pack or undo operation is in progress."""
17 changes: 9 additions & 8 deletions relstorage/adapters/locker.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
"""Locker implementations.
"""

from ZODB.POSException import StorageError
from perfmetrics import metricmethod
from relstorage.adapters.interfaces import ILocker
from .interfaces import UnableToAcquireCommitLockError
from .interfaces import UnableToAcquirePackUndoLockError
from zope.interface import implements


Expand Down Expand Up @@ -63,7 +64,7 @@ def hold_commit_lock(self, cursor, ensure_current=False, nowait=False):
except self.lock_exceptions:
if nowait:
return False
raise StorageError('Acquiring a commit lock failed')
raise UnableToAcquireCommitLockError('Acquiring a commit lock failed')
return True

def release_commit_lock(self, cursor):
Expand All @@ -87,13 +88,13 @@ def hold_pack_lock(self, cursor):
cursor.execute("SELECT pg_try_advisory_lock(1)")
locked = cursor.fetchone()[0]
if not locked:
raise StorageError('A pack or undo operation is in progress')
raise UnableToAcquirePackUndoLockError('A pack or undo operation is in progress')
else:
# b/w compat
try:
cursor.execute("LOCK pack_lock IN EXCLUSIVE MODE NOWAIT")
except self.lock_exceptions: # psycopg2.DatabaseError:
raise StorageError('A pack or undo operation is in progress')
raise UnableToAcquirePackUndoLockError('A pack or undo operation is in progress')

def release_pack_lock(self, cursor):
"""Release the pack lock."""
Expand All @@ -114,7 +115,7 @@ def hold_commit_lock(self, cursor, ensure_current=False, nowait=False):
if nowait and locked in (0, 1):
return bool(locked)
if not locked:
raise StorageError("Unable to acquire commit lock")
raise UnableToAcquireCommitLockError("Unable to acquire commit lock")

def release_commit_lock(self, cursor):
stmt = "SELECT RELEASE_LOCK(CONCAT(DATABASE(), '.commit'))"
Expand All @@ -129,7 +130,7 @@ def hold_pack_lock(self, cursor):
cursor.execute(stmt)
res = cursor.fetchone()[0]
if not res:
raise StorageError('A pack or undo operation is in progress')
raise UnableToAcquirePackUndoLockError('A pack or undo operation is in progress')

def release_pack_lock(self, cursor):
"""Release the pack lock."""
Expand Down Expand Up @@ -166,7 +167,7 @@ def hold_commit_lock(self, cursor, ensure_current=False, nowait=False):
'lock already owned', 'illegal handle')[int(status)]
else:
msg = str(status)
raise StorageError(
raise UnableToAcquireCommitLockError(
"Unable to acquire commit lock (%s)" % msg)

# Alternative:
Expand Down Expand Up @@ -197,7 +198,7 @@ def hold_pack_lock(self, cursor):
try:
cursor.execute(stmt)
except self.lock_exceptions: # cx_Oracle.DatabaseError:
raise StorageError('A pack or undo operation is in progress')
raise UnableToAcquirePackUndoLockError('A pack or undo operation is in progress')

def release_pack_lock(self, cursor):
"""Release the pack lock."""
Expand Down