提交 f5e08cdf 编写于 作者: S Shengliang Guan

tfs cfg

上级 0a38853f
...@@ -59,7 +59,6 @@ typedef struct SConfigItem { ...@@ -59,7 +59,6 @@ typedef struct SConfigItem {
int32_t i32; int32_t i32;
int64_t i64; int64_t i64;
char *str; char *str;
SArray *array; // SDiskCfg
}; };
union { union {
int64_t imin; int64_t imin;
...@@ -69,6 +68,7 @@ typedef struct SConfigItem { ...@@ -69,6 +68,7 @@ typedef struct SConfigItem {
int64_t imax; int64_t imax;
double fmax; double fmax;
}; };
SArray *array; // SDiskCfg
} SConfigItem; } SConfigItem;
typedef struct { typedef struct {
......
...@@ -79,9 +79,25 @@ int32_t cfgLoadArray(SConfig *pCfg, SArray *pArgs) { ...@@ -79,9 +79,25 @@ int32_t cfgLoadArray(SConfig *pCfg, SArray *pArgs) {
return 0; return 0;
} }
static void cfgFreeItem(SConfigItem *pItem) {
if (pItem->dtype == CFG_DTYPE_STRING || pItem->dtype == CFG_DTYPE_DIR || pItem->dtype == CFG_DTYPE_LOCALE ||
pItem->dtype == CFG_DTYPE_CHARSET || pItem->dtype == CFG_DTYPE_TIMEZONE) {
tfree(pItem->str);
}
if (pItem->array) {
taosArrayDestroy(pItem->array);
pItem->array = NULL;
}
}
void cfgCleanup(SConfig *pCfg) { void cfgCleanup(SConfig *pCfg) {
if (pCfg != NULL) { if (pCfg != NULL) {
if (pCfg->hash != NULL) { if (pCfg->hash != NULL) {
SConfigItem *pItem = taosHashIterate(pCfg->hash, NULL);
while (pItem != NULL) {
cfgFreeItem(pItem);
pItem = taosHashIterate(pCfg->hash, pItem);
}
taosHashCleanup(pCfg->hash); taosHashCleanup(pCfg->hash);
pCfg->hash == NULL; pCfg->hash == NULL;
} }
...@@ -96,7 +112,7 @@ SConfigItem *cfgIterate(SConfig *pCfg, SConfigItem *pIter) { return taosHashIter ...@@ -96,7 +112,7 @@ SConfigItem *cfgIterate(SConfig *pCfg, SConfigItem *pIter) { return taosHashIter
void cfgCancelIterate(SConfig *pCfg, SConfigItem *pIter) { return taosHashCancelIterate(pCfg->hash, pIter); } void cfgCancelIterate(SConfig *pCfg, SConfigItem *pIter) { return taosHashCancelIterate(pCfg->hash, pIter); }
static int32_t cfgCheckAndSetTimezone(SConfigItem *pItem, const char *timezone) { static int32_t cfgCheckAndSetTimezone(SConfigItem *pItem, const char *timezone) {
tfree(pItem->str); cfgFreeItem(pItem);
pItem->str = strdup(timezone); pItem->str = strdup(timezone);
if (pItem->str == NULL) { if (pItem->str == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY; terrno = TSDB_CODE_OUT_OF_MEMORY;
...@@ -107,7 +123,7 @@ static int32_t cfgCheckAndSetTimezone(SConfigItem *pItem, const char *timezone) ...@@ -107,7 +123,7 @@ static int32_t cfgCheckAndSetTimezone(SConfigItem *pItem, const char *timezone)
} }
static int32_t cfgCheckAndSetCharset(SConfigItem *pItem, const char *charset) { static int32_t cfgCheckAndSetCharset(SConfigItem *pItem, const char *charset) {
tfree(pItem->str); cfgFreeItem(pItem);
pItem->str = strdup(charset); pItem->str = strdup(charset);
if (pItem->str == NULL) { if (pItem->str == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY; terrno = TSDB_CODE_OUT_OF_MEMORY;
...@@ -118,7 +134,7 @@ static int32_t cfgCheckAndSetCharset(SConfigItem *pItem, const char *charset) { ...@@ -118,7 +134,7 @@ static int32_t cfgCheckAndSetCharset(SConfigItem *pItem, const char *charset) {
} }
static int32_t cfgCheckAndSetLocale(SConfigItem *pItem, const char *locale) { static int32_t cfgCheckAndSetLocale(SConfigItem *pItem, const char *locale) {
tfree(pItem->str); cfgFreeItem(pItem);
pItem->str = strdup(locale); pItem->str = strdup(locale);
if (pItem->str == NULL) { if (pItem->str == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY; terrno = TSDB_CODE_OUT_OF_MEMORY;
...@@ -147,7 +163,7 @@ static int32_t cfgCheckAndSetDir(SConfigItem *pItem, const char *inputDir) { ...@@ -147,7 +163,7 @@ static int32_t cfgCheckAndSetDir(SConfigItem *pItem, const char *inputDir) {
return -1; return -1;
} }
tfree(pItem->str); cfgFreeItem(pItem);
pItem->str = strdup(fullDir); pItem->str = strdup(fullDir);
if (pItem->str == NULL) { if (pItem->str == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY; terrno = TSDB_CODE_OUT_OF_MEMORY;
...@@ -288,6 +304,33 @@ static int32_t cfgSetTimezone(SConfigItem *pItem, const char *value, ECfgSrcType ...@@ -288,6 +304,33 @@ static int32_t cfgSetTimezone(SConfigItem *pItem, const char *value, ECfgSrcType
return 0; return 0;
} }
static int32_t cfgSetTfsItem(SConfig *pCfg, const char *name, const char *value, const char *level, const char *primary,
ECfgSrcType stype) {
SConfigItem *pItem = cfgGetItem(pCfg, name);
if (pItem == NULL) return -1;
if (pItem->array == NULL) {
pItem->array = taosArrayInit(16, sizeof(SDiskCfg));
if (pItem->array == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1;
}
}
SDiskCfg cfg = {0};
tstrncpy(cfg.dir, value, sizeof(cfg.dir));
cfg.level = atoi(level);
cfg.primary = atoi(primary);
void *ret = taosArrayPush(pItem->array, &cfg);
if (ret == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1;
}
pItem->stype = stype;
return 0;
}
int32_t cfgSetItem(SConfig *pCfg, const char *name, const char *value, ECfgSrcType stype) { int32_t cfgSetItem(SConfig *pCfg, const char *name, const char *value, ECfgSrcType stype) {
SConfigItem *pItem = cfgGetItem(pCfg, name); SConfigItem *pItem = cfgGetItem(pCfg, name);
if (pItem == NULL) { if (pItem == NULL) {
...@@ -322,32 +365,6 @@ int32_t cfgSetItem(SConfig *pCfg, const char *name, const char *value, ECfgSrcTy ...@@ -322,32 +365,6 @@ int32_t cfgSetItem(SConfig *pCfg, const char *name, const char *value, ECfgSrcTy
return -1; return -1;
} }
static int32_t cfgSetTfsItem(SConfig *pCfg, const char *name, const char *value, const char *level,
const char *primary, ECfgSrcType stype) {
SConfigItem *pItem = cfgGetItem(pCfg, name);
if (pItem == NULL) return -1;
if (pItem->array == NULL) {
pItem->array = taosArrayInit(16, sizeof(SDiskCfg));
if (pItem->array == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1;
}
}
SDiskCfg cfg = {0};
tstrncpy(cfg.dir, name, sizeof(cfg.dir));
cfg.level = atoi(level);
cfg.primary = atoi(primary);
void *ret = taosArrayPush(pItem->array, &cfg);
if (ret == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1;
}
return 0;
}
SConfigItem *cfgGetItem(SConfig *pCfg, const char *name) { SConfigItem *cfgGetItem(SConfig *pCfg, const char *name) {
char lowcaseName[CFG_NAME_MAX_LEN + 1] = {0}; char lowcaseName[CFG_NAME_MAX_LEN + 1] = {0};
memcpy(lowcaseName, name, CFG_NAME_MAX_LEN); memcpy(lowcaseName, name, CFG_NAME_MAX_LEN);
...@@ -620,7 +637,6 @@ int32_t cfgLoadFromCfgFile(SConfig *pConfig, const char *filepath) { ...@@ -620,7 +637,6 @@ int32_t cfgLoadFromCfgFile(SConfig *pConfig, const char *filepath) {
} }
while (!taosEOFFile(pFile)) { while (!taosEOFFile(pFile)) {
name = value = value2 = value3 = NULL; name = value = value2 = value3 = NULL;
olen = vlen = vlen2 = vlen3 = 0; olen = vlen = vlen2 = vlen3 = 0;
...@@ -653,7 +669,7 @@ int32_t cfgLoadFromCfgFile(SConfig *pConfig, const char *filepath) { ...@@ -653,7 +669,7 @@ int32_t cfgLoadFromCfgFile(SConfig *pConfig, const char *filepath) {
} }
taosCloseFile(&pFile); taosCloseFile(&pFile);
if(line != NULL) tfree(line); if (line != NULL) tfree(line);
uInfo("load from cfg file %s success", filepath); uInfo("load from cfg file %s success", filepath);
return 0; return 0;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册