Merge pull request #4459 from taosdata/patch/TD-2342
[TD-2342]<fix>: disallow cross db create child table
This commit is contained in:
commit
6de0da5412
|
@ -25,6 +25,8 @@ void extractTableName(const char *tableId, char *name);
|
||||||
|
|
||||||
char* extractDBName(const char *tableId, char *name);
|
char* extractDBName(const char *tableId, char *name);
|
||||||
|
|
||||||
|
size_t tableIdPrefix(const char* name, char* prefix, int32_t len);
|
||||||
|
|
||||||
void extractTableNameFromToken(SStrToken *pToken, SStrToken* pTable);
|
void extractTableNameFromToken(SStrToken *pToken, SStrToken* pTable);
|
||||||
|
|
||||||
SSchema tGetTableNameColumnSchema();
|
SSchema tGetTableNameColumnSchema();
|
||||||
|
|
|
@ -39,6 +39,13 @@ char* extractDBName(const char* tableId, char* name) {
|
||||||
return strncpy(name, &tableId[offset1 + 1], len);
|
return strncpy(name, &tableId[offset1 + 1], len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t tableIdPrefix(const char* name, char* prefix, int32_t len) {
|
||||||
|
tstrncpy(prefix, name, len);
|
||||||
|
strcat(prefix, TS_PATH_DELIMITER);
|
||||||
|
|
||||||
|
return strlen(prefix);
|
||||||
|
}
|
||||||
|
|
||||||
SSchema tGetTableNameColumnSchema() {
|
SSchema tGetTableNameColumnSchema() {
|
||||||
SSchema s = {0};
|
SSchema s = {0};
|
||||||
s.bytes = TSDB_TABLE_NAME_LEN - 1 + VARSTR_HEADER_SIZE;
|
s.bytes = TSDB_TABLE_NAME_LEN - 1 + VARSTR_HEADER_SIZE;
|
||||||
|
|
|
@ -1734,6 +1734,16 @@ static int32_t mnodeDoCreateChildTable(SMnodeMsg *pMsg, int32_t tid) {
|
||||||
|
|
||||||
if (pTable->info.type == TSDB_CHILD_TABLE) {
|
if (pTable->info.type == TSDB_CHILD_TABLE) {
|
||||||
STagData *pTagData = (STagData *)pCreate->schema; // it is a tag key
|
STagData *pTagData = (STagData *)pCreate->schema; // it is a tag key
|
||||||
|
|
||||||
|
char prefix[64] = {0};
|
||||||
|
size_t prefixLen = tableIdPrefix(pMsg->pDb->name, prefix, 64);
|
||||||
|
if (0 != strncasecmp(prefix, pTagData->name, prefixLen)) {
|
||||||
|
mError("msg:%p, app:%p table:%s, corresponding super table:%s not in this db", pMsg, pMsg->rpcMsg.ahandle,
|
||||||
|
pCreate->tableId, pTagData->name);
|
||||||
|
mnodeDestroyChildTable(pTable);
|
||||||
|
return TSDB_CODE_TDB_INVALID_CREATE_TB_MSG;
|
||||||
|
}
|
||||||
|
|
||||||
if (pMsg->pSTable == NULL) pMsg->pSTable = mnodeGetSuperTable(pTagData->name);
|
if (pMsg->pSTable == NULL) pMsg->pSTable = mnodeGetSuperTable(pTagData->name);
|
||||||
if (pMsg->pSTable == NULL) {
|
if (pMsg->pSTable == NULL) {
|
||||||
mError("msg:%p, app:%p table:%s, corresponding super table:%s does not exist", pMsg, pMsg->rpcMsg.ahandle,
|
mError("msg:%p, app:%p table:%s, corresponding super table:%s does not exist", pMsg, pMsg->rpcMsg.ahandle,
|
||||||
|
@ -2629,9 +2639,7 @@ static int32_t mnodeRetrieveShowTables(SShowObj *pShow, char *data, int32_t rows
|
||||||
SPatternCompareInfo info = PATTERN_COMPARE_INFO_INITIALIZER;
|
SPatternCompareInfo info = PATTERN_COMPARE_INFO_INITIALIZER;
|
||||||
|
|
||||||
char prefix[64] = {0};
|
char prefix[64] = {0};
|
||||||
tstrncpy(prefix, pDb->name, 64);
|
int32_t prefixLen = tableIdPrefix(pDb->name, prefix, 64);
|
||||||
strcat(prefix, TS_PATH_DELIMITER);
|
|
||||||
int32_t prefixLen = strlen(prefix);
|
|
||||||
|
|
||||||
char* pattern = NULL;
|
char* pattern = NULL;
|
||||||
if (pShow->payloadLen > 0) {
|
if (pShow->payloadLen > 0) {
|
||||||
|
|
Loading…
Reference in New Issue