From 9f6dd2b405fc5bbc1d80dd8dd2e3fbcb072be849 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 20 Oct 2023 09:42:11 +0800 Subject: [PATCH 1/4] change gen first tag name --- source/dnode/mnode/impl/src/mndStb.c | 3 +++ source/os/src/osRand.c | 3 +-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/source/dnode/mnode/impl/src/mndStb.c b/source/dnode/mnode/impl/src/mndStb.c index eaf74a96cb..faeff90904 100644 --- a/source/dnode/mnode/impl/src/mndStb.c +++ b/source/dnode/mnode/impl/src/mndStb.c @@ -868,6 +868,9 @@ static int32_t mndGenIdxNameForFirstTag(char *fullname, char *dbname, char *tagn int8_t end = left >= 24 ? 24 : left - 1; // gen rand str len [base:end] // note: ignore rand performance issues + + taosSeedRand(taosSafeRand()); + int64_t len = taosRand() % (end - start + 1) + start; taosRandStr2(randStr, len); sprintf(fullname, "%s.%s_%s", dbname, tagname, randStr); diff --git a/source/os/src/osRand.c b/source/os/src/osRand.c index b71be59f1d..0e58b7a8ec 100644 --- a/source/os/src/osRand.c +++ b/source/os/src/osRand.c @@ -86,8 +86,7 @@ void taosRandStr(char* str, int32_t size) { } void taosRandStr2(char* str, int32_t size) { - - const char* set = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ@"; + const char* set = "abcdefghijklmnopqrstuvwxyz0123456789@"; int32_t len = strlen(set); for (int32_t i = 0; i < size; ++i) { From 08fc4814cb90d7fa833cc31022f8caad95f9678f Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 20 Oct 2023 10:43:44 +0800 Subject: [PATCH 2/4] enh gen first tag name --- source/dnode/mnode/impl/src/mndStb.c | 25 +++++-------------------- 1 file changed, 5 insertions(+), 20 deletions(-) diff --git a/source/dnode/mnode/impl/src/mndStb.c b/source/dnode/mnode/impl/src/mndStb.c index faeff90904..5516b9d653 100644 --- a/source/dnode/mnode/impl/src/mndStb.c +++ b/source/dnode/mnode/impl/src/mndStb.c @@ -858,25 +858,10 @@ int32_t mndBuildStbFromReq(SMnode *pMnode, SStbObj *pDst, SMCreateStbReq *pCreat } return 0; } -static int32_t mndGenIdxNameForFirstTag(char *fullname, char *dbname, char *tagname) { - char randStr[TSDB_COL_NAME_LEN] = {0}; - int32_t left = TSDB_COL_NAME_LEN - strlen(tagname) - 1; - if (left <= 1) { - sprintf(fullname, "%s.%s", dbname, tagname); - } else { - int8_t start = left < 8 ? 0 : 8; - int8_t end = left >= 24 ? 24 : left - 1; - // gen rand str len [base:end] - // note: ignore rand performance issues - - taosSeedRand(taosSafeRand()); - - int64_t len = taosRand() % (end - start + 1) + start; - taosRandStr2(randStr, len); - sprintf(fullname, "%s.%s_%s", dbname, tagname, randStr); - } - - return 0; +static int32_t mndGenIdxNameForFirstTag(char *fullname, char *dbname, char *stbname, char *tagname) { + SName name = {0}; + tNameFromString(&name, stbname, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE); + return snprintf(fullname, TSDB_INDEX_FNAME_LEN - 1, "%s.%s_%s", dbname, tagname, tNameGetTableName(&name)); } static int32_t mndCreateStb(SMnode *pMnode, SRpcMsg *pReq, SMCreateStbReq *pCreate, SDbObj *pDb) { @@ -892,7 +877,7 @@ static int32_t mndCreateStb(SMnode *pMnode, SRpcMsg *pReq, SMCreateStbReq *pCrea if (mndBuildStbFromReq(pMnode, &stbObj, pCreate, pDb) != 0) goto _OVER; SSchema *pSchema = &(stbObj.pTags[0]); - mndGenIdxNameForFirstTag(fullIdxName, pDb->name, pSchema->name); + mndGenIdxNameForFirstTag(fullIdxName, pDb->name, stbObj.name, pSchema->name); SSIdx idx = {0}; if (mndAcquireGlobalIdx(pMnode, fullIdxName, SDB_IDX, &idx) == 0 && idx.pIdx != NULL) { terrno = TSDB_CODE_MND_TAG_INDEX_ALREADY_EXIST; From e13fb887b8f136533f54f8312501893569a06f7d Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 20 Oct 2023 10:47:27 +0800 Subject: [PATCH 3/4] enh gen first tag name --- source/dnode/mnode/impl/src/mndStb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/dnode/mnode/impl/src/mndStb.c b/source/dnode/mnode/impl/src/mndStb.c index 5516b9d653..16825d73b1 100644 --- a/source/dnode/mnode/impl/src/mndStb.c +++ b/source/dnode/mnode/impl/src/mndStb.c @@ -861,7 +861,7 @@ int32_t mndBuildStbFromReq(SMnode *pMnode, SStbObj *pDst, SMCreateStbReq *pCreat static int32_t mndGenIdxNameForFirstTag(char *fullname, char *dbname, char *stbname, char *tagname) { SName name = {0}; tNameFromString(&name, stbname, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE); - return snprintf(fullname, TSDB_INDEX_FNAME_LEN - 1, "%s.%s_%s", dbname, tagname, tNameGetTableName(&name)); + return snprintf(fullname, TSDB_INDEX_FNAME_LEN, "%s.%s_%s", dbname, tagname, tNameGetTableName(&name)); } static int32_t mndCreateStb(SMnode *pMnode, SRpcMsg *pReq, SMCreateStbReq *pCreate, SDbObj *pDb) { From 1bc7e5eb85d04fd20967be53424b4018f9011324 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 20 Oct 2023 14:02:13 +0800 Subject: [PATCH 4/4] enh gen first tag name --- source/dnode/mnode/impl/src/mndStb.c | 1 - 1 file changed, 1 deletion(-) diff --git a/source/dnode/mnode/impl/src/mndStb.c b/source/dnode/mnode/impl/src/mndStb.c index 16825d73b1..a7997f6fa7 100644 --- a/source/dnode/mnode/impl/src/mndStb.c +++ b/source/dnode/mnode/impl/src/mndStb.c @@ -882,7 +882,6 @@ static int32_t mndCreateStb(SMnode *pMnode, SRpcMsg *pReq, SMCreateStbReq *pCrea if (mndAcquireGlobalIdx(pMnode, fullIdxName, SDB_IDX, &idx) == 0 && idx.pIdx != NULL) { terrno = TSDB_CODE_MND_TAG_INDEX_ALREADY_EXIST; mndReleaseIdx(pMnode, idx.pIdx); - goto _OVER; }