def handle_cmd(self, frame): """ Method: handle_cmd Description: 同步消息处理函数 Parameter: frame: 请求消息 Return: 无 Others: """ buf = frame.get_data() tracelog.info('received data from client at %s' % datetime.datetime.now().isoformat()) ne_id = NEInfoMgr.get_ne_id_by_pid(frame.get_sender_pid()) if ne_id is None: tracelog.error("received unknow data sync notification from NE, " "pid:%d" % frame.get_sender_pid()) return debug.info('ne id: %d' % (ne_id)) # 如果网元正处于全同步中,那么直接忽视本次事件通知 if not NEInfoMgr.is_ne_state_normal(ne_id): tracelog.info('database is full-synchonizing') return sync_object = DBSyncObject.deserialize(buf) result = DBSyncResult() result.id = sync_object.id debug.info('sync object id: %d' % sync_object.id) for event in sync_object.sync_events: if event.type == DBSyncType.FULL: self.__handle_full_sync_ntf(frame, ne_id, sync_object, event) self.get_worker().get_app().set_sync_sn(ne_id, event.priority, event.id) return events = [] for event in sync_object.sync_events: sync_sn = self.get_worker().get_app().get_sync_sn(ne_id, event.priority) debug.info('ne_id: %d, priority: %d, event_id: %d sync_sn: %d' % (ne_id, event.priority, event.id, sync_sn)) if event.id <= sync_sn: #该Event已经同步成功,重复提交将被忽略 tracelog.info('event#%d was already synchonized.current sn: %d' % (event.id, sync_sn)) result.event_ids.append(event.id) else: events.append(event) manager = self.get_worker().get_app().get_data_manager() debug.info('incremental sync starts') ret_code = manager.sync_data(events, ne_id) if ret_code != DBSyncStatus.ERROR_SUCCESS: tracelog.info('sync data failed. exit code: %d' % ret_code) if ret_code == DBSyncStatus.ERROR_CONFLICT: # 将EAU的状态设置为需要全同步 NEInfoMgr.set_ne_need_sync_full(ne_id , self.get_worker().get_app().get_mit_manager() , True) # 不给EAU回应答;EAU收到收不到应答超时后,下次重试 return for event in events: self.get_worker().get_app().set_sync_sn(ne_id, event.priority, event.id) debug.info(' event#%04d: return %d' % (event.id, ret_code)) result.event_ids.append(event.id) self.__send_ack(frame, result.serialize()) tracelog.info(result.event_ids) tracelog.info('sync processing completed.')