Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def removeNodeFromCluster(self, node, callback = None):
"""Remove single node from cluster (dynamic membership changes). Async.
You should wait until node successfully added before adding
next node.
:param node: node object or 'nodeHost:nodePort'
:type node: Node | str
:param callback: will be called on success or fail
:type callback: function(`FAIL_REASON <#pysyncobj.FAIL_REASON>`_, None)
"""
if not self.__conf.dynamicMembershipChange:
raise Exception('dynamicMembershipChange is disabled')
if not isinstance(node, Node):
node = self.__nodeClass(node)
self._applyCommand(pickle.dumps(['rem', node.id, node]), callback, _COMMAND_TYPE.MEMBERSHIP)
def send(self, message):
if self.sendRandKey:
message = (self.sendRandKey, message)
data = zlib.compress(pickle.dumps(message), 3)
if self.encryptor:
data = self.encryptor.encrypt(data)
data = struct.pack('i', len(data)) + data
self.__writeBuffer += data
self.__trySendBuffer()
continue
sendSingle = True
sendingSerialized = False
nextNodeIndex = self.__raftNextIndex[node]
while nextNodeIndex <= self.__getCurrentLogIndex() or sendSingle or sendingSerialized:
if nextNodeIndex > self.__raftLog[0][1]:
prevLogIdx, prevLogTerm = self.__getPrevLogIndexTerm(nextNodeIndex)
entries = []
if nextNodeIndex <= self.__getCurrentLogIndex():
entries = self.__getEntries(nextNodeIndex, None, batchSizeBytes)
self.__raftNextIndex[node] = entries[-1][1] + 1
if len(entries) == 1 and len(entries[0][0]) >= batchSizeBytes:
entry = pickle.dumps(entries[0])
for pos in xrange(0, len(entry), batchSizeBytes):
currData = entry[pos:pos + batchSizeBytes]
if pos == 0:
transmission = 'start'
elif pos + batchSizeBytes >= len(entries[0][0]):
transmission = 'finish'
else:
transmission = 'process'
message = {
'type': 'append_entries',
'transmission': transmission,
'data': currData,
'term': self.__raftCurrentTerm,
'commit_index': self.__raftCommitIndex,
'prevLogIdx': prevLogIdx,
'prevLogTerm': prevLogTerm,
def dumps(obj, protocol=None):
return pickle.dumps(obj, __protocol)