From ac5119208471cc29f83d9ace35b7ab6990216850 Mon Sep 17 00:00:00 2001 From: Minghao Li Date: Thu, 21 Jul 2022 13:54:24 +0800 Subject: [PATCH] refactor(sync): add trace log --- source/libs/sync/src/syncAppendEntries.c | 12 ++--- source/libs/sync/test/sh/a.sh | 58 ++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 6 deletions(-) create mode 100644 source/libs/sync/test/sh/a.sh diff --git a/source/libs/sync/src/syncAppendEntries.c b/source/libs/sync/src/syncAppendEntries.c index 50c66172da..4295abeaa1 100644 --- a/source/libs/sync/src/syncAppendEntries.c +++ b/source/libs/sync/src/syncAppendEntries.c @@ -473,13 +473,13 @@ static bool syncNodeOnAppendEntriesBatchLogOK(SSyncNode* pSyncNode, SyncAppendEn SyncIndex myLastIndex = syncNodeGetLastIndex(pSyncNode); if (pMsg->prevLogIndex > myLastIndex) { - sDebug("vgId:%d sync log not ok, preindex:%" PRId64, pSyncNode->vgId, pMsg->prevLogIndex); + sDebug("vgId:%d, sync log not ok, preindex:%" PRId64, pSyncNode->vgId, pMsg->prevLogIndex); return false; } SyncTerm myPreLogTerm = syncNodeGetPreTerm(pSyncNode, pMsg->prevLogIndex + 1); if (myPreLogTerm == SYNC_TERM_INVALID) { - sDebug("vgId:%d sync log not ok2, preindex:%" PRId64, pSyncNode->vgId, pMsg->prevLogIndex); + sDebug("vgId:%d, sync log not ok2, preindex:%" PRId64, pSyncNode->vgId, pMsg->prevLogIndex); return false; } @@ -487,7 +487,7 @@ static bool syncNodeOnAppendEntriesBatchLogOK(SSyncNode* pSyncNode, SyncAppendEn return true; } - sDebug("vgId:%d sync log not ok3, preindex:%" PRId64, pSyncNode->vgId, pMsg->prevLogIndex); + sDebug("vgId:%d, sync log not ok3, preindex:%" PRId64, pSyncNode->vgId, pMsg->prevLogIndex); return false; } @@ -500,13 +500,13 @@ static bool syncNodeOnAppendEntriesLogOK(SSyncNode* pSyncNode, SyncAppendEntries SyncIndex myLastIndex = syncNodeGetLastIndex(pSyncNode); if (pMsg->prevLogIndex > myLastIndex) { - sDebug("vgId:%d sync log not ok, preindex:%" PRId64, pSyncNode->vgId, pMsg->prevLogIndex); + sDebug("vgId:%d, sync log not ok, preindex:%" PRId64, pSyncNode->vgId, pMsg->prevLogIndex); return false; } SyncTerm myPreLogTerm = syncNodeGetPreTerm(pSyncNode, pMsg->prevLogIndex + 1); if (myPreLogTerm == SYNC_TERM_INVALID) { - sDebug("vgId:%d sync log not ok2, preindex:%" PRId64, pSyncNode->vgId, pMsg->prevLogIndex); + sDebug("vgId:%d, sync log not ok2, preindex:%" PRId64, pSyncNode->vgId, pMsg->prevLogIndex); return false; } @@ -514,7 +514,7 @@ static bool syncNodeOnAppendEntriesLogOK(SSyncNode* pSyncNode, SyncAppendEntries return true; } - sDebug("vgId:%d sync log not ok3, preindex:%" PRId64, pSyncNode->vgId, pMsg->prevLogIndex); + sDebug("vgId:%d, sync log not ok3, preindex:%" PRId64, pSyncNode->vgId, pMsg->prevLogIndex); return false; } diff --git a/source/libs/sync/test/sh/a.sh b/source/libs/sync/test/sh/a.sh new file mode 100644 index 0000000000..b2d8f88809 --- /dev/null +++ b/source/libs/sync/test/sh/a.sh @@ -0,0 +1,58 @@ +#!/bin/bash + +if [ $# != 1 ] ; then + echo "Uasge: $0 log-path" + echo "" + exit 1 +fi + +logpath=$1 +echo "logpath: ${logpath}" + +echo "" +echo "clean old log ..." +rm -f ${logpath}/log.* + +echo "" +echo "generate log.dnode ..." +for dnode in `ls ${logpath} | grep dnode`;do + echo "generate log.${dnode}" + cat ${logpath}/${dnode}/log/taosdlog.* | grep SYN > ${logpath}/log.${dnode} +done + +echo "" +echo "generate vgId ..." +cat ${logpath}/log.dnode* | grep "vgId:" | grep -v ERROR | awk '{print $5}' | sort | uniq > ${logpath}/log.vgIds.tmp +echo "all vgIds:" > ${logpath}/log.vgIds +cat ${logpath}/log.dnode* | grep "vgId:" | grep -v ERROR | awk '{print $5}' | sort | uniq >> ${logpath}/log.vgIds +for dnode in `ls ${logpath} | grep dnode | grep -v log`;do + echo "" >> ${logpath}/log.vgIds + echo "" >> ${logpath}/log.vgIds + echo "${dnode}:" >> ${logpath}/log.vgIds + cat ${logpath}/${dnode}/log/taosdlog.* | grep SYN | grep "vgId:" | grep -v ERROR | awk '{print $5}' | sort | uniq >> ${logpath}/log.vgIds +done + +echo "" +echo "generate log.dnode.vgId ..." +for logdnode in `ls ${logpath}/log.dnode*`;do + for vgId in `cat ${logpath}/log.vgIds.tmp`;do + rowNum=`cat ${logdnode} | grep "${vgId}" | awk 'BEGIN{rowNum=0}{rowNum++}END{print rowNum}'` + #echo "-----${rowNum}" + if [ $rowNum -gt 0 ] ; then + echo "generate ${logdnode}.${vgId}" + cat ${logdnode} | grep "${vgId}" > ${logdnode}.${vgId} + fi + done +done + +echo "" +echo "generate log.dnode.main ..." +for file in `ls ${logpath}/log.dnode* | grep -v vgId`;do + echo "generate ${file}.main" + cat ${file} | awk '{ if(index($0, "sync open") > 0 || index($0, "sync close") > 0 || index($0, "become leader") > 0) {print $0} }' > ${file}.main +done + + + + +exit 0 -- GitLab