Commit b70de293 authored by Julien Muchembled's avatar Julien Muchembled

client: code clean up

parent 769f4ef8
...@@ -49,8 +49,7 @@ class Storage(BaseStorage.BaseStorage, ...@@ -49,8 +49,7 @@ class Storage(BaseStorage.BaseStorage,
))) )))
def __init__(self, master_nodes, name, read_only=False, def __init__(self, master_nodes, name, read_only=False,
compress=None, logfile=None, _app=None, compress=None, logfile=None, _app=None, **kw):
dynamic_master_list=None, **kw):
""" """
Do not pass those parameters (used internally): Do not pass those parameters (used internally):
_app _app
...@@ -63,17 +62,8 @@ class Storage(BaseStorage.BaseStorage, ...@@ -63,17 +62,8 @@ class Storage(BaseStorage.BaseStorage,
# Warning: _is_read_only is used in BaseStorage, do not rename it. # Warning: _is_read_only is used in BaseStorage, do not rename it.
self._is_read_only = read_only self._is_read_only = read_only
if _app is None: if _app is None:
_app = Application(master_nodes, name, compress=compress, _app = Application(master_nodes, name, compress=compress, **kw)
dynamic_master_list=dynamic_master_list)
self.app = _app self.app = _app
# Used to clone self (see new_instance & IMVCCStorage definition).
self._init_args = (master_nodes, name)
self._init_kw = {
'read_only': read_only,
'compress': compress,
'dynamic_master_list': dynamic_master_list,
'_app': _app,
}
@property @property
def _cache(self): def _cache(self):
...@@ -105,27 +95,23 @@ class Storage(BaseStorage.BaseStorage, ...@@ -105,27 +95,23 @@ class Storage(BaseStorage.BaseStorage,
""" """
Note: never blocks in NEO. Note: never blocks in NEO.
""" """
return self.app.tpc_begin(transaction=transaction, tid=tid, return self.app.tpc_begin(transaction, tid, status)
status=status)
@check_read_only @check_read_only
def tpc_vote(self, transaction): def tpc_vote(self, transaction):
return self.app.tpc_vote(transaction=transaction, return self.app.tpc_vote(transaction, self.tryToResolveConflict)
tryToResolveConflict=self.tryToResolveConflict)
@check_read_only @check_read_only
def tpc_abort(self, transaction): def tpc_abort(self, transaction):
return self.app.tpc_abort(transaction=transaction) return self.app.tpc_abort(transaction)
def tpc_finish(self, transaction, f=None): def tpc_finish(self, transaction, f=None):
return self.app.tpc_finish(transaction=transaction, return self.app.tpc_finish(transaction, self.tryToResolveConflict, f)
tryToResolveConflict=self.tryToResolveConflict, f=f)
@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' assert version == '', 'Versions are not supported'
return self.app.store(oid=oid, serial=serial, return self.app.store(oid, serial, data, version, transaction)
data=data, version=version, transaction=transaction)
@check_read_only @check_read_only
def deleteObject(self, oid, serial, transaction): def deleteObject(self, oid, serial, transaction):
...@@ -149,10 +135,8 @@ class Storage(BaseStorage.BaseStorage, ...@@ -149,10 +135,8 @@ class Storage(BaseStorage.BaseStorage,
def iterator(self, start=None, stop=None): def iterator(self, start=None, stop=None):
# Iterator lives in its own transaction, so get a fresh snapshot. # Iterator lives in its own transaction, so get a fresh snapshot.
snapshot_tid = self.lastTransaction() snapshot_tid = self.lastTransaction()
if stop is None: if not stop or snapshot_tid < stop:
stop = snapshot_tid stop = snapshot_tid
else:
stop = min(snapshot_tid, stop)
return self.app.iterator(start, stop) return self.app.iterator(start, stop)
# undo # undo
...@@ -186,7 +170,7 @@ class Storage(BaseStorage.BaseStorage, ...@@ -186,7 +170,7 @@ class Storage(BaseStorage.BaseStorage,
return data, serial, '' return data, serial, ''
def __len__(self): def __len__(self):
return self.app.getStorageSize() return self.app.getObjectCount()
def registerDB(self, db, limit=None): def registerDB(self, db, limit=None):
self.app.registerDB(db, limit) self.app.registerDB(db, limit)
...@@ -213,9 +197,6 @@ class Storage(BaseStorage.BaseStorage, ...@@ -213,9 +197,6 @@ class Storage(BaseStorage.BaseStorage,
return self.app.importFrom(source, start, stop, return self.app.importFrom(source, start, stop,
self.tryToResolveConflict, preindex) self.tryToResolveConflict, preindex)
def restore(self, oid, serial, data, version, prev_txn, transaction):
raise NotImplementedError
def pack(self, t, referencesf, gc=False): def pack(self, t, referencesf, gc=False):
if gc: if gc:
logging.warning('Garbage Collection is not available in NEO,' logging.warning('Garbage Collection is not available in NEO,'
...@@ -253,6 +234,3 @@ class Storage(BaseStorage.BaseStorage, ...@@ -253,6 +234,3 @@ class Storage(BaseStorage.BaseStorage,
def checkCurrentSerialInTransaction(self, oid, serial, transaction): def checkCurrentSerialInTransaction(self, oid, serial, transaction):
self.app.checkCurrentSerialInTransaction(oid, serial, transaction) self.app.checkCurrentSerialInTransaction(oid, serial, transaction)
def new_instance(self):
return Storage(*self._init_args, **self._init_kw)
...@@ -70,7 +70,7 @@ class Application(object): ...@@ -70,7 +70,7 @@ class Application(object):
"""The client node application.""" """The client node application."""
def __init__(self, master_nodes, name, compress=True, def __init__(self, master_nodes, name, compress=True,
dynamic_master_list=None, **kw): dynamic_master_list=None):
# Start polling thread # Start polling thread
self.em = EventManager() self.em = EventManager()
self.poll_thread = ThreadedPoll(self.em, name=name) self.poll_thread = ThreadedPoll(self.em, name=name)
...@@ -368,8 +368,8 @@ class Application(object): ...@@ -368,8 +368,8 @@ class Application(object):
finally: finally:
self._oid_lock_release() self._oid_lock_release()
def getStorageSize(self): def getObjectCount(self):
# return the last OID used, this is innacurate # return the last OID used, this is inaccurate
return int(u64(self.last_oid)) return int(u64(self.last_oid))
@profiler_decorator @profiler_decorator
......
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