change stb hash value to stbName
This commit is contained in:
parent
7a78d81232
commit
bb89ceb6bd
|
@ -45,7 +45,7 @@ extern "C" {
|
||||||
|
|
||||||
#define ERROR_MSG_BUF_DEFAULT_SIZE 512
|
#define ERROR_MSG_BUF_DEFAULT_SIZE 512
|
||||||
#define HEARTBEAT_INTERVAL 1500 // ms
|
#define HEARTBEAT_INTERVAL 1500 // ms
|
||||||
#define SYNC_ON_TOP_OF_ASYNC 1
|
#define SYNC_ON_TOP_OF_ASYNC 0
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
RES_TYPE__QUERY = 1,
|
RES_TYPE__QUERY = 1,
|
||||||
|
|
|
@ -230,6 +230,7 @@ _return:
|
||||||
|
|
||||||
int32_t ctgAcquireTbMetaFromCache(SCatalog* pCtg, char *dbFName, char* tbName, SCtgDBCache **pDb, SCtgTbCache** pTb) {
|
int32_t ctgAcquireTbMetaFromCache(SCatalog* pCtg, char *dbFName, char* tbName, SCtgDBCache **pDb, SCtgTbCache** pTb) {
|
||||||
SCtgDBCache *dbCache = NULL;
|
SCtgDBCache *dbCache = NULL;
|
||||||
|
SCtgTbCache* pCache = NULL;
|
||||||
ctgAcquireDBCache(pCtg, dbFName, &dbCache);
|
ctgAcquireDBCache(pCtg, dbFName, &dbCache);
|
||||||
if (NULL == dbCache) {
|
if (NULL == dbCache) {
|
||||||
ctgDebug("db %s not in cache", dbFName);
|
ctgDebug("db %s not in cache", dbFName);
|
||||||
|
@ -237,7 +238,7 @@ int32_t ctgAcquireTbMetaFromCache(SCatalog* pCtg, char *dbFName, char* tbName, S
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t sz = 0;
|
int32_t sz = 0;
|
||||||
SCtgTbCache* pCache = taosHashAcquire(dbCache->tbCache, tbName, strlen(tbName));
|
pCache = taosHashAcquire(dbCache->tbCache, tbName, strlen(tbName));
|
||||||
if (NULL == pCache) {
|
if (NULL == pCache) {
|
||||||
ctgDebug("tb %s not in cache, dbFName:%s", tbName, dbFName);
|
ctgDebug("tb %s not in cache, dbFName:%s", tbName, dbFName);
|
||||||
goto _return;
|
goto _return;
|
||||||
|
@ -267,6 +268,54 @@ _return:
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t ctgAcquireStbMetaFromCache(SCatalog* pCtg, char *dbFName, uint64_t suid, SCtgDBCache **pDb, SCtgTbCache** pTb) {
|
||||||
|
SCtgDBCache* dbCache = NULL;
|
||||||
|
SCtgTbCache* pCache = NULL;
|
||||||
|
ctgAcquireDBCache(pCtg, dbFName, &dbCache);
|
||||||
|
if (NULL == dbCache) {
|
||||||
|
ctgDebug("db %s not in cache", dbFName);
|
||||||
|
goto _return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t sz = 0;
|
||||||
|
char* stName = taosHashAcquire(dbCache->stbCache, &suid, sizeof(suid));
|
||||||
|
if (NULL == stName) {
|
||||||
|
ctgDebug("stb %" PRIx64 " not in cache, dbFName:%s", suid, dbFName);
|
||||||
|
goto _return;
|
||||||
|
}
|
||||||
|
|
||||||
|
pCache = taosHashAcquire(dbCache->tbCache, stName, strlen(stName));
|
||||||
|
if (NULL == pCache) {
|
||||||
|
ctgDebug("stb %" PRIx64 " name %s not in cache, dbFName:%s", suid, stName, dbFName);
|
||||||
|
taosHashRelease(dbCache->stbCache, stName);
|
||||||
|
goto _return;
|
||||||
|
}
|
||||||
|
|
||||||
|
CTG_LOCK(CTG_READ, &pCache->metaLock);
|
||||||
|
if (NULL == pCache->pMeta) {
|
||||||
|
ctgDebug("stb %" PRIx64 " meta not in cache, dbFName:%s", suid, dbFName);
|
||||||
|
goto _return;
|
||||||
|
}
|
||||||
|
|
||||||
|
*pDb = dbCache;
|
||||||
|
*pTb = pCache;
|
||||||
|
|
||||||
|
ctgDebug("stb %" PRIx64 " meta got in cache, dbFName:%s", suid, dbFName);
|
||||||
|
|
||||||
|
CTG_CACHE_STAT_INC(tbMetaHitNum, 1);
|
||||||
|
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
|
||||||
|
_return:
|
||||||
|
|
||||||
|
ctgReleaseTbMetaToCache(pCtg, dbCache, pCache);
|
||||||
|
|
||||||
|
CTG_CACHE_STAT_INC(tbMetaMissNum, 1);
|
||||||
|
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int32_t ctgAcquireTbIndexFromCache(SCatalog* pCtg, char *dbFName, char* tbName, SCtgDBCache **pDb, SCtgTbCache** pTb) {
|
int32_t ctgAcquireTbIndexFromCache(SCatalog* pCtg, char *dbFName, char* tbName, SCtgDBCache **pDb, SCtgTbCache** pTb) {
|
||||||
SCtgDBCache *dbCache = NULL;
|
SCtgDBCache *dbCache = NULL;
|
||||||
ctgAcquireDBCache(pCtg, dbFName, &dbCache);
|
ctgAcquireDBCache(pCtg, dbFName, &dbCache);
|
||||||
|
@ -348,31 +397,61 @@ int32_t ctgReadTbMetaFromCache(SCatalog* pCtg, SCtgTbMetaCtx* ctx, STableMeta**
|
||||||
ctx->tbInfo.dbId = dbCache->dbId;
|
ctx->tbInfo.dbId = dbCache->dbId;
|
||||||
ctx->tbInfo.suid = tbMeta->suid;
|
ctx->tbInfo.suid = tbMeta->suid;
|
||||||
ctx->tbInfo.tbType = tbMeta->tableType;
|
ctx->tbInfo.tbType = tbMeta->tableType;
|
||||||
|
|
||||||
if (tbMeta->tableType != TSDB_CHILD_TABLE) {
|
if (tbMeta->tableType != TSDB_CHILD_TABLE) {
|
||||||
|
int32_t metaSize = CTG_META_SIZE(tbMeta);
|
||||||
|
*pTableMeta = taosMemoryCalloc(1, metaSize);
|
||||||
|
if (NULL == *pTableMeta) {
|
||||||
|
ctgReleaseTbMetaToCache(pCtg, dbCache, tbCache);
|
||||||
|
CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY);
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(*pTableMeta, tbMeta, metaSize);
|
||||||
|
|
||||||
ctgReleaseTbMetaToCache(pCtg, dbCache, tbCache);
|
ctgReleaseTbMetaToCache(pCtg, dbCache, tbCache);
|
||||||
ctgDebug("Got tb %s meta from cache, type:%d, dbFName:%s", ctx->pName->tname, tbMeta->tableType, dbFName);
|
ctgDebug("Got tb %s meta from cache, type:%d, dbFName:%s", ctx->pName->tname, tbMeta->tableType, dbFName);
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PROCESS FOR CHILD TABLE
|
||||||
|
|
||||||
STableMeta **stbMeta = taosHashGet(dbCache->stbCache, &tbMeta->suid, sizeof(tbMeta->suid));
|
int32_t metaSize = sizeof(SCTableMeta);
|
||||||
if (NULL == stbMeta || NULL == *stbMeta) {
|
*pTableMeta = taosMemoryCalloc(1, metaSize);
|
||||||
ctgError("stb not in stbCache, suid:%"PRIx64, tbMeta->suid);
|
if (NULL == *pTableMeta) {
|
||||||
goto _return;
|
CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((*stbMeta)->suid != tbMeta->suid) {
|
memcpy(*pTableMeta, tbMeta, metaSize);
|
||||||
ctgError("stb suid %" PRIx64 " in stbCache mis-match, expected suid:%"PRIx64 , (*stbMeta)->suid, tbMeta->suid);
|
|
||||||
|
ctgReleaseTbMetaToCache(pCtg, dbCache, tbCache);
|
||||||
|
ctgDebug("Got ctb %s meta from cache, will continue to get its stb meta, type:%d, dbFName:%s",
|
||||||
|
ctx->pName->tname, ctx->tbInfo.tbType, dbFName);
|
||||||
|
|
||||||
|
dbCache = NULL;
|
||||||
|
tbCache = NULL;
|
||||||
|
ctgAcquireStbMetaFromCache(pCtg, dbFName, ctx->tbInfo.suid, &dbCache, &tbCache);
|
||||||
|
if (NULL == tbCache) {
|
||||||
|
ctgReleaseTbMetaToCache(pCtg, dbCache, tbCache);
|
||||||
|
taosMemoryFreeClear(*pTableMeta);
|
||||||
|
ctgDebug("stb %" PRIx64 " meta not in cache", ctx->tbInfo.suid);
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
STableMeta* stbMeta = tbCache->pMeta;
|
||||||
|
if (stbMeta->suid != ctx->tbInfo.suid) {
|
||||||
|
ctgReleaseTbMetaToCache(pCtg, dbCache, tbCache);
|
||||||
|
ctgError("stb suid %" PRIx64 " in stbCache mis-match, expected suid:%"PRIx64 , stbMeta->suid, ctx->tbInfo.suid);
|
||||||
CTG_ERR_JRET(TSDB_CODE_CTG_INTERNAL_ERROR);
|
CTG_ERR_JRET(TSDB_CODE_CTG_INTERNAL_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t metaSize = CTG_META_SIZE(*stbMeta);
|
metaSize = CTG_META_SIZE(stbMeta);
|
||||||
*pTableMeta = taosMemoryRealloc(*pTableMeta, metaSize);
|
*pTableMeta = taosMemoryRealloc(*pTableMeta, metaSize);
|
||||||
if (NULL == *pTableMeta) {
|
if (NULL == *pTableMeta) {
|
||||||
|
ctgReleaseTbMetaToCache(pCtg, dbCache, tbCache);
|
||||||
CTG_ERR_JRET(TSDB_CODE_CTG_MEM_ERROR);
|
CTG_ERR_JRET(TSDB_CODE_CTG_MEM_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(&(*pTableMeta)->sversion, &(*stbMeta)->sversion, metaSize - sizeof(SCTableMeta));
|
memcpy(&(*pTableMeta)->sversion, &stbMeta->sversion, metaSize - sizeof(SCTableMeta));
|
||||||
|
|
||||||
ctgReleaseTbMetaToCache(pCtg, dbCache, tbCache);
|
ctgReleaseTbMetaToCache(pCtg, dbCache, tbCache);
|
||||||
|
|
||||||
|
@ -419,27 +498,33 @@ int32_t ctgReadTbVerFromCache(SCatalog *pCtg, SName *pTableName, int32_t *sver,
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
STableMeta **stbMeta = taosHashGet(dbCache->stbCache, suid, sizeof(*suid));
|
// PROCESS FOR CHILD TABLE
|
||||||
if (NULL == stbMeta || NULL == *stbMeta) {
|
|
||||||
|
ctgReleaseTbMetaToCache(pCtg, dbCache, tbCache);
|
||||||
|
ctgDebug("Got ctb %s ver from cache, will continue to get its stb ver, dbFName:%s", pTableName->tname, dbFName);
|
||||||
|
|
||||||
|
ctgAcquireStbMetaFromCache(pCtg, dbFName, *suid, &dbCache, &tbCache);
|
||||||
|
if (NULL == tbCache) {
|
||||||
ctgReleaseTbMetaToCache(pCtg, dbCache, tbCache);
|
ctgReleaseTbMetaToCache(pCtg, dbCache, tbCache);
|
||||||
ctgDebug("stb not in stbCache, suid:%" PRIx64, *suid);
|
ctgDebug("stb %" PRIx64 " meta not in cache", *suid);
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((*stbMeta)->suid != *suid) {
|
STableMeta* stbMeta = tbCache->pMeta;
|
||||||
|
if (stbMeta->suid != *suid) {
|
||||||
ctgReleaseTbMetaToCache(pCtg, dbCache, tbCache);
|
ctgReleaseTbMetaToCache(pCtg, dbCache, tbCache);
|
||||||
ctgError("stb suid %" PRIx64 " in stbCache mis-match, expected suid:%" PRIx64 , (*stbMeta)->suid, *suid);
|
ctgError("stb suid %" PRIx64 " in stbCache mis-match, expected suid:%" PRIx64 , stbMeta->suid, *suid);
|
||||||
CTG_ERR_RET(TSDB_CODE_CTG_INTERNAL_ERROR);
|
CTG_ERR_RET(TSDB_CODE_CTG_INTERNAL_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t nameLen = 0;
|
size_t nameLen = 0;
|
||||||
char *name = taosHashGetKey(*stbMeta, &nameLen);
|
char *name = taosHashGetKey(tbCache, &nameLen);
|
||||||
|
|
||||||
strncpy(stbName, name, nameLen);
|
strncpy(stbName, name, nameLen);
|
||||||
stbName[nameLen] = 0;
|
stbName[nameLen] = 0;
|
||||||
|
|
||||||
*sver = (*stbMeta)->sversion;
|
*sver = stbMeta->sversion;
|
||||||
*tver = (*stbMeta)->tversion;
|
*tver = stbMeta->tversion;
|
||||||
|
|
||||||
ctgReleaseTbMetaToCache(pCtg, dbCache, tbCache);
|
ctgReleaseTbMetaToCache(pCtg, dbCache, tbCache);
|
||||||
|
|
||||||
|
@ -1320,14 +1405,14 @@ int32_t ctgWriteTbMetaToCache(SCatalog *pCtg, SCtgDBCache *dbCache, char *dbFNam
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (origSuid != meta->suid && taosHashPut(dbCache->stbCache, &meta->suid, sizeof(meta->suid), &pCache, POINTER_BYTES) != 0) {
|
if (origSuid != meta->suid && taosHashPut(dbCache->stbCache, &meta->suid, sizeof(meta->suid), tbName, strlen(tbName) + 1) != 0) {
|
||||||
ctgError("taosHashPut to stable cache failed, suid:%"PRIx64, meta->suid);
|
ctgError("taosHashPut to stable cache failed, suid:%"PRIx64, meta->suid);
|
||||||
CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR);
|
CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
CTG_CACHE_STAT_INC(stblNum, 1);
|
CTG_CACHE_STAT_INC(stblNum, 1);
|
||||||
|
|
||||||
ctgDebug("stb updated to stbCache, dbFName:%s, tbName:%s, tbType:%d", dbFName, tbName, meta->tableType);
|
ctgDebug("stb %" PRIx64 " updated to cache, dbFName:%s, tbName:%s, tbType:%d", meta->suid, dbFName, tbName, meta->tableType);
|
||||||
|
|
||||||
CTG_ERR_RET(ctgUpdateRentStbVersion(pCtg, dbFName, tbName, dbId, meta->suid, pCache));
|
CTG_ERR_RET(ctgUpdateRentStbVersion(pCtg, dbFName, tbName, dbId, meta->suid, pCache));
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
#include "catalogInt.h"
|
#include "catalogInt.h"
|
||||||
|
|
||||||
extern SCatalogMgmt gCtgMgmt;
|
extern SCatalogMgmt gCtgMgmt;
|
||||||
SCtgDebug gCTGDebug = {.apiEnable = true};
|
SCtgDebug gCTGDebug = {.apiEnable = true, .lockEnable = true};
|
||||||
|
|
||||||
void ctgdUserCallback(SMetaData* pResult, void* param, int32_t code) {
|
void ctgdUserCallback(SMetaData* pResult, void* param, int32_t code) {
|
||||||
ASSERT(*(int32_t*)param == 1);
|
ASSERT(*(int32_t*)param == 1);
|
||||||
|
|
Loading…
Reference in New Issue