enh: support drop table by uid
This commit is contained in:
parent
981bfe3e88
commit
e16ac8aa5d
|
@ -240,6 +240,7 @@ typedef struct SDropTableStmt {
|
|||
ENodeType type;
|
||||
SNodeList* pTables;
|
||||
bool withTsma;
|
||||
bool withUid;
|
||||
} SDropTableStmt;
|
||||
|
||||
typedef struct SDropSuperTableStmt {
|
||||
|
@ -247,6 +248,7 @@ typedef struct SDropSuperTableStmt {
|
|||
char dbName[TSDB_DB_NAME_LEN];
|
||||
char tableName[TSDB_TABLE_NAME_LEN];
|
||||
bool ignoreNotExists;
|
||||
bool withUid;
|
||||
} SDropSuperTableStmt;
|
||||
|
||||
typedef struct SAlterTableStmt {
|
||||
|
|
|
@ -159,6 +159,7 @@ static const SSysDbTableSchema userStbsSchema[] = {
|
|||
{.name = "watermark", .bytes = 64 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
|
||||
{.name = "max_delay", .bytes = 64 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
|
||||
{.name = "rollup", .bytes = 128 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
|
||||
{.name = "uid", .bytes = 8, .type = TSDB_DATA_TYPE_BIGINT, .sysInfo = false},
|
||||
};
|
||||
|
||||
static const SSysDbTableSchema streamSchema[] = {
|
||||
|
|
|
@ -3588,6 +3588,11 @@ static int32_t mndRetrieveStb(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBloc
|
|||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
(void)colDataSetVal(pColInfo, numOfRows, (const char *)rollup, false);
|
||||
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
if (pColInfo) {
|
||||
(void)colDataSetVal(pColInfo, numOfRows, (const char *)(&pStb->uid), false);
|
||||
}
|
||||
|
||||
numOfRows++;
|
||||
sdbRelease(pSdb, pStb);
|
||||
}
|
||||
|
|
|
@ -1525,7 +1525,8 @@ int32_t ctgMakeVgArray(SDBVgInfo* dbInfo) {
|
|||
}
|
||||
|
||||
if (dbInfo->vgHash && NULL == dbInfo->vgArray) {
|
||||
dbInfo->vgArray = taosArrayInit(100, sizeof(SVgroupInfo));
|
||||
int32_t vgSize = taosHashGetSize(dbInfo->vgHash);
|
||||
dbInfo->vgArray = taosArrayInit(vgSize, sizeof(SVgroupInfo));
|
||||
if (NULL == dbInfo->vgArray) {
|
||||
CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
|
|
@ -6038,6 +6038,7 @@ static int32_t jsonToDropTableStmt(const SJson* pJson, void* pObj) {
|
|||
static const char* jkDropSuperTableStmtDbName = "DbName";
|
||||
static const char* jkDropSuperTableStmtTableName = "TableName";
|
||||
static const char* jkDropSuperTableStmtIgnoreNotExists = "IgnoreNotExists";
|
||||
static const char* jkDropSuperTableStmtWithUid = "WithUid";
|
||||
|
||||
static int32_t dropStableStmtToJson(const void* pObj, SJson* pJson) {
|
||||
const SDropSuperTableStmt* pNode = (const SDropSuperTableStmt*)pObj;
|
||||
|
@ -6049,6 +6050,9 @@ static int32_t dropStableStmtToJson(const void* pObj, SJson* pJson) {
|
|||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddBoolToObject(pJson, jkDropSuperTableStmtIgnoreNotExists, pNode->ignoreNotExists);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddBoolToObject(pJson, jkDropSuperTableStmtWithUid, pNode->withUid);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
@ -6063,6 +6067,9 @@ static int32_t jsonToDropStableStmt(const SJson* pJson, void* pObj) {
|
|||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonGetBoolValue(pJson, jkDropSuperTableStmtIgnoreNotExists, &pNode->ignoreNotExists);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonGetBoolValue(pJson, jkDropSuperTableStmtWithUid, &pNode->withUid);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
|
|
@ -211,8 +211,8 @@ SNode* createCreateSubTableFromFileClause(SAstCreateContext* pCxt, bool ignoreEx
|
|||
SNodeList* pSpecificTags, const SToken* pFilePath);
|
||||
SNode* createCreateMultiTableStmt(SAstCreateContext* pCxt, SNodeList* pSubTables);
|
||||
SNode* createDropTableClause(SAstCreateContext* pCxt, bool ignoreNotExists, SNode* pRealTable);
|
||||
SNode* createDropTableStmt(SAstCreateContext* pCxt, SNodeList* pTables);
|
||||
SNode* createDropSuperTableStmt(SAstCreateContext* pCxt, bool ignoreNotExists, SNode* pRealTable);
|
||||
SNode* createDropTableStmt(SAstCreateContext* pCxt, bool withOpt, SNodeList* pTables);
|
||||
SNode* createDropSuperTableStmt(SAstCreateContext* pCxt, bool withOpt, bool ignoreNotExists, SNode* pRealTable);
|
||||
SNode* createAlterTableModifyOptions(SAstCreateContext* pCxt, SNode* pRealTable, SNode* pOptions);
|
||||
SNode* createAlterTableAddModifyCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType, SToken* pColName,
|
||||
SDataType dataType);
|
||||
|
|
|
@ -124,8 +124,8 @@ sysinfo_opt(A) ::= .
|
|||
sysinfo_opt(A) ::= SYSINFO NK_INTEGER(B). { A = taosStr2Int8(B.z, NULL, 10); }
|
||||
|
||||
/************************************************ grant/revoke ********************************************************/
|
||||
cmd ::= GRANT privileges(A) ON priv_level(B) with_opt(D) TO user_name(C). { pCxt->pRootNode = createGrantStmt(pCxt, A, &B, &C, D); }
|
||||
cmd ::= REVOKE privileges(A) ON priv_level(B) with_opt(D) FROM user_name(C). { pCxt->pRootNode = createRevokeStmt(pCxt, A, &B, &C, D); }
|
||||
cmd ::= GRANT privileges(A) ON priv_level(B) with_clause_opt(D) TO user_name(C). { pCxt->pRootNode = createGrantStmt(pCxt, A, &B, &C, D); }
|
||||
cmd ::= REVOKE privileges(A) ON priv_level(B) with_clause_opt(D) FROM user_name(C). { pCxt->pRootNode = createRevokeStmt(pCxt, A, &B, &C, D); }
|
||||
|
||||
%type privileges { int64_t }
|
||||
%destructor privileges { }
|
||||
|
@ -151,8 +151,8 @@ priv_level(A) ::= db_name(B) NK_DOT NK_STAR(C).
|
|||
priv_level(A) ::= db_name(B) NK_DOT table_name(C). { A.first = B; A.second = C; }
|
||||
priv_level(A) ::= topic_name(B). { A.first = B; A.second = nil_token; }
|
||||
|
||||
with_opt(A) ::= . { A = NULL; }
|
||||
with_opt(A) ::= WITH search_condition(B). { A = B; }
|
||||
with_clause_opt(A) ::= . { A = NULL; }
|
||||
with_clause_opt(A) ::= WITH search_condition(B). { A = B; }
|
||||
|
||||
/************************************************ create encrypt_key *********************************************/
|
||||
cmd ::= CREATE ENCRYPT_KEY NK_STRING(A). { pCxt->pRootNode = createEncryptKeyStmt(pCxt, &A); }
|
||||
|
@ -357,8 +357,8 @@ cmd ::= CREATE TABLE not_exists_opt(B) USING full_table_name(C)
|
|||
NK_LP tag_list_opt(D) NK_RP FILE NK_STRING(E). { pCxt->pRootNode = createCreateSubTableFromFileClause(pCxt, B, C, D, &E); }
|
||||
cmd ::= CREATE STABLE not_exists_opt(A) full_table_name(B)
|
||||
NK_LP column_def_list(C) NK_RP tags_def(D) table_options(E). { pCxt->pRootNode = createCreateTableStmt(pCxt, A, B, C, D, E); }
|
||||
cmd ::= DROP TABLE multi_drop_clause(A). { pCxt->pRootNode = createDropTableStmt(pCxt, A); }
|
||||
cmd ::= DROP STABLE exists_opt(A) full_table_name(B). { pCxt->pRootNode = createDropSuperTableStmt(pCxt, A, B); }
|
||||
cmd ::= DROP TABLE with_opt(A) multi_drop_clause(B). { pCxt->pRootNode = createDropTableStmt(pCxt, A, B); }
|
||||
cmd ::= DROP STABLE with_opt(A) exists_opt(B) full_table_name(C). { pCxt->pRootNode = createDropSuperTableStmt(pCxt, A, B, C); }
|
||||
|
||||
cmd ::= ALTER TABLE alter_table_clause(A). { pCxt->pRootNode = A; }
|
||||
cmd ::= ALTER STABLE alter_table_clause(A). { pCxt->pRootNode = setAlterSuperTableType(A); }
|
||||
|
@ -399,6 +399,11 @@ multi_drop_clause(A) ::= multi_drop_clause(B) NK_COMMA drop_table_clause(C).
|
|||
|
||||
drop_table_clause(A) ::= exists_opt(B) full_table_name(C). { A = createDropTableClause(pCxt, B, C); }
|
||||
|
||||
%type with_opt { bool }
|
||||
%destructor with_opt { }
|
||||
with_opt(A) ::= . { A = false; }
|
||||
with_opt(A) ::= WITH. { A = true; }
|
||||
|
||||
%type specific_cols_opt { SNodeList* }
|
||||
%destructor specific_cols_opt { nodesDestroyList($$); }
|
||||
specific_cols_opt(A) ::= . { A = NULL; }
|
||||
|
|
|
@ -2354,19 +2354,20 @@ _err:
|
|||
return NULL;
|
||||
}
|
||||
|
||||
SNode* createDropTableStmt(SAstCreateContext* pCxt, SNodeList* pTables) {
|
||||
SNode* createDropTableStmt(SAstCreateContext* pCxt, bool withOpt, SNodeList* pTables) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
SDropTableStmt* pStmt = NULL;
|
||||
pCxt->errCode = nodesMakeNode(QUERY_NODE_DROP_TABLE_STMT, (SNode**)&pStmt);
|
||||
CHECK_MAKE_NODE(pStmt);
|
||||
pStmt->pTables = pTables;
|
||||
pStmt->withUid = withOpt;
|
||||
return (SNode*)pStmt;
|
||||
_err:
|
||||
nodesDestroyList(pTables);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SNode* createDropSuperTableStmt(SAstCreateContext* pCxt, bool ignoreNotExists, SNode* pRealTable) {
|
||||
SNode* createDropSuperTableStmt(SAstCreateContext* pCxt, bool withOpt, bool ignoreNotExists, SNode* pRealTable) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
SDropSuperTableStmt* pStmt = NULL;
|
||||
pCxt->errCode = nodesMakeNode(QUERY_NODE_DROP_SUPER_TABLE_STMT, (SNode**)&pStmt);
|
||||
|
@ -2374,6 +2375,7 @@ SNode* createDropSuperTableStmt(SAstCreateContext* pCxt, bool ignoreNotExists, S
|
|||
strcpy(pStmt->dbName, ((SRealTableNode*)pRealTable)->table.dbName);
|
||||
strcpy(pStmt->tableName, ((SRealTableNode*)pRealTable)->table.tableName);
|
||||
pStmt->ignoreNotExists = ignoreNotExists;
|
||||
pStmt->withUid = withOpt;
|
||||
nodesDestroyNode(pRealTable);
|
||||
return (SNode*)pStmt;
|
||||
_err:
|
||||
|
|
|
@ -377,16 +377,27 @@ static int32_t collectMetaKeyFromCreateSubTableFromFile(SCollectMetaKeyCxt*
|
|||
static int32_t collectMetaKeyFromDropTable(SCollectMetaKeyCxt* pCxt, SDropTableStmt* pStmt) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
SNode* pNode = NULL;
|
||||
char tableName[50] = "aa\u00bf\u200bstb0";
|
||||
FOREACH(pNode, pStmt->pTables) {
|
||||
SDropTableClause* pClause = (SDropTableClause*)pNode;
|
||||
code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, pClause->dbName, pClause->tableName, pCxt->pMetaCache);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, pClause->dbName, tableName, pCxt->pMetaCache);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = reserveTableVgroupInCache(pCxt->pParseCxt->acctId, pClause->dbName, pClause->tableName, pCxt->pMetaCache);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = reserveTableVgroupInCache(pCxt->pParseCxt->acctId, pClause->dbName, tableName, pCxt->pMetaCache);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pClause->dbName,
|
||||
pClause->tableName, AUTH_TYPE_WRITE, pCxt->pMetaCache);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pClause->dbName,
|
||||
tableName, AUTH_TYPE_WRITE, pCxt->pMetaCache);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -14449,12 +14449,31 @@ int32_t serializeVgroupsDropTableBatch(SHashObj* pVgroupHashmap, SArray** pOut)
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t rewriteDropTableWithUid(STranslateContext* pCxt, SDropTableStmt* pStmt) {
|
||||
if (!pStmt->withUid) return TSDB_CODE_SUCCESS;
|
||||
|
||||
SNode* pNode = NULL;
|
||||
const char* pTableName = NULL;
|
||||
FOREACH(pNode, pStmt->pTables) {
|
||||
SDropTableClause* pClause = (SDropTableClause*)pNode;
|
||||
pTableName = "aa\u00bf\u200bstb0";
|
||||
if (!pTableName) {
|
||||
return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_TABLE_NOT_EXIST, "Table does not exist: '%s'",
|
||||
pClause->tableName);
|
||||
}
|
||||
tstrncpy(pClause->tableName, pTableName, TSDB_TABLE_NAME_LEN);
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t rewriteDropTable(STranslateContext* pCxt, SQuery* pQuery) {
|
||||
SDropTableStmt* pStmt = (SDropTableStmt*)pQuery->pRoot;
|
||||
int8_t tableType;
|
||||
SNode* pNode;
|
||||
SArray* pTsmas = NULL;
|
||||
|
||||
TAOS_CHECK_RETURN(rewriteDropTableWithUid(pCxt, pStmt));
|
||||
|
||||
SHashObj* pVgroupHashmap = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_NO_LOCK);
|
||||
if (NULL == pVgroupHashmap) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -956,6 +956,8 @@ void* varObtainThread(void* param) {
|
|||
// return true is need update value by async
|
||||
bool updateTireValue(int type, bool autoFill) {
|
||||
// TYPE CONTEXT GET FROM DB
|
||||
return true;
|
||||
#if 0
|
||||
taosThreadMutexLock(&tiresMutex);
|
||||
|
||||
// check need obtain from server
|
||||
|
@ -981,8 +983,8 @@ bool updateTireValue(int type, bool autoFill) {
|
|||
return true;
|
||||
}
|
||||
taosThreadMutexUnlock(&tiresMutex);
|
||||
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
// only match next one word from all match words, return valuue must free by caller
|
||||
|
|
Loading…
Reference in New Issue