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

tfs config

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