Optimising the duration and keep of the show create database
This commit is contained in:
parent
b8588feeff
commit
33c284a1d9
|
@ -344,23 +344,27 @@ static const char* encryptAlgorithmStr(int8_t encryptAlgorithm) {
|
|||
return TSDB_CACHE_MODEL_NONE_STR;
|
||||
}
|
||||
|
||||
static void formatDurationOrKeep(char** buffer, int32_t timeInMinutes) {
|
||||
static 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);
|
||||
} 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);
|
||||
} else {
|
||||
len = snprintf(NULL, 0, "%dm", timeInMinutes);
|
||||
*buffer = (char*)taosMemoryCalloc(len + 1, sizeof(char));
|
||||
if(*buffer == NULL) return terrno;
|
||||
sprintf(*buffer, "%dm", timeInMinutes);
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t setCreateDBResultIntoDataBlock(SSDataBlock* pBlock, char* dbName, char* dbFName, SDbCfgInfo* pCfg) {
|
||||
|
@ -401,13 +405,24 @@ static int32_t setCreateDBResultIntoDataBlock(SSDataBlock* pBlock, char* dbName,
|
|||
hashPrefix = pCfg->hashPrefix + dbFNameLen + 1;
|
||||
}
|
||||
char* durationStr = NULL;
|
||||
(void)formatDurationOrKeep(&durationStr, pCfg->daysPerFile);
|
||||
char* keep0Str = NULL;
|
||||
(void)formatDurationOrKeep(&keep0Str, pCfg->daysToKeep0);
|
||||
char* keep1Str = NULL;
|
||||
(void)formatDurationOrKeep(&keep1Str, pCfg->daysToKeep1);
|
||||
char* keep2Str = NULL;
|
||||
(void)formatDurationOrKeep(&keep2Str, pCfg->daysToKeep2);
|
||||
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;
|
||||
}
|
||||
if (IS_SYS_DBNAME(dbName)) {
|
||||
len += sprintf(buf2 + VARSTR_HEADER_SIZE, "CREATE DATABASE `%s`", dbName);
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue