From e04fa907bb0e65e0832b6df987c9b98deab2bb3c Mon Sep 17 00:00:00 2001 From: zhouwenbin_db <506739837@qq.com> Date: Fri, 18 Nov 2022 08:38:03 +0000 Subject: [PATCH] =?UTF-8?q?CM=E5=90=8C=E6=AD=A5dn=E8=87=AA=E5=A2=9E?= =?UTF-8?q?=E7=9A=84term?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cms_arbitrate_datanode_pms_utils.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/cm_server/cms_arbitrate_datanode_pms_utils.cpp b/src/cm_server/cms_arbitrate_datanode_pms_utils.cpp index 4ab2626..dc5e4d6 100644 --- a/src/cm_server/cms_arbitrate_datanode_pms_utils.cpp +++ b/src/cm_server/cms_arbitrate_datanode_pms_utils.cpp @@ -24,6 +24,7 @@ #include "cms_arbitrate_datanode_pms_utils.h" #include "cms_az.h" #include "cms_process_messages.h" +#include "cms_ddb.h" /** * @brief @@ -237,6 +238,20 @@ void InitDnArbitInfo(DnArbitInfo *info) info->staRoleIndex = -1; } +void UpdateGlobalTermByMaxTerm(uint32 maxTerm) +{ + (void)pthread_rwlock_wrlock(&term_update_rwlock); + uint32 currentTerm = g_dynamic_header->term; + if (maxTerm > currentTerm) { + currentTerm = maxTerm + CM_INCREMENT_TERM_VALUE; + write_runlog(LOG, "global term %u is smaller than instance maxterm %u, update global term to %u\n", + g_dynamic_header->term, maxTerm, currentTerm); + g_dynamic_header->term = currentTerm; + (void)SetTermToDdb(currentTerm); + } + (void)pthread_rwlock_unlock(&term_update_rwlock); +} + void GetDnArbitInfo(uint32 groupIdx, DnArbitInfo *info) { int32 count = GetInstanceCountsInGroup(groupIdx); @@ -254,6 +269,8 @@ void GetDnArbitInfo(uint32 groupIdx, DnArbitInfo *info) info->switchoverIdx = i; } } + /* term may increment without cm, the global term needs to be synchronized */ + UpdateGlobalTermByMaxTerm(info->maxTerm); } uint32 GetInstanceTerm(uint32 groupIndex, int memberIndex)