diff --git a/include/util/taoserror.h b/include/util/taoserror.h index c6f0c759afac70e94e6f0727e0f2c7f773697876..1cec7e1c54e13b5998a0121f87520df3e852e6f1 100644 --- a/include/util/taoserror.h +++ b/include/util/taoserror.h @@ -218,18 +218,19 @@ int32_t* taosGetErrno(); // mnode-stable #define TSDB_CODE_MND_STB_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x03A0) #define TSDB_CODE_MND_STB_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x03A1) -#define TSDB_CODE_MND_TOO_MANY_STBS TAOS_DEF_ERROR_CODE(0, 0x03A2) -#define TSDB_CODE_MND_INVALID_STB TAOS_DEF_ERROR_CODE(0, 0x03A3) -#define TSDB_CODE_MND_INVALID_STB_OPTION TAOS_DEF_ERROR_CODE(0, 0x03A4) -#define TSDB_CODE_MND_STB_OPTION_UNCHNAGED TAOS_DEF_ERROR_CODE(0, 0x03A5) -#define TSDB_CODE_MND_TOO_MANY_TAGS TAOS_DEF_ERROR_CODE(0, 0x03A6) -#define TSDB_CODE_MND_TAG_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x03A7) -#define TSDB_CODE_MND_TAG_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x03A8) -#define TSDB_CODE_MND_TOO_MANY_COLUMNS TAOS_DEF_ERROR_CODE(0, 0x03A9) -#define TSDB_CODE_MND_COLUMN_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x03AA) -#define TSDB_CODE_MND_COLUMN_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x03AB) -#define TSDB_CODE_MND_INVALID_ROW_BYTES TAOS_DEF_ERROR_CODE(0, 0x03AC) -#define TSDB_CODE_MND_NAME_CONFLICT_WITH_TOPIC TAOS_DEF_ERROR_CODE(0, 0x03AD) +#define TSDB_CODE_MND_NAME_CONFLICT_WITH_TOPIC TAOS_DEF_ERROR_CODE(0, 0x03A2) +#define TSDB_CODE_MND_TOO_MANY_STBS TAOS_DEF_ERROR_CODE(0, 0x03A3) +#define TSDB_CODE_MND_INVALID_STB TAOS_DEF_ERROR_CODE(0, 0x03A4) +#define TSDB_CODE_MND_INVALID_STB_OPTION TAOS_DEF_ERROR_CODE(0, 0x03A5) +#define TSDB_CODE_MND_INVALID_STB_ALTER_OPTION TAOS_DEF_ERROR_CODE(0, 0x03A6) +#define TSDB_CODE_MND_STB_OPTION_UNCHNAGED TAOS_DEF_ERROR_CODE(0, 0x03A7) +#define TSDB_CODE_MND_INVALID_ROW_BYTES TAOS_DEF_ERROR_CODE(0, 0x03A8) +#define TSDB_CODE_MND_TOO_MANY_TAGS TAOS_DEF_ERROR_CODE(0, 0x03A9) +#define TSDB_CODE_MND_TAG_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x03AA) +#define TSDB_CODE_MND_TAG_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x03AB) +#define TSDB_CODE_MND_TOO_MANY_COLUMNS TAOS_DEF_ERROR_CODE(0, 0x03AC) +#define TSDB_CODE_MND_COLUMN_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x03AD) +#define TSDB_CODE_MND_COLUMN_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x03AE) // mnode-func #define TSDB_CODE_MND_FUNC_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x03C0) diff --git a/source/dnode/mnode/impl/src/mndStb.c b/source/dnode/mnode/impl/src/mndStb.c index 2280d36ac346d6133da458a2691ade2c6e33c07d..e184c7e04e08d2754854b296996783ff939d299a 100644 --- a/source/dnode/mnode/impl/src/mndStb.c +++ b/source/dnode/mnode/impl/src/mndStb.c @@ -740,16 +740,17 @@ static int32_t mndAlterStbTagBytes(const SStbObj *pOld, SStbObj *pNew, const SSc } SSchema *pTag = pNew->pTags + tag; - if (pSchema->bytes <= pTag->bytes) { - terrno = TSDB_CODE_MND_INVALID_ROW_BYTES; - return -1; - } if (!(pTag->type == TSDB_DATA_TYPE_BINARY || pTag->type == TSDB_DATA_TYPE_NCHAR)) { terrno = TSDB_CODE_MND_INVALID_STB_OPTION; return -1; } + if (pSchema->bytes <= pTag->bytes) { + terrno = TSDB_CODE_MND_INVALID_ROW_BYTES; + return -1; + } + pTag->bytes = pSchema->bytes; pNew->version++; @@ -765,12 +766,12 @@ static int32_t mndAddSuperTableColumn(const SStbObj *pOld, SStbObj *pNew, const for (int32_t i = 0; i < ncols; i++) { if (mndFindSuperTableColumnIndex(pOld, pSchemas[i].name) > 0) { - terrno = TSDB_CODE_MND_TAG_ALREADY_EXIST; + terrno = TSDB_CODE_MND_COLUMN_ALREADY_EXIST; return -1; } if (mndFindSuperTableTagIndex(pOld, pSchemas[i].name) > 0) { - terrno = TSDB_CODE_MND_COLUMN_ALREADY_EXIST; + terrno = TSDB_CODE_MND_TAG_ALREADY_EXIST; return -1; } } @@ -795,11 +796,21 @@ static int32_t mndAddSuperTableColumn(const SStbObj *pOld, SStbObj *pNew, const static int32_t mndDropSuperTableColumn(const SStbObj *pOld, SStbObj *pNew, const char *colName) { int32_t col = mndFindSuperTableColumnIndex(pOld, colName); - if (col <= 0) { + if (col < 0) { terrno = TSDB_CODE_MND_COLUMN_NOT_EXIST; return -1; } + if (col == 0) { + terrno = TSDB_CODE_MND_INVALID_STB_ALTER_OPTION; + return -1; + } + + if (pOld->numOfColumns == 2) { + terrno = TSDB_CODE_MND_INVALID_STB_ALTER_OPTION; + return -1; + } + if (mndAllocStbSchemas(pOld, pNew) != 0) { return -1; } @@ -834,13 +845,13 @@ static int32_t mndAlterStbColumnBytes(const SStbObj *pOld, SStbObj *pNew, const } SSchema *pCol = pNew->pColumns + col; - if (pSchema->bytes <= pCol->bytes) { - terrno = TSDB_CODE_MND_INVALID_ROW_BYTES; + if (!(pCol->type == TSDB_DATA_TYPE_BINARY || pCol->type == TSDB_DATA_TYPE_NCHAR)) { + terrno = TSDB_CODE_MND_INVALID_STB_OPTION; return -1; } - if (!(pCol->type == TSDB_DATA_TYPE_BINARY || pCol->type == TSDB_DATA_TYPE_NCHAR)) { - terrno = TSDB_CODE_MND_INVALID_STB_OPTION; + if (pSchema->bytes <= pCol->bytes) { + terrno = TSDB_CODE_MND_INVALID_ROW_BYTES; return -1; } diff --git a/source/dnode/mnode/impl/test/stb/stb.cpp b/source/dnode/mnode/impl/test/stb/stb.cpp index fd0a7dbb7337ae6c437ae3cb0a849f79d3842d19..402795eb039bd8992545f690318ca9aabbf02acb 100644 --- a/source/dnode/mnode/impl/test/stb/stb.cpp +++ b/source/dnode/mnode/impl/test/stb/stb.cpp @@ -23,13 +23,18 @@ class MndTestStb : public ::testing::Test { void TearDown() override {} SCreateDbReq* BuildCreateDbReq(const char* dbname, int32_t* pContLen); + SDropDbReq* BuildDropDbReq(const char* dbname, int32_t* pContLen); SMCreateStbReq* BuildCreateStbReq(const char* stbname, int32_t* pContLen); SMAltertbReq* BuildAlterStbAddTagReq(const char* stbname, const char* tagname, int32_t* pContLen); SMAltertbReq* BuildAlterStbDropTagReq(const char* stbname, const char* tagname, int32_t* pContLen); SMAltertbReq* BuildAlterStbUpdateTagNameReq(const char* stbname, const char* tagname, const char* newtagname, int32_t* pContLen); SMAltertbReq* BuildAlterStbUpdateTagBytesReq(const char* stbname, const char* tagname, int32_t bytes, - int32_t* pContLen); + int32_t* pContLen); + SMAltertbReq* BuildAlterStbAddColumnReq(const char* stbname, const char* colname, int32_t* pContLen); + SMAltertbReq* BuildAlterStbDropColumnReq(const char* stbname, const char* colname, int32_t* pContLen); + SMAltertbReq* BuildAlterStbUpdateColumnBytesReq(const char* stbname, const char* colname, int32_t bytes, + int32_t* pContLen); }; Testbase MndTestStb::test; @@ -63,6 +68,16 @@ SCreateDbReq* MndTestStb::BuildCreateDbReq(const char* dbname, int32_t* pContLen return pReq; } +SDropDbReq* MndTestStb::BuildDropDbReq(const char* dbname, int32_t* pContLen) { + int32_t contLen = sizeof(SDropDbReq); + + SDropDbReq* pReq = (SDropDbReq*)rpcMallocCont(contLen); + strcpy(pReq->db, dbname); + + *pContLen = contLen; + return pReq; +} + SMCreateStbReq* MndTestStb::BuildCreateStbReq(const char* stbname, int32_t* pContLen) { int32_t cols = 2; int32_t tags = 3; @@ -82,8 +97,8 @@ SMCreateStbReq* MndTestStb::BuildCreateStbReq(const char* stbname, int32_t* pCon { SSchema* pSchema = &pReq->pSchemas[1]; - pSchema->bytes = htonl(4); - pSchema->type = TSDB_DATA_TYPE_INT; + pSchema->bytes = htonl(12); + pSchema->type = TSDB_DATA_TYPE_BINARY; strcpy(pSchema->name, "col1"); } @@ -112,6 +127,126 @@ SMCreateStbReq* MndTestStb::BuildCreateStbReq(const char* stbname, int32_t* pCon return pReq; } +SMAltertbReq* MndTestStb::BuildAlterStbAddTagReq(const char* stbname, const char* tagname, int32_t* pContLen) { + int32_t contLen = sizeof(SMAltertbReq) + sizeof(SSchema); + SMAltertbReq* pReq = (SMAltertbReq*)rpcMallocCont(contLen); + strcpy(pReq->name, stbname); + pReq->numOfSchemas = htonl(1); + pReq->alterType = TSDB_ALTER_TABLE_ADD_TAG; + + SSchema* pSchema = &pReq->pSchemas[0]; + pSchema->bytes = htonl(12); + pSchema->type = TSDB_DATA_TYPE_BINARY; + strcpy(pSchema->name, tagname); + + *pContLen = contLen; + return pReq; +} + +SMAltertbReq* MndTestStb::BuildAlterStbDropTagReq(const char* stbname, const char* tagname, int32_t* pContLen) { + int32_t contLen = sizeof(SMAltertbReq) + sizeof(SSchema); + SMAltertbReq* pReq = (SMAltertbReq*)rpcMallocCont(contLen); + strcpy(pReq->name, stbname); + pReq->numOfSchemas = htonl(1); + pReq->alterType = TSDB_ALTER_TABLE_DROP_TAG; + + SSchema* pSchema = &pReq->pSchemas[0]; + pSchema->bytes = htonl(12); + pSchema->type = TSDB_DATA_TYPE_BINARY; + strcpy(pSchema->name, tagname); + + *pContLen = contLen; + return pReq; +} + +SMAltertbReq* MndTestStb::BuildAlterStbUpdateTagNameReq(const char* stbname, const char* tagname, + const char* newtagname, int32_t* pContLen) { + int32_t contLen = sizeof(SMAltertbReq) + 2 * sizeof(SSchema); + SMAltertbReq* pReq = (SMAltertbReq*)rpcMallocCont(contLen); + strcpy(pReq->name, stbname); + pReq->numOfSchemas = htonl(1); + pReq->alterType = TSDB_ALTER_TABLE_UPDATE_TAG_NAME; + + SSchema* pSchema = &pReq->pSchemas[0]; + pSchema->bytes = htonl(12); + pSchema->type = TSDB_DATA_TYPE_BINARY; + strcpy(pSchema->name, tagname); + + pSchema = &pReq->pSchemas[1]; + pSchema->bytes = htonl(12); + pSchema->type = TSDB_DATA_TYPE_BINARY; + strcpy(pSchema->name, newtagname); + + *pContLen = contLen; + return pReq; +} + +SMAltertbReq* MndTestStb::BuildAlterStbUpdateTagBytesReq(const char* stbname, const char* tagname, int32_t bytes, + int32_t* pContLen) { + int32_t contLen = sizeof(SMAltertbReq) + sizeof(SSchema); + SMAltertbReq* pReq = (SMAltertbReq*)rpcMallocCont(contLen); + strcpy(pReq->name, stbname); + pReq->numOfSchemas = htonl(1); + pReq->alterType = TSDB_ALTER_TABLE_UPDATE_TAG_BYTES; + + SSchema* pSchema = &pReq->pSchemas[0]; + pSchema->bytes = htonl(bytes); + pSchema->type = TSDB_DATA_TYPE_BINARY; + strcpy(pSchema->name, tagname); + + *pContLen = contLen; + return pReq; +} + +SMAltertbReq* MndTestStb::BuildAlterStbAddColumnReq(const char* stbname, const char* colname, int32_t* pContLen) { + int32_t contLen = sizeof(SMAltertbReq) + sizeof(SSchema); + SMAltertbReq* pReq = (SMAltertbReq*)rpcMallocCont(contLen); + strcpy(pReq->name, stbname); + pReq->numOfSchemas = htonl(1); + pReq->alterType = TSDB_ALTER_TABLE_ADD_COLUMN; + + SSchema* pSchema = &pReq->pSchemas[0]; + pSchema->bytes = htonl(12); + pSchema->type = TSDB_DATA_TYPE_BINARY; + strcpy(pSchema->name, colname); + + *pContLen = contLen; + return pReq; +} + +SMAltertbReq* MndTestStb::BuildAlterStbDropColumnReq(const char* stbname, const char* colname, int32_t* pContLen) { + int32_t contLen = sizeof(SMAltertbReq) + sizeof(SSchema); + SMAltertbReq* pReq = (SMAltertbReq*)rpcMallocCont(contLen); + strcpy(pReq->name, stbname); + pReq->numOfSchemas = htonl(1); + pReq->alterType = TSDB_ALTER_TABLE_DROP_COLUMN; + + SSchema* pSchema = &pReq->pSchemas[0]; + pSchema->bytes = htonl(12); + pSchema->type = TSDB_DATA_TYPE_BINARY; + strcpy(pSchema->name, colname); + + *pContLen = contLen; + return pReq; +} + +SMAltertbReq* MndTestStb::BuildAlterStbUpdateColumnBytesReq(const char* stbname, const char* colname, int32_t bytes, + int32_t* pContLen) { + int32_t contLen = sizeof(SMAltertbReq) + sizeof(SSchema); + SMAltertbReq* pReq = (SMAltertbReq*)rpcMallocCont(contLen); + strcpy(pReq->name, stbname); + pReq->numOfSchemas = htonl(1); + pReq->alterType = TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES; + + SSchema* pSchema = &pReq->pSchemas[0]; + pSchema->bytes = htonl(bytes); + pSchema->type = TSDB_DATA_TYPE_BINARY; + strcpy(pSchema->name, colname); + + *pContLen = contLen; + return pReq; +} + TEST_F(MndTestStb, 01_Create_Show_Meta_Drop_Restart_Stb) { const char* dbname = "1.d1"; const char* stbname = "1.d1.stb"; @@ -197,9 +332,9 @@ TEST_F(MndTestStb, 01_Create_Show_Meta_Drop_Restart_Stb) { { SSchema* pSchema = &pRsp->pSchema[1]; - EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_INT); + EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_BINARY); EXPECT_EQ(pSchema->colId, 2); - EXPECT_EQ(pSchema->bytes, 4); + EXPECT_EQ(pSchema->bytes, 12); EXPECT_STREQ(pSchema->name, "col1"); } @@ -254,89 +389,28 @@ TEST_F(MndTestStb, 01_Create_Show_Meta_Drop_Restart_Stb) { ASSERT_EQ(pRsp->code, 0); } - test.SendShowMetaReq(TSDB_MGMT_TABLE_STB, dbname); - CHECK_META("show stables", 4); - test.SendShowRetrieveReq(); - EXPECT_EQ(test.GetShowRows(), 0); -} - -SMAltertbReq* MndTestStb::BuildAlterStbAddTagReq(const char* stbname, const char* tagname, int32_t* pContLen) { - int32_t contLen = sizeof(SMAltertbReq) + sizeof(SSchema); - SMAltertbReq* pReq = (SMAltertbReq*)rpcMallocCont(contLen); - strcpy(pReq->name, stbname); - pReq->numOfSchemas = htonl(1); - pReq->alterType = TSDB_ALTER_TABLE_ADD_TAG; - - SSchema* pSchema = &pReq->pSchemas[0]; - pSchema->bytes = htonl(12); - pSchema->type = TSDB_DATA_TYPE_BINARY; - strcpy(pSchema->name, tagname); - - *pContLen = contLen; - return pReq; -} - -SMAltertbReq* MndTestStb::BuildAlterStbDropTagReq(const char* stbname, const char* tagname, int32_t* pContLen) { - int32_t contLen = sizeof(SMAltertbReq) + sizeof(SSchema); - SMAltertbReq* pReq = (SMAltertbReq*)rpcMallocCont(contLen); - strcpy(pReq->name, stbname); - pReq->numOfSchemas = htonl(1); - pReq->alterType = TSDB_ALTER_TABLE_DROP_TAG; - - SSchema* pSchema = &pReq->pSchemas[0]; - pSchema->bytes = htonl(12); - pSchema->type = TSDB_DATA_TYPE_BINARY; - strcpy(pSchema->name, tagname); - - *pContLen = contLen; - return pReq; -} - -SMAltertbReq* MndTestStb::BuildAlterStbUpdateTagNameReq(const char* stbname, const char* tagname, - const char* newtagname, int32_t* pContLen) { - int32_t contLen = sizeof(SMAltertbReq) + 2 * sizeof(SSchema); - SMAltertbReq* pReq = (SMAltertbReq*)rpcMallocCont(contLen); - strcpy(pReq->name, stbname); - pReq->numOfSchemas = htonl(1); - pReq->alterType = TSDB_ALTER_TABLE_UPDATE_TAG_NAME; - - SSchema* pSchema = &pReq->pSchemas[0]; - pSchema->bytes = htonl(12); - pSchema->type = TSDB_DATA_TYPE_BINARY; - strcpy(pSchema->name, tagname); - - pSchema = &pReq->pSchemas[1]; - pSchema->bytes = htonl(12); - pSchema->type = TSDB_DATA_TYPE_BINARY; - strcpy(pSchema->name, newtagname); - - *pContLen = contLen; - return pReq; -} - -SMAltertbReq* MndTestStb::BuildAlterStbUpdateTagBytesReq(const char* stbname, const char* tagname, int32_t bytes, - int32_t* pContLen) { - int32_t contLen = sizeof(SMAltertbReq) + sizeof(SSchema); - SMAltertbReq* pReq = (SMAltertbReq*)rpcMallocCont(contLen); - strcpy(pReq->name, stbname); - pReq->numOfSchemas = htonl(1); - pReq->alterType = TSDB_ALTER_TABLE_UPDATE_TAG_BYTES; - - SSchema* pSchema = &pReq->pSchemas[0]; - pSchema->bytes = htonl(bytes); - pSchema->type = TSDB_DATA_TYPE_BINARY; - strcpy(pSchema->name, tagname); + { + test.SendShowMetaReq(TSDB_MGMT_TABLE_STB, dbname); + CHECK_META("show stables", 4); + test.SendShowRetrieveReq(); + EXPECT_EQ(test.GetShowRows(), 0); + } - *pContLen = contLen; - return pReq; + { + int32_t contLen = 0; + SDropDbReq* pReq = BuildDropDbReq(dbname, &contLen); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_DB, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); + } } TEST_F(MndTestStb, 02_Alter_Stb_AddTag) { const char* dbname = "1.d2"; const char* stbname = "1.d2.stb"; + int32_t contLen = 0; { - int32_t contLen = 0; SCreateDbReq* pReq = BuildCreateDbReq(dbname, &contLen); SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen); ASSERT_NE(pRsp, nullptr); @@ -344,15 +418,12 @@ TEST_F(MndTestStb, 02_Alter_Stb_AddTag) { } { - int32_t contLen = 0; SMCreateStbReq* pReq = BuildCreateStbReq(stbname, &contLen); SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_STB, pReq, contLen); ASSERT_NE(pRsp, nullptr); ASSERT_EQ(pRsp->code, 0); } - int32_t contLen = 0; - { SMAltertbReq* pReq = BuildAlterStbAddTagReq("1.d3.stb", "tag4", &contLen); SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen); @@ -391,6 +462,13 @@ TEST_F(MndTestStb, 02_Alter_Stb_AddTag) { CheckInt32(2); CheckInt32(4); } + + { + SDropDbReq* pReq = BuildDropDbReq(dbname, &contLen); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_DB, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); + } } TEST_F(MndTestStb, 03_Alter_Stb_DropTag) { @@ -430,6 +508,13 @@ TEST_F(MndTestStb, 03_Alter_Stb_DropTag) { CheckInt32(2); CheckInt32(2); } + + { + SDropDbReq* pReq = BuildDropDbReq(dbname, &contLen); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_DB, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); + } } TEST_F(MndTestStb, 04_Alter_Stb_AlterTagName) { @@ -492,10 +577,16 @@ TEST_F(MndTestStb, 04_Alter_Stb_AlterTagName) { CheckInt32(2); CheckInt32(3); } -} + { + SDropDbReq* pReq = BuildDropDbReq(dbname, &contLen); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_DB, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); + } +} -TEST_F(MndTestStb, 04_Alter_Stb_AlterTagBytes) { +TEST_F(MndTestStb, 05_Alter_Stb_AlterTagBytes) { const char* dbname = "1.d5"; const char* stbname = "1.d5.stb"; int32_t contLen = 0; @@ -534,7 +625,7 @@ TEST_F(MndTestStb, 04_Alter_Stb_AlterTagBytes) { SMAltertbReq* pReq = BuildAlterStbUpdateTagBytesReq(stbname, "tag3", 20, &contLen); SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen); ASSERT_EQ(pRsp->code, 0); - + test.SendShowMetaReq(TSDB_MGMT_TABLE_STB, dbname); test.SendShowRetrieveReq(); EXPECT_EQ(test.GetShowRows(), 1); @@ -543,4 +634,205 @@ TEST_F(MndTestStb, 04_Alter_Stb_AlterTagBytes) { CheckInt32(2); CheckInt32(3); } -} \ No newline at end of file + + { + SDropDbReq* pReq = BuildDropDbReq(dbname, &contLen); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_DB, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); + } +} + +TEST_F(MndTestStb, 06_Alter_Stb_AddColumn) { + const char* dbname = "1.d6"; + const char* stbname = "1.d6.stb"; + int32_t contLen = 0; + + { + SCreateDbReq* pReq = BuildCreateDbReq(dbname, &contLen); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); + } + + { + SMCreateStbReq* pReq = BuildCreateStbReq(stbname, &contLen); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_STB, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); + } + + { + SMAltertbReq* pReq = BuildAlterStbAddColumnReq("1.d7.stb", "tag4", &contLen); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen); + ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_DB); + } + + { + SMAltertbReq* pReq = BuildAlterStbAddColumnReq("1.d6.stb3", "tag4", &contLen); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen); + ASSERT_EQ(pRsp->code, TSDB_CODE_MND_STB_NOT_EXIST); + } + + { + SMAltertbReq* pReq = BuildAlterStbAddColumnReq(stbname, "tag3", &contLen); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen); + ASSERT_EQ(pRsp->code, TSDB_CODE_MND_TAG_ALREADY_EXIST); + } + + { + SMAltertbReq* pReq = BuildAlterStbAddColumnReq(stbname, "col1", &contLen); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen); + ASSERT_EQ(pRsp->code, TSDB_CODE_MND_COLUMN_ALREADY_EXIST); + } + + { + SMAltertbReq* pReq = BuildAlterStbAddColumnReq(stbname, "col2", &contLen); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); + + test.SendShowMetaReq(TSDB_MGMT_TABLE_STB, dbname); + test.SendShowRetrieveReq(); + EXPECT_EQ(test.GetShowRows(), 1); + CheckBinary("stb", TSDB_TABLE_NAME_LEN); + CheckTimestamp(); + CheckInt32(3); + CheckInt32(3); + } + + { + SDropDbReq* pReq = BuildDropDbReq(dbname, &contLen); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_DB, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); + } +} + +TEST_F(MndTestStb, 07_Alter_Stb_DropColumn) { + const char* dbname = "1.d7"; + const char* stbname = "1.d7.stb"; + int32_t contLen = 0; + + { + SCreateDbReq* pReq = BuildCreateDbReq(dbname, &contLen); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen); + ASSERT_EQ(pRsp->code, 0); + } + + { + SMCreateStbReq* pReq = BuildCreateStbReq(stbname, &contLen); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_STB, pReq, contLen); + ASSERT_EQ(pRsp->code, 0); + } + + { + SMAltertbReq* pReq = BuildAlterStbDropColumnReq(stbname, "col4", &contLen); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen); + ASSERT_EQ(pRsp->code, TSDB_CODE_MND_COLUMN_NOT_EXIST); + } + + { + SMAltertbReq* pReq = BuildAlterStbDropColumnReq(stbname, "col1", &contLen); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen); + ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_STB_ALTER_OPTION); + } + + { + SMAltertbReq* pReq = BuildAlterStbDropColumnReq(stbname, "ts", &contLen); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen); + ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_STB_ALTER_OPTION); + } + + { + SMAltertbReq* pReq = BuildAlterStbAddColumnReq(stbname, "col2", &contLen); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); + } + + { + SMAltertbReq* pReq = BuildAlterStbDropColumnReq(stbname, "col1", &contLen); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); + + test.SendShowMetaReq(TSDB_MGMT_TABLE_STB, dbname); + test.SendShowRetrieveReq(); + EXPECT_EQ(test.GetShowRows(), 1); + CheckBinary("stb", TSDB_TABLE_NAME_LEN); + CheckTimestamp(); + CheckInt32(2); + CheckInt32(3); + } + + { + SDropDbReq* pReq = BuildDropDbReq(dbname, &contLen); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_DB, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); + } +} + +TEST_F(MndTestStb, 08_Alter_Stb_AlterTagBytes) { + const char* dbname = "1.d8"; + const char* stbname = "1.d8.stb"; + int32_t contLen = 0; + + { + SCreateDbReq* pReq = BuildCreateDbReq(dbname, &contLen); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen); + ASSERT_EQ(pRsp->code, 0); + } + + { + SMCreateStbReq* pReq = BuildCreateStbReq(stbname, &contLen); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_STB, pReq, contLen); + ASSERT_EQ(pRsp->code, 0); + } + + { + SMAltertbReq* pReq = BuildAlterStbUpdateColumnBytesReq(stbname, "col5", 12, &contLen); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen); + ASSERT_EQ(pRsp->code, TSDB_CODE_MND_COLUMN_NOT_EXIST); + } + + { + SMAltertbReq* pReq = BuildAlterStbUpdateColumnBytesReq(stbname, "ts", 8, &contLen); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen); + ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_STB_OPTION); + } + + { + SMAltertbReq* pReq = BuildAlterStbUpdateColumnBytesReq(stbname, "col1", 8, &contLen); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen); + ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_ROW_BYTES); + } + + { + SMAltertbReq* pReq = BuildAlterStbUpdateColumnBytesReq(stbname, "col1", TSDB_MAX_BYTES_PER_ROW, &contLen); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen); + ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_ROW_BYTES); + } + + { + SMAltertbReq* pReq = BuildAlterStbUpdateColumnBytesReq(stbname, "col1", 20, &contLen); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen); + ASSERT_EQ(pRsp->code, 0); + + test.SendShowMetaReq(TSDB_MGMT_TABLE_STB, dbname); + test.SendShowRetrieveReq(); + EXPECT_EQ(test.GetShowRows(), 1); + CheckBinary("stb", TSDB_TABLE_NAME_LEN); + CheckTimestamp(); + CheckInt32(2); + CheckInt32(3); + } + + { + SDropDbReq* pReq = BuildDropDbReq(dbname, &contLen); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_DB, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); + } +} diff --git a/source/util/src/terror.c b/source/util/src/terror.c index fd67067b7cd8657c1152c162279efb092a77af34..0cfffab52198a20e0b20b5e7b13d265a4c640e2f 100644 --- a/source/util/src/terror.c +++ b/source/util/src/terror.c @@ -228,17 +228,19 @@ TAOS_DEFINE_ERROR(TSDB_CODE_MND_VGROUP_NOT_EXIST, "VGroup does not exist // mnode-stable TAOS_DEFINE_ERROR(TSDB_CODE_MND_STB_ALREADY_EXIST, "Stable already exists") TAOS_DEFINE_ERROR(TSDB_CODE_MND_STB_NOT_EXIST, "Stable not exist") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_NAME_CONFLICT_WITH_TOPIC, "Stable confilct with topic") TAOS_DEFINE_ERROR(TSDB_CODE_MND_TOO_MANY_STBS, "Too many stables") TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_STB, "Invalid stable name") TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_STB_OPTION, "Invalid stable options") -TAOS_DEFINE_ERROR(TSDB_CODE_MND_STB_OPTION_UNCHNAGED, "Stable options not changed") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_STB_ALTER_OPTION, "Invalid stable alter options") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_STB_OPTION_UNCHNAGED, "Stable option unchanged") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_ROW_BYTES, "Invalid row bytes") TAOS_DEFINE_ERROR(TSDB_CODE_MND_TOO_MANY_TAGS, "Too many tags") TAOS_DEFINE_ERROR(TSDB_CODE_MND_TAG_ALREADY_EXIST, "Tag already exists") TAOS_DEFINE_ERROR(TSDB_CODE_MND_TAG_NOT_EXIST, "Tag does not exist") TAOS_DEFINE_ERROR(TSDB_CODE_MND_TOO_MANY_COLUMNS, "Too many columns") TAOS_DEFINE_ERROR(TSDB_CODE_MND_COLUMN_ALREADY_EXIST, "Column already exists") TAOS_DEFINE_ERROR(TSDB_CODE_MND_COLUMN_NOT_EXIST, "Column does not exist") -TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_ROW_BYTES, "Invalid row bytes") // mnode-func TAOS_DEFINE_ERROR(TSDB_CODE_MND_FUNC_ALREADY_EXIST, "Func already exists")