From 4e6aad2baccf8e3113b3dc3647500eca3c1bd1c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Wisniewski?= <gregory@nexedi.com> Date: Tue, 23 Mar 2010 09:31:00 +0000 Subject: [PATCH] Update packet logger to avoid decode again non-logged packets. The logger use dispatch tables from EventHandler to known the expected method name then retreive its own packet handler. git-svn-id: https://svn.erp5.org/repos/neo/trunk@1949 71dcc9de-d417-0410-9af5-da40c76e7ee4 --- neo/logger.py | 203 ++------------------------------------------------ 1 file changed, 6 insertions(+), 197 deletions(-) diff --git a/neo/logger.py b/neo/logger.py index 6ac8434a..f7397c13 100644 --- a/neo/logger.py +++ b/neo/logger.py @@ -23,11 +23,13 @@ from neo.profiling import profiler_decorator LOGGER_ENABLED = False -class PacketLogger(EventHandler): +class PacketLogger(object): """ Logger at packet level (for debugging purpose) """ def __init__(self): - EventHandler.__init__(self, None) + _temp = EventHandler(None) + self.packet_dispatch_table = _temp.packet_dispatch_table + self.error_dispatch_table = _temp.error_dispatch_table def dispatch(self, conn, packet, direction): """This is a helper method to handle various packet types.""" @@ -37,7 +39,9 @@ class PacketLogger(EventHandler): ip, port = conn.getAddress() logging.debug('#0x%08x %-30s %s %s (%s:%d)', packet.getId(), packet.__class__.__name__, direction, uuid, ip, port) + # look for custom packet logger logger = self.packet_dispatch_table.get(klass, None) + logger = logger and getattr(self, logger.im_func.__name__, None) if logger is None: return # enhanced log @@ -50,34 +54,9 @@ class PacketLogger(EventHandler): if log_message is not None: logging.debug('#0x%08x %s', packet.getId(), log_message) - - # Packet loggers - def error(self, conn, code, message): return "%s (%s)" % (code, message) - def requestIdentification(self, conn, node_type, - uuid, address, name): - logging.debug('Request identification for cluster %s' % (name, )) - pass - - def acceptIdentification(self, conn, node_type, - uuid, num_partitions, num_replicas, your_uuid): - pass - - def askPrimary(self, conn): - pass - - def answerPrimary(self, conn, primary_uuid, - known_master_list): - pass - - def announcePrimary(self, conn): - pass - - def reelectPrimary(self, conn): - pass - def notifyNodeInformation(self, conn, node_list): for node_type, address, uuid, state in node_list: if address is not None: @@ -87,176 +66,6 @@ class PacketLogger(EventHandler): node = (dump(uuid), node_type, address, state) logging.debug(' ! %s | %8s | %22s | %s' % node) - def askLastIDs(self, conn): - pass - - def answerLastIDs(self, conn, loid, ltid, lptid): - pass - - def askPartitionTable(self, conn, offset_list): - pass - - def answerPartitionTable(self, conn, ptid, row_list): - pass - - def sendPartitionTable(self, conn, ptid, row_list): - pass - - def notifyPartitionChanges(self, conn, ptid, cell_list): - pass - - def startOperation(self, conn): - pass - - def stopOperation(self, conn): - pass - - def askUnfinishedTransactions(self, conn): - pass - - def answerUnfinishedTransactions(self, conn, tid_list): - pass - - def askObjectPresent(self, conn, oid, tid): - pass - - def answerObjectPresent(self, conn, oid, tid): - pass - - def deleteTransaction(self, conn, tid): - pass - - def commitTransaction(self, conn, tid): - pass - - def askBeginTransaction(self, conn, tid): - pass - - def answerBeginTransaction(self, conn, tid): - pass - - def askNewOIDs(self, conn, num_oids): - pass - - def answerNewOIDs(self, conn, num_oids): - pass - - def askFinishTransaction(self, conn, oid_list, tid): - pass - - def answerTransactionFinished(self, conn, tid): - pass - - def askLockInformation(self, conn, tid): - pass - - def answerInformationLocked(self, conn, tid): - pass - - def invalidateObjects(self, conn, oid_list, tid): - pass - - def notifyUnlockInformation(self, conn, tid): - pass - - def askStoreObject(self, conn, oid, serial, - compression, checksum, data, tid): - pass - - def answerStoreObject(self, conn, conflicting, oid, serial): - pass - - def abortTransaction(self, conn, tid): - pass - - def askStoreTransaction(self, conn, tid, user, desc, - ext, oid_list): - pass - - def answerStoreTransaction(self, conn, tid): - pass - - def askObject(self, conn, oid, serial, tid): - pass - - def answerObject(self, conn, oid, serial_start, - serial_end, compression, checksum, data): - pass - - def askTIDs(self, conn, first, last, partition): - pass - - def answerTIDs(self, conn, tid_list): - pass - - def askTransactionInformation(self, conn, tid): - pass - - def answerTransactionInformation(self, conn, tid, - user, desc, ext, packed, oid_list): - pass - - def askObjectHistory(self, conn, oid, first, last): - pass - - def answerObjectHistory(self, conn, oid, history_list): - pass - - def askOIDs(self, conn, first, last, partition): - pass - - def answerOIDs(self, conn, oid_list): - pass - - def askPartitionList(self, conn, min_offset, max_offset, uuid): - pass - - def answerPartitionList(self, conn, ptid, row_list): - pass - - def askNodeList(self, conn, offset_list): - pass - - def answerNodeList(self, conn, node_list): - pass - - def setNodeState(self, conn, uuid, state, modify_partition_table): - pass - - def answerNodeState(self, conn, uuid, state): - pass - - def addPendingNodes(self, conn, uuid_list): - pass - - def answerNewNodes(self, conn, uuid_list): - pass - - def askNodeInformation(self, conn): - pass - - def answerNodeInformation(self, conn): - pass - - def askClusterState(self, conn): - pass - - def answerClusterState(self, conn, state): - pass - - def setClusterState(self, conn, state): - pass - - def notifyClusterInformation(self, conn, state): - pass - - def notifyLastOID(self, conn, oid): - pass - - def notifyReplicationDone(self, conn, offset): - pass - - PACKET_LOGGER = PacketLogger() if not LOGGER_ENABLED: # disable logger -- 2.30.9