How to use the pysyncobj.pysyncobj3.node.Node function in pysyncobj

To help you get started, we’ve selected a few pysyncobj 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 bakwc / PySyncObj / pysyncobj / pysyncobj3 / syncobj.py View on Github external
adding = reverse
        else:
            return False

        if self.__selfNodeAddr is not None:
            shouldConnect = None
        else:
            shouldConnect = True

        if adding:
            newNode = requestNode
            # Node already exists in cluster
            if newNode == self.__selfNodeAddr or newNode in self.__otherNodesAddrs:
                return False
            self.__otherNodesAddrs.append(newNode)
            self.__nodes.append(Node(self, newNode, shouldConnect))
            self.__raftNextIndex[newNode] = self.__getCurrentLogIndex() + 1
            self.__raftMatchIndex[newNode] = 0
            return True
        else:
            oldNode = requestNode
            if oldNode == self.__selfNodeAddr:
                return False
            if oldNode not in self.__otherNodesAddrs:
                return False
            for i in range(len(self.__nodes)):
                if self.__nodes[i].getAddress() == oldNode:
                    self.__nodes[i]._destroy()
                    self.__nodes.pop(i)
                    self.__otherNodesAddrs.pop(i)
                    del self.__raftNextIndex[oldNode]
                    del self.__raftMatchIndex[oldNode]
github bakwc / PySyncObj / pysyncobj / pysyncobj3 / syncobj.py View on Github external
def __initInTickThread(self):
        try:
            self.__lastInitTryTime = time.time()
            if self.__selfNodeAddr is not None:
                self.__server.bind()
                shouldConnect = None
            else:
                shouldConnect = True
            self.__nodes = []
            for nodeAddr in self.__otherNodesAddrs:
                self.__nodes.append(Node(self, nodeAddr, shouldConnect))
                self.__raftNextIndex[nodeAddr] = self.__getCurrentLogIndex() + 1
                self.__raftMatchIndex[nodeAddr] = 0
            self.__needLoadDumpFile = True
            self.__isInitialized = True
            self.__bindedEvent.set()
        except:
            self.__bindRetries += 1
            if self.__conf.maxBindRetries and self.__bindRetries >= self.__conf.maxBindRetries:
                self.__bindedEvent.set()
                raise SyncObjException('BindError')
            logging.exception('failed to perform initialization')
github bakwc / PySyncObj / pysyncobj / pysyncobj3 / syncobj.py View on Github external
partnerNode = None
        for node in self.__nodes:
            if node.getAddress() == message:
                partnerNode = node
                break

        if partnerNode is None and message != 'readonly':
            conn.disconnect()
            self.__unknownConnections.pop(descr, None)
            return

        if partnerNode is not None:
            partnerNode.onPartnerConnected(conn)
        else:
            nodeAddr = str(self.__readonlyNodesCounter)
            node = Node(self, nodeAddr, shouldConnect=False)
            node.onPartnerConnected(conn)
            self.__readonlyNodes.append(node)
            self.__raftNextIndex[nodeAddr] = self.__getCurrentLogIndex() + 1
            self.__raftMatchIndex[nodeAddr] = 0
            self.__readonlyNodesCounter += 1

        self.__unknownConnections.pop(descr, None)
github bakwc / PySyncObj / pysyncobj / pysyncobj3 / syncobj.py View on Github external
for i in range(len(self.__nodes) -1, -1, -1):
            nodeAddr = self.__nodes[i].getAddress()
            if nodeAddr not in self.__otherNodesAddrs:
                self.__nodes[i]._destroy()
                self.__nodes.pop(i)
            else:
                currentNodes.add(nodeAddr)

        if self.__selfNodeAddr is not None:
            shouldConnect = None
        else:
            shouldConnect = True

        for nodeAddr in self.__otherNodesAddrs:
            if nodeAddr not in currentNodes:
                self.__nodes.append(Node(self, nodeAddr, shouldConnect))
                self.__raftNextIndex[nodeAddr] = self.__getCurrentLogIndex() + 1
                self.__raftMatchIndex[nodeAddr] = 0