From 52fb827f0a5f42f33f952c313b8bcd02009ec928 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Tue, 21 Jul 2020 20:40:19 +0800 Subject: [PATCH] [TD-972] --- src/mnode/inc/mnodeDef.h | 32 +++++++++++++++----------------- src/mnode/src/mnodeSdb.c | 14 ++++++++++---- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/src/mnode/inc/mnodeDef.h b/src/mnode/inc/mnodeDef.h index 3154a441ca..a454f413f0 100644 --- a/src/mnode/inc/mnodeDef.h +++ b/src/mnode/inc/mnodeDef.h @@ -50,8 +50,8 @@ typedef struct SDnodeObj { int8_t alternativeRole; // from dnode status msg, 0-any, 1-mgmt, 2-dnode int8_t status; // set in balance function int8_t isMgmt; - int8_t reserve1[14]; - int8_t updateEnd[1]; + int8_t reserve1[11]; + int8_t updateEnd[4]; int32_t refCount; uint32_t moduleStatus; uint32_t lastReboot; // time stamp for last reboot @@ -68,8 +68,8 @@ typedef struct SMnodeObj { int32_t mnodeId; int8_t reserved0[4]; int64_t createdTime; - int8_t reserved1[7]; - int8_t updateEnd[1]; + int8_t reserved1[4]; + int8_t updateEnd[4]; int32_t refCount; int8_t role; int8_t reserved2[3]; @@ -90,8 +90,7 @@ typedef struct SSuperTableObj { int32_t tversion; int32_t numOfColumns; int32_t numOfTags; - int8_t reserved1[3]; - int8_t updateEnd[1]; + int8_t updateEnd[4]; int32_t refCount; int32_t numOfTables; SSchema * schema; @@ -111,8 +110,7 @@ typedef struct { int32_t sid; int32_t vgId; int32_t sqlLen; - int8_t updateEnd[1]; - int8_t reserved1[1]; + int8_t updateEnd[4]; int32_t refCount; char* sql; //used by normal table SSchema* schema; //used by normal table @@ -138,8 +136,8 @@ typedef struct SVgObj { int8_t status; int8_t reserved0[4]; SVnodeGid vnodeGid[TSDB_MAX_REPLICA]; - int8_t reserved1[7]; - int8_t updateEnd[1]; + int8_t reserved1[4]; + int8_t updateEnd[4]; int32_t refCount; int32_t numOfTables; int64_t totalStorage; @@ -176,8 +174,8 @@ typedef struct SDbObj { int32_t cfgVersion; SDbCfg cfg; int8_t status; - int8_t reserved1[14]; - int8_t updateEnd[1]; + int8_t reserved1[11]; + int8_t updateEnd[4]; int32_t refCount; int32_t numOfVgroups; int32_t numOfTables; @@ -196,8 +194,8 @@ typedef struct SUserObj { int64_t createdTime; int8_t superAuth; int8_t writeAuth; - int8_t reserved[13]; - int8_t updateEnd[1]; + int8_t reserved[10]; + int8_t updateEnd[4]; int32_t refCount; struct SAcctObj * pAcct; } SUserObj; @@ -228,11 +226,11 @@ typedef struct SAcctObj { int64_t createdTime; int32_t acctId; int8_t status; - int8_t reserved0[10]; - int8_t updateEnd[1]; - SAcctInfo acctInfo; + int8_t reserved0[7]; + int8_t updateEnd[4]; int32_t refCount; int8_t reserved1[4]; + SAcctInfo acctInfo; pthread_mutex_t mutex; } SAcctObj; diff --git a/src/mnode/src/mnodeSdb.c b/src/mnode/src/mnodeSdb.c index dee82f53be..26b0f60fcd 100644 --- a/src/mnode/src/mnodeSdb.c +++ b/src/mnode/src/mnodeSdb.c @@ -406,7 +406,7 @@ void sdbDecRef(void *handle, void *pObj) { int32_t refCount = atomic_sub_fetch_32(pRefCount, 1); sdbTrace("def ref of table:%s record:%p:%s:%d", pTable->tableName, pObj, sdbGetKeyStrFromObj(pTable, pObj), *pRefCount); - int8_t *updateEnd = pObj + pTable->refCountPos - 1; + int32_t *updateEnd = pObj + pTable->refCountPos - 4; if (refCount <= 0 && *updateEnd) { sdbTrace("table:%s, record:%p:%s:%d is destroyed", pTable->tableName, pObj, sdbGetKeyStrFromObj(pTable, pObj), *pRefCount); SSdbOper oper = {.pObj = pObj}; @@ -472,6 +472,14 @@ static int32_t sdbInsertHash(SSdbTable *pTable, SSdbOper *pOper) { } static int32_t sdbDeleteHash(SSdbTable *pTable, SSdbOper *pOper) { + int32_t *updateEnd = pOper->pObj + pTable->refCountPos - 4; + bool set = atomic_val_compare_exchange_32(updateEnd, 0, 1) == 0; + if (!set) { + sdbError("table:%s, failed to delete record:%s from hash, for it already removed", pTable->tableName, + sdbGetKeyStrFromObj(pTable, pOper->pObj)); + return TSDB_CODE_MND_SDB_OBJ_NOT_THERE; + } + (*pTable->deleteFp)(pOper); void * key = sdbGetObjKey(pTable, pOper->pObj); @@ -486,8 +494,6 @@ static int32_t sdbDeleteHash(SSdbTable *pTable, SSdbOper *pOper) { sdbDebug("table:%s, delete record:%s from hash, numOfRows:%" PRId64 ", msg:%p", pTable->tableName, sdbGetKeyStrFromObj(pTable, pOper->pObj), pTable->numOfRows, pOper->pMsg); - int8_t *updateEnd = pOper->pObj + pTable->refCountPos - 1; - *updateEnd = 1; sdbDecRef(pTable, pOper->pObj); return TSDB_CODE_SUCCESS; @@ -654,7 +660,7 @@ bool sdbCheckRowDeleted(void *pTableInput, void *pRow) { SSdbTable *pTable = pTableInput; if (pTable == NULL) return false; - int8_t *updateEnd = pRow + pTable->refCountPos - 1; + int32_t *updateEnd = pRow + pTable->refCountPos - 4; return (*updateEnd == 1); } -- GitLab