feat:Optimising the duration and keep

This commit is contained in:
lyh250-666 2024-09-11 01:11:56 +00:00
parent 2f06ba4cc1
commit 25c0b92885
4 changed files with 32 additions and 45 deletions

View File

@ -29,5 +29,6 @@ int32_t qExecExplainBegin(SQueryPlan *pDag, SExplainCtx **pCtx, int64_t startTs)
int32_t qExecExplainEnd(SExplainCtx *pCtx, SRetrieveTableRsp **pRsp);
int32_t qExplainUpdateExecInfo(SExplainCtx *pCtx, SExplainRsp *pRspMsg, int32_t groupId, SRetrieveTableRsp **pRsp);
void qExplainFreeCtx(SExplainCtx *pCtx);
int32_t formatDurationOrKeep(char* buffer, int32_t timeInMinutes);
#endif

View File

@ -34,6 +34,7 @@
#include "systable.h"
#include "thttp.h"
#include "tjson.h"
#include "command.h"
#define DB_VER_NUMBER 1
#define DB_RESERVE_SIZE 27
@ -2321,18 +2322,25 @@ static void mndDumpDbInfoData(SMnode *pMnode, SSDataBlock *pBlock, SDbObj *pDb,
(void)colDataSetVal(pColInfo, rows, (const char *)strictVstr, false);
char durationVstr[128] = {0};
int32_t len = sprintf(&durationVstr[VARSTR_HEADER_SIZE], "%dm", pDb->cfg.daysPerFile);
int32_t len = formatDurationOrKeep(&durationVstr[VARSTR_HEADER_SIZE], pDb->cfg.daysPerFile);
varDataSetLen(durationVstr, len);
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
(void)colDataSetVal(pColInfo, rows, (const char *)durationVstr, false);
char keepVstr[128] = {0};
char keepVstr[512] = {0};
char keep0Str[128] = {0};
char keep1Str[128] = {0};
char keep2Str[128] = {0};
formatDurationOrKeep(keep0Str, pDb->cfg.daysToKeep0);
formatDurationOrKeep(keep1Str, pDb->cfg.daysToKeep1);
formatDurationOrKeep(keep2Str, pDb->cfg.daysToKeep2);
if (pDb->cfg.daysToKeep0 > pDb->cfg.daysToKeep1 || pDb->cfg.daysToKeep0 > pDb->cfg.daysToKeep2) {
len = sprintf(&keepVstr[VARSTR_HEADER_SIZE], "%dm,%dm,%dm", pDb->cfg.daysToKeep1, pDb->cfg.daysToKeep2,
pDb->cfg.daysToKeep0);
len = sprintf(&keepVstr[VARSTR_HEADER_SIZE], "%s,%s,%s", keep1Str, keep2Str, keep0Str);
} else {
len = sprintf(&keepVstr[VARSTR_HEADER_SIZE], "%dm,%dm,%dm", pDb->cfg.daysToKeep0, pDb->cfg.daysToKeep1,
pDb->cfg.daysToKeep2);
len = sprintf(&keepVstr[VARSTR_HEADER_SIZE], "%s,%s,%s", keep0Str, keep1Str, keep2Str);
}
varDataSetLen(keepVstr, len);
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);

View File

@ -344,27 +344,18 @@ static const char* encryptAlgorithmStr(int8_t encryptAlgorithm) {
return TSDB_CACHE_MODEL_NONE_STR;
}
static int32_t formatDurationOrKeep(char** buffer, int32_t timeInMinutes) {
int32_t formatDurationOrKeep(char* buffer, int32_t timeInMinutes) {
int len = 0;
if (timeInMinutes % 1440 == 0) {
int days = timeInMinutes / 1440;
len = snprintf(NULL, 0, "%dd", days);
*buffer = (char*)taosMemoryCalloc(len + 1, sizeof(char));
if(*buffer == NULL) return terrno;
sprintf(*buffer, "%dd", days);
len = sprintf(buffer, "%dd", days);
} else if (timeInMinutes % 60 == 0) {
int hours = timeInMinutes / 60;
len = snprintf(NULL, 0, "%dh", hours);
*buffer = (char*)taosMemoryCalloc(len + 1, sizeof(char));
if(*buffer == NULL) return terrno;
sprintf(*buffer, "%dh", hours);
len = sprintf(buffer, "%dh", hours);
} else {
len = snprintf(NULL, 0, "%dm", timeInMinutes);
*buffer = (char*)taosMemoryCalloc(len + 1, sizeof(char));
if(*buffer == NULL) return terrno;
sprintf(*buffer, "%dm", timeInMinutes);
len = sprintf(buffer, "%dm", timeInMinutes);
}
return TSDB_CODE_SUCCESS;
return len;
}
static int32_t setCreateDBResultIntoDataBlock(SSDataBlock* pBlock, char* dbName, char* dbFName, SDbCfgInfo* pCfg) {
@ -404,25 +395,16 @@ static int32_t setCreateDBResultIntoDataBlock(SSDataBlock* pBlock, char* dbName,
} else if (pCfg->hashPrefix < 0) {
hashPrefix = pCfg->hashPrefix + dbFNameLen + 1;
}
char* durationStr = NULL;
char* keep0Str = NULL;
char* keep1Str = NULL;
char* keep2Str = NULL;
int32_t codeDuration = formatDurationOrKeep(&durationStr, pCfg->daysPerFile);
int32_t codeKeep0 = formatDurationOrKeep(&keep0Str, pCfg->daysToKeep0);
int32_t codeKeep1 = formatDurationOrKeep(&keep1Str, pCfg->daysToKeep1);
int32_t codeKeep2 = formatDurationOrKeep(&keep2Str, pCfg->daysToKeep2);
if(codeDuration != TSDB_CODE_SUCCESS || codeKeep0 != TSDB_CODE_SUCCESS || codeKeep1 != TSDB_CODE_SUCCESS || codeKeep2 != TSDB_CODE_SUCCESS) {
int32_t firstErrorCode = codeDuration != TSDB_CODE_SUCCESS ? codeDuration :
codeKeep0 != TSDB_CODE_SUCCESS ? codeKeep0 :
codeKeep1 != TSDB_CODE_SUCCESS ? codeKeep1 : codeKeep2;
taosMemoryFree(pRetentions);
taosMemoryFree(durationStr);
taosMemoryFree(keep0Str);
taosMemoryFree(keep1Str);
taosMemoryFree(keep2Str);
return firstErrorCode;
}
char durationStr[128] = {0};
char keep0Str[128] = {0};
char keep1Str[128] = {0};
char keep2Str[128] = {0};
int32_t lenDuration = formatDurationOrKeep(durationStr, pCfg->daysPerFile);
int32_t lenKeep0 = formatDurationOrKeep(keep0Str, pCfg->daysToKeep0);
int32_t lenKeep1 = formatDurationOrKeep(keep1Str, pCfg->daysToKeep1);
int32_t lenKeep2 = formatDurationOrKeep(keep2Str, pCfg->daysToKeep2);
if (IS_SYS_DBNAME(dbName)) {
len += sprintf(buf2 + VARSTR_HEADER_SIZE, "CREATE DATABASE `%s`", dbName);
} else {
@ -449,10 +431,6 @@ static int32_t setCreateDBResultIntoDataBlock(SSDataBlock* pBlock, char* dbName,
}
taosMemoryFree(pRetentions);
taosMemoryFree(durationStr);
taosMemoryFree(keep0Str);
taosMemoryFree(keep1Str);
taosMemoryFree(keep2Str);
(varDataLen(buf2)) = len;

View File

@ -92,10 +92,10 @@ endi
if $data5_db != on then # strict
return -1
endi
if $data6_db != 14400m then # duration
if $data6_db != 10d then # duration
return -1
endi
if $data7_db != 5256000m,5256000m,5256000m then # keep
if $data7_db != 3650d,3650d,3650d then # keep
return -1
endi
if $data8_db != 256 then # buffer