本文整理汇总了Python中serializer.Serializer.checkSerializing方法的典型用法代码示例。如果您正苦于以下问题:Python Serializer.checkSerializing方法的具体用法?Python Serializer.checkSerializing怎么用?Python Serializer.checkSerializing使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类serializer.Serializer
的用法示例。
在下文中一共展示了Serializer.checkSerializing方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SyncObj
# 需要导入模块: from serializer import Serializer [as 别名]
# 或者: from serializer.Serializer import checkSerializing [as 别名]
#.........这里部分代码省略.........
entries = []
if nextNodeIndex <= self.__getCurrentLogIndex():
entries = self.__getEntries(nextNodeIndex, None, self.__conf.appendEntriesBatchSizeBytes)
self.__raftNextIndex[nodeAddr] = entries[-1][1] + 1
message = {
'type': 'append_entries',
'term': self.__raftCurrentTerm,
'commit_index': self.__raftCommitIndex,
'entries': entries,
'prevLogIdx': prevLogIdx,
'prevLogTerm': prevLogTerm,
}
node.send(message)
else:
transmissionData = self.__serializer.getTransmissionData(nodeAddr)
message = {
'type': 'append_entries',
'term': self.__raftCurrentTerm,
'commit_index': self.__raftCommitIndex,
'serialized': transmissionData,
}
node.send(message)
if transmissionData is not None:
isLast = transmissionData[2]
if isLast:
self.__raftNextIndex[nodeAddr] = self.__raftLog[0][1]
sendingSerialized = False
else:
sendingSerialized = True
else:
sendingSerialized = False
nextNodeIndex = self.__raftNextIndex[nodeAddr]
sendSingle = False
delta = time.time() - startTime
if delta > self.__conf.appendEntriesPeriod:
break
def __send(self, nodeAddr, message):
for node in self.__nodes:
if node.getAddress() == nodeAddr:
node.send(message)
break
def __connectedToAnyone(self):
for node in self.__nodes:
if node.getStatus() == NODE_STATUS.CONNECTED:
return True
return False
def _getSelfNodeAddr(self):
return self.__selfNodeAddr
def _getConf(self):
return self.__conf
def _getEncryptor(self):
return self.__encryptor
def __tryLogCompaction(self):
currTime = time.time()
serializeState, serializeID = self.__serializer.checkSerializing()
if serializeState == SERIALIZER_STATE.SUCCESS:
self.__lastSerializedTime = currTime
self.__deleteEntriesTo(serializeID)
if serializeState == SERIALIZER_STATE.FAILED:
LOG_WARNING("Failed to store full dump")
if serializeState != SERIALIZER_STATE.NOT_SERIALIZING:
return
if len(self.__raftLog) <= self.__conf.logCompactionMinEntries and \
currTime - self.__lastSerializedTime <= self.__conf.logCompactionMinTime and \
not self.__forceLogCompaction:
return
self.__forceLogCompaction = False
lastAppliedEntries = self.__getEntries(self.__raftLastApplied - 1, 2)
if len(lastAppliedEntries) < 2:
return
data = dict([(k, self.__dict__[k]) for k in self.__dict__.keys() if k not in self.__properies])
self.__serializer.serialize((data, lastAppliedEntries[1], lastAppliedEntries[0]), lastAppliedEntries[0][1])
def __loadDumpFile(self):
try:
data = self.__serializer.deserialize()
for k, v in data[0].iteritems():
self.__dict__[k] = v
self.__raftLog = [data[2], data[1]]
self.__raftLastApplied = data[1][1]
except:
LOG_WARNING('Failed to load full dump')
LOG_CURRENT_EXCEPTION()
示例2: SyncObj
# 需要导入模块: from serializer import Serializer [as 别名]
# 或者: from serializer.Serializer import checkSerializing [as 别名]
#.........这里部分代码省略.........
self.__raftNextIndex[nodeAddr] = self.__raftLog[0][1]
sendingSerialized = False
else:
sendingSerialized = True
else:
sendingSerialized = False
nextNodeIndex = self.__raftNextIndex[nodeAddr]
sendSingle = False
delta = time.time() - startTime
if delta > self.__conf.appendEntriesPeriod:
break
def __send(self, nodeAddr, message):
for node in self.__nodes:
if node.getAddress() == nodeAddr:
node.send(message)
break
def __processUnknownConnections(self, descr, event):
conn = self.__unknownConnections[descr]
partnerNode = None
remove = False
if event & POLL_EVENT_TYPE.READ:
conn.read()
nodeAddr = conn.getMessage()
if nodeAddr is not None:
for node in self.__nodes:
if node.getAddress() == nodeAddr:
partnerNode = node
break
else:
remove = True
if event & POLL_EVENT_TYPE.ERROR:
remove = True
if remove or conn.isDisconnected():
self.__unknownConnections.pop(descr)
self.__poller.unsubscribe(descr)
conn.close()
return
if partnerNode is not None:
self.__unknownConnections.pop(descr)
assert conn.fileno() is not None
partnerNode.onPartnerConnected(conn)
def _getSelfNodeAddr(self):
return self.__selfNodeAddr
def _getConf(self):
return self.__conf
def _getResolver(self):
return self.__resolver
def _getPoller(self):
return self.__poller
def __tryLogCompaction(self):
currTime = time.time()
serializeState, serializeID = self.__serializer.checkSerializing()
if serializeState == SERIALIZER_STATE.SUCCESS:
self.__lastSerializedTime = currTime
self.__deleteEntriesTo(serializeID)
if serializeState == SERIALIZER_STATE.FAILED:
LOG_WARNING("Failed to store full dump")
if serializeState != SERIALIZER_STATE.NOT_SERIALIZING:
return
if len(self.__raftLog) <= self.__conf.logCompactionMinEntries and \
currTime - self.__lastSerializedTime <= self.__conf.logCompactionMinTime and\
not self.__forceLogCompaction:
return
self.__forceLogCompaction = False
lastAppliedEntries = self.__getEntries(self.__raftLastApplied - 1, 2)
if not lastAppliedEntries:
return
data = dict([(k, self.__dict__[k]) for k in self.__dict__.keys() if k not in self.__properies])
self.__serializer.serialize((data, lastAppliedEntries[1], lastAppliedEntries[0]), lastAppliedEntries[1][1])
def __loadDumpFile(self):
try:
data = self.__serializer.deserialize()
for k, v in data[0].iteritems():
self.__dict__[k] = v
self.__raftLog = [data[2], data[1]]
self.__raftLastApplied = data[1][1]
except:
LOG_WARNING('Failed to load full dump')
LOG_CURRENT_EXCEPTION()
示例3: SyncObj
# 需要导入模块: from serializer import Serializer [as 别名]
# 或者: from serializer.Serializer import checkSerializing [as 别名]
#.........这里部分代码省略.........
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 xrange(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]
return True
return False
def __parseChangeClusterRequest(self, command):
commandType = ord(command[:1])
if commandType != _COMMAND_TYPE.MEMBERSHIP:
return None
return cPickle.loads(command[1:])
def __tryLogCompaction(self):
currTime = time.time()
serializeState, serializeID = self.__serializer.checkSerializing()
if serializeState == SERIALIZER_STATE.SUCCESS:
self.__lastSerializedTime = currTime
self.__deleteEntriesTo(serializeID)
self.__lastSerializedEntry = serializeID
if serializeState == SERIALIZER_STATE.FAILED:
logging.warning('Failed to store full dump')
if serializeState != SERIALIZER_STATE.NOT_SERIALIZING:
return
if len(self.__raftLog) <= self.__conf.logCompactionMinEntries and \
currTime - self.__lastSerializedTime <= self.__conf.logCompactionMinTime and \
not self.__forceLogCompaction:
return
if self.__conf.logCompactionSplit:
allNodes = sorted(self.__otherNodesAddrs + [self.__selfNodeAddr])
nodesCount = len(allNodes)
selfIdx = allNodes.index(self.__selfNodeAddr)
interval = self.__conf.logCompactionMinTime
periodStart = int(currTime) / interval * interval
nodeInterval = float(interval) / nodesCount
nodeIntervalStart = periodStart + selfIdx * nodeInterval
nodeIntervalEnd = nodeIntervalStart + 0.3 * nodeInterval
if currTime < nodeIntervalStart or currTime >= nodeIntervalEnd:
return
self.__forceLogCompaction = False
lastAppliedEntries = self.__getEntries(self.__raftLastApplied - 1, 2)