Commit 8d74bdb4 authored by Vincent Pelletier's avatar Vincent Pelletier

Provide IStorage.

Also, some manual tweaks to fix easy differences between implementation and
interface / related comments:
- make name unique (provided name option is itself unique)
- __name__ property definition is delegated to BaseStorage.__init__
- warn about _is_read_only as being somewhat part of the interface
- make "load"'s "version" mandatory, and assert it is ''
- store: likewise
- registerDB shouldn't require a second argument
- note that tpc_begin doesn't follow interface described behaviour when
  a commit is already running. This is a feature actually, and should be
  harmless to caller.

git-svn-id: https://svn.erp5.org/repos/neo/trunk@2510 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent aa4a267f
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
from ZODB import BaseStorage, ConflictResolution, POSException from ZODB import BaseStorage, ConflictResolution, POSException
from zope.interface import implements
import ZODB.interfaces
from neo import setupLog from neo import setupLog
from neo.client.app import Application from neo.client.app import Application
...@@ -40,20 +42,24 @@ class Storage(BaseStorage.BaseStorage, ...@@ -40,20 +42,24 @@ class Storage(BaseStorage.BaseStorage,
ConflictResolution.ConflictResolvingStorage): ConflictResolution.ConflictResolvingStorage):
"""Wrapper class for neoclient.""" """Wrapper class for neoclient."""
__name__ = 'NEOStorage' implements(
ZODB.interfaces.IStorage,
)
def __init__(self, master_nodes, name, connector=None, read_only=False, def __init__(self, master_nodes, name, connector=None, read_only=False,
compress=None, logfile=None, verbose=False, **kw): compress=None, logfile=None, verbose=False, **kw):
if compress is None: if compress is None:
compress = True compress = True
setupLog('CLIENT', filename=logfile, verbose=verbose) setupLog('CLIENT', filename=logfile, verbose=verbose)
BaseStorage.BaseStorage.__init__(self, name) BaseStorage.BaseStorage.__init__(self, 'NEOStorage(%s)' % (name, ))
# Warning: _is_read_only is used in BaseStorage, do not rename it.
self._is_read_only = read_only self._is_read_only = read_only
self.app = Application(master_nodes, name, connector, self.app = Application(master_nodes, name, connector,
compress=compress) compress=compress)
self._cache = DummyCache(self.app) self._cache = DummyCache(self.app)
def load(self, oid, version=None): def load(self, oid, version):
assert version == '', 'Versions are not supported'
try: try:
return self.app.load(oid=oid) return self.app.load(oid=oid)
except NEOStorageNotFoundError: except NEOStorageNotFoundError:
...@@ -65,6 +71,9 @@ class Storage(BaseStorage.BaseStorage, ...@@ -65,6 +71,9 @@ class Storage(BaseStorage.BaseStorage,
@check_read_only @check_read_only
def tpc_begin(self, transaction, tid=None, status=' '): def tpc_begin(self, transaction, tid=None, status=' '):
"""
Note: never blocks in NEO.
"""
return self.app.tpc_begin(transaction=transaction, tid=tid, return self.app.tpc_begin(transaction=transaction, tid=tid,
status=status) status=status)
...@@ -83,6 +92,7 @@ class Storage(BaseStorage.BaseStorage, ...@@ -83,6 +92,7 @@ class Storage(BaseStorage.BaseStorage,
@check_read_only @check_read_only
def store(self, oid, serial, data, version, transaction): def store(self, oid, serial, data, version, transaction):
assert version == '', 'Versions are not supported'
return self.app.store(oid=oid, serial=serial, return self.app.store(oid=oid, serial=serial,
data=data, version=version, transaction=transaction) data=data, version=version, transaction=transaction)
...@@ -143,7 +153,7 @@ class Storage(BaseStorage.BaseStorage, ...@@ -143,7 +153,7 @@ class Storage(BaseStorage.BaseStorage,
def __len__(self): def __len__(self):
return self.app.getStorageSize() return self.app.getStorageSize()
def registerDB(self, db, limit): def registerDB(self, db, limit=None):
self.app.registerDB(db, limit) self.app.registerDB(db, limit)
def history(self, oid, version=None, size=1, filter=None): def history(self, oid, version=None, size=1, filter=None):
......
...@@ -293,7 +293,7 @@ class ClientTests(NEOFunctionalTest): ...@@ -293,7 +293,7 @@ class ClientTests(NEOFunctionalTest):
t3.description = 'desc' t3.description = 'desc'
st3.tpc_begin(t3) st3.tpc_begin(t3)
# retreive the last revision # retreive the last revision
data, serial = st3.load(oid) data, serial = st3.load(oid, '')
# try to store again, should not be delayed # try to store again, should not be delayed
st3.store(oid, serial, data, '', t3) st3.store(oid, serial, data, '', t3)
# the vote should not timeout # the vote should not timeout
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment