How to use the neo.lib.util.dump function in neo

To help you get started, we’ve selected a few neo examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Nexedi / neoppod / neo / storage / handlers / client.py View on Github external
data_serial, ttid, request_time):
        try:
            locked = self.app.tm.storeObject(ttid, serial, oid, compression,
                    checksum, data, data_serial)
        except ConflictError, err:
            # resolvable or not
            locked = err.tid
        except NonReadableCell:
            logging.info('Ignore store of %s:%s by %s: unassigned partition',
                dump(oid), dump(serial), dump(ttid))
            locked = ZERO_TID
        except NotRegisteredError:
            # transaction was aborted, cancel this event
            logging.info('Forget store of %s:%s by %s delayed by %s',
                    dump(oid), dump(serial), dump(ttid),
                    dump(self.app.tm.getLockingTID(oid)))
            locked = ZERO_TID
        else:
            if request_time and SLOW_STORE is not None:
                duration = time.time() - request_time
                if duration > SLOW_STORE:
                    logging.info('StoreObject delay: %.02fs', duration)
        conn.answer(Packets.AnswerStoreObject(locked))
github Nexedi / neoppod / neo / client / app.py View on Github external
return
            try:
                data, old_serial, _ = data_dict.pop(oid)
            except KeyError:
                assert oid is None, (oid, serial)
                # Storage refused us from taking object lock, to avoid a
                # possible deadlock. TID is actually used for some kind of
                # "locking priority": when a higher value has the lock,
                # this means we stored objects "too late", and we would
                # otherwise cause a deadlock.
                # To recover, we must ask storages to release locks we
                # hold (to let possibly-competing transactions acquire
                # them), and requeue our already-sent store requests.
                ttid = txn_context.ttid
                logging.info('Deadlock avoidance triggered for TXN %s'
                  ' with new locking TID %s', dump(ttid), dump(serial))
                txn_context.locking_tid = serial
                packet = Packets.AskRebaseTransaction(ttid, serial)
                for uuid in txn_context.conn_dict:
                    self._askStorageForWrite(txn_context, uuid, packet)
            else:
                if data is CHECKED_SERIAL:
                    raise ReadConflictError(oid=oid,
                        serials=(serial, old_serial))
                # TODO: data can be None if a conflict happens during undo
                if data:
                    txn_context.data_size -= len(data)
                if self.last_tid < serial:
                    self.sync() # possible late invalidation (very rare)
                try:
                    data = tryToResolveConflict(oid, serial, old_serial, data)
                except ConflictError:
github Nexedi / neoppod / neo / storage / database / manager.py View on Github external
def _setTruncateTID(self, tid):
        tid = util.dump(tid)
        logging.debug('truncate_tid = %s', tid)
        return self._setConfiguration('truncate_tid', tid)
github Nexedi / neoppod / neo / client / app.py View on Github external
def askStorage(conn, packet):
            tid, next_tid, compression, checksum, data, data_tid \
                = self._askStorage(conn, packet)
            if data or checksum != ZERO_HASH:
                if checksum != makeChecksum(data):
                    logging.error('wrong checksum from %s for oid %s',
                              conn, dump(oid))
                    raise NEOStorageReadRetry(False)
                return (decompress_list[compression](data),
                        tid, next_tid, data_tid)
            raise NEOStorageCreationUndoneError(dump(oid))
        return self._askStorageForRead(oid,
github Nexedi / neoppod / neo / storage / transactions.py View on Github external
# not expected to have the partition in full.
                    # We'll return a successful answer to the client, which
                    # is fine because there's at least one other cell that is
                    # readable for this oid.
                    raise
                with self._app.dm.replicated(partition):
                    previous_serial = self._app.dm.getLastObjectTID(oid)
        # Locking before reporting a conflict would speed up the case of
        # cascading conflict resolution by avoiding incremental resolution,
        # assuming that the time to resolve a conflict is often constant:
        # "C+A vs. B -> C+A+B" rarely costs more than "C+A vs. C+B -> C+A+B".
        # However, this would be against the optimistic principle of ZODB.
        if previous_serial is not None and previous_serial != serial:
            assert serial < previous_serial, (serial, previous_serial)
            logging.info('Conflict on %s:%s with %s',
                dump(oid), dump(ttid), dump(previous_serial))
            raise ConflictError(previous_serial)
        logging.debug('Transaction %s locking %s', dump(ttid), dump(oid))
        self._store_lock_dict[oid] = ttid
        return True
github Nexedi / neoppod / neo / storage / transactions.py View on Github external
# already resolved).
                raise DelayEvent(transaction)
            if oid in transaction.lockless:
                # This is a consequence of not having taken a lock during
                # replication. After a ConflictError, we may be asked to "lock"
                # it again. The current lock is a special one that only delays
                # new transactions.
                # For the cluster, we're still out-of-date and like above,
                # at least 1 other (readable) cell checks for conflicts.
                return
            if other is not transaction:
                # We have a smaller "TTID" than locking transaction, so we are
                # older: this is a possible deadlock case, as we might already
                # hold locks the younger transaction is waiting upon.
                logging.info('Deadlock on %s:%s with %s',
                             dump(oid), dump(ttid), dump(locked))
                # Ask master to give the client a new locking tid, which will
                # be used to ask all involved storage nodes to rebase the
                # already locked oids for this transaction.
                self._app.master_conn.send(Packets.NotifyDeadlock(
                    ttid, transaction.locking_tid))
                self._rebase(transaction, ttid)
                raise DelayEvent(transaction)
            # If previous store was an undo, next store must be based on
            # undo target.
            try:
                previous_serial = transaction.store_dict[oid][2]
            except KeyError:
                # Similarly to below for store, cascaded deadlock for
                # checkCurrentSerial is possible because rebase() may return
                # oids for which previous rebaseObject are delayed, or being
                # received, and the client will bindly resend them.
github Nexedi / neoppod / neo / admin / app.py View on Github external
upstream = None
            x = datetimeFromTID(tid)
            if upstream:
                lag = (upstream[0] - x).total_seconds()
                if lag or tid >= upstream[1]:
                    lagging = self.max_lag < lag
                else:
                    lag = 'ε'
                    lagging = self.max_lag <= 0
                extra = '; lag=%s' % lag
                if self.lagging != lagging:
                    self.lagging = lagging
                    self.monitor_changed = True
            else:
                extra = ' (%s)' % x
            return (x, tid), '%s; ltid=%s%s' % (summary, dump(tid), extra)
        return None, summary
github Nexedi / neoppod / neo / master / transactions.py View on Github external
def deadlock(self, storage_id, ttid, locking_tid):
        try:
            txn = self._ttid_dict[ttid]
        except KeyError:
            return
        if txn.locking_tid <= locking_tid:
            client = txn.getNode()
            txn.locking_tid = locking_tid = self._nextTID()
            logging.info('Deadlock avoidance triggered by %s for %s:'
                ' new locking tid for TXN %s is %s', uuid_str(storage_id),
                uuid_str(client.getUUID()), dump(ttid), dump(locking_tid))
            client.send(Packets.NotifyDeadlock(ttid, locking_tid))