How to use the neo.lib.protocol.Packets 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 / storage.py View on Github external
def check():
            r = app.dm.checkSerialRange(*args)
            try:
                conn.send(Packets.AnswerCheckSerialRange(*r), msg_id)
            except (weakref.ReferenceError, ConnectionClosed):
                pass
            return; yield # same as in askCheckTIDRange
        app.newTask(check())
github Nexedi / neoppod / neo / admin / handler.py View on Github external
def askNodeList(self, conn, node_type):
        if node_type is None:
            node_type = 'all'
            node_filter = None
        else:
            node_filter = lambda n: n.getType() is node_type
        logging.info("ask list of %s nodes", node_type)
        node_list = self.app.nm.getList(node_filter)
        node_information_list = [node.asTuple() for node in node_list ]
        p = Packets.AnswerNodeList(node_information_list)
        conn.answer(p)
github Nexedi / neoppod / neo / storage / checker.py View on Github external
def connected(self, node):
        conn = node.getConnection()
        if self.conn_dict.get(conn, self) is None:
            self.conn_dict[conn] = conn.ask(Packets.AskCheckTIDRange(
                self.partition, CHECK_COUNT, self.next_tid, self.max_tid))
github Nexedi / neoppod / neo / master / verification.py View on Github external
if self._tid is not None:
                    self._locked_dict[ttid] = self._tid
                    break
            else:
                # Transaction not locked. No need to tell nodes to delete it,
                # since they drop any unfinished data just before being
                # operational.
                pass

        # Finish all transactions for which we know that tpc_finish was called
        # but not fully processed. This may include replicas with transactions
        # that were not even locked.
        for ttid, tid in self._locked_dict.iteritems():
            uuid_set = self._voted_dict.get(ttid)
            if uuid_set:
                packet = Packets.ValidateTransaction(ttid, tid)
                for node in getIdentifiedList(pool_set=uuid_set):
                    node.send(packet)
github Nexedi / neoppod / neo / master / app.py View on Github external
" defined in configuration")
                    truncate = Packets.Truncate(
                        self.backup_app.provideService())
                except StoppedOperation, e:
                    logging.critical('No longer operational')
                    truncate = Packets.Truncate(*e.args) if e.args else None
                    # Automatic restart except if we truncate or retry to.
                    self._startup_allowed = not (self.truncate_tid or truncate)
                self.storage_readiness = 0
                self.storage_ready_dict.clear()
                self.storage_starting_set.clear()
                node_list = []
                for node in self.nm.getIdentifiedList():
                    if node.isStorage() or node.isClient():
                        conn = node.getConnection()
                        conn.send(Packets.StopOperation())
                        if node.isClient():
                            conn.abort()
                            continue
                        if truncate:
                            conn.send(truncate)
                        if node.isRunning():
                            node.setPending()
                            node_list.append(node)
                self.broadcastNodesInformation(node_list)
        except StateChangedException, e:
            assert e.args[0] == ClusterStates.STOPPING
            self.shutdown()
        except PrimaryElected, e:
            self.primary_master, = e.args
github Nexedi / neoppod / neo / lib / handler.py View on Github external
def packetReceived(self, conn, packet, kw={}):
        """Redirect all received packet to dispatcher thread."""
        if packet.isResponse():
            if packet.poll_thread:
                self.dispatch(conn, packet, kw)
                kw = {}
            if not (self.dispatcher.dispatch(conn, packet.getId(), packet, kw)
                    or type(packet) is Packets.Pong or conn.isClosed()):
                raise ProtocolError('Unexpected response packet from %r: %r'
                                    % (conn, packet))
        else:
            self.dispatch(conn, packet, kw)
github Nexedi / neoppod / neo / admin / handler.py View on Github external
def askPrimary(self, conn):
        master_node = self.app.master_node
        conn.answer(Packets.AnswerPrimary(master_node.getUUID()))
github Nexedi / neoppod / neo / storage / handlers / client.py View on Github external
def askTIDsFrom(self, conn, min_tid, max_tid, length, partition):
        conn.answer(Packets.AnswerTIDsFrom(self.app.dm.getReplicationTIDList(
            min_tid, max_tid, length, partition)))
github Nexedi / neoppod / neo / storage / replicator.py View on Github external
try:
                addr, name = self.source_dict[offset]
            except KeyError:
                pass
            else:
                if addr != self.current_node.getAddress():
                    return self.abort()
            min_tid = p.next_trans
            self.replicate_tid = self.replicate_dict.pop(offset)
            logging.debug("starting replication of  from %r", offset, dump(min_tid),
                dump(self.replicate_tid), self.current_node)
        max_tid = self.replicate_tid
        tid_list = self.app.dm.getReplicationTIDList(min_tid, max_tid,
            FETCH_COUNT, offset)
        self._conn_msg_id = self.current_node.ask(Packets.AskFetchTransactions(
            offset, FETCH_COUNT, min_tid, max_tid, tid_list))
github Nexedi / neoppod / neo / storage / handlers / replication.py View on Github external
def _doAskCheckTIDRange(self, min_tid, max_tid, length=RANGE_LENGTH):
        replicator = self.app.replicator
        partition = replicator.getCurrentOffset()
        neo.lib.logging.debug(
            "Check TID range (offset=%s, min_tid=%x, max_tid=%x, length=%s)",
            partition, u64(min_tid), u64(max_tid), length)
        replicator.checkTIDRange(min_tid, max_tid, length, partition)
        return Packets.AskCheckTIDRange(min_tid, max_tid, length, partition)