From 2d3f5274b7fc5fd24979df037b011f93cfe4d463 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Sat, 22 Oct 2022 08:39:43 +0800 Subject: [PATCH] fix: compile error in mac --- source/libs/sync/src/syncAppendEntries.c | 17 ++++----- source/libs/sync/src/syncCommit.c | 6 ++-- source/libs/sync/src/syncMain.c | 46 +++++++++++++----------- source/libs/sync/src/syncMessage.c | 8 ++--- source/libs/sync/src/syncReplication.c | 8 ++--- source/libs/sync/src/syncTimeout.c | 8 ++--- 6 files changed, 50 insertions(+), 43 deletions(-) diff --git a/source/libs/sync/src/syncAppendEntries.c b/source/libs/sync/src/syncAppendEntries.c index 8b037e97b5..5ad36f7f97 100644 --- a/source/libs/sync/src/syncAppendEntries.c +++ b/source/libs/sync/src/syncAppendEntries.c @@ -174,7 +174,7 @@ static int32_t syncNodeDoMakeLogSame(SSyncNode* ths, SyncIndex FromIndex) { do { char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "update delete begin to %ld", delBegin); + snprintf(logBuf, sizeof(logBuf), "update delete begin to %" PRId64, delBegin); syncNodeEventLog(ths, logBuf); } while (0); } @@ -185,7 +185,8 @@ static int32_t syncNodeDoMakeLogSame(SSyncNode* ths, SyncIndex FromIndex) { do { char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "make log same from:%ld, delbegin:%ld, pass:%d", FromIndex, delBegin, pass); + snprintf(logBuf, sizeof(logBuf), "make log same from:%l" PRId64 ", delbegin:%" PRId64 ", pass:%d", FromIndex, + delBegin, pass); syncNodeEventLog(ths, logBuf); } while (0); @@ -371,7 +372,7 @@ int32_t syncNodeOnAppendEntries(SSyncNode* ths, SyncAppendEntries* pMsg) { // do nothing char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "log match, do nothing, index:%ld", appendIndex); + snprintf(logBuf, sizeof(logBuf), "log match, do nothing, index:%" PRId64, appendIndex); syncNodeEventLog(ths, logBuf); } else { @@ -379,7 +380,7 @@ int32_t syncNodeOnAppendEntries(SSyncNode* ths, SyncAppendEntries* pMsg) { code = ths->pLogStore->syncLogTruncate(ths->pLogStore, appendIndex); if (code != 0) { char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "ignore, truncate error, append-index:%ld", appendIndex); + snprintf(logBuf, sizeof(logBuf), "ignore, truncate error, append-index:%" PRId64, appendIndex); syncLogRecvAppendEntries(ths, pMsg, logBuf); goto _IGNORE; @@ -389,7 +390,7 @@ int32_t syncNodeOnAppendEntries(SSyncNode* ths, SyncAppendEntries* pMsg) { code = ths->pLogStore->syncLogAppendEntry(ths->pLogStore, pAppendEntry); if (code != 0) { char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "ignore, append error, append-index:%ld", appendIndex); + snprintf(logBuf, sizeof(logBuf), "ignore, append error, append-index:%" PRId64, appendIndex); syncLogRecvAppendEntries(ths, pMsg, logBuf); goto _IGNORE; @@ -404,7 +405,7 @@ int32_t syncNodeOnAppendEntries(SSyncNode* ths, SyncAppendEntries* pMsg) { code = ths->pLogStore->syncLogTruncate(ths->pLogStore, appendIndex); if (code != 0) { char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "ignore, log not exist, truncate error, append-index:%ld", appendIndex); + snprintf(logBuf, sizeof(logBuf), "ignore, log not exist, truncate error, append-index:%" PRId64, appendIndex); syncLogRecvAppendEntries(ths, pMsg, logBuf); goto _IGNORE; @@ -414,7 +415,7 @@ int32_t syncNodeOnAppendEntries(SSyncNode* ths, SyncAppendEntries* pMsg) { code = ths->pLogStore->syncLogAppendEntry(ths->pLogStore, pAppendEntry); if (code != 0) { char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "ignore, log not exist, append error, append-index:%ld", appendIndex); + snprintf(logBuf, sizeof(logBuf), "ignore, log not exist, append error, append-index:%" PRId64, appendIndex); syncLogRecvAppendEntries(ths, pMsg, logBuf); goto _IGNORE; @@ -423,7 +424,7 @@ int32_t syncNodeOnAppendEntries(SSyncNode* ths, SyncAppendEntries* pMsg) { } else { // error char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "ignore, get local entry error, append-index:%ld", appendIndex); + snprintf(logBuf, sizeof(logBuf), "ignore, get local entry error, append-index:%" PRId64, appendIndex); syncLogRecvAppendEntries(ths, pMsg, logBuf); goto _IGNORE; diff --git a/source/libs/sync/src/syncCommit.c b/source/libs/sync/src/syncCommit.c index b9d7789ca2..811a7b8e99 100644 --- a/source/libs/sync/src/syncCommit.c +++ b/source/libs/sync/src/syncCommit.c @@ -80,7 +80,7 @@ void syncMaybeAdvanceCommitIndex(SSyncNode* pSyncNode) { int32_t code = pSyncNode->pLogStore->syncLogGetEntry(pSyncNode->pLogStore, index, &pEntry); if (code != 0) { char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "advance commit index error, read wal index:%ld", index); + snprintf(logBuf, sizeof(logBuf), "advance commit index error, read wal index:%" PRId64, index); syncNodeErrorLog(pSyncNode, logBuf); return; } @@ -136,8 +136,8 @@ void syncMaybeAdvanceCommitIndex(SSyncNode* pSyncNode) { int32_t code = syncNodeDoCommit(pSyncNode, beginIndex, endIndex, pSyncNode->state); if (code != 0) { char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "advance commit index error, do commit begin:%ld, end:%ld", beginIndex, - endIndex); + snprintf(logBuf, sizeof(logBuf), "advance commit index error, do commit begin:%" PRId64 ", end:%" PRId64, + beginIndex, endIndex); syncNodeErrorLog(pSyncNode, logBuf); return; } diff --git a/source/libs/sync/src/syncMain.c b/source/libs/sync/src/syncMain.c index 4ca137d8b1..be6b0d4d0f 100644 --- a/source/libs/sync/src/syncMain.c +++ b/source/libs/sync/src/syncMain.c @@ -339,7 +339,7 @@ char* syncNodePeerState2Str(const SSyncNode* pSyncNode) { ASSERT(pState != NULL); p = pStr + useLen; - use = snprintf(p, leftLen, "%d:%ld,%ld, ", i, pState->lastSendIndex, pState->lastSendTime); + use = snprintf(p, leftLen, "%d:%" PRId64 " ,%" PRId64, i, pState->lastSendIndex, pState->lastSendTime); useLen += use; leftLen -= use; } @@ -374,8 +374,9 @@ int32_t syncBeginSnapshot(int64_t rid, int64_t lastApplyIndex) { if (isEmpty || (!isEmpty && logNum < logRetention)) { char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), "new-snapshot-index:%ld, log-num:%ld, empty:%d, do not delete wal", - lastApplyIndex, logNum, isEmpty); + snprintf(logBuf, sizeof(logBuf), + "new-snapshot-index:%" PRId64 ", log-num:%" PRId64 ", empty:%d, do not delete wal", lastApplyIndex, + logNum, isEmpty); syncNodeEventLog(pSyncNode, logBuf); taosReleaseRef(tsNodeRefId, pSyncNode->rid); @@ -401,7 +402,8 @@ int32_t syncBeginSnapshot(int64_t rid, int64_t lastApplyIndex) { syncUtilU642Addr(pSyncNode->peersId[i].addr, host, sizeof(host), &port); char logBuf[256]; snprintf(logBuf, sizeof(logBuf), - "new-snapshot-index:%ld is greater than match-index:%ld of %s:%d, do not delete wal", + "new-snapshot-index:%" PRId64 " is greater than match-index:%" PRId64 + " of %s:%d, do not delete wal", lastApplyIndex, matchIndex, host, port); syncNodeEventLog(pSyncNode, logBuf); } while (0); @@ -415,8 +417,8 @@ int32_t syncBeginSnapshot(int64_t rid, int64_t lastApplyIndex) { if (lastApplyIndex > pSyncNode->minMatchIndex) { char logBuf[256]; snprintf(logBuf, sizeof(logBuf), - "new-snapshot-index:%ld is greater than min-match-index:%ld, do not delete wal", lastApplyIndex, - pSyncNode->minMatchIndex); + "new-snapshot-index:%" PRId64 " is greater than min-match-index:%" PRId64 ", do not delete wal", + lastApplyIndex, pSyncNode->minMatchIndex); syncNodeEventLog(pSyncNode, logBuf); taosReleaseRef(tsNodeRefId, pSyncNode->rid); @@ -425,7 +427,7 @@ int32_t syncBeginSnapshot(int64_t rid, int64_t lastApplyIndex) { } else if (pSyncNode->state == TAOS_SYNC_STATE_CANDIDATE) { char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), "new-snapshot-index:%ld candidate, do not delete wal", lastApplyIndex); + snprintf(logBuf, sizeof(logBuf), "new-snapshot-index:%" PRId64 " candidate, do not delete wal", lastApplyIndex); syncNodeEventLog(pSyncNode, logBuf); taosReleaseRef(tsNodeRefId, pSyncNode->rid); @@ -433,7 +435,8 @@ int32_t syncBeginSnapshot(int64_t rid, int64_t lastApplyIndex) { } else { char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), "new-snapshot-index:%ld unknown state, do not delete wal", lastApplyIndex); + snprintf(logBuf, sizeof(logBuf), "new-snapshot-index:%" PRId64 " unknown state, do not delete wal", + lastApplyIndex); syncNodeEventLog(pSyncNode, logBuf); taosReleaseRef(tsNodeRefId, pSyncNode->rid); @@ -462,14 +465,15 @@ _DEL_WAL: code = walBeginSnapshot(pData->pWal, lastApplyIndex); if (code == 0) { char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), "wal snapshot begin, index:%ld, last apply index:%ld", + snprintf(logBuf, sizeof(logBuf), "wal snapshot begin, index:%" PRId64 ", last apply index:%" PRId64, pSyncNode->snapshottingIndex, lastApplyIndex); syncNodeEventLog(pSyncNode, logBuf); } else { char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), "wal snapshot begin error since:%s, index:%ld, last apply index:%ld", - terrstr(terrno), pSyncNode->snapshottingIndex, lastApplyIndex); + snprintf(logBuf, sizeof(logBuf), + "wal snapshot begin error since:%s, index:%" PRId64 ", last apply index:%" PRId64, terrstr(terrno), + pSyncNode->snapshottingIndex, lastApplyIndex); syncNodeErrorLog(pSyncNode, logBuf); atomic_store_64(&pSyncNode->snapshottingIndex, SYNC_INDEX_INVALID); @@ -477,8 +481,9 @@ _DEL_WAL: } else { char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), "snapshotting for %ld, do not delete wal for new-snapshot-index:%ld", - snapshottingIndex, lastApplyIndex); + snprintf(logBuf, sizeof(logBuf), + "snapshotting for %" PRId64 ", do not delete wal for new-snapshot-index:%" PRId64, snapshottingIndex, + lastApplyIndex); syncNodeEventLog(pSyncNode, logBuf); } } while (0); @@ -507,7 +512,8 @@ int32_t syncEndSnapshot(int64_t rid) { } else { do { char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), "wal snapshot end, index:%ld", atomic_load_64(&pSyncNode->snapshottingIndex)); + snprintf(logBuf, sizeof(logBuf), "wal snapshot end, index:%" PRId64, + atomic_load_64(&pSyncNode->snapshottingIndex)); syncNodeEventLog(pSyncNode, logBuf); } while (0); @@ -989,8 +995,8 @@ int32_t syncNodePropose(SSyncNode* pSyncNode, SRpcMsg* pMsg, bool isWeak) { if (!pSyncNode->restoreFinish && pSyncNode->vgId != 1) { ret = -1; terrno = TSDB_CODE_SYN_PROPOSE_NOT_READY; - sError("vgId:%d, failed to sync propose since not ready, type:%s, last:%ld, cmt:%ld", pSyncNode->vgId, - TMSG_INFO(pMsg->msgType), syncNodeGetLastIndex(pSyncNode), pSyncNode->commitIndex); + sError("vgId:%d, failed to sync propose since not ready, type:%s, last:%" PRId64 ", cmt:%" PRId64, + pSyncNode->vgId, TMSG_INFO(pMsg->msgType), syncNodeGetLastIndex(pSyncNode), pSyncNode->commitIndex); goto _END; } @@ -3144,7 +3150,7 @@ int32_t syncDoLeaderTransfer(SSyncNode* ths, SRpcMsg* pRpcMsg, SSyncRaftEntry* p if (pEntry->index < syncNodeGetLastIndex(ths)) { char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "little index:%ld, can not do leader transfer", pEntry->index); + snprintf(logBuf, sizeof(logBuf), "little index:%" PRId64, can not do leader transfer", pEntry->index); syncNodeEventLog(ths, logBuf); return 0; } @@ -3160,7 +3166,7 @@ int32_t syncDoLeaderTransfer(SSyncNode* ths, SRpcMsg* pRpcMsg, SSyncRaftEntry* p do { char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "do leader transfer, index:%ld", pEntry->index); + snprintf(logBuf, sizeof(logBuf), "do leader transfer, index:%" PRId64, pEntry->index); syncNodeEventLog(ths, logBuf); } while (0); @@ -3416,8 +3422,8 @@ int32_t syncNodeDoCommit(SSyncNode* ths, SyncIndex beginIndex, SyncIndex endInde int64_t restoreDelay = taosGetTimestampMs() - ths->leaderTime; char eventLog[128]; - snprintf(eventLog, sizeof(eventLog), "restore finish, index:%ld, elapsed:%ld ms, ", pEntry->index, - restoreDelay); + snprintf(eventLog, sizeof(eventLog), "restore finish, index:%" PRId64 ", elapsed:%" PRId64 " ms, ", + pEntry->index, restoreDelay); syncNodeEventLog(ths, eventLog); } } diff --git a/source/libs/sync/src/syncMessage.c b/source/libs/sync/src/syncMessage.c index 7c871d0542..a4913d2854 100644 --- a/source/libs/sync/src/syncMessage.c +++ b/source/libs/sync/src/syncMessage.c @@ -1400,28 +1400,28 @@ char* syncRequestVoteReply2Str(const SyncRequestVoteReply* pMsg) { // for debug ---------------------- void syncRequestVoteReplyPrint(const SyncRequestVoteReply* pMsg) { char* serialized = syncRequestVoteReply2Str(pMsg); - printf("syncRequestVoteReplyPrint | len:%ld | %s \n", strlen(serialized), serialized); + printf("syncRequestVoteReplyPrint | len:%" PRId64 " | %s \n", strlen(serialized), serialized); fflush(NULL); taosMemoryFree(serialized); } void syncRequestVoteReplyPrint2(char* s, const SyncRequestVoteReply* pMsg) { char* serialized = syncRequestVoteReply2Str(pMsg); - printf("syncRequestVoteReplyPrint2 | len:%ld | %s | %s \n", strlen(serialized), s, serialized); + printf("syncRequestVoteReplyPrint2 | len:%" PRId64 " | %s | %s \n", strlen(serialized), s, serialized); fflush(NULL); taosMemoryFree(serialized); } void syncRequestVoteReplyLog(const SyncRequestVoteReply* pMsg) { char* serialized = syncRequestVoteReply2Str(pMsg); - sTrace("syncRequestVoteReplyLog | len:%ld | %s", strlen(serialized), serialized); + sTrace("syncRequestVoteReplyLog | len:%" PRId64 " | %s", strlen(serialized), serialized); taosMemoryFree(serialized); } void syncRequestVoteReplyLog2(char* s, const SyncRequestVoteReply* pMsg) { if (gRaftDetailLog) { char* serialized = syncRequestVoteReply2Str(pMsg); - sTrace("syncRequestVoteReplyLog2 | len:%ld | %s | %s", strlen(serialized), s, serialized); + sTrace("syncRequestVoteReplyLog2 | len:%" PRId64 " | %s | %s", strlen(serialized), s, serialized); taosMemoryFree(serialized); } } diff --git a/source/libs/sync/src/syncReplication.c b/source/libs/sync/src/syncReplication.c index 4231033e5d..e040310e15 100644 --- a/source/libs/sync/src/syncReplication.c +++ b/source/libs/sync/src/syncReplication.c @@ -57,8 +57,8 @@ int32_t syncNodeReplicateOne(SSyncNode* pSyncNode, SRaftId* pDestId) { SyncIndex logEndIndex = pSyncNode->pLogStore->syncLogEndIndex(pSyncNode->pLogStore); if (nextIndex < logStartIndex || nextIndex - 1 > logEndIndex) { char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "start snapshot for next-index:%ld, start:%ld, end:%ld", nextIndex, logStartIndex, - logEndIndex); + snprintf(logBuf, sizeof(logBuf), "start snapshot for next-index:%" PRId64 ", start:%" PRId64 ", end:%" PRId64, + nextIndex, logStartIndex, logEndIndex); syncNodeEventLog(pSyncNode, logBuf); // start snapshot @@ -105,7 +105,7 @@ int32_t syncNodeReplicateOne(SSyncNode* pSyncNode, SRaftId* pDestId) { syncUtilU642Addr(pDestId->addr, host, sizeof(host), &port); char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "replicate to %s:%d error, next-index:%ld", host, port, nextIndex); + snprintf(logBuf, sizeof(logBuf), "replicate to %s:%d error, next-index:%" PRId64, host, port, nextIndex); syncNodeErrorLog(pSyncNode, logBuf); } while (0); @@ -184,7 +184,7 @@ int32_t syncNodeMaybeSendAppendEntries(SSyncNode* pSyncNode, const SRaftId* dest int16_t port; syncUtilU642Addr(destRaftId->addr, host, sizeof(host), &port); - snprintf(logBuf, sizeof(logBuf), "do not repcate to %s:%d for index:%ld", host, port, pMsg->prevLogIndex + 1); + snprintf(logBuf, sizeof(logBuf), "do not repcate to %s:%d for index:%" PRId64, host, port, pMsg->prevLogIndex + 1); syncNodeEventLog(pSyncNode, logBuf); } diff --git a/source/libs/sync/src/syncTimeout.c b/source/libs/sync/src/syncTimeout.c index 447d975ded..1a19c0fb16 100644 --- a/source/libs/sync/src/syncTimeout.c +++ b/source/libs/sync/src/syncTimeout.c @@ -81,7 +81,7 @@ int32_t syncNodeTimerRoutine(SSyncNode* ths) { } else { do { char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), "wal snapshot end, index:%ld", atomic_load_64(&ths->snapshottingIndex)); + snprintf(logBuf, sizeof(logBuf), "wal snapshot end, index:%" PRId64, atomic_load_64(&ths->snapshottingIndex)); syncNodeEventLog(ths, logBuf); } while (0); @@ -115,7 +115,7 @@ int32_t syncNodeOnTimer(SSyncNode* ths, SyncTimeout* pMsg) { } else if (pMsg->timeoutType == SYNC_TIMEOUT_ELECTION) { if (atomic_load_64(&ths->electTimerLogicClockUser) <= pMsg->logicClock) { ++(ths->electTimerCounter); - sTrace("vgId:%d, sync timer, type:election count:%lu, lc-user:%ld", ths->vgId, ths->electTimerCounter, + sTrace("vgId:%d, sync timer, type:election count:%lu, lc-user:%" PRId64, ths->vgId, ths->electTimerCounter, ths->electTimerLogicClockUser); syncNodeElect(ths); @@ -124,8 +124,8 @@ int32_t syncNodeOnTimer(SSyncNode* ths, SyncTimeout* pMsg) { } else if (pMsg->timeoutType == SYNC_TIMEOUT_HEARTBEAT) { if (atomic_load_64(&ths->heartbeatTimerLogicClockUser) <= pMsg->logicClock) { ++(ths->heartbeatTimerCounter); - sTrace("vgId:%d, sync timer, type:replicate count:%lu, lc-user:%ld", ths->vgId, ths->heartbeatTimerCounter, - ths->heartbeatTimerLogicClockUser); + sTrace("vgId:%d, sync timer, type:replicate count:%" PRIu64 ", lc-user:%" PRId64, ths->vgId, + ths->heartbeatTimerCounter, ths->heartbeatTimerLogicClockUser); // syncNodeReplicate(ths, true); } -- GitLab