提交 0a38853f 编写于 作者: S Shengliang Guan

tfs config

上级 79d965d7
......@@ -59,6 +59,7 @@ typedef struct SConfigItem {
int32_t i32;
int64_t i64;
char *str;
SArray *array; // SDiskCfg
};
union {
int64_t imin;
......@@ -71,15 +72,15 @@ typedef struct SConfigItem {
} SConfigItem;
typedef struct {
char *name;
char *value;
const char *name;
const char *value;
} SConfigPair;
typedef struct SConfig SConfig;
SConfig *cfgInit();
int32_t cfgLoad(SConfig *pCfg, ECfgSrcType cfgType, const char *sourceStr);
int32_t cfgLoadArray(SConfig *pCfg, SArray *pArgs);
int32_t cfgLoadArray(SConfig *pCfg, SArray *pArgs); // SConfigPair
void cfgCleanup(SConfig *pCfg);
int32_t cfgGetSize(SConfig *pCfg);
......
......@@ -154,19 +154,20 @@ static void taosAddDataDir(int32_t index, char *v1, int32_t level, int32_t prima
uTrace("dataDir:%s, level:%d primary:%d is configured", v1, level, primary);
}
static void taosReadDataDirCfg(char *v1, char *v2, char *v3) {
if (tsDiskCfgNum == 1) {
SDiskCfg *cfg = &tsDiskCfg[0];
uInfo("dataDir:%s, level:%d primary:%d is replaced by %s", cfg->dir, cfg->level, cfg->primary, v1);
}
taosAddDataDir(0, v1, 0, 1);
tsDiskCfgNum = 1;
}
static void taosPrintDataDirCfg() {
for (int32_t i = 0; i < tsDiskCfgNum; ++i) {
SDiskCfg *cfg = &tsDiskCfg[i];
uInfo(" dataDir: %s", cfg->dir);
static void taosSetTfsCfg(SConfig *pCfg) {
SConfigItem *pItem = cfgGetItem(pCfg, "dataDir");
if (pItem == NULL) return;
int32_t size = taosArrayGetSize(pItem->array);
if (size <= 0) {
tsDiskCfgNum = 1;
taosAddDataDir(0, pItem->str, 0, 1);
} else {
tsDiskCfgNum = size < TFS_MAX_DISKS ? size : TFS_MAX_DISKS;
for (int32_t index = 0; index < tsDiskCfgNum; ++index) {
SDiskCfg *pCfg = taosArrayGet(pItem->array, index);
memcpy(&tsDiskCfg[index], pCfg, sizeof(SDiskCfg));
}
}
}
......@@ -270,7 +271,7 @@ static int32_t taosAddClientCfg(SConfig *pCfg) {
return 0;
}
static int32_t taosAddSystemInfo(SConfig *pCfg) {
static int32_t taosAddSystemCfg(SConfig *pCfg) {
SysNameInfo info = taosGetSysNameInfo();
if (cfgAddTimezone(pCfg, "timezone", tsTimezone) != 0) return -1;
......@@ -440,6 +441,12 @@ int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDi
return -1;
}
if (cfgLoadArray(pCfg, pArgs) != 0) {
uError("failed to load cfg from array since %s", terrstr());
cfgCleanup(pCfg);
return -1;
}
if (tsc) {
taosSetClientLogCfg(pCfg);
} else {
......@@ -472,7 +479,7 @@ int32_t taosInitCfg(const char *cfgDir, const char *envFile, const char *apolloU
if (taosAddClientCfg(tsCfg) != 0) return -1;
if (taosAddServerCfg(tsCfg) != 0) return -1;
}
taosAddSystemInfo(tsCfg);
taosAddSystemCfg(tsCfg);
if (taosLoadCfg(tsCfg, cfgDir, envFile, apolloUrl) != 0) {
uError("failed to load cfg since %s", terrstr());
......@@ -481,11 +488,18 @@ int32_t taosInitCfg(const char *cfgDir, const char *envFile, const char *apolloU
return -1;
}
if (cfgLoadArray(tsCfg, pArgs) != 0) {
uError("failed to load cfg from array since %s", terrstr());
cfgCleanup(tsCfg);
return -1;
}
if (tsc) {
taosSetClientCfg(tsCfg);
} else {
taosSetClientCfg(tsCfg);
taosSetServerCfg(tsCfg);
taosSetTfsCfg(tsCfg);
}
taosSetSystemCfg(tsCfg);
......
......@@ -25,7 +25,7 @@ static int32_t tfsOpendirImpl(STfs *pTfs, STfsDir *pDir);
static STfsDisk *tfsNextDisk(STfs *pTfs, SDiskIter *pIter);
STfs *tfsOpen(SDiskCfg *pCfg, int32_t ndisk) {
if (ndisk < 0 || ndisk > TFS_MAX_DISKS) {
if (ndisk <= 0 || ndisk > TFS_MAX_DISKS) {
terrno = TSDB_CODE_INVALID_PARA;
return NULL;
}
......
......@@ -16,6 +16,7 @@
#define _DEFAULT_SOURCE
#include "tconfig.h"
#include "taoserror.h"
#include "tcfg.h"
#include "thash.h"
#include "tutil.h"
#include "ulog.h"
......@@ -321,6 +322,32 @@ int32_t cfgSetItem(SConfig *pCfg, const char *name, const char *value, ECfgSrcTy
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) {
char lowcaseName[CFG_NAME_MAX_LEN + 1] = {0};
memcpy(lowcaseName, name, CFG_NAME_MAX_LEN);
......@@ -487,12 +514,12 @@ const char *cfgDtypeStr(ECfgDataType type) {
void cfgDumpCfg(SConfig *pCfg, bool tsc, bool dump) {
if (dump) {
printf(" global config");
printf(" global config");
printf("\n");
printf("=================================================================");
printf("\n");
} else {
uInfo(" global config");
uInfo(" global config");
uInfo("=================================================================");
}
......@@ -620,7 +647,9 @@ int32_t cfgLoadFromCfgFile(SConfig *pConfig, const char *filepath) {
}
cfgSetItem(pConfig, name, value, CFG_STYPE_CFG_FILE);
// taosReadConfigOption(name, value, value2, value3);
if (value2 != NULL && value3 != NULL && value2[0] != 0 && value3[0] != 0) {
cfgSetTfsItem(pConfig, name, value, value2, value3, CFG_STYPE_CFG_FILE);
}
}
taosCloseFile(&pFile);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册