From 43eee9ab84ae8709b6e69a6f98b900fab6eb3bad Mon Sep 17 00:00:00 2001 From: kailixu Date: Thu, 28 Sep 2023 16:30:52 +0800 Subject: [PATCH 1/9] chore: add notify test --- tests/script/api/passwdTest.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/tests/script/api/passwdTest.c b/tests/script/api/passwdTest.c index 24059bd35d..7fb70ec5aa 100644 --- a/tests/script/api/passwdTest.c +++ b/tests/script/api/passwdTest.c @@ -30,7 +30,7 @@ #define nDup 1 #define nRoot 10 -#define nUser 10 +#define nUser 1 #define USER_LEN 24 #define BUF_LEN 1024 @@ -207,8 +207,8 @@ int main(int argc, char *argv[]) { exit(1); } createUsers(taos, argv[1], qstr); - passVerTestMulti(argv[1], qstr); - sysInfoTest(taos, argv[1], qstr); + // passVerTestMulti(argv[1], qstr); + // sysInfoTest(taos, argv[1], qstr); userDroppedTest(taos, argv[1], qstr); taos_close(taos); @@ -391,6 +391,10 @@ _REP: void userDroppedTest(TAOS *taos, const char *host, char *qstr) { // users int nTestUsers = nUser; + int nLoop = 0; +_loop: + ++nLoop; + printf("%s:%d loop %d\n", __func__, __LINE__, nLoop); for (int i = 0; i < nTestUsers; ++i) { // sprintf(users[i], "user%d", i); taosu[i] = taos_connect(host, users[i], "taos", NULL, 0); @@ -437,5 +441,14 @@ void userDroppedTest(TAOS *taos, const char *host, char *qstr) { exit(1); } fprintf(stderr, "######## %s #########\n", __func__); - // sleep(300); + + if (nLoop < 5) { + for (int i = 0; i < nTestUsers; ++i) { + sprintf(users[i], "user%d", i); + sprintf(qstr, "CREATE USER %s PASS 'taos'", users[i]); + queryDB(taos, qstr); + goto _loop; + } + // sleep(300); + } } \ No newline at end of file From ca0c2c321887ccefb5bdd2aa8ab28622ef036d8a Mon Sep 17 00:00:00 2001 From: kailixu Date: Thu, 28 Sep 2023 16:33:29 +0800 Subject: [PATCH 2/9] chore: add notify test --- tests/script/api/passwdTest.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/script/api/passwdTest.c b/tests/script/api/passwdTest.c index 7fb70ec5aa..eb3c37cfa8 100644 --- a/tests/script/api/passwdTest.c +++ b/tests/script/api/passwdTest.c @@ -30,7 +30,7 @@ #define nDup 1 #define nRoot 10 -#define nUser 1 +#define nUser 10 #define USER_LEN 24 #define BUF_LEN 1024 From 808b226d41fd41e8b4734560971afa6e35d4631e Mon Sep 17 00:00:00 2001 From: kailixu Date: Thu, 28 Sep 2023 17:05:44 +0800 Subject: [PATCH 3/9] chore: more test --- tests/script/api/passwdTest.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/script/api/passwdTest.c b/tests/script/api/passwdTest.c index eb3c37cfa8..932f258a4b 100644 --- a/tests/script/api/passwdTest.c +++ b/tests/script/api/passwdTest.c @@ -446,9 +446,10 @@ _loop: for (int i = 0; i < nTestUsers; ++i) { sprintf(users[i], "user%d", i); sprintf(qstr, "CREATE USER %s PASS 'taos'", users[i]); + fprintf(stderr, "%s:%d create user:%s\n", __func__, __LINE__, users[i]); queryDB(taos, qstr); - goto _loop; } + goto _loop; // sleep(300); } } \ No newline at end of file From e677e41573710073bb792a1dc495883eb422b9c7 Mon Sep 17 00:00:00 2001 From: kailixu Date: Sat, 30 Sep 2023 12:29:44 +0800 Subject: [PATCH 4/9] fix: support check and merge activeCode --- include/common/tgrant.h | 3 ++ include/util/taoserror.h | 5 +++ source/dnode/mnode/impl/src/mndDnode.c | 57 +++++++++++++++++++++----- source/util/src/terror.c | 4 ++ 4 files changed, 58 insertions(+), 11 deletions(-) diff --git a/include/common/tgrant.h b/include/common/tgrant.h index 31d34add24..4d33889336 100644 --- a/include/common/tgrant.h +++ b/include/common/tgrant.h @@ -51,6 +51,9 @@ typedef enum { } EGrantType; int32_t grantCheck(EGrantType grant); +#ifdef TD_ENTERPRISE +int32_t grantAlterActiveCode(const char* old, const char* new, char* out, int8_t type); +#endif #ifndef GRANTS_CFG #ifdef TD_ENTERPRISE diff --git a/include/util/taoserror.h b/include/util/taoserror.h index 39bf2b5681..46a85661d5 100644 --- a/include/util/taoserror.h +++ b/include/util/taoserror.h @@ -541,6 +541,11 @@ int32_t* taosGetErrno(); #define TSDB_CODE_GRANT_CPU_LIMITED TAOS_DEF_ERROR_CODE(0, 0x080B) #define TSDB_CODE_GRANT_STABLE_LIMITED TAOS_DEF_ERROR_CODE(0, 0x080C) #define TSDB_CODE_GRANT_TABLE_LIMITED TAOS_DEF_ERROR_CODE(0, 0x080D) +#define TSDB_CODE_GRANT_PAR_INVALID_ACTIVE TAOS_DEF_ERROR_CODE(0, 0x080E) +#define TSDB_CODE_GRANT_GEN_INVALID_KEY TAOS_DEF_ERROR_CODE(0, 0x080F) +#define TSDB_CODE_GRANT_GEN_APP_LIMIT TAOS_DEF_ERROR_CODE(0, 0x0810) +#define TSDB_CODE_GRANT_GEN_INVALID_KLEN TAOS_DEF_ERROR_CODE(0, 0x0811) + // sync // #define TSDB_CODE_SYN_INVALID_CONFIG TAOS_DEF_ERROR_CODE(0, 0x0900) // 2.x diff --git a/source/dnode/mnode/impl/src/mndDnode.c b/source/dnode/mnode/impl/src/mndDnode.c index f2a8c82192..2bd99c1afc 100644 --- a/source/dnode/mnode/impl/src/mndDnode.c +++ b/source/dnode/mnode/impl/src/mndDnode.c @@ -763,9 +763,14 @@ static int32_t mndConfigDnode(SMnode *pMnode, SRpcMsg *pReq, SMCfgDnodeReq *pCfg SSdbRaw *pRaw = NULL; STrans *pTrans = NULL; SDnodeObj *pDnode = NULL; + SArray *failRecord = NULL; bool cfgAll = pCfgReq->dnodeId == -1; int32_t iter = 0; + if (cfgAll && !(failRecord = taosArrayInit(1, sizeof(int32_t)))) { + goto _OVER; + } + SSdb *pSdb = pMnode->pSdb; void *pIter = NULL; while (1) { @@ -774,6 +779,39 @@ static int32_t mndConfigDnode(SMnode *pMnode, SRpcMsg *pReq, SMCfgDnodeReq *pCfg if (pIter == NULL) break; ++iter; } else if (!(pDnode = mndAcquireDnode(pMnode, pCfgReq->dnodeId))) { + terrno = TSDB_CODE_MND_INVALID_DNODE_ID; + goto _OVER; + } + + SDnodeObj tmpDnode = *pDnode; + if (action == DND_ACTIVE_CODE) { +#ifndef MND_MERGE_ACTIVE_CODE + strncpy(tmpDnode.active, pCfgReq->value, TSDB_ACTIVE_KEY_LEN); +#else + if (grantAlterActiveCode(pDnode->active, pCfgReq->value, tmpDnode.active, 0) != 0) { + if (TSDB_CODE_DUP_KEY != terrno) { + mError("dnode:%d, config dnode, cfg:%d, app:%p config:%s value:%s failed since %s", pDnode->id, + pCfgReq->dnodeId, pReq->info.ahandle, pCfgReq->config, pCfgReq->value, terrstr()); + taosArrayPush(failRecord, pDnode->id); + continue; + } + } +#endif + } else if (action == DND_CONN_ACTIVE_CODE) { +#ifndef MND_MERGE_ACTIVE_CODE + strncpy(tmpDnode.connActive, pCfgReq->value, TSDB_CONN_ACTIVE_KEY_LEN); +#else + if (grantAlterActiveCode(pDnode->connActive, pCfgReq->value, tmpDnode.connActive, 1) != 0) { + if (TSDB_CODE_DUP_KEY != terrno) { + mError("dnode:%d, config dnode, cfg:%d, app:%p config:%s value:%s failed since %s", pDnode->id, + pCfgReq->dnodeId, pReq->info.ahandle, pCfgReq->config, pCfgReq->value, terrstr()); + taosArrayPush(failRecord, pDnode->id); + continue; + } + } +#endif + } else { + terrno = TSDB_CODE_INVALID_CFG; goto _OVER; } @@ -783,16 +821,6 @@ static int32_t mndConfigDnode(SMnode *pMnode, SRpcMsg *pReq, SMCfgDnodeReq *pCfg if (mndTrancCheckConflict(pMnode, pTrans) != 0) goto _OVER; } - SDnodeObj tmpDnode = *pDnode; - if (action == DND_ACTIVE_CODE) { - strncpy(tmpDnode.active, pCfgReq->value, TSDB_ACTIVE_KEY_LEN); - } else if (action == DND_CONN_ACTIVE_CODE) { - strncpy(tmpDnode.connActive, pCfgReq->value, TSDB_CONN_ACTIVE_KEY_LEN); - } else { - terrno = TSDB_CODE_INVALID_CFG; - goto _OVER; - } - pRaw = mndDnodeActionEncode(&tmpDnode); if (pRaw == NULL || mndTransAppendCommitlog(pTrans, pRaw) != 0) goto _OVER; (void)sdbSetRawStatus(pRaw, SDB_STATUS_READY); @@ -816,12 +844,18 @@ static int32_t mndConfigDnode(SMnode *pMnode, SRpcMsg *pReq, SMCfgDnodeReq *pCfg _OVER: if (cfgAll) { sdbRelease(pSdb, pDnode); + int32_t nFail = taosArrayGetSize(failRecord); + if (nFail > 0) { + mError("config dnode, cfg:%d, app:%p config:%s value:%s. total:%d, fail:%d", pCfgReq->dnodeId, pReq->info.ahandle, + pCfgReq->config, pCfgReq->value, iter, nFail); + } } else { mndReleaseDnode(pMnode, pDnode); } sdbCancelFetch(pSdb, pIter); mndTransDrop(pTrans); sdbFreeRaw(pRaw); + taosArrayDestroy(failRecord); return terrno; } @@ -1262,7 +1296,8 @@ static int32_t mndProcessConfigDnodeReq(SRpcMsg *pReq) { snprintf(dcfgReq.value, TSDB_DNODE_VALUE_LEN, "%s", cfgReq.value); if (mndConfigDnode(pMnode, pReq, &cfgReq, opt) != 0) { - mError("dnode:%d, failed to config activeCode since %s", cfgReq.dnodeId, terrstr()); + mError("dnode:%d, failed to config activeCode since %s. conf:%s, val:%s", cfgReq.dnodeId, terrstr(), + cfgReq.config, cfgReq.value); return -1; } return 0; diff --git a/source/util/src/terror.c b/source/util/src/terror.c index 9832720994..116600f393 100644 --- a/source/util/src/terror.c +++ b/source/util/src/terror.c @@ -430,6 +430,10 @@ TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_QUERYTIME_LIMITED, "Query time limited by TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_CPU_LIMITED, "CPU cores limited by license") TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_STABLE_LIMITED, "STable creation limited by license") TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_TABLE_LIMITED, "Table creation limited by license") +TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_PAR_INVALID_ACTIVE, "Invalid active code") +TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_GEN_INVALID_KEY, "Invalid key to gen active code") +TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_GEN_APP_LIMIT, "Gen active code limited by app num") +TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_GEN_INVALID_KLEN, "Invalid klen to gen active code") // sync TAOS_DEFINE_ERROR(TSDB_CODE_SYN_TIMEOUT, "Sync timeout") From 5067eb8cc503a5a263ab1f0889140959c6045700 Mon Sep 17 00:00:00 2001 From: kailixu Date: Sat, 30 Sep 2023 16:00:14 +0800 Subject: [PATCH 5/9] chore: more code for check active code --- include/util/taoserror.h | 11 +++++++---- source/dnode/mnode/impl/src/mndDnode.c | 12 ++++++------ source/util/src/terror.c | 11 +++++++---- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/include/util/taoserror.h b/include/util/taoserror.h index 46a85661d5..56a0cddce5 100644 --- a/include/util/taoserror.h +++ b/include/util/taoserror.h @@ -541,10 +541,13 @@ int32_t* taosGetErrno(); #define TSDB_CODE_GRANT_CPU_LIMITED TAOS_DEF_ERROR_CODE(0, 0x080B) #define TSDB_CODE_GRANT_STABLE_LIMITED TAOS_DEF_ERROR_CODE(0, 0x080C) #define TSDB_CODE_GRANT_TABLE_LIMITED TAOS_DEF_ERROR_CODE(0, 0x080D) -#define TSDB_CODE_GRANT_PAR_INVALID_ACTIVE TAOS_DEF_ERROR_CODE(0, 0x080E) -#define TSDB_CODE_GRANT_GEN_INVALID_KEY TAOS_DEF_ERROR_CODE(0, 0x080F) -#define TSDB_CODE_GRANT_GEN_APP_LIMIT TAOS_DEF_ERROR_CODE(0, 0x0810) -#define TSDB_CODE_GRANT_GEN_INVALID_KLEN TAOS_DEF_ERROR_CODE(0, 0x0811) +#define TSDB_CODE_GRANT_PAR_IVLD_ACTIVE TAOS_DEF_ERROR_CODE(0, 0x080E) +#define TSDB_CODE_GRANT_PAR_IVLD_KEY TAOS_DEF_ERROR_CODE(0, 0x080F) +#define TSDB_CODE_GRANT_PAR_DEC_IVLD_KEY TAOS_DEF_ERROR_CODE(0, 0x0810) +#define TSDB_CODE_GRANT_PAR_DEC_IVLD_KLEN TAOS_DEF_ERROR_CODE(0, 0x0811) +#define TSDB_CODE_GRANT_GEN_IVLD_KEY TAOS_DEF_ERROR_CODE(0, 0x0812) +#define TSDB_CODE_GRANT_GEN_APP_LIMIT TAOS_DEF_ERROR_CODE(0, 0x0813) +#define TSDB_CODE_GRANT_GEN_ENC_IVLD_KLEN TAOS_DEF_ERROR_CODE(0, 0x0814) // sync diff --git a/source/dnode/mnode/impl/src/mndDnode.c b/source/dnode/mnode/impl/src/mndDnode.c index 2bd99c1afc..04fbbd8660 100644 --- a/source/dnode/mnode/impl/src/mndDnode.c +++ b/source/dnode/mnode/impl/src/mndDnode.c @@ -785,28 +785,28 @@ static int32_t mndConfigDnode(SMnode *pMnode, SRpcMsg *pReq, SMCfgDnodeReq *pCfg SDnodeObj tmpDnode = *pDnode; if (action == DND_ACTIVE_CODE) { -#ifndef MND_MERGE_ACTIVE_CODE +#ifndef TD_CHECK_ACTIVE strncpy(tmpDnode.active, pCfgReq->value, TSDB_ACTIVE_KEY_LEN); #else if (grantAlterActiveCode(pDnode->active, pCfgReq->value, tmpDnode.active, 0) != 0) { if (TSDB_CODE_DUP_KEY != terrno) { mError("dnode:%d, config dnode, cfg:%d, app:%p config:%s value:%s failed since %s", pDnode->id, pCfgReq->dnodeId, pReq->info.ahandle, pCfgReq->config, pCfgReq->value, terrstr()); - taosArrayPush(failRecord, pDnode->id); - continue; + if (failRecord) taosArrayPush(failRecord, &pDnode->id); + if (!cfgAll) goto _OVER; } } #endif } else if (action == DND_CONN_ACTIVE_CODE) { -#ifndef MND_MERGE_ACTIVE_CODE +#ifndef TD_CHECK_ACTIVE strncpy(tmpDnode.connActive, pCfgReq->value, TSDB_CONN_ACTIVE_KEY_LEN); #else if (grantAlterActiveCode(pDnode->connActive, pCfgReq->value, tmpDnode.connActive, 1) != 0) { if (TSDB_CODE_DUP_KEY != terrno) { mError("dnode:%d, config dnode, cfg:%d, app:%p config:%s value:%s failed since %s", pDnode->id, pCfgReq->dnodeId, pReq->info.ahandle, pCfgReq->config, pCfgReq->value, terrstr()); - taosArrayPush(failRecord, pDnode->id); - continue; + if (failRecord) taosArrayPush(failRecord, &pDnode->id); + if (!cfgAll) goto _OVER; } } #endif diff --git a/source/util/src/terror.c b/source/util/src/terror.c index 116600f393..b4a1a2eae2 100644 --- a/source/util/src/terror.c +++ b/source/util/src/terror.c @@ -430,10 +430,13 @@ TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_QUERYTIME_LIMITED, "Query time limited by TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_CPU_LIMITED, "CPU cores limited by license") TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_STABLE_LIMITED, "STable creation limited by license") TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_TABLE_LIMITED, "Table creation limited by license") -TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_PAR_INVALID_ACTIVE, "Invalid active code") -TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_GEN_INVALID_KEY, "Invalid key to gen active code") -TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_GEN_APP_LIMIT, "Gen active code limited by app num") -TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_GEN_INVALID_KLEN, "Invalid klen to gen active code") +TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_PAR_IVLD_ACTIVE, "Invalid active code") +TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_PAR_IVLD_KEY, "Invalid key to parse active code") +TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_PAR_DEC_IVLD_KEY, "Invalid key to decode active code") +TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_PAR_DEC_IVLD_KLEN, "Invalid klen to decode active code") +TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_GEN_IVLD_KEY, "Invalid key to gen active code") +TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_GEN_APP_LIMIT, "Limited app num to gen active code") +TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_GEN_ENC_IVLD_KLEN, "Invalid klen to encode active code") // sync TAOS_DEFINE_ERROR(TSDB_CODE_SYN_TIMEOUT, "Sync timeout") From a19efd266e59f007b17a451f6dcdee1ca3cc3a04 Mon Sep 17 00:00:00 2001 From: kailixu Date: Sun, 1 Oct 2023 21:55:17 +0800 Subject: [PATCH 6/9] chore: more code --- source/dnode/mnode/impl/src/mndDnode.c | 16 +++++++++++----- source/dnode/mnode/impl/src/mndMain.c | 2 ++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/source/dnode/mnode/impl/src/mndDnode.c b/source/dnode/mnode/impl/src/mndDnode.c index 04fbbd8660..d93fb8ee0f 100644 --- a/source/dnode/mnode/impl/src/mndDnode.c +++ b/source/dnode/mnode/impl/src/mndDnode.c @@ -765,6 +765,7 @@ static int32_t mndConfigDnode(SMnode *pMnode, SRpcMsg *pReq, SMCfgDnodeReq *pCfg SDnodeObj *pDnode = NULL; SArray *failRecord = NULL; bool cfgAll = pCfgReq->dnodeId == -1; + int32_t cfgAllErr = 0; int32_t iter = 0; if (cfgAll && !(failRecord = taosArrayInit(1, sizeof(int32_t)))) { @@ -790,11 +791,13 @@ static int32_t mndConfigDnode(SMnode *pMnode, SRpcMsg *pReq, SMCfgDnodeReq *pCfg #else if (grantAlterActiveCode(pDnode->active, pCfgReq->value, tmpDnode.active, 0) != 0) { if (TSDB_CODE_DUP_KEY != terrno) { - mError("dnode:%d, config dnode, cfg:%d, app:%p config:%s value:%s failed since %s", pDnode->id, + mError("dnode:%d, config dnode:%d, app:%p config:%s value:%s failed since %s", pDnode->id, pCfgReq->dnodeId, pReq->info.ahandle, pCfgReq->config, pCfgReq->value, terrstr()); if (failRecord) taosArrayPush(failRecord, &pDnode->id); - if (!cfgAll) goto _OVER; + if (cfgAll && (0 == cfgAllErr)) cfgAllErr = terrno; } + if (cfgAll) continue; + goto _OVER; } #endif } else if (action == DND_CONN_ACTIVE_CODE) { @@ -803,11 +806,13 @@ static int32_t mndConfigDnode(SMnode *pMnode, SRpcMsg *pReq, SMCfgDnodeReq *pCfg #else if (grantAlterActiveCode(pDnode->connActive, pCfgReq->value, tmpDnode.connActive, 1) != 0) { if (TSDB_CODE_DUP_KEY != terrno) { - mError("dnode:%d, config dnode, cfg:%d, app:%p config:%s value:%s failed since %s", pDnode->id, + mError("dnode:%d, config dnode:%d, app:%p config:%s value:%s failed since %s", pDnode->id, pCfgReq->dnodeId, pReq->info.ahandle, pCfgReq->config, pCfgReq->value, terrstr()); if (failRecord) taosArrayPush(failRecord, &pDnode->id); - if (!cfgAll) goto _OVER; + if (cfgAll && (0 == cfgAllErr)) cfgAllErr = terrno; } + if (cfgAll) continue; + goto _OVER; } #endif } else { @@ -826,7 +831,7 @@ static int32_t mndConfigDnode(SMnode *pMnode, SRpcMsg *pReq, SMCfgDnodeReq *pCfg (void)sdbSetRawStatus(pRaw, SDB_STATUS_READY); pRaw = NULL; - mInfo("dnode:%d, config dnode, cfg:%d, app:%p config:%s value:%s", pDnode->id, pCfgReq->dnodeId, pReq->info.ahandle, + mInfo("dnode:%d, config dnode:%d, app:%p config:%s value:%s", pDnode->id, pCfgReq->dnodeId, pReq->info.ahandle, pCfgReq->config, pCfgReq->value); if (cfgAll) { @@ -844,6 +849,7 @@ static int32_t mndConfigDnode(SMnode *pMnode, SRpcMsg *pReq, SMCfgDnodeReq *pCfg _OVER: if (cfgAll) { sdbRelease(pSdb, pDnode); + if (cfgAllErr != 0) terrno = cfgAllErr; int32_t nFail = taosArrayGetSize(failRecord); if (nFail > 0) { mError("config dnode, cfg:%d, app:%p config:%s value:%s. total:%d, fail:%d", pCfgReq->dnodeId, pReq->info.ahandle, diff --git a/source/dnode/mnode/impl/src/mndMain.c b/source/dnode/mnode/impl/src/mndMain.c index 1c87cde78a..3ac42c2120 100644 --- a/source/dnode/mnode/impl/src/mndMain.c +++ b/source/dnode/mnode/impl/src/mndMain.c @@ -593,7 +593,9 @@ int32_t mndStart(SMnode *pMnode) { mndSetRestored(pMnode, true); } +#ifndef TD_CHECK_ACTIVE grantReset(pMnode, TSDB_GRANT_ALL, 0); +#endif return mndInitTimer(pMnode); } From 53c4c56206165824aa6878ca9c59c626c2d3964c Mon Sep 17 00:00:00 2001 From: kailixu Date: Mon, 2 Oct 2023 09:23:51 +0800 Subject: [PATCH 7/9] chore: code optimization --- source/dnode/mnode/impl/src/mndDnode.c | 31 +++++++++++++++----------- source/dnode/mnode/impl/src/mndMain.c | 2 -- tests/script/api/passwdTest.c | 20 +++-------------- 3 files changed, 21 insertions(+), 32 deletions(-) diff --git a/source/dnode/mnode/impl/src/mndDnode.c b/source/dnode/mnode/impl/src/mndDnode.c index d93fb8ee0f..ea7ded1879 100644 --- a/source/dnode/mnode/impl/src/mndDnode.c +++ b/source/dnode/mnode/impl/src/mndDnode.c @@ -768,10 +768,6 @@ static int32_t mndConfigDnode(SMnode *pMnode, SRpcMsg *pReq, SMCfgDnodeReq *pCfg int32_t cfgAllErr = 0; int32_t iter = 0; - if (cfgAll && !(failRecord = taosArrayInit(1, sizeof(int32_t)))) { - goto _OVER; - } - SSdb *pSdb = pMnode->pSdb; void *pIter = NULL; while (1) { @@ -780,7 +776,6 @@ static int32_t mndConfigDnode(SMnode *pMnode, SRpcMsg *pReq, SMCfgDnodeReq *pCfg if (pIter == NULL) break; ++iter; } else if (!(pDnode = mndAcquireDnode(pMnode, pCfgReq->dnodeId))) { - terrno = TSDB_CODE_MND_INVALID_DNODE_ID; goto _OVER; } @@ -791,10 +786,15 @@ static int32_t mndConfigDnode(SMnode *pMnode, SRpcMsg *pReq, SMCfgDnodeReq *pCfg #else if (grantAlterActiveCode(pDnode->active, pCfgReq->value, tmpDnode.active, 0) != 0) { if (TSDB_CODE_DUP_KEY != terrno) { - mError("dnode:%d, config dnode:%d, app:%p config:%s value:%s failed since %s", pDnode->id, - pCfgReq->dnodeId, pReq->info.ahandle, pCfgReq->config, pCfgReq->value, terrstr()); - if (failRecord) taosArrayPush(failRecord, &pDnode->id); - if (cfgAll && (0 == cfgAllErr)) cfgAllErr = terrno; + mError("dnode:%d, config dnode:%d, app:%p config:%s value:%s failed since %s", pDnode->id, pCfgReq->dnodeId, + pReq->info.ahandle, pCfgReq->config, pCfgReq->value, terrstr()); + if (cfgAll) { // alter all dnodes: + if (!failRecord) failRecord = taosArrayInit(1, sizeof(int32_t)); + if (failRecord) taosArrayPush(failRecord, &pDnode->id); + if (0 == cfgAllErr) cfgAllErr = terrno; // output 1st terrno. + } + } else { + terrno = 0; // no action for dup active code } if (cfgAll) continue; goto _OVER; @@ -806,10 +806,15 @@ static int32_t mndConfigDnode(SMnode *pMnode, SRpcMsg *pReq, SMCfgDnodeReq *pCfg #else if (grantAlterActiveCode(pDnode->connActive, pCfgReq->value, tmpDnode.connActive, 1) != 0) { if (TSDB_CODE_DUP_KEY != terrno) { - mError("dnode:%d, config dnode:%d, app:%p config:%s value:%s failed since %s", pDnode->id, - pCfgReq->dnodeId, pReq->info.ahandle, pCfgReq->config, pCfgReq->value, terrstr()); - if (failRecord) taosArrayPush(failRecord, &pDnode->id); - if (cfgAll && (0 == cfgAllErr)) cfgAllErr = terrno; + mError("dnode:%d, config dnode:%d, app:%p config:%s value:%s failed since %s", pDnode->id, pCfgReq->dnodeId, + pReq->info.ahandle, pCfgReq->config, pCfgReq->value, terrstr()); + if (cfgAll) { + if (!failRecord) failRecord = taosArrayInit(1, sizeof(int32_t)); + if (failRecord) taosArrayPush(failRecord, &pDnode->id); + if (0 == cfgAllErr) cfgAllErr = terrno; + } + } else { + terrno = 0; } if (cfgAll) continue; goto _OVER; diff --git a/source/dnode/mnode/impl/src/mndMain.c b/source/dnode/mnode/impl/src/mndMain.c index 3ac42c2120..1c87cde78a 100644 --- a/source/dnode/mnode/impl/src/mndMain.c +++ b/source/dnode/mnode/impl/src/mndMain.c @@ -593,9 +593,7 @@ int32_t mndStart(SMnode *pMnode) { mndSetRestored(pMnode, true); } -#ifndef TD_CHECK_ACTIVE grantReset(pMnode, TSDB_GRANT_ALL, 0); -#endif return mndInitTimer(pMnode); } diff --git a/tests/script/api/passwdTest.c b/tests/script/api/passwdTest.c index 932f258a4b..24059bd35d 100644 --- a/tests/script/api/passwdTest.c +++ b/tests/script/api/passwdTest.c @@ -207,8 +207,8 @@ int main(int argc, char *argv[]) { exit(1); } createUsers(taos, argv[1], qstr); - // passVerTestMulti(argv[1], qstr); - // sysInfoTest(taos, argv[1], qstr); + passVerTestMulti(argv[1], qstr); + sysInfoTest(taos, argv[1], qstr); userDroppedTest(taos, argv[1], qstr); taos_close(taos); @@ -391,10 +391,6 @@ _REP: void userDroppedTest(TAOS *taos, const char *host, char *qstr) { // users int nTestUsers = nUser; - int nLoop = 0; -_loop: - ++nLoop; - printf("%s:%d loop %d\n", __func__, __LINE__, nLoop); for (int i = 0; i < nTestUsers; ++i) { // sprintf(users[i], "user%d", i); taosu[i] = taos_connect(host, users[i], "taos", NULL, 0); @@ -441,15 +437,5 @@ _loop: exit(1); } fprintf(stderr, "######## %s #########\n", __func__); - - if (nLoop < 5) { - for (int i = 0; i < nTestUsers; ++i) { - sprintf(users[i], "user%d", i); - sprintf(qstr, "CREATE USER %s PASS 'taos'", users[i]); - fprintf(stderr, "%s:%d create user:%s\n", __func__, __LINE__, users[i]); - queryDB(taos, qstr); - } - goto _loop; - // sleep(300); - } + // sleep(300); } \ No newline at end of file From bb797a9a0e5ab58323bb700b5fb795d8eccc8662 Mon Sep 17 00:00:00 2001 From: kailixu Date: Mon, 2 Oct 2023 17:26:55 +0800 Subject: [PATCH 8/9] chore: test case adaption for alter active code --- tests/system-test/0-others/information_schema.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/system-test/0-others/information_schema.py b/tests/system-test/0-others/information_schema.py index 77bfb5dca8..c02778cf0a 100644 --- a/tests/system-test/0-others/information_schema.py +++ b/tests/system-test/0-others/information_schema.py @@ -242,11 +242,11 @@ class TDTestCase: self.str510 = self.str255 + self.str255 tdSql.error('alter dnode 1 "activeCode" "a"') tdSql.error('alter dnode 1 "activeCode" "' + self.str107 + '"') - tdSql.execute('alter all dnodes "activeCode" "' + self.str108 + '"') +# tdSql.error('alter all dnodes "activeCode" "' + self.str108 + '"') tdSql.error('alter dnode 1 "activeCode" "' + self.str109 + '"') tdSql.error('alter all dnodes "activeCode" "' + self.str510 + '"') tdSql.query(f'select * from information_schema.ins_dnodes') - tdSql.checkEqual(tdSql.queryResult[0][8],self.str108) + tdSql.checkEqual(tdSql.queryResult[0][8],"") tdSql.execute('alter dnode 1 "activeCode" ""') tdSql.query(f'select active_code,c_active_code from information_schema.ins_dnodes') tdSql.checkEqual(tdSql.queryResult[0][0],"") @@ -257,14 +257,14 @@ class TDTestCase: tdSql.error('alter all dnodes "cActiveCode" "' + self.str255 + '"') tdSql.error('alter all dnodes "cActiveCode" "' + self.str256 + '"') tdSql.error('alter all dnodes "cActiveCode" "' + self.str257 + '"') - tdSql.execute('alter all dnodes "cActiveCode" "' + self.str254 + '"') +# tdSql.error('alter all dnodes "cActiveCode" "' + self.str254 + '"') tdSql.error('alter dnode 1 "cActiveCode" "' + self.str510 + '"') tdSql.query(f'select active_code,c_active_code from information_schema.ins_dnodes') tdSql.checkEqual(tdSql.queryResult[0][0],"") - tdSql.checkEqual(tdSql.queryResult[0][1],self.str254) - tdSql.execute('alter dnode 1 "cActiveCode" "' + self.str109 + '"') + tdSql.checkEqual(tdSql.queryResult[0][1],"") +# tdSql.error('alter dnode 1 "cActiveCode" "' + self.str109 + '"') tdSql.query(f'show dnodes') - tdSql.checkEqual(tdSql.queryResult[0][9],self.str109) + tdSql.checkEqual(tdSql.queryResult[0][9],"") tdSql.execute('alter all dnodes "cActiveCode" ""') tdSql.query(f'select c_active_code from information_schema.ins_dnodes') tdSql.checkEqual(tdSql.queryResult[0][0],'') From 638bfe30e43fc3c2b5b226d1d39cbe9899c2911f Mon Sep 17 00:00:00 2001 From: kailixu Date: Mon, 2 Oct 2023 17:50:36 +0800 Subject: [PATCH 9/9] chore: more code --- include/util/taoserror.h | 1 - tests/system-test/0-others/information_schema.py | 6 +++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/include/util/taoserror.h b/include/util/taoserror.h index 56a0cddce5..227e8520e3 100644 --- a/include/util/taoserror.h +++ b/include/util/taoserror.h @@ -549,7 +549,6 @@ int32_t* taosGetErrno(); #define TSDB_CODE_GRANT_GEN_APP_LIMIT TAOS_DEF_ERROR_CODE(0, 0x0813) #define TSDB_CODE_GRANT_GEN_ENC_IVLD_KLEN TAOS_DEF_ERROR_CODE(0, 0x0814) - // sync // #define TSDB_CODE_SYN_INVALID_CONFIG TAOS_DEF_ERROR_CODE(0, 0x0900) // 2.x // #define TSDB_CODE_SYN_NOT_ENABLED TAOS_DEF_ERROR_CODE(0, 0x0901) // 2.x diff --git a/tests/system-test/0-others/information_schema.py b/tests/system-test/0-others/information_schema.py index c02778cf0a..7f4b291776 100644 --- a/tests/system-test/0-others/information_schema.py +++ b/tests/system-test/0-others/information_schema.py @@ -242,7 +242,7 @@ class TDTestCase: self.str510 = self.str255 + self.str255 tdSql.error('alter dnode 1 "activeCode" "a"') tdSql.error('alter dnode 1 "activeCode" "' + self.str107 + '"') -# tdSql.error('alter all dnodes "activeCode" "' + self.str108 + '"') + # tdSql.error('alter all dnodes "activeCode" "' + self.str108 + '"') tdSql.error('alter dnode 1 "activeCode" "' + self.str109 + '"') tdSql.error('alter all dnodes "activeCode" "' + self.str510 + '"') tdSql.query(f'select * from information_schema.ins_dnodes') @@ -257,12 +257,12 @@ class TDTestCase: tdSql.error('alter all dnodes "cActiveCode" "' + self.str255 + '"') tdSql.error('alter all dnodes "cActiveCode" "' + self.str256 + '"') tdSql.error('alter all dnodes "cActiveCode" "' + self.str257 + '"') -# tdSql.error('alter all dnodes "cActiveCode" "' + self.str254 + '"') + # tdSql.error('alter all dnodes "cActiveCode" "' + self.str254 + '"') tdSql.error('alter dnode 1 "cActiveCode" "' + self.str510 + '"') tdSql.query(f'select active_code,c_active_code from information_schema.ins_dnodes') tdSql.checkEqual(tdSql.queryResult[0][0],"") tdSql.checkEqual(tdSql.queryResult[0][1],"") -# tdSql.error('alter dnode 1 "cActiveCode" "' + self.str109 + '"') + # tdSql.error('alter dnode 1 "cActiveCode" "' + self.str109 + '"') tdSql.query(f'show dnodes') tdSql.checkEqual(tdSql.queryResult[0][9],"") tdSql.execute('alter all dnodes "cActiveCode" ""')