Merge pull request #5486 from taosdata/feature/linux
[TD-3355]<fix>: Fix invalid table id problem caused by idpool
This commit is contained in:
commit
af2f6bb02c
|
@ -44,7 +44,7 @@ void mnodeDropVgroup(SVgObj *pVgroup, void *ahandle);
|
||||||
void mnodeAlterVgroup(SVgObj *pVgroup, void *ahandle);
|
void mnodeAlterVgroup(SVgObj *pVgroup, void *ahandle);
|
||||||
int32_t mnodeGetAvailableVgroup(struct SMnodeMsg *pMsg, SVgObj **pVgroup, int32_t *sid);
|
int32_t mnodeGetAvailableVgroup(struct SMnodeMsg *pMsg, SVgObj **pVgroup, int32_t *sid);
|
||||||
|
|
||||||
void mnodeAddTableIntoVgroup(SVgObj *pVgroup, SCTableObj *pTable);
|
int32_t mnodeAddTableIntoVgroup(SVgObj *pVgroup, SCTableObj *pTable, bool needCheck);
|
||||||
void mnodeRemoveTableFromVgroup(SVgObj *pVgroup, SCTableObj *pTable);
|
void mnodeRemoveTableFromVgroup(SVgObj *pVgroup, SCTableObj *pTable);
|
||||||
void mnodeSendDropVnodeMsg(int32_t vgId, SRpcEpSet *epSet, void *ahandle);
|
void mnodeSendDropVnodeMsg(int32_t vgId, SRpcEpSet *epSet, void *ahandle);
|
||||||
void mnodeSendCreateVgroupMsg(SVgObj *pVgroup, void *ahandle);
|
void mnodeSendCreateVgroupMsg(SVgObj *pVgroup, void *ahandle);
|
||||||
|
|
|
@ -552,7 +552,7 @@ static int32_t sdbInsertHash(SSdbTable *pTable, SSdbRow *pRow) {
|
||||||
|
|
||||||
int32_t code = (*pTable->fpInsert)(pRow);
|
int32_t code = (*pTable->fpInsert)(pRow);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
sdbError("vgId:1, sdb:%s, failed to insert key:%s to hash, remove it", pTable->name,
|
sdbError("vgId:1, sdb:%s, failed to perform insert action for key:%s, remove it", pTable->name,
|
||||||
sdbGetRowStr(pTable, pRow->pObj));
|
sdbGetRowStr(pTable, pRow->pObj));
|
||||||
sdbDeleteHash(pTable, pRow);
|
sdbDeleteHash(pTable, pRow);
|
||||||
}
|
}
|
||||||
|
|
|
@ -108,10 +108,12 @@ static int32_t mnodeChildTableActionDestroy(SSdbRow *pRow) {
|
||||||
|
|
||||||
static int32_t mnodeChildTableActionInsert(SSdbRow *pRow) {
|
static int32_t mnodeChildTableActionInsert(SSdbRow *pRow) {
|
||||||
SCTableObj *pTable = pRow->pObj;
|
SCTableObj *pTable = pRow->pObj;
|
||||||
|
int32_t code = 0;
|
||||||
|
|
||||||
SVgObj *pVgroup = mnodeGetVgroup(pTable->vgId);
|
SVgObj *pVgroup = mnodeGetVgroup(pTable->vgId);
|
||||||
if (pVgroup == NULL) {
|
if (pVgroup == NULL) {
|
||||||
mError("ctable:%s, not in vgId:%d", pTable->info.tableId, pTable->vgId);
|
mError("ctable:%s, not in vgId:%d", pTable->info.tableId, pTable->vgId);
|
||||||
|
code = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDbObj *pDb = NULL;
|
SDbObj *pDb = NULL;
|
||||||
|
@ -119,6 +121,7 @@ static int32_t mnodeChildTableActionInsert(SSdbRow *pRow) {
|
||||||
pDb = mnodeGetDb(pVgroup->dbName);
|
pDb = mnodeGetDb(pVgroup->dbName);
|
||||||
if (pDb == NULL) {
|
if (pDb == NULL) {
|
||||||
mError("ctable:%s, vgId:%d not in db:%s", pTable->info.tableId, pVgroup->vgId, pVgroup->dbName);
|
mError("ctable:%s, vgId:%d not in db:%s", pTable->info.tableId, pVgroup->vgId, pVgroup->dbName);
|
||||||
|
code = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,6 +130,7 @@ static int32_t mnodeChildTableActionInsert(SSdbRow *pRow) {
|
||||||
pAcct = mnodeGetAcct(pDb->acct);
|
pAcct = mnodeGetAcct(pDb->acct);
|
||||||
if (pAcct == NULL) {
|
if (pAcct == NULL) {
|
||||||
mError("ctable:%s, acct:%s not exists", pTable->info.tableId, pDb->acct);
|
mError("ctable:%s, acct:%s not exists", pTable->info.tableId, pDb->acct);
|
||||||
|
code = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,6 +143,7 @@ static int32_t mnodeChildTableActionInsert(SSdbRow *pRow) {
|
||||||
if (pAcct) pAcct->acctInfo.numOfTimeSeries += (pTable->superTable->numOfColumns - 1);
|
if (pAcct) pAcct->acctInfo.numOfTimeSeries += (pTable->superTable->numOfColumns - 1);
|
||||||
} else {
|
} else {
|
||||||
mError("table:%s:%p, correspond stable not found suid:%" PRIu64, pTable->info.tableId, pTable, pTable->suid);
|
mError("table:%s:%p, correspond stable not found suid:%" PRIu64, pTable->info.tableId, pTable, pTable->suid);
|
||||||
|
code = -1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
grantAdd(TSDB_GRANT_TIMESERIES, pTable->numOfColumns - 1);
|
grantAdd(TSDB_GRANT_TIMESERIES, pTable->numOfColumns - 1);
|
||||||
|
@ -146,18 +151,31 @@ static int32_t mnodeChildTableActionInsert(SSdbRow *pRow) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pDb) mnodeAddTableIntoDb(pDb);
|
if (pDb) mnodeAddTableIntoDb(pDb);
|
||||||
if (pVgroup) mnodeAddTableIntoVgroup(pVgroup, pTable);
|
if (pVgroup) {
|
||||||
|
if (mnodeAddTableIntoVgroup(pVgroup, pTable, pRow->pMsg == NULL) != 0) {
|
||||||
|
mError("table:%s, vgId:%d tid:%d, failed to perform insert action, uid:%" PRIu64 " suid:%" PRIu64,
|
||||||
|
pTable->info.tableId, pTable->vgId, pTable->tid, pTable->uid, pTable->suid);
|
||||||
|
code = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
mnodeDecVgroupRef(pVgroup);
|
mnodeDecVgroupRef(pVgroup);
|
||||||
mnodeDecDbRef(pDb);
|
mnodeDecDbRef(pDb);
|
||||||
mnodeDecAcctRef(pAcct);
|
mnodeDecAcctRef(pAcct);
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
if (code == 0) {
|
||||||
|
mTrace("table:%s, vgId:%d tid:%d, perform insert action, uid:%" PRIu64 " suid:%" PRIu64, pTable->info.tableId,
|
||||||
|
pTable->vgId, pTable->tid, pTable->uid, pTable->suid);
|
||||||
|
}
|
||||||
|
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mnodeChildTableActionDelete(SSdbRow *pRow) {
|
static int32_t mnodeChildTableActionDelete(SSdbRow *pRow) {
|
||||||
SCTableObj *pTable = pRow->pObj;
|
SCTableObj *pTable = pRow->pObj;
|
||||||
if (pTable->vgId == 0) {
|
if (pTable->vgId == 0) {
|
||||||
|
mError("table:%s, vgId:%d tid:%d, failed to perform delete action, uid:%" PRIu64 " suid:%" PRIu64,
|
||||||
|
pTable->info.tableId, pTable->vgId, pTable->tid, pTable->uid, pTable->suid);
|
||||||
return TSDB_CODE_MND_VGROUP_NOT_EXIST;
|
return TSDB_CODE_MND_VGROUP_NOT_EXIST;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -188,6 +206,8 @@ static int32_t mnodeChildTableActionDelete(SSdbRow *pRow) {
|
||||||
mnodeDecDbRef(pDb);
|
mnodeDecDbRef(pDb);
|
||||||
mnodeDecAcctRef(pAcct);
|
mnodeDecAcctRef(pAcct);
|
||||||
|
|
||||||
|
mTrace("table:%s, vgId:%d tid:%d, perform delete action, uid:%" PRIu64 " suid:%" PRIu64, pTable->info.tableId,
|
||||||
|
pTable->vgId, pTable->tid, pTable->uid, pTable->suid);
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -399,13 +419,13 @@ static void mnodeAddTableIntoStable(SSTableObj *pStable, SCTableObj *pCtable) {
|
||||||
|
|
||||||
if (pStable->vgHash == NULL) {
|
if (pStable->vgHash == NULL) {
|
||||||
pStable->vgHash = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_ENTRY_LOCK);
|
pStable->vgHash = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_ENTRY_LOCK);
|
||||||
mDebug("table:%s, create hash:%p", pStable->info.tableId, pStable->vgHash);
|
mDebug("stable:%s, create vgId hash:%p", pStable->info.tableId, pStable->vgHash);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pStable->vgHash != NULL) {
|
if (pStable->vgHash != NULL) {
|
||||||
if (taosHashGet(pStable->vgHash, &pCtable->vgId, sizeof(pCtable->vgId)) == NULL) {
|
if (taosHashGet(pStable->vgHash, &pCtable->vgId, sizeof(pCtable->vgId)) == NULL) {
|
||||||
taosHashPut(pStable->vgHash, &pCtable->vgId, sizeof(pCtable->vgId), &pCtable->vgId, sizeof(pCtable->vgId));
|
taosHashPut(pStable->vgHash, &pCtable->vgId, sizeof(pCtable->vgId), &pCtable->vgId, sizeof(pCtable->vgId));
|
||||||
mDebug("table:%s, vgId:%d is put into stable hash:%p, sizeOfVgList:%d", pStable->info.tableId, pCtable->vgId,
|
mDebug("stable:%s, vgId:%d is put into stable vgId hash:%p, sizeOfVgList:%d", pStable->info.tableId, pCtable->vgId,
|
||||||
pStable->vgHash, taosHashGetSize(pStable->vgHash));
|
pStable->vgHash, taosHashGetSize(pStable->vgHash));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -443,19 +463,21 @@ static int32_t mnodeSuperTableActionDestroy(SSdbRow *pRow) {
|
||||||
|
|
||||||
static int32_t mnodeSuperTableActionInsert(SSdbRow *pRow) {
|
static int32_t mnodeSuperTableActionInsert(SSdbRow *pRow) {
|
||||||
SSTableObj *pStable = pRow->pObj;
|
SSTableObj *pStable = pRow->pObj;
|
||||||
SDbObj *pDb = mnodeGetDbByTableName(pStable->info.tableId);
|
SDbObj * pDb = mnodeGetDbByTableName(pStable->info.tableId);
|
||||||
if (pDb != NULL && pDb->status == TSDB_DB_STATUS_READY) {
|
if (pDb != NULL && pDb->status == TSDB_DB_STATUS_READY) {
|
||||||
mnodeAddSuperTableIntoDb(pDb);
|
mnodeAddSuperTableIntoDb(pDb);
|
||||||
}
|
}
|
||||||
mnodeDecDbRef(pDb);
|
mnodeDecDbRef(pDb);
|
||||||
|
|
||||||
taosHashPut(tsSTableUidHash, &pStable->uid, sizeof(int64_t), &pStable, sizeof(int64_t));
|
taosHashPut(tsSTableUidHash, &pStable->uid, sizeof(int64_t), &pStable, sizeof(int64_t));
|
||||||
|
|
||||||
|
mTrace("stable:%s, perform insert action, uid:%" PRIu64, pStable->info.tableId, pStable->uid);
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mnodeSuperTableActionDelete(SSdbRow *pRow) {
|
static int32_t mnodeSuperTableActionDelete(SSdbRow *pRow) {
|
||||||
SSTableObj *pStable = pRow->pObj;
|
SSTableObj *pStable = pRow->pObj;
|
||||||
SDbObj *pDb = mnodeGetDbByTableName(pStable->info.tableId);
|
SDbObj * pDb = mnodeGetDbByTableName(pStable->info.tableId);
|
||||||
if (pDb != NULL) {
|
if (pDb != NULL) {
|
||||||
mnodeRemoveSuperTableFromDb(pDb);
|
mnodeRemoveSuperTableFromDb(pDb);
|
||||||
mnodeDropAllChildTablesInStable((SSTableObj *)pStable);
|
mnodeDropAllChildTablesInStable((SSTableObj *)pStable);
|
||||||
|
@ -463,6 +485,8 @@ static int32_t mnodeSuperTableActionDelete(SSdbRow *pRow) {
|
||||||
mnodeDecDbRef(pDb);
|
mnodeDecDbRef(pDb);
|
||||||
|
|
||||||
taosHashRemove(tsSTableUidHash, &pStable->uid, sizeof(int64_t));
|
taosHashRemove(tsSTableUidHash, &pStable->uid, sizeof(int64_t));
|
||||||
|
|
||||||
|
mTrace("stable:%s, perform delete action, uid:%" PRIu64, pStable->info.tableId, pStable->uid);
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1888,15 +1912,14 @@ static int32_t mnodeDoCreateChildTableCb(SMnodeMsg *pMsg, int32_t code) {
|
||||||
pMsg->rpcMsg.handle);
|
pMsg->rpcMsg.handle);
|
||||||
|
|
||||||
if (pMsg->pBatchMasterMsg) {
|
if (pMsg->pBatchMasterMsg) {
|
||||||
++pMsg->pBatchMasterMsg->successed;
|
++pMsg->pBatchMasterMsg->successed;
|
||||||
if (pMsg->pBatchMasterMsg->successed + pMsg->pBatchMasterMsg->received
|
if (pMsg->pBatchMasterMsg->successed + pMsg->pBatchMasterMsg->received >= pMsg->pBatchMasterMsg->expected) {
|
||||||
>= pMsg->pBatchMasterMsg->expected) {
|
dnodeSendRpcMWriteRsp(pMsg->pBatchMasterMsg, code);
|
||||||
dnodeSendRpcMWriteRsp(pMsg->pBatchMasterMsg, code);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
mnodeDestroySubMsg(pMsg);
|
mnodeDestroySubMsg(pMsg);
|
||||||
|
|
||||||
return TSDB_CODE_MND_ACTION_IN_PROGRESS;
|
return TSDB_CODE_MND_ACTION_IN_PROGRESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
dnodeSendRpcMWriteRsp(pMsg, TSDB_CODE_SUCCESS);
|
dnodeSendRpcMWriteRsp(pMsg, TSDB_CODE_SUCCESS);
|
||||||
|
@ -1911,9 +1934,8 @@ static int32_t mnodeDoCreateChildTableCb(SMnodeMsg *pMsg, int32_t code) {
|
||||||
if (pMsg->pBatchMasterMsg) {
|
if (pMsg->pBatchMasterMsg) {
|
||||||
++pMsg->pBatchMasterMsg->received;
|
++pMsg->pBatchMasterMsg->received;
|
||||||
pMsg->pBatchMasterMsg->code = code;
|
pMsg->pBatchMasterMsg->code = code;
|
||||||
if (pMsg->pBatchMasterMsg->successed + pMsg->pBatchMasterMsg->received
|
if (pMsg->pBatchMasterMsg->successed + pMsg->pBatchMasterMsg->received >= pMsg->pBatchMasterMsg->expected) {
|
||||||
>= pMsg->pBatchMasterMsg->expected) {
|
dnodeSendRpcMWriteRsp(pMsg->pBatchMasterMsg, code);
|
||||||
dnodeSendRpcMWriteRsp(pMsg->pBatchMasterMsg, code);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mnodeDestroySubMsg(pMsg);
|
mnodeDestroySubMsg(pMsg);
|
||||||
|
@ -2662,9 +2684,8 @@ static void mnodeProcessCreateChildTableRsp(SRpcMsg *rpcMsg) {
|
||||||
|
|
||||||
if (pMsg->pBatchMasterMsg) {
|
if (pMsg->pBatchMasterMsg) {
|
||||||
++pMsg->pBatchMasterMsg->successed;
|
++pMsg->pBatchMasterMsg->successed;
|
||||||
if (pMsg->pBatchMasterMsg->successed + pMsg->pBatchMasterMsg->received
|
if (pMsg->pBatchMasterMsg->successed + pMsg->pBatchMasterMsg->received >= pMsg->pBatchMasterMsg->expected) {
|
||||||
>= pMsg->pBatchMasterMsg->expected) {
|
dnodeSendRpcMWriteRsp(pMsg->pBatchMasterMsg, rpcMsg->code);
|
||||||
dnodeSendRpcMWriteRsp(pMsg->pBatchMasterMsg, rpcMsg->code);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mnodeDestroySubMsg(pMsg);
|
mnodeDestroySubMsg(pMsg);
|
||||||
|
|
|
@ -443,6 +443,7 @@ int32_t mnodeGetAvailableVgroup(SMnodeMsg *pMsg, SVgObj **ppVgroup, int32_t *pSi
|
||||||
mDebug("msg:%p, app:%p db:%s, no enough sid in vgId:%d", pMsg, pMsg->rpcMsg.ahandle, pDb->name, pVgroup->vgId);
|
mDebug("msg:%p, app:%p db:%s, no enough sid in vgId:%d", pMsg, pMsg->rpcMsg.ahandle, pDb->name, pVgroup->vgId);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
mTrace("vgId:%d, alloc tid:%d", pVgroup->vgId, sid);
|
||||||
|
|
||||||
*pSid = sid;
|
*pSid = sid;
|
||||||
*ppVgroup = pVgroup;
|
*ppVgroup = pVgroup;
|
||||||
|
@ -507,6 +508,7 @@ int32_t mnodeGetAvailableVgroup(SMnodeMsg *pMsg, SVgObj **ppVgroup, int32_t *pSi
|
||||||
pDb->vgListIndex = 0;
|
pDb->vgListIndex = 0;
|
||||||
pthread_mutex_unlock(&pDb->mutex);
|
pthread_mutex_unlock(&pDb->mutex);
|
||||||
|
|
||||||
|
mTrace("vgId:%d, alloc tid:%d", pVgroup->vgId, sid);
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -832,26 +834,37 @@ static int32_t mnodeRetrieveVgroups(SShowObj *pShow, char *data, int32_t rows, v
|
||||||
return numOfRows;
|
return numOfRows;
|
||||||
}
|
}
|
||||||
|
|
||||||
void mnodeAddTableIntoVgroup(SVgObj *pVgroup, SCTableObj *pTable) {
|
int32_t mnodeAddTableIntoVgroup(SVgObj *pVgroup, SCTableObj *pTable, bool needCheck) {
|
||||||
int32_t idPoolSize = taosIdPoolMaxSize(pVgroup->idPool);
|
int32_t idPoolSize = taosIdPoolMaxSize(pVgroup->idPool);
|
||||||
if (pTable->tid > idPoolSize) {
|
if (pTable->tid > idPoolSize) {
|
||||||
mnodeAllocVgroupIdPool(pVgroup);
|
mnodeAllocVgroupIdPool(pVgroup);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pTable->tid >= 1) {
|
if (pTable->tid >= 1) {
|
||||||
taosIdPoolMarkStatus(pVgroup->idPool, pTable->tid);
|
if (taosIdPoolMarkStatus(pVgroup->idPool, pTable->tid) || !needCheck) {
|
||||||
pVgroup->numOfTables++;
|
pVgroup->numOfTables++;
|
||||||
// The create vgroup message may be received later than the create table message
|
mTrace("table:%s, vgId:%d tid:%d, mark tid used, uid:%" PRIu64, pTable->info.tableId, pTable->vgId, pTable->tid,
|
||||||
// and the writing order in sdb is therefore uncertain
|
pTable->uid);
|
||||||
// which will cause the reference count of the vgroup to be incorrect when restarting
|
// The create vgroup message may be received later than the create table message
|
||||||
// mnodeIncVgroupRef(pVgroup);
|
// and the writing order in sdb is therefore uncertain
|
||||||
|
// which will cause the reference count of the vgroup to be incorrect when restarting
|
||||||
|
// mnodeIncVgroupRef(pVgroup);
|
||||||
|
} else {
|
||||||
|
mError("table:%s, vgId:%d tid:%d, failed to mark tid, uid:%" PRIu64, pTable->info.tableId, pTable->vgId,
|
||||||
|
pTable->tid, pTable->uid);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void mnodeRemoveTableFromVgroup(SVgObj *pVgroup, SCTableObj *pTable) {
|
void mnodeRemoveTableFromVgroup(SVgObj *pVgroup, SCTableObj *pTable) {
|
||||||
if (pTable->tid >= 1) {
|
if (pTable->tid >= 1) {
|
||||||
taosFreeId(pVgroup->idPool, pTable->tid);
|
taosFreeId(pVgroup->idPool, pTable->tid);
|
||||||
pVgroup->numOfTables--;
|
pVgroup->numOfTables--;
|
||||||
|
mTrace("table:%s, vgId:%d tid:%d, put tid back uid:%" PRIu64, pTable->info.tableId, pTable->vgId, pTable->tid,
|
||||||
|
pTable->uid);
|
||||||
// The create vgroup message may be received later than the create table message
|
// The create vgroup message may be received later than the create table message
|
||||||
// and the writing order in sdb is therefore uncertain
|
// and the writing order in sdb is therefore uncertain
|
||||||
// which will cause the reference count of the vgroup to be incorrect when restarting
|
// which will cause the reference count of the vgroup to be incorrect when restarting
|
||||||
|
|
|
@ -34,7 +34,7 @@ void taosIdPoolCleanUp(void *handle);
|
||||||
|
|
||||||
int taosIdPoolNumOfUsed(void *handle);
|
int taosIdPoolNumOfUsed(void *handle);
|
||||||
|
|
||||||
void taosIdPoolMarkStatus(void *handle, int id);
|
bool taosIdPoolMarkStatus(void *handle, int id);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -104,10 +104,16 @@ void taosIdPoolCleanUp(void *handle) {
|
||||||
|
|
||||||
int taosIdPoolNumOfUsed(void *handle) {
|
int taosIdPoolNumOfUsed(void *handle) {
|
||||||
id_pool_t *pIdPool = handle;
|
id_pool_t *pIdPool = handle;
|
||||||
return pIdPool->maxId - pIdPool->numOfFree;
|
|
||||||
|
pthread_mutex_lock(&pIdPool->mutex);
|
||||||
|
int ret = pIdPool->maxId - pIdPool->numOfFree;
|
||||||
|
pthread_mutex_unlock(&pIdPool->mutex);
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void taosIdPoolMarkStatus(void *handle, int id) {
|
bool taosIdPoolMarkStatus(void *handle, int id) {
|
||||||
|
bool ret = false;
|
||||||
id_pool_t *pIdPool = handle;
|
id_pool_t *pIdPool = handle;
|
||||||
pthread_mutex_lock(&pIdPool->mutex);
|
pthread_mutex_lock(&pIdPool->mutex);
|
||||||
|
|
||||||
|
@ -115,9 +121,13 @@ void taosIdPoolMarkStatus(void *handle, int id) {
|
||||||
if (!pIdPool->freeList[slot]) {
|
if (!pIdPool->freeList[slot]) {
|
||||||
pIdPool->freeList[slot] = true;
|
pIdPool->freeList[slot] = true;
|
||||||
pIdPool->numOfFree--;
|
pIdPool->numOfFree--;
|
||||||
|
ret = true;
|
||||||
|
} else {
|
||||||
|
ret = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
pthread_mutex_unlock(&pIdPool->mutex);
|
pthread_mutex_unlock(&pIdPool->mutex);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int taosUpdateIdPool(id_pool_t *handle, int maxId) {
|
int taosUpdateIdPool(id_pool_t *handle, int maxId) {
|
||||||
|
@ -147,6 +157,11 @@ int taosUpdateIdPool(id_pool_t *handle, int maxId) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int taosIdPoolMaxSize(void *handle) {
|
int taosIdPoolMaxSize(void *handle) {
|
||||||
id_pool_t *pIdPool = (id_pool_t*)handle;
|
id_pool_t *pIdPool = (id_pool_t *)handle;
|
||||||
return pIdPool->maxId;
|
|
||||||
|
pthread_mutex_lock(&pIdPool->mutex);
|
||||||
|
int ret = pIdPool->maxId;
|
||||||
|
pthread_mutex_unlock(&pIdPool->mutex);
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
Loading…
Reference in New Issue