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

os env

上级 ca634993
......@@ -27,7 +27,6 @@ extern int8_t tsDaylight;
extern int32_t tsCompressMsgSize;
extern int32_t tsCompressColData;
extern int32_t tsMaxNumOfDistinctResults;
extern char tsTempDir[];
extern int tsCompatibleModel; // 2.0 compatible model
extern int8_t tsEnableSlaveQuery;
extern int8_t tsEnableAdjustMaster;
......
......@@ -16,28 +16,32 @@
#ifndef _TD_OS_ENV_H_
#define _TD_OS_ENV_H_
#include "osSysinfo.h"
#ifdef __cplusplus
extern "C" {
#endif
extern char tsOsName[];
typedef struct SEnvVar {
char dataDir[PATH_MAX];
char logDir[PATH_MAX];
char tempDir[PATH_MAX];
char osName[16];
SDiskSpace dataSpace;
SDiskSpace logSpace;
SDiskSpace tempSpace;
} SEnvVar;
extern char tsDataDir[];
extern char tsLogDir[];
extern char tsTempDir[];
extern char configDir[];
extern struct SDiskSpace tsLogSpace;
extern struct SDiskSpace tsTempSpace;
extern struct SDiskSpace tsDataSpace;
void taosUpdateLogSpace();
void taosUpdateTempSpace();
void taosUpdateDataSpace();
bool taosLogSpaceAvailable();
bool taosTmpSpaceAvailable();
bool taosDataSpaceAvailable();
void taosUpdateAllSpace();
void osInit();
SEnvVar *osEnv();
void osUpdate();
bool osLogSpaceAvailable();
char * osLogDir();
char * osTempDir();
char * osDataDir();
char * osName();
#ifdef __cplusplus
}
......
......@@ -67,7 +67,7 @@ static int32_t tscAddLogCfg(SConfig *pCfg) {
}
static int32_t tscSetLogCfg(SConfig *pCfg) {
tstrncpy(tsLogDir, cfgGetItem(pCfg, "logDir")->str, PATH_MAX);
tstrncpy(osLogDir(), cfgGetItem(pCfg, "logDir")->str, PATH_MAX);
tsAsyncLog = cfgGetItem(pCfg, "asyncLog")->bval;
tsNumOfLogLines = cfgGetItem(pCfg, "numOfLogLines")->i32;
tsLogKeepDays = cfgGetItem(pCfg, "logKeepDays")->i32;
......@@ -146,7 +146,7 @@ static int32_t tscAddCfg(SConfig *pCfg) {
// if (cfgAddString(pCfg, "gitinfo", gitinfo) != 0) return -1;
// if (cfgAddString(pCfg, "version", version) != 0) return -1;
// if (cfgAddDir(pCfg, "dataDir", tsDataDir) != 0) return -1;
// if (cfgAddDir(pCfg, "dataDir", osDataDir()) != 0) return -1;
if (cfgAddTimezone(pCfg, "timezone", "") != 0) return -1;
if (cfgAddLocale(pCfg, "locale", "") != 0) return -1;
if (cfgAddCharset(pCfg, "charset", "") != 0) return -1;
......
......@@ -235,7 +235,7 @@ static void doInitGlobalConfig(void) {
cfg.option = "dataDir";
cfg.ptr = tsDataDir;
cfg.ptr = osDataDir();
cfg.valType = TAOS_CFG_VTYPE_DATA_DIRCTORY;
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG;
cfg.minValue = 0;
......@@ -419,7 +419,7 @@ static void doInitGlobalConfig(void) {
taosAddConfigOption(cfg);
cfg.option = "tempDir";
cfg.ptr = tsTempDir;
cfg.ptr = osTempDir();
cfg.valType = TAOS_CFG_VTYPE_STRING;
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT;
cfg.minValue = 0;
......
......@@ -23,7 +23,7 @@ STSBuf* tsBufCreate(bool autoDelete, int32_t order) {
pTSBuf->autoDelete = autoDelete;
taosGetTmpfilePath(tsTempDir, "join", pTSBuf->path);
taosGetTmpfilePath(osTempDir(), "join", pTSBuf->path);
pTSBuf->f = fopen(pTSBuf->path, "wb+");
if (pTSBuf->f == NULL) {
free(pTSBuf);
......
......@@ -40,18 +40,19 @@ static int32_t dmnAddEpCfg(SConfig *pCfg) {
}
static int32_t dmnAddDirCfg(SConfig *pCfg) {
if (cfgAddDir(pCfg, "dataDir", tsDataDir) != 0) return -1;
if (cfgAddDir(pCfg, "tempDir", tsTempDir) != 0) return -1;
if (cfgAddDir(pCfg, "dataDir", osDataDir()) != 0) return -1;
if (cfgAddDir(pCfg, "tempDir", osTempDir()) != 0) return -1;
if (cfgAddFloat(pCfg, "minimalDataDirGB", 2.0f, 0.001f, 10000000) != 0) return -1;
if (cfgAddFloat(pCfg, "minimalTempDirGB", 1.0f, 0.001f, 10000000) != 0) return -1;
return 0;
}
static int32_t dmnCheckDirCfg(SConfig *pCfg) {
tstrncpy(tsDataDir, cfgGetItem(pCfg, "dataDir")->str, PATH_MAX);
tstrncpy(tsTempDir, cfgGetItem(pCfg, "tempDir")->str, PATH_MAX);
tsDataSpace.reserved = cfgGetItem(pCfg, "minimalDataDirGB")->fval;
tsTempSpace.reserved = cfgGetItem(pCfg, "minimalTempDirGB")->fval;
SEnvVar *pEnv = osEnv();
tstrncpy(pEnv->dataDir, cfgGetItem(pCfg, "dataDir")->str, PATH_MAX);
tstrncpy(pEnv->tempDir, cfgGetItem(pCfg, "tempDir")->str, PATH_MAX);
pEnv->dataSpace.reserved = cfgGetItem(pCfg, "minimalDataDirGB")->fval;
pEnv->tempSpace.reserved = cfgGetItem(pCfg, "minimalTempDirGB")->fval;
return 0;
}
......
......@@ -41,8 +41,10 @@ int32_t dmnAddLogCfg(SConfig *pCfg) {
}
int32_t dmnSetLogCfg(SConfig *pCfg) {
tstrncpy(tsLogDir, cfgGetItem(pCfg, "logDir")->str, PATH_MAX);
tsLogSpace.reserved = cfgGetItem(pCfg, "minimalLogDirGB")->fval;
SEnvVar *pEnv = osEnv();
tstrncpy(pEnv->logDir, cfgGetItem(pCfg, "logDir")->str, PATH_MAX);
pEnv->logSpace.reserved = cfgGetItem(pCfg, "minimalLogDirGB")->fval;
tsAsyncLog = cfgGetItem(pCfg, "asyncLog")->bval;
tsNumOfLogLines = cfgGetItem(pCfg, "numOfLogLines")->i32;
tsLogKeepDays = cfgGetItem(pCfg, "logKeepDays")->i32;
......
......@@ -33,7 +33,7 @@ void Testbase::InitLog(const char* path) {
taosRemoveDir(path);
taosMkDir(path);
tstrncpy(tsLogDir, path, PATH_MAX);
tstrncpy(osLogDir(), path, PATH_MAX);
if (taosInitLog("taosdlog", 1) != 0) {
printf("failed to init log file\n");
}
......
......@@ -132,7 +132,7 @@ void ctgTestInitLogFile() {
ctgDbgEnableDebug("api");
if (taosInitLog(defaultLogFileNamePrefix, maxLogFileNum) < 0) {
printf("failed to open log file in directory:%s\n", tsLogDir);
printf("failed to open log file in directory:%s\n", osLogDir());
}
}
......
......@@ -593,16 +593,16 @@ void cfgDumpCfg(SConfig *pCfg) {
// pItem = cfgGetItem(pCfg, "dataDir");
// if (pItem != NULL) {
// tstrncpy(tsDataDir, pItem->str, PATH_MAX);
// tstrncpy(osDataDir(), pItem->str, PATH_MAX);
// }
// if (tsDiskCfgNum <= 0) {
// taosAddDataDir(0, tsDataDir, 0, 1);
// taosAddDataDir(0, osDataDir(), 0, 1);
// tsDiskCfgNum = 1;
// uTrace("dataDir:%s, level:0 primary:1 is configured by default", tsDataDir);
// uTrace("dataDir:%s, level:0 primary:1 is configured by default", osDataDir());
// }
// if (taosDirExist(tsTempDir) != 0) {
// if (taosDirExist(osTempDir()) != 0) {
// return -1;
// }
......
......@@ -4629,7 +4629,7 @@ int32_t doInitQInfo(SQInfo* pQInfo, STSBuf* pTsBuf, void* tsdb, void* sourceOptr
getIntermediateBufInfo(pRuntimeEnv, &ps, &pQueryAttr->intermediateResultRowSize);
int32_t TENMB = 1024*1024*10;
int32_t code = createDiskbasedBuffer(&pRuntimeEnv->pResultBuf, ps, TENMB, pQInfo->qId, tsTempDir);
int32_t code = createDiskbasedBuffer(&pRuntimeEnv->pResultBuf, ps, TENMB, pQInfo->qId, osTempDir());
if (code != TSDB_CODE_SUCCESS) {
return code;
}
......
......@@ -254,7 +254,7 @@ tMemBucket *tMemBucketCreate(int16_t nElemSize, int16_t dataType, double minval,
resetSlotInfo(pBucket);
int32_t ret = createDiskbasedBuffer(&pBucket->pBuffer, pBucket->bufPageSize, pBucket->bufPageSize * 512, 1, tsTempDir);
int32_t ret = createDiskbasedBuffer(&pBucket->pBuffer, pBucket->bufPageSize, pBucket->bufPageSize * 512, 1, osTempDir());
if (ret != 0) {
tMemBucketDestroy(pBucket);
return NULL;
......
......@@ -55,7 +55,7 @@ int32_t initUdfInfo(SUdfInfo* pUdfInfo) {
} else {
char path[PATH_MAX] = {0};
taosGetTmpfilePath("script", path, tsTempDir);
taosGetTmpfilePath("script", path, osTempDir());
FILE* file = fopen(path, "w+");
......
......@@ -30,7 +30,7 @@ static void EnvInit() {
taosRemoveDir(path.c_str());
taosMkDir(path.c_str());
// init log file
tstrncpy(tsLogDir, path.c_str(), PATH_MAX);
tstrncpy(osLogDir(), path.c_str(), PATH_MAX);
if (taosInitLog("tindex.idx", 1) != 0) {
printf("failed to init log");
}
......
......@@ -102,7 +102,7 @@ void qwtInitLogFile() {
qDebugFlag = 159;
if (taosInitLog(defaultLogFileNamePrefix, maxLogFileNum) < 0) {
printf("failed to open log file in directory:%s\n", tsLogDir);
printf("failed to open log file in directory:%s\n", osLogDir());
}
}
......
......@@ -53,7 +53,7 @@ void flttInitLogFile() {
qDebugFlag = 159;
if (taosInitLog(defaultLogFileNamePrefix, maxLogFileNum) < 0) {
printf("failed to open log file in directory:%s\n", tsLogDir);
printf("failed to open log file in directory:%s\n", osLogDir());
}
}
......
......@@ -52,7 +52,7 @@ void scltInitLogFile() {
qDebugFlag = 159;
if (taosInitLog(defaultLogFileNamePrefix, maxLogFileNum) < 0) {
printf("failed to open log file in directory:%s\n", tsLogDir);
printf("failed to open log file in directory:%s\n", osLogDir());
}
}
......
......@@ -67,7 +67,7 @@ void schtInitLogFile() {
qDebugFlag = 159;
if (taosInitLog(defaultLogFileNamePrefix, maxLogFileNum) < 0) {
printf("failed to open log file in directory:%s\n", tsLogDir);
printf("failed to open log file in directory:%s\n", osLogDir());
}
}
......
......@@ -155,7 +155,7 @@ class TransObj {
taosRemoveDir(path.c_str());
taosMkDir(path.c_str());
tstrncpy(tsLogDir, path.c_str(), PATH_MAX);
tstrncpy(osLogDir(), path.c_str(), PATH_MAX);
if (taosInitLog("taosdlog", 1) != 0) {
printf("failed to init log file\n");
}
......
......@@ -13,77 +13,77 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define _DEFAULT_SOURCE
#include "os.h"
#include "osEnv.h"
#include "os.h"
#include "osSysinfo.h"
SDiskSpace tsLogSpace;
SDiskSpace tsTempSpace;
SDiskSpace tsDataSpace;
void taosUpdateLogSpace() { taosGetDiskSize(tsLogDir, &tsLogSpace.size); }
void taosUpdateTempSpace() { taosGetDiskSize(tsTempDir, &tsTempSpace.size); }
void taosUpdateDataSpace() { taosGetDiskSize(tsDataDir, &tsDataSpace.size); }
bool taosLogSpaceAvailable() { return tsLogSpace.reserved < tsLogSpace.size.avail; }
bool taosTempSpaceAvailable() { return tsTempSpace.reserved < tsTempSpace.size.avail; }
bool taosDataSpaceAvailable() { return tsDataSpace.reserved < tsDataSpace.size.avail; }
void taosUpdateAllSpace() {
taosUpdateLogSpace();
taosUpdateTempSpace();
taosUpdateDataSpace();
}
SEnvVar env = {0};
char configDir[PATH_MAX] = {0};
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
char tsOsName[10] = "Windows";
char configDir[PATH_MAX] = "C:/TDengine/cfg";
char tsDataDir[PATH_MAX] = "C:/TDengine/data";
char tsLogDir[PATH_MAX] = "C:/TDengine/log";
char tsTempDir[PATH_MAX] = "C:\\Windows\\Temp";
extern taosWinSocketInit();
void osInit() {
srand(taosSafeRand());
taosWinSocketInit();
const char *tmpDir = getenv("tmp");
if (tmpDir == NULL) {
tmpDir = getenv("temp");
}
if (tmpDir != NULL) {
strcpy(tsTempDir, tmpDir);
strcpy(env.tempDir, tmpDir);
}
strcpy(configDir, "C:\\TDengine\\cfg");
strcpy(env.dataDir, "C:\\TDengine\\data");
strcpy(env.logDir, "C:\\TDengine\\log");
strcpy(env.tempDir, "C:\\Windows\\Temp");
strcpy(env.osName, "Windows");
}
#elif defined(_TD_DARWIN_64)
char tsOsName[10] = "Darwin";
char configDir[PATH_MAX] = "/usr/local/etc/taos";
char tsDataDir[PATH_MAX] = "/usr/local/var/lib/taos";
char tsLogDir[PATH_MAX] = "/usr/local/var/log/taos";
char tsTempDir[PATH_MAX] = "/tmp/taosd";
void osInit() {}
void osInit() {
srand(taosSafeRand());
strcpy(configDir, "/tmp/taosd");
strcpy(env.dataDir, "/usr/local/var/lib/taos");
strcpy(env.logDir, "/usr/local/var/log/taos");
strcpy(env.tempDir, "/usr/local/etc/taos");
strcpy(env.osName, "Darwin");
}
#else
char tsOsName[10] = "Linux";
char configDir[PATH_MAX] = "/etc/taos";
char tsDataDir[PATH_MAX] = "/var/lib/taos";
char tsLogDir[PATH_MAX] = "/var/log/taos";
char tsTempDir[PATH_MAX] = "/tmp/";
void osInit() {
srand(taosSafeRand());
srand(taosSafeRand());
strcpy(configDir, "/etc/taos");
strcpy(env.dataDir, "/var/lib/taos");
strcpy(env.logDir, "/var/log/taos");
strcpy(env.tempDir, "/tmp");
strcpy(env.osName, "Linux");
}
#endif
SEnvVar *osEnv() { return &env; }
void osUpdate() {
if (env.logDir[0] != 0) {
taosGetDiskSize(env.logDir, &env.logSpace.size);
}
if (env.dataDir[0] != 0) {
taosGetDiskSize(env.dataDir, &env.dataSpace.size);
}
if (env.tempDir[0] != 0) {
taosGetDiskSize(env.tempDir, &env.tempSpace.size);
}
}
bool osLogSpaceAvailable() { return env.logSpace.reserved < env.logSpace.size.avail; }
char *osLogDir() { return env.logDir; }
char *osTempDir() { return env.tempDir; }
char *osDataDir() { return env.dataDir; }
char *osName() { return env.osName; }
......@@ -134,7 +134,7 @@ int32_t taosGetDiskSize(char *dataDir, SDiskSize *diskSize) {
diskSize->used = (int64_t)(i64TotalBytes - i64FreeBytes);
return 0;
} else {
//printf("failed to get disk size, dataDir:%s errno:%s", tsDataDir, strerror(errno));
//printf("failed to get disk size, dataDir:%s errno:%s", osDataDir(), strerror(errno));
terrno = TAOS_SYSTEM_ERROR(errno);
return -1;
}
......@@ -441,7 +441,7 @@ void taosSetCoreDump() {}
int32_t taosGetDiskSize(char *dataDir, SDiskSize *diskSize) {
struct statvfs info;
if (statvfs(dataDir, &info)) {
//printf("failed to get disk size, dataDir:%s errno:%s", tsDataDir, strerror(errno));
//printf("failed to get disk size, dataDir:%s errno:%s", osDataDir(), strerror(errno));
terrno = TAOS_SYSTEM_ERROR(errno);
return -1;
} else {
......
......@@ -118,10 +118,9 @@ static int32_t taosStartLog() {
int32_t taosInitLog(const char *logName, int maxFiles) {
if (tsLogInited) return 0;
taosUpdateLogSpace();
char fullName[PATH_MAX] = {0};
snprintf(fullName, PATH_MAX, "%s" TD_DIRSEP "%s", tsLogDir, logName);
snprintf(fullName, PATH_MAX, "%s" TD_DIRSEP "%s", osLogDir(), logName);
tsLogObj.logHandle = taosLogBuffNew(TSDB_DEFAULT_LOG_BUF_SIZE);
if (tsLogObj.logHandle == NULL) return -1;
......@@ -187,7 +186,7 @@ static void taosKeepOldLog(char *oldName) {
}
}
taosRemoveOldFiles(tsLogDir, TABS(tsLogKeepDays));
taosRemoveOldFiles(osLogDir(), TABS(tsLogKeepDays));
}
static void *taosThreadToOpenNewFile(void *param) {
......@@ -380,7 +379,7 @@ static int32_t taosOpenLogFile(char *fn, int32_t maxLines, int32_t maxFileNum) {
}
void taosPrintLog(const char *flags, int32_t dflag, const char *format, ...) {
if (!taosLogSpaceAvailable()) return;
if (!osLogSpaceAvailable()) return;
va_list argpointer;
char buffer[MAX_LOGLINE_BUFFER_SIZE] = {0};
......@@ -434,7 +433,7 @@ void taosPrintLog(const char *flags, int32_t dflag, const char *format, ...) {
}
void taosDumpData(unsigned char *msg, int32_t len) {
if (!taosLogSpaceAvailable()) return;
if (!osLogSpaceAvailable()) return;
char temp[256];
int32_t i, pos = 0, c = 0;
......@@ -457,7 +456,7 @@ void taosDumpData(unsigned char *msg, int32_t len) {
}
void taosPrintLongString(const char *flags, int32_t dflag, const char *format, ...) {
if (!taosLogSpaceAvailable()) return;
if (!osLogSpaceAvailable()) return;
va_list argpointer;
char buffer[MAX_LOGLINE_DUMP_BUFFER_SIZE];
......
......@@ -68,11 +68,11 @@ TAOS *shellInit(SShellArguments *_args) {
printf("\n");
if (!_args->is_use_passwd) {
#ifdef TD_WINDOWS
strcpy(tsOsName, "Windows");
strcpy(osName(), "Windows");
#elif defined(TD_DARWIN)
strcpy(tsOsName, "Darwin");
strcpy(osName(), "Darwin");
#endif
printf(CLIENT_VERSION, tsOsName, taos_get_client_info());
printf(CLIENT_VERSION, osName(), taos_get_client_info());
}
fflush(stdout);
......
......@@ -184,8 +184,8 @@ static void parse_args(
for (int i = 1; i < argc; i++) {
if ((strncmp(argv[i], "-p", 2) == 0)
|| (strncmp(argv[i], "--password", 10) == 0)) {
strcpy(tsOsName, "Linux");
printf(LINUXCLIENT_VERSION, tsOsName, taos_get_client_info());
strcpy(osName(), "Linux");
printf(LINUXCLIENT_VERSION, osName(), taos_get_client_info());
if ((strlen(argv[i]) == 2)
|| (strncmp(argv[i], "--password", 10) == 0)) {
printf("Enter password: ");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册