提交 f7908813 编写于 作者: S Shengliang Guan

fix sdb bugs

上级 90922fd2
...@@ -55,9 +55,9 @@ typedef struct { ...@@ -55,9 +55,9 @@ typedef struct {
int32_t mnodeInit(SMnodePara para); int32_t mnodeInit(SMnodePara para);
void mnodeCleanup(); void mnodeCleanup();
int32_t mnodeDeploy(char *path, SMnodeCfg *pCfg); int32_t mnodeDeploy(SMnodeCfg *pCfg);
void mnodeUnDeploy(char *path); void mnodeUnDeploy();
int32_t mnodeStart(char *path, SMnodeCfg *pCfg); int32_t mnodeStart(SMnodeCfg *pCfg);
int32_t mnodeAlter(SMnodeCfg *pCfg); int32_t mnodeAlter(SMnodeCfg *pCfg);
void mnodeStop(); void mnodeStop();
......
...@@ -157,8 +157,8 @@ void sdbUnDeploy(); ...@@ -157,8 +157,8 @@ void sdbUnDeploy();
void *sdbAcquire(ESdbType sdb, void *pKey); void *sdbAcquire(ESdbType sdb, void *pKey);
void sdbRelease(void *pObj); void sdbRelease(void *pObj);
void *sdbFetch(ESdbType sdb, void *pIter); void *sdbFetch(ESdbType sdb, void *pIter, void **ppObj);
void sdbCancelFetch(ESdbType sdb, void *pIter); void sdbCancelFetch(void *pIter);
int32_t sdbGetSize(ESdbType sdb); int32_t sdbGetSize(ESdbType sdb);
SSdbRaw *sdbAllocRaw(ESdbType sdb, int8_t sver, int32_t dataLen); SSdbRaw *sdbAllocRaw(ESdbType sdb, int8_t sver, int32_t dataLen);
......
...@@ -136,8 +136,8 @@ static int32_t dnodeWriteMnodeFile() { ...@@ -136,8 +136,8 @@ static int32_t dnodeWriteMnodeFile() {
char *content = calloc(1, maxLen + 1); char *content = calloc(1, maxLen + 1);
len += snprintf(content + len, maxLen - len, "{\n"); len += snprintf(content + len, maxLen - len, "{\n");
len += snprintf(content + len, maxLen - len, " \"deployed\": \"%d\",\n", tsMnode.dropped); len += snprintf(content + len, maxLen - len, " \"deployed\": \"%d\",\n", tsMnode.deployed);
len += snprintf(content + len, maxLen - len, " \"dropped\": \"%d\",\n", tsMnode.dropped); len += snprintf(content + len, maxLen - len, " \"dropped\": \"%d\"\n", tsMnode.dropped);
len += snprintf(content + len, maxLen - len, "}\n"); len += snprintf(content + len, maxLen - len, "}\n");
fwrite(content, 1, len, fp); fwrite(content, 1, len, fp);
...@@ -180,7 +180,7 @@ static int32_t dnodeStartMnode() { ...@@ -180,7 +180,7 @@ static int32_t dnodeStartMnode() {
tsMnode.deployed = 1; tsMnode.deployed = 1;
taosWUnLockLatch(&tsMnode.latch); taosWUnLockLatch(&tsMnode.latch);
return code; return mnodeStart(NULL);
} }
static void dnodeStopMnode() { static void dnodeStopMnode() {
...@@ -212,14 +212,14 @@ static int32_t dnodeUnDeployMnode() { ...@@ -212,14 +212,14 @@ static int32_t dnodeUnDeployMnode() {
} }
dnodeStopMnode(); dnodeStopMnode();
mnodeUnDeploy(tsMnodeDir); mnodeUnDeploy();
dnodeWriteMnodeFile(); dnodeWriteMnodeFile();
return code; return code;
} }
static int32_t dnodeDeployMnode(SMnodeCfg *pCfg) { static int32_t dnodeDeployMnode(SMnodeCfg *pCfg) {
int32_t code = mnodeDeploy(tsMnodeDir, pCfg); int32_t code = mnodeDeploy(pCfg);
if (code != 0) { if (code != 0) {
dError("failed to deploy mnode since %s", tstrerror(code)); dError("failed to deploy mnode since %s", tstrerror(code));
return code; return code;
......
...@@ -134,10 +134,11 @@ static int32_t mnodeAllocInitSteps() { ...@@ -134,10 +134,11 @@ static int32_t mnodeAllocInitSteps() {
} }
static int32_t mnodeAllocStartSteps() { static int32_t mnodeAllocStartSteps() {
struct SSteps *steps = taosStepInit(7, NULL); struct SSteps *steps = taosStepInit(8, NULL);
if (steps == NULL) return -1; if (steps == NULL) return -1;
taosStepAdd(steps, "mnode-timer", mnodeInitTimer, NULL); taosStepAdd(steps, "mnode-timer", mnodeInitTimer, NULL);
taosStepAdd(steps, "mnode-sdb-file", sdbRead, (CleanupFp)sdbCommit);
taosStepAdd(steps, "mnode-balance", mnodeInitBalance, mnodeCleanupBalance); taosStepAdd(steps, "mnode-balance", mnodeInitBalance, mnodeCleanupBalance);
taosStepAdd(steps, "mnode-profile", mnodeInitProfile, mnodeCleanupProfile); taosStepAdd(steps, "mnode-profile", mnodeInitProfile, mnodeCleanupProfile);
taosStepAdd(steps, "mnode-show", mnodeInitShow, mnodeCleanUpShow); taosStepAdd(steps, "mnode-show", mnodeInitShow, mnodeCleanUpShow);
...@@ -170,7 +171,7 @@ int32_t mnodeInit(SMnodePara para) { ...@@ -170,7 +171,7 @@ int32_t mnodeInit(SMnodePara para) {
void mnodeCleanup() { taosStepCleanup(tsMint.pInitSteps); } void mnodeCleanup() { taosStepCleanup(tsMint.pInitSteps); }
int32_t mnodeDeploy(char *path, SMnodeCfg *pCfg) { int32_t mnodeDeploy(SMnodeCfg *pCfg) {
if (tsMint.para.dnodeId <= 0 && tsMint.para.clusterId <= 0) { if (tsMint.para.dnodeId <= 0 && tsMint.para.clusterId <= 0) {
if (sdbDeploy() != 0) { if (sdbDeploy() != 0) {
mError("failed to deploy sdb since %s", terrstr()); mError("failed to deploy sdb since %s", terrstr());
...@@ -182,9 +183,9 @@ int32_t mnodeDeploy(char *path, SMnodeCfg *pCfg) { ...@@ -182,9 +183,9 @@ int32_t mnodeDeploy(char *path, SMnodeCfg *pCfg) {
return 0; return 0;
} }
void mnodeUnDeploy(char *path) { sdbUnDeploy(); } void mnodeUnDeploy() { sdbUnDeploy(); }
int32_t mnodeStart(char *path, SMnodeCfg *pCfg) { return taosStepExec(tsMint.pStartSteps); } int32_t mnodeStart(SMnodeCfg *pCfg) { return taosStepExec(tsMint.pStartSteps); }
int32_t mnodeAlter(SMnodeCfg *pCfg) { return 0; } int32_t mnodeAlter(SMnodeCfg *pCfg) { return 0; }
......
...@@ -73,7 +73,9 @@ static int32_t mnodeAcctActionInsert(SAcctObj *pAcct) { return 0; } ...@@ -73,7 +73,9 @@ static int32_t mnodeAcctActionInsert(SAcctObj *pAcct) { return 0; }
static int32_t mnodeAcctActionDelete(SAcctObj *pAcct) { return 0; } static int32_t mnodeAcctActionDelete(SAcctObj *pAcct) { return 0; }
static int32_t mnodeAcctActionUpdate(SAcctObj *pSrcAcct, SAcctObj *pDstAcct) { static int32_t mnodeAcctActionUpdate(SAcctObj *pSrcAcct, SAcctObj *pDstAcct) {
memcpy(pDstAcct, pSrcAcct, (int32_t)((char *)&pDstAcct->info - (char *)&pDstAcct)); SAcctObj tObj;
int32_t len = (int32_t)((int8_t *)&tObj.info - (int8_t *)&tObj);
memcpy(pDstAcct, pSrcAcct, len);
return 0; return 0;
} }
......
...@@ -28,7 +28,7 @@ static SSdbRaw *mnodeUserActionEncode(SUserObj *pUser) { ...@@ -28,7 +28,7 @@ static SSdbRaw *mnodeUserActionEncode(SUserObj *pUser) {
int32_t dataPos = 0; int32_t dataPos = 0;
SDB_SET_BINARY(pRaw, dataPos, pUser->user, TSDB_USER_LEN) SDB_SET_BINARY(pRaw, dataPos, pUser->user, TSDB_USER_LEN)
SDB_SET_BINARY(pRaw, dataPos, pUser->pass, TSDB_KEY_LEN) SDB_SET_BINARY(pRaw, dataPos, pUser->pass, TSDB_KEY_LEN)
SDB_SET_BINARY(pRaw, dataPos, pUser->acct, TSDB_KEY_LEN) SDB_SET_BINARY(pRaw, dataPos, pUser->acct, TSDB_USER_LEN)
SDB_SET_INT64(pRaw, dataPos, pUser->createdTime) SDB_SET_INT64(pRaw, dataPos, pUser->createdTime)
SDB_SET_INT64(pRaw, dataPos, pUser->updateTime) SDB_SET_INT64(pRaw, dataPos, pUser->updateTime)
SDB_SET_INT8(pRaw, dataPos, pUser->rootAuth) SDB_SET_INT8(pRaw, dataPos, pUser->rootAuth)
...@@ -46,7 +46,7 @@ static SSdbRow *mnodeUserActionDecode(SSdbRaw *pRaw) { ...@@ -46,7 +46,7 @@ static SSdbRow *mnodeUserActionDecode(SSdbRaw *pRaw) {
return NULL; return NULL;
} }
SSdbRow *pRow = sdbAllocRow(sizeof(SAcctObj)); SSdbRow *pRow = sdbAllocRow(sizeof(SUserObj));
SUserObj *pUser = sdbGetRowObj(pRow); SUserObj *pUser = sdbGetRowObj(pRow);
if (pUser == NULL) return NULL; if (pUser == NULL) return NULL;
...@@ -92,7 +92,9 @@ static int32_t mnodeUserActionDelete(SUserObj *pUser) { ...@@ -92,7 +92,9 @@ static int32_t mnodeUserActionDelete(SUserObj *pUser) {
} }
static int32_t mnodeUserActionUpdate(SUserObj *pSrcUser, SUserObj *pDstUser) { static int32_t mnodeUserActionUpdate(SUserObj *pSrcUser, SUserObj *pDstUser) {
memcpy(pDstUser, pSrcUser, (int32_t)((char *)&pDstUser->prohibitDbHash - (char *)&pDstUser)); SUserObj tObj;
int32_t len = (int32_t)((int8_t *)tObj.prohibitDbHash - (int8_t *)&tObj);
memcpy(pDstUser, pSrcUser, len);
return 0; return 0;
} }
......
...@@ -71,6 +71,8 @@ typedef struct { ...@@ -71,6 +71,8 @@ typedef struct {
extern SSdbMgr tsSdb; extern SSdbMgr tsSdb;
int32_t sdbWriteImp(SSdbRaw *pRaw);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
...@@ -66,7 +66,7 @@ static int32_t sdbReadDataFile() { ...@@ -66,7 +66,7 @@ static int32_t sdbReadDataFile() {
char file[PATH_MAX] = {0}; char file[PATH_MAX] = {0};
snprintf(file, sizeof(file), "%ssdb.data", tsSdb.currDir); snprintf(file, sizeof(file), "%ssdb.data", tsSdb.currDir);
FileFd fd = taosOpenFileCreateWrite(file); FileFd fd = taosOpenFileRead(file);
if (fd <= 0) { if (fd <= 0) {
free(pRaw); free(pRaw);
terrno = TAOS_SYSTEM_ERROR(errno); terrno = TAOS_SYSTEM_ERROR(errno);
...@@ -76,9 +76,12 @@ static int32_t sdbReadDataFile() { ...@@ -76,9 +76,12 @@ static int32_t sdbReadDataFile() {
int64_t offset = 0; int64_t offset = 0;
int32_t code = 0; int32_t code = 0;
int32_t readLen = 0;
int64_t ret = 0;
while (1) { while (1) {
int64_t ret = taosReadFile(fd, pRaw, sizeof(SSdbRaw)); readLen = sizeof(SSdbRaw);
ret = taosReadFile(fd, pRaw, readLen);
if (ret == 0) break; if (ret == 0) break;
if (ret < 0) { if (ret < 0) {
...@@ -87,33 +90,34 @@ static int32_t sdbReadDataFile() { ...@@ -87,33 +90,34 @@ static int32_t sdbReadDataFile() {
break; break;
} }
if (ret < sizeof(SSdbRaw)) { if (ret != readLen) {
code = TSDB_CODE_FILE_CORRUPTED; code = TSDB_CODE_FILE_CORRUPTED;
mError("failed to read file:%s since %s", file, tstrerror(code)); mError("failed to read file:%s since %s", file, tstrerror(code));
break; break;
} }
ret = taosReadFile(fd, pRaw->pData, pRaw->dataLen + sizeof(int32_t)); readLen = pRaw->dataLen + sizeof(int32_t);
ret = taosReadFile(fd, pRaw->pData, readLen);
if (ret < 0) { if (ret < 0) {
code = TAOS_SYSTEM_ERROR(errno); code = TAOS_SYSTEM_ERROR(errno);
mError("failed to read file:%s since %s", file, tstrerror(code)); mError("failed to read file:%s since %s", file, tstrerror(code));
break; break;
} }
if (ret < pRaw->dataLen + sizeof(int32_t)) { if (ret != readLen) {
code = TSDB_CODE_FILE_CORRUPTED; code = TSDB_CODE_FILE_CORRUPTED;
mError("failed to read file:%s since %s", file, tstrerror(code)); mError("failed to read file:%s since %s", file, tstrerror(code));
break; break;
} }
uint32_t cksum = *(int32_t *)(pRaw->pData + pRaw->dataLen); int32_t totalLen = sizeof(SSdbRaw) + pRaw->dataLen + sizeof(int32_t);
if (!taosCheckChecksumWhole(pRaw, sizeof(SSdbRaw) + pRaw->dataLen + sizeof(int32_t)) != 0) { if (!taosCheckChecksumWhole((const uint8_t *)pRaw, totalLen) != 0) {
code = TSDB_CODE_CHECKSUM_ERROR; code = TSDB_CODE_CHECKSUM_ERROR;
mError("failed to read file:%s since %s", file, tstrerror(code)); mError("failed to read file:%s since %s", file, tstrerror(code));
break; break;
} }
code = sdbWrite(pRaw); code = sdbWriteImp(pRaw);
if (code != 0) { if (code != 0) {
mError("failed to read file:%s since %s", file, terrstr()); mError("failed to read file:%s since %s", file, terrstr());
goto PARSE_SDB_DATA_ERROR; goto PARSE_SDB_DATA_ERROR;
...@@ -150,39 +154,47 @@ static int32_t sdbWriteDataFile() { ...@@ -150,39 +154,47 @@ static int32_t sdbWriteDataFile() {
SRWLatch *pLock = &tsSdb.locks[i]; SRWLatch *pLock = &tsSdb.locks[i];
taosWLockLatch(pLock); taosWLockLatch(pLock);
SSdbRow *pRow = taosHashIterate(hash, NULL); SSdbRow **ppRow = taosHashIterate(hash, NULL);
while (pRow != NULL) { while (ppRow != NULL) {
if (pRow->status != SDB_STATUS_READY) continue; SSdbRow *pRow = *ppRow;
if (pRow == NULL || pRow->status != SDB_STATUS_READY) {
ppRow = taosHashIterate(hash, ppRow);
continue;
}
SSdbRaw *pRaw = (*encodeFp)(pRow->pObj); SSdbRaw *pRaw = (*encodeFp)(pRow->pObj);
if (pRaw != NULL) { if (pRaw != NULL) {
pRaw->status = pRow->status;
int32_t writeLen = sizeof(SSdbRaw) + pRaw->dataLen; int32_t writeLen = sizeof(SSdbRaw) + pRaw->dataLen;
if (taosWriteFile(fd, pRaw, writeLen) != writeLen) { if (taosWriteFile(fd, pRaw, writeLen) != writeLen) {
code = TAOS_SYSTEM_ERROR(terrno); code = TAOS_SYSTEM_ERROR(terrno);
taosHashCancelIterate(hash, ppRow);
break; break;
} }
int32_t cksum = taosCalcChecksum(0, pRaw, sizeof(SSdbRaw) + pRaw->dataLen);
int32_t cksum = taosCalcChecksum(0, (const uint8_t *)pRaw, sizeof(SSdbRaw) + pRaw->dataLen);
if (taosWriteFile(fd, &cksum, sizeof(int32_t)) != sizeof(int32_t)) { if (taosWriteFile(fd, &cksum, sizeof(int32_t)) != sizeof(int32_t)) {
code = TAOS_SYSTEM_ERROR(terrno); code = TAOS_SYSTEM_ERROR(terrno);
taosHashCancelIterate(hash, ppRow);
break; break;
} }
} else { } else {
taosHashCancelIterate(hash, pRow);
code = TSDB_CODE_SDB_APP_ERROR; code = TSDB_CODE_SDB_APP_ERROR;
taosHashCancelIterate(hash, ppRow);
break; break;
} }
pRow = taosHashIterate(hash, pRow); ppRow = taosHashIterate(hash, ppRow);
} }
taosWUnLockLatch(pLock); taosWUnLockLatch(pLock);
} }
taosCloseFile(fd);
if (code == 0) { if (code == 0) {
code = taosFsyncFile(fd); code = taosFsyncFile(fd);
} }
taosCloseFile(fd);
if (code == 0) { if (code == 0) {
char curfile[PATH_MAX] = {0}; char curfile[PATH_MAX] = {0};
snprintf(curfile, sizeof(curfile), "%ssdb.data", tsSdb.currDir); snprintf(curfile, sizeof(curfile), "%ssdb.data", tsSdb.currDir);
...@@ -210,13 +222,11 @@ int32_t sdbRead() { ...@@ -210,13 +222,11 @@ int32_t sdbRead() {
} }
int32_t sdbCommit() { int32_t sdbCommit() {
mDebug("start to commit mnode file"); mDebug("start to write mnode file");
return sdbWriteDataFile(); return sdbWriteDataFile();
} }
int32_t sdbDeploy() { int32_t sdbDeploy() {
mDebug("start to deploy mnode");
if (sdbCreateDir() != 0) { if (sdbCreateDir() != 0) {
return -1; return -1;
} }
......
...@@ -86,12 +86,12 @@ static int32_t sdbUpdateRow(SHashObj *hash, SSdbRaw *pRaw, SSdbRow *pRow, int32_ ...@@ -86,12 +86,12 @@ static int32_t sdbUpdateRow(SHashObj *hash, SSdbRaw *pRaw, SSdbRow *pRow, int32_
SRWLatch *pLock = &tsSdb.locks[pRow->sdb]; SRWLatch *pLock = &tsSdb.locks[pRow->sdb];
taosRLockLatch(pLock); taosRLockLatch(pLock);
SSdbRow *pDstRow = taosHashGet(hash, pRow->pObj, keySize); SSdbRow **ppDstRow = taosHashGet(hash, pRow->pObj, keySize);
if (pDstRow == NULL) { if (ppDstRow == NULL || *ppDstRow == NULL) {
terrno = TSDB_CODE_SDB_OBJ_NOT_THERE;
taosRUnLockLatch(pLock); taosRUnLockLatch(pLock);
return -1; return sdbInsertRow(hash, pRaw, pRow, keySize);
} }
SSdbRow *pDstRow = *ppDstRow;
pRow->status = pRaw->status; pRow->status = pRaw->status;
taosRUnLockLatch(pLock); taosRUnLockLatch(pLock);
...@@ -110,12 +110,13 @@ static int32_t sdbDeleteRow(SHashObj *hash, SSdbRaw *pRaw, SSdbRow *pRow, int32_ ...@@ -110,12 +110,13 @@ static int32_t sdbDeleteRow(SHashObj *hash, SSdbRaw *pRaw, SSdbRow *pRow, int32_
SRWLatch *pLock = &tsSdb.locks[pRow->sdb]; SRWLatch *pLock = &tsSdb.locks[pRow->sdb];
taosWLockLatch(pLock); taosWLockLatch(pLock);
SSdbRow *pDstRow = taosHashGet(hash, pRow->pObj, keySize); SSdbRow **ppDstRow = taosHashGet(hash, pRow->pObj, keySize);
if (pDstRow == NULL) { if (ppDstRow == NULL || *ppDstRow) {
terrno = TSDB_CODE_SDB_OBJ_NOT_THERE; terrno = TSDB_CODE_SDB_OBJ_NOT_THERE;
taosWUnLockLatch(pLock); taosWUnLockLatch(pLock);
return -1; return -1;
} }
SSdbRow *pDstRow = *ppDstRow;
pRow->status = pRaw->status; pRow->status = pRaw->status;
taosHashRemove(hash, pRow->pObj, keySize); taosHashRemove(hash, pRow->pObj, keySize);
...@@ -123,16 +124,14 @@ static int32_t sdbDeleteRow(SHashObj *hash, SSdbRaw *pRaw, SSdbRow *pRow, int32_ ...@@ -123,16 +124,14 @@ static int32_t sdbDeleteRow(SHashObj *hash, SSdbRaw *pRaw, SSdbRow *pRow, int32_
SdbDeleteFp deleteFp = tsSdb.deleteFps[pRow->sdb]; SdbDeleteFp deleteFp = tsSdb.deleteFps[pRow->sdb];
if (deleteFp != NULL) { if (deleteFp != NULL) {
if ((*deleteFp)(pRow->pObj) != 0) { (void)(*deleteFp)(pRow->pObj);
return -1;
}
} }
sdbRelease(pRow->pObj); sdbRelease(pRow->pObj);
return 0; return 0;
} }
int32_t sdbWrite(SSdbRaw *pRaw) { int32_t sdbWriteImp(SSdbRaw *pRaw) {
SHashObj *hash = sdbGetHash(pRaw->sdb); SHashObj *hash = sdbGetHash(pRaw->sdb);
if (hash == NULL) return -1; if (hash == NULL) return -1;
...@@ -171,6 +170,12 @@ int32_t sdbWrite(SSdbRaw *pRaw) { ...@@ -171,6 +170,12 @@ int32_t sdbWrite(SSdbRaw *pRaw) {
return 0; return 0;
} }
int32_t sdbWrite(SSdbRaw *pRaw) {
int32_t code = sdbWriteImp(pRaw);
sdbFreeRaw(pRaw);
return code;
}
void *sdbAcquire(ESdbType sdb, void *pKey) { void *sdbAcquire(ESdbType sdb, void *pKey) {
SHashObj *hash = sdbGetHash(sdb); SHashObj *hash = sdbGetHash(sdb);
if (hash == NULL) return NULL; if (hash == NULL) return NULL;
...@@ -182,7 +187,7 @@ void *sdbAcquire(ESdbType sdb, void *pKey) { ...@@ -182,7 +187,7 @@ void *sdbAcquire(ESdbType sdb, void *pKey) {
taosRLockLatch(pLock); taosRLockLatch(pLock);
SSdbRow **ppRow = taosHashGet(hash, pKey, keySize); SSdbRow **ppRow = taosHashGet(hash, pKey, keySize);
if (ppRow == NULL || *ppRow) { if (ppRow == NULL || *ppRow == NULL) {
terrno = TSDB_CODE_SDB_OBJ_NOT_THERE; terrno = TSDB_CODE_SDB_OBJ_NOT_THERE;
taosRUnLockLatch(pLock); taosRUnLockLatch(pLock);
return NULL; return NULL;
...@@ -226,27 +231,37 @@ void sdbRelease(void *pObj) { ...@@ -226,27 +231,37 @@ void sdbRelease(void *pObj) {
taosRUnLockLatch(pLock); taosRUnLockLatch(pLock);
} }
void *sdbFetchRow(ESdbType sdb, void *pIter) { void *sdbFetch(ESdbType sdb, void *pIter, void **ppObj) {
SHashObj *hash = sdbGetHash(sdb); SHashObj *hash = sdbGetHash(sdb);
if (hash == NULL) { if (hash == NULL) return NULL;
return NULL;
}
SRWLatch *pLock = &tsSdb.locks[sdb]; SRWLatch *pLock = &tsSdb.locks[sdb];
taosRLockLatch(pLock); taosRLockLatch(pLock);
void *pRet = taosHashIterate(hash, pIter);
SSdbRow **ppRow = taosHashIterate(hash, ppRow);
while (ppRow != NULL) {
SSdbRow *pRow = *ppRow;
if (pRow == NULL || pRow->status != SDB_STATUS_READY) {
ppRow = taosHashIterate(hash, ppRow);
continue;
}
atomic_add_fetch_32(&pRow->refCount, 1);
*ppObj = pRow->pObj;
break;
}
taosRUnLockLatch(pLock); taosRUnLockLatch(pLock);
return pRet; return ppRow;
} }
void sdbCancelFetch(ESdbType sdb, void *pIter) { void sdbCancelFetch(void *pIter) {
SHashObj *hash = sdbGetHash(sdb); if (pIter == NULL) return;
if (hash == NULL) { SSdbRow *pRow = *(SSdbRow **)pIter;
return; SHashObj *hash = sdbGetHash(pRow->sdb);
} if (hash == NULL) return;
SRWLatch *pLock = &tsSdb.locks[sdb]; SRWLatch *pLock = &tsSdb.locks[pRow->sdb];
taosRLockLatch(pLock); taosRLockLatch(pLock);
taosHashCancelIterate(hash, pIter); taosHashCancelIterate(hash, pIter);
taosRUnLockLatch(pLock); taosRUnLockLatch(pLock);
...@@ -254,9 +269,7 @@ void sdbCancelFetch(ESdbType sdb, void *pIter) { ...@@ -254,9 +269,7 @@ void sdbCancelFetch(ESdbType sdb, void *pIter) {
int32_t sdbGetSize(ESdbType sdb) { int32_t sdbGetSize(ESdbType sdb) {
SHashObj *hash = sdbGetHash(sdb); SHashObj *hash = sdbGetHash(sdb);
if (hash == NULL) { if (hash == NULL) return 0;
return 0;
}
SRWLatch *pLock = &tsSdb.locks[sdb]; SRWLatch *pLock = &tsSdb.locks[sdb];
taosRLockLatch(pLock); taosRLockLatch(pLock);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册