feat: support uniq grant
This commit is contained in:
parent
44d264456d
commit
015fb4d679
|
@ -320,14 +320,19 @@ typedef struct SCtgUserAuth {
|
||||||
uint64_t userCacheSize;
|
uint64_t userCacheSize;
|
||||||
} SCtgUserAuth;
|
} SCtgUserAuth;
|
||||||
|
|
||||||
|
typedef struct SCtgGrantCache {
|
||||||
|
SRWLatch lock;
|
||||||
|
SGrantHbRsp grantInfo;
|
||||||
|
uint64_t grantCacheSize;
|
||||||
|
} SCtgGrantCache;
|
||||||
|
|
||||||
typedef struct SCatalog {
|
typedef struct SCatalog {
|
||||||
uint64_t clusterId;
|
uint64_t clusterId;
|
||||||
bool stopUpdate;
|
bool stopUpdate;
|
||||||
SDynViewVersion dynViewVer;
|
SDynViewVersion dynViewVer;
|
||||||
SHashObj* userCache; // key:user, value:SCtgUserAuth
|
SHashObj* userCache; // key:user, value:SCtgUserAuth
|
||||||
SHashObj* dbCache; // key:dbname, value:SCtgDBCache
|
SHashObj* dbCache; // key:dbname, value:SCtgDBCache
|
||||||
SHashObj* grantCache;
|
SCtgGrantCache grantCache;
|
||||||
SGrantHbRsp _grantCache;
|
|
||||||
SCtgRentMgmt dbRent;
|
SCtgRentMgmt dbRent;
|
||||||
SCtgRentMgmt stbRent;
|
SCtgRentMgmt stbRent;
|
||||||
SCtgRentMgmt viewRent;
|
SCtgRentMgmt viewRent;
|
||||||
|
@ -377,6 +382,7 @@ typedef struct SCtgJob {
|
||||||
int32_t tbCfgNum;
|
int32_t tbCfgNum;
|
||||||
int32_t svrVerNum;
|
int32_t svrVerNum;
|
||||||
int32_t viewNum;
|
int32_t viewNum;
|
||||||
|
int32_t grantNum;
|
||||||
} SCtgJob;
|
} SCtgJob;
|
||||||
|
|
||||||
typedef struct SCtgMsgCtx {
|
typedef struct SCtgMsgCtx {
|
||||||
|
@ -560,6 +566,10 @@ typedef struct SCtgUpdateGrantInfoMsg {
|
||||||
SGrantHbRsp* pRsp;
|
SGrantHbRsp* pRsp;
|
||||||
} SCtgUpdateGrantInfoMsg;
|
} SCtgUpdateGrantInfoMsg;
|
||||||
|
|
||||||
|
typedef struct SCtgDropGrantInfoMsg {
|
||||||
|
SCatalog* pCtg;
|
||||||
|
} SCtgDropGrantInfoMsg;
|
||||||
|
|
||||||
typedef struct SCtgCacheOperation {
|
typedef struct SCtgCacheOperation {
|
||||||
int32_t opId;
|
int32_t opId;
|
||||||
void* data;
|
void* data;
|
||||||
|
@ -922,6 +932,7 @@ int32_t ctgOpDropDbVgroup(SCtgCacheOperation* action);
|
||||||
int32_t ctgOpDropStbMeta(SCtgCacheOperation* action);
|
int32_t ctgOpDropStbMeta(SCtgCacheOperation* action);
|
||||||
int32_t ctgOpDropTbMeta(SCtgCacheOperation* action);
|
int32_t ctgOpDropTbMeta(SCtgCacheOperation* action);
|
||||||
int32_t ctgOpDropViewMeta(SCtgCacheOperation* action);
|
int32_t ctgOpDropViewMeta(SCtgCacheOperation* action);
|
||||||
|
int32_t ctgOpDropGrantInfo(SCtgCacheOperation* action);
|
||||||
int32_t ctgOpUpdateUser(SCtgCacheOperation* action);
|
int32_t ctgOpUpdateUser(SCtgCacheOperation* action);
|
||||||
int32_t ctgOpUpdateEpset(SCtgCacheOperation* operation);
|
int32_t ctgOpUpdateEpset(SCtgCacheOperation* operation);
|
||||||
int32_t ctgAcquireVgInfoFromCache(SCatalog* pCtg, const char* dbFName, SCtgDBCache** pCache);
|
int32_t ctgAcquireVgInfoFromCache(SCatalog* pCtg, const char* dbFName, SCtgDBCache** pCache);
|
||||||
|
@ -969,6 +980,7 @@ int32_t ctgOpDropTbIndex(SCtgCacheOperation* operation);
|
||||||
int32_t ctgOpUpdateTbIndex(SCtgCacheOperation* operation);
|
int32_t ctgOpUpdateTbIndex(SCtgCacheOperation* operation);
|
||||||
int32_t ctgOpClearCache(SCtgCacheOperation* operation);
|
int32_t ctgOpClearCache(SCtgCacheOperation* operation);
|
||||||
int32_t ctgOpUpdateViewMeta(SCtgCacheOperation *operation);
|
int32_t ctgOpUpdateViewMeta(SCtgCacheOperation *operation);
|
||||||
|
int32_t ctgOpUpdateGrantInfo(SCtgCacheOperation *operation);
|
||||||
int32_t ctgReadTbTypeFromCache(SCatalog* pCtg, char* dbFName, char* tableName, int32_t* tbType);
|
int32_t ctgReadTbTypeFromCache(SCatalog* pCtg, char* dbFName, char* tableName, int32_t* tbType);
|
||||||
int32_t ctgGetTbHashVgroupFromCache(SCatalog* pCtg, const SName* pTableName, SVgroupInfo** pVgroup);
|
int32_t ctgGetTbHashVgroupFromCache(SCatalog* pCtg, const SName* pTableName, SVgroupInfo** pVgroup);
|
||||||
int32_t ctgGetViewsFromCache(SCatalog *pCtg, SRequestConnInfo *pConn, SCtgViewsCtx *ctx, int32_t dbIdx,
|
int32_t ctgGetViewsFromCache(SCatalog *pCtg, SRequestConnInfo *pConn, SCtgViewsCtx *ctx, int32_t dbIdx,
|
||||||
|
|
|
@ -160,6 +160,16 @@ int32_t ctgGetDBCache(SCatalog *pCtg, const char *dbFName, SCtgDBCache **pCache)
|
||||||
CTG_RET(ctgAcquireDBCacheImpl(pCtg, dbFName, pCache, false));
|
CTG_RET(ctgAcquireDBCacheImpl(pCtg, dbFName, pCache, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t ctgAcquireGrantCache(SCatalog *pCtg, SCtgGrantCache **ppCache) {
|
||||||
|
CTG_RET(ctgAcquireDBCacheImpl(pCtg, dbFName, pCache, true));
|
||||||
|
}
|
||||||
|
|
||||||
|
void ctgReleaseGrantCache(SCatalog *pCtg, SCtgGrantCache *pCache) {
|
||||||
|
CTG_UNLOCK(CTG_READ, &dbCache->dbLock);
|
||||||
|
taosHashRelease(pCtg->dbCache, dbCache);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void ctgReleaseVgInfoToCache(SCatalog *pCtg, SCtgDBCache *dbCache) {
|
void ctgReleaseVgInfoToCache(SCatalog *pCtg, SCtgDBCache *dbCache) {
|
||||||
ctgRUnlockVgInfo(dbCache);
|
ctgRUnlockVgInfo(dbCache);
|
||||||
ctgReleaseDBCache(pCtg, dbCache);
|
ctgReleaseDBCache(pCtg, dbCache);
|
||||||
|
@ -1512,6 +1522,47 @@ int32_t ctgGetAddDBCache(SCatalog *pCtg, const char *dbFName, uint64_t dbId, SCt
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t ctgGetAddGrantCache(SCatalog *pCtg, const char *dbFName, uint64_t dbId, SCtgDBCache **pCache) {
|
||||||
|
int32_t code = 0;
|
||||||
|
SCtgDBCache *dbCache = NULL;
|
||||||
|
ctgGetDBCache(pCtg, dbFName, &dbCache);
|
||||||
|
|
||||||
|
if (dbCache) {
|
||||||
|
// TODO OPEN IT
|
||||||
|
#if 0
|
||||||
|
if (dbCache->dbId == dbId) {
|
||||||
|
*pCache = dbCache;
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
if (0 == dbId) {
|
||||||
|
*pCache = dbCache;
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dbId && (dbCache->dbId == 0)) {
|
||||||
|
dbCache->dbId = dbId;
|
||||||
|
*pCache = dbCache;
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dbCache->dbId == dbId) {
|
||||||
|
*pCache = dbCache;
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
CTG_ERR_RET(ctgRemoveDBFromCache(pCtg, dbCache, dbFName));
|
||||||
|
}
|
||||||
|
|
||||||
|
CTG_ERR_RET(ctgAddNewDBCache(pCtg, dbFName, dbId));
|
||||||
|
|
||||||
|
ctgGetDBCache(pCtg, dbFName, &dbCache);
|
||||||
|
|
||||||
|
*pCache = dbCache;
|
||||||
|
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t ctgWriteTbMetaToCache(SCatalog *pCtg, SCtgDBCache *dbCache, char *dbFName, uint64_t dbId, char *tbName,
|
int32_t ctgWriteTbMetaToCache(SCatalog *pCtg, SCtgDBCache *dbCache, char *dbFName, uint64_t dbId, char *tbName,
|
||||||
STableMeta *meta, int32_t metaSize) {
|
STableMeta *meta, int32_t metaSize) {
|
||||||
if (NULL == dbCache->tbCache || NULL == dbCache->stbCache) {
|
if (NULL == dbCache->tbCache || NULL == dbCache->stbCache) {
|
||||||
|
@ -2488,8 +2539,6 @@ int32_t ctgOpUpdateGrantInfo(SCtgCacheOperation *operation) {
|
||||||
SCtgUpdateGrantInfoMsg *msg = operation->data;
|
SCtgUpdateGrantInfoMsg *msg = operation->data;
|
||||||
SCatalog *pCtg = msg->pCtg;
|
SCatalog *pCtg = msg->pCtg;
|
||||||
SGrantHbRsp *pRsp = msg->pRsp;
|
SGrantHbRsp *pRsp = msg->pRsp;
|
||||||
SCtgDBCache *dbCache = NULL;
|
|
||||||
SViewMeta *pMeta = NULL;
|
|
||||||
|
|
||||||
taosMemoryFreeClear(msg);
|
taosMemoryFreeClear(msg);
|
||||||
|
|
||||||
|
@ -2523,56 +2572,16 @@ _return:
|
||||||
CTG_RET(code);
|
CTG_RET(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t ctgOpDropViewMeta(SCtgCacheOperation *operation) {
|
int32_t ctgOpDropGrantInfo(SCtgCacheOperation *operation) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
SCtgDropViewMetaMsg *msg = operation->data;
|
SCtgDropGrantInfoMsg *msg = operation->data;
|
||||||
SCatalog *pCtg = msg->pCtg;
|
SCatalog *pCtg = msg->pCtg;
|
||||||
int32_t tblType = 0;
|
|
||||||
|
|
||||||
if (pCtg->stopUpdate) {
|
if (pCtg->stopUpdate) {
|
||||||
goto _return;
|
goto _return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SCtgDBCache *dbCache = NULL;
|
printf("prop:%s:%d grant %s removed from rent\n");
|
||||||
ctgGetDBCache(pCtg, msg->dbFName, &dbCache);
|
|
||||||
if (NULL == dbCache) {
|
|
||||||
goto _return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((0 != msg->dbId) && (dbCache->dbId != msg->dbId)) {
|
|
||||||
ctgDebug("dbId 0x%" PRIx64 " not match with curId 0x%" PRIx64 ", dbFName:%s, viewName:%s", msg->dbId, dbCache->dbId,
|
|
||||||
msg->dbFName, msg->viewName);
|
|
||||||
goto _return;
|
|
||||||
}
|
|
||||||
|
|
||||||
SCtgViewCache *pViewCache = taosHashGet(dbCache->viewCache, msg->viewName, strlen(msg->viewName));
|
|
||||||
if (NULL == pViewCache) {
|
|
||||||
ctgDebug("view %s already not in cache", msg->viewName);
|
|
||||||
goto _return;
|
|
||||||
}
|
|
||||||
|
|
||||||
int64_t viewId = pViewCache->pMeta->viewId;
|
|
||||||
if (0 != msg->viewId && viewId != msg->viewId) {
|
|
||||||
ctgDebug("viewId 0x%" PRIx64 " not match with curId 0x%" PRIx64 ", viewName:%s", msg->viewId, viewId, msg->viewName);
|
|
||||||
goto _return;
|
|
||||||
}
|
|
||||||
|
|
||||||
atomic_sub_fetch_64(&dbCache->dbCacheSize, ctgGetViewMetaCacheSize(pViewCache->pMeta));
|
|
||||||
ctgFreeViewCacheImpl(pViewCache, true);
|
|
||||||
|
|
||||||
if (taosHashRemove(dbCache->viewCache, msg->viewName, strlen(msg->viewName))) {
|
|
||||||
ctgError("view %s not exist in cache, dbFName:%s", msg->viewName, msg->dbFName);
|
|
||||||
CTG_ERR_JRET(TSDB_CODE_CTG_INTERNAL_ERROR);
|
|
||||||
} else {
|
|
||||||
atomic_sub_fetch_64(&dbCache->dbCacheSize, sizeof(SCtgViewCache) + strlen(msg->viewName));
|
|
||||||
CTG_DB_NUM_DEC(CTG_CI_VIEW);
|
|
||||||
}
|
|
||||||
|
|
||||||
ctgDebug("view %s removed from cache, dbFName:%s", msg->viewName, msg->dbFName);
|
|
||||||
|
|
||||||
CTG_ERR_JRET(ctgMetaRentRemove(&msg->pCtg->viewRent, viewId, ctgViewVersionSortCompare, ctgViewVersionSearchCompare));
|
|
||||||
|
|
||||||
ctgDebug("view %s removed from rent, dbFName:%s, viewId:0x%" PRIx64, msg->viewName, msg->dbFName, viewId);
|
|
||||||
|
|
||||||
_return:
|
_return:
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue