提交 c712e581 编写于 作者: wafwerar's avatar wafwerar

[TD-13772]<fix>: add timezone enum.

上级 ed308f45
......@@ -75,7 +75,6 @@ extern "C" {
#include "osDef.h"
#include "osDir.h"
#include "osEndian.h"
#include "osEnv.h"
#include "osFile.h"
#include "osLocale.h"
#include "osLz4.h"
......@@ -93,8 +92,9 @@ extern "C" {
#include "osTime.h"
#include "osTimer.h"
#include "osTimezone.h"
#include "osEnv.h"
void osInit();
void osDefaultInit();
#ifdef __cplusplus
}
......
......@@ -22,17 +22,18 @@
extern "C" {
#endif
extern char tsOsName[];
extern char tsTimezone[];
extern char tsCharset[];
extern char tsLocale[];
extern int8_t tsDaylight;
extern bool tsEnableCoreFile;
extern int64_t tsPageSizeKB;
extern int64_t tsOpenMax;
extern int64_t tsStreamMax;
extern float tsNumOfCores;
extern int64_t tsTotalMemoryKB;
extern char tsOsName[];
extern char tsTimezoneStr[];
extern enum TdTimezone tsTimezone;
extern char tsCharset[];
extern char tsLocale[];
extern int8_t tsDaylight;
extern bool tsEnableCoreFile;
extern int64_t tsPageSizeKB;
extern int64_t tsOpenMax;
extern int64_t tsStreamMax;
extern float tsNumOfCores;
extern int64_t tsTotalMemoryKB;
extern char configDir[];
extern char tsDataDir[];
......@@ -43,11 +44,12 @@ extern SDiskSpace tsDataSpace;
extern SDiskSpace tsLogSpace;
extern SDiskSpace tsTempSpace;
void osInit();
void osDefaultInit();
void osUpdate();
void osCleanup();
bool osLogSpaceAvailable();
void osSetTimezone(const char *timezone);
void osSetSystemLocale(const char *inLocale, const char *inCharSet);
#ifdef __cplusplus
}
......
......@@ -26,8 +26,37 @@ extern "C" {
#define tzset TZSET_FUNC_TAOS_FORBID
#endif
void taosGetSystemTimezone(char *outTimezone);
void taosSetSystemTimezone(const char *inTimezone, char *outTimezone, int8_t *outDaylight);
enum TdTimezone
{
TdWestZone12=-12,
TdWestZone11,
TdWestZone10,
TdWestZone9,
TdWestZone8,
TdWestZone7,
TdWestZone6,
TdWestZone5,
TdWestZone4,
TdWestZone3,
TdWestZone2,
TdWestZone1,
TdZeroZero,
TdEastZone1,
TdEastZone2,
TdEastZone3,
TdEastZone4,
TdEastZone5,
TdEastZone6,
TdEastZone7,
TdEastZone8,
TdEastZone9,
TdEastZone10,
TdEastZone11,
TdEastZone12
};
void taosGetSystemTimezone(char *outTimezone, enum TdTimezone *tsTimezone);
void taosSetSystemTimezone(const char *inTimezone, char *outTimezone, int8_t *outDaylight, enum TdTimezone *tsTimezone);
#ifdef __cplusplus
}
......
......@@ -408,10 +408,10 @@ int taos_options_imp(TSDB_OPTION option, const char *str) {
assert(cfg != NULL);
if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_OPTION) {
tstrncpy(tsTimezone, str, TD_TIMEZONE_LEN);
tstrncpy(tsTimezoneStr, str, TD_TIMEZONE_LEN);
tsSetTimeZone();
cfg->cfgStatus = TAOS_CFG_CSTATUS_OPTION;
tscDebug("timezone set:%s, input:%s by taos_options", tsTimezone, str);
tscDebug("timezone set:%s, input:%s by taos_options", tsTimezoneStr, str);
} else {
tscWarn("config option:%s, input value:%s, is configured by %s, use %s", cfg->option, str,
tsCfgStatusStr[cfg->cfgStatus], (char *)cfg->ptr);
......
......@@ -303,7 +303,7 @@ static int32_t taosAddClientCfg(SConfig *pCfg) {
static int32_t taosAddSystemCfg(SConfig *pCfg) {
SysNameInfo info = taosGetSysNameInfo();
if (cfgAddTimezone(pCfg, "timezone", tsTimezone) != 0) return -1;
if (cfgAddTimezone(pCfg, "timezone", tsTimezoneStr) != 0) return -1;
if (cfgAddLocale(pCfg, "locale", tsLocale) != 0) return -1;
if (cfgAddCharset(pCfg, "charset", tsCharset) != 0) return -1;
if (cfgAddBool(pCfg, "enableCoreFile", 1, 1) != 0) return -1;
......@@ -431,12 +431,13 @@ static int32_t taosSetClientCfg(SConfig *pCfg) {
static void taosSetSystemCfg(SConfig *pCfg) {
SConfigItem *pItem = cfgGetItem(pCfg, "timezone");
osSetTimezone(pItem->str);
uDebug("timezone format changed from %s to %s", pItem->str, tsTimezone);
cfgSetItem(pCfg, "timezone", tsTimezone, pItem->stype);
uDebug("timezone format changed from %s to %s", pItem->str, tsTimezoneStr);
cfgSetItem(pCfg, "timezone", tsTimezoneStr, pItem->stype);
const char *locale = cfgGetItem(pCfg, "locale")->str;
const char *charset = cfgGetItem(pCfg, "charset")->str;
taosSetSystemLocale(locale, charset);
osSetSystemLocale(locale, charset);
bool enableCore = cfgGetItem(pCfg, "enableCoreFile")->bval;
taosSetConsoleEcho(enableCore);
......@@ -483,7 +484,7 @@ static int32_t taosSetServerCfg(SConfig *pCfg) {
int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDir, const char *envFile,
const char *apolloUrl, SArray *pArgs, bool tsc) {
osInit();
osDefaultInit();
SConfig *pCfg = cfgInit();
if (pCfg == NULL) return -1;
......
......@@ -36,7 +36,7 @@ void dmSendStatusReq(SDnodeMgmt *pMgmt) {
req.clusterCfg.checkTime = 0;
char timestr[32] = "1970-01-01 00:00:00.00";
(void)taosParseTime(timestr, &req.clusterCfg.checkTime, (int32_t)strlen(timestr), TSDB_TIME_PRECISION_MILLI, 0);
memcpy(req.clusterCfg.timezone, tsTimezone, TD_TIMEZONE_LEN);
memcpy(req.clusterCfg.timezone, tsTimezoneStr, TD_TIMEZONE_LEN);
memcpy(req.clusterCfg.locale, tsLocale, TD_LOCALE_LEN);
memcpy(req.clusterCfg.charset, tsCharset, TD_LOCALE_LEN);
taosRUnLockLatch(&pMgmt->latch);
......
......@@ -277,8 +277,8 @@ static int32_t mndCheckClusterCfgPara(SMnode *pMnode, const SClusterCfg *pCfg) {
return DND_REASON_STATUS_INTERVAL_NOT_MATCH;
}
if ((0 != strcasecmp(pCfg->timezone, tsTimezone)) && (pMnode->checkTime != pCfg->checkTime)) {
mError("timezone [%s - %s] [%" PRId64 " - %" PRId64 "] cfg inconsistent", pCfg->timezone, tsTimezone,
if ((0 != strcasecmp(pCfg->timezone, tsTimezoneStr)) && (pMnode->checkTime != pCfg->checkTime)) {
mError("timezone [%s - %s] [%" PRId64 " - %" PRId64 "] cfg inconsistent", pCfg->timezone, tsTimezoneStr,
pCfg->checkTime, pMnode->checkTime);
return DND_REASON_TIME_ZONE_NOT_MATCH;
}
......@@ -677,7 +677,7 @@ static int32_t mndRetrieveConfigs(SNodeMsg *pReq, SShowObj *pShow, char *data, i
totalRows++;
cfgOpts[totalRows] = "timezone";
snprintf(cfgVals[totalRows], TSDB_CONIIG_VALUE_LEN, "%s", tsTimezone);
snprintf(cfgVals[totalRows], TSDB_CONIIG_VALUE_LEN, "%s", tsTimezoneStr);
totalRows++;
cfgOpts[totalRows] = "locale";
......
......@@ -176,7 +176,7 @@ int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
}
// record current timezone of server side
tstrncpy(vCreateSmaReq.tSma.timezone, tsTimezone, TD_TIMEZONE_LEN);
tstrncpy(vCreateSmaReq.tSma.timezone, tsTimezoneStr, TD_TIMEZONE_LEN);
if (metaCreateTSma(pVnode->pMeta, &vCreateSmaReq) < 0) {
// TODO: handle error
......
......@@ -18,30 +18,31 @@
extern void taosWinSocketInit();
char configDir[PATH_MAX] = {0};
char tsDataDir[PATH_MAX] = {0};
char tsLogDir[PATH_MAX] = {0};
char tsTempDir[PATH_MAX] = {0};
SDiskSpace tsDataSpace = {0};
SDiskSpace tsLogSpace = {0};
SDiskSpace tsTempSpace = {0};
char tsOsName[16] = {0};
char tsTimezone[TD_TIMEZONE_LEN] = {0};
char tsLocale[TD_LOCALE_LEN] = {0};
char tsCharset[TD_CHARSET_LEN] = {0};
int8_t tsDaylight = 0;
bool tsEnableCoreFile = 0;
int64_t tsPageSizeKB = 0;
int64_t tsOpenMax = 0;
int64_t tsStreamMax = 0;
float tsNumOfCores = 0;
int64_t tsTotalMemoryKB = 0;
void osInit() {
char configDir[PATH_MAX] = {0};
char tsDataDir[PATH_MAX] = {0};
char tsLogDir[PATH_MAX] = {0};
char tsTempDir[PATH_MAX] = {0};
SDiskSpace tsDataSpace = {0};
SDiskSpace tsLogSpace = {0};
SDiskSpace tsTempSpace = {0};
char tsOsName[16] = {0};
char tsTimezoneStr[TD_TIMEZONE_LEN] = {0};
enum TdTimezone tsTimezone = TdZeroZero;
char tsLocale[TD_LOCALE_LEN] = {0};
char tsCharset[TD_CHARSET_LEN] = {0};
int8_t tsDaylight = 0;
bool tsEnableCoreFile = 0;
int64_t tsPageSizeKB = 0;
int64_t tsOpenMax = 0;
int64_t tsStreamMax = 0;
float tsNumOfCores = 0;
int64_t tsTotalMemoryKB = 0;
void osDefaultInit() {
taosSeedRand(taosSafeRand());
taosGetSystemLocale(tsLocale, tsCharset);
taosGetSystemTimezone(tsTimezone);
taosSetSystemTimezone(tsTimezone, tsTimezone, &tsDaylight);
taosGetSystemTimezone(tsTimezoneStr, &tsTimezone);
taosSetSystemTimezone(tsTimezoneStr, tsTimezoneStr, &tsDaylight, &tsTimezone);
taosGetSystemInfo();
// deadlock in query
......@@ -105,4 +106,9 @@ void osCleanup() {}
bool osLogSpaceAvailable() { return tsLogSpace.reserved <= tsLogSpace.size.avail; }
void osSetTimezone(const char *timezone) { taosSetSystemTimezone(tsTimezone, tsTimezone, &tsDaylight); }
void osSetTimezone(const char *timezone) { taosSetSystemTimezone(timezone, tsTimezoneStr, &tsDaylight, &tsTimezone); }
void osSetSystemLocale(const char *inLocale, const char *inCharSet) {
memcpy(tsLocale, inLocale, strlen(inLocale) + 1);
memcpy(tsCharset, inCharSet, strlen(inCharSet) + 1);
}
......@@ -16,8 +16,6 @@
#define ALLOW_FORBID_FUNC
#include "os.h"
#define USE_TD_MEMORY
#define TD_MEMORY_SYMBOL ('T'<<24|'A'<<16|'O'<<8|'S')
#define TD_MEMORY_STACK_TRACE_DEPTH 10
......@@ -47,16 +45,16 @@ int32_t taosBackTrace(void **buffer, int32_t size) {
int32_t frame = 0;
void **ebp;
void **ret = NULL;
unsigned long long func_frame_distance = 0;
size_t func_frame_distance = 0;
if (buffer != NULL && size > 0) {
ebp = taosGetEbp();
func_frame_distance = (unsigned long long)(*ebp) - (unsigned long long)ebp;
func_frame_distance = (size_t)*ebp - (size_t)ebp;
while (ebp && frame < size && (func_frame_distance < (1ULL << 24)) // assume function ebp more than 16M
&& (func_frame_distance > 0)) {
ret = ebp + 1;
buffer[frame++] = *ret;
ebp = (void **)(*ebp);
func_frame_distance = (unsigned long long)(*ebp) - (unsigned long long)ebp;
func_frame_distance = (size_t)*ebp - (size_t)ebp;
}
}
return frame;
......
......@@ -46,12 +46,22 @@
#include <unistd.h>
#endif
void taosSetSystemTimezone(const char *inTimezone, char *outTimezone, int8_t *outDaylight) {
if (inTimezone == NULL || inTimezone[0] == 0) return;
void taosSetSystemTimezone(const char *inTimezoneStr, char *outTimezoneStr, int8_t *outDaylight, enum TdTimezone *tsTimezone) {
if (inTimezoneStr == NULL || inTimezoneStr[0] == 0) return;
char *buf = taosMemoryMalloc(strlen(inTimezoneStr) + 1);
buf[strlen(inTimezoneStr)] = 0;
for (int32_t i = 0; i < strlen(inTimezoneStr); i++) {
if(inTimezoneStr[i]==' ' || inTimezoneStr[i]=='(') {
buf[i] = 0;
break;
}
buf[i] = inTimezoneStr[i];
}
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
char winStr[TD_LOCALE_LEN * 2];
sprintf(winStr, "TZ=%s", inTimezone);
sprintf(winStr, "TZ=%s", buf);
putenv(winStr);
tzset();
* get CURRENT time zone.
......@@ -70,44 +80,48 @@ void taosSetSystemTimezone(const char *inTimezone, char *outTimezone, int8_t *ou
#endif
int32_t tz = (int32_t)((-timezone * MILLISECOND_PER_SECOND) / MILLISECOND_PER_HOUR);
*tsTimezone = tz;
tz += daylight;
/*
* format:
* (CST, +0800)
* (BST, +0100)
*/
sprintf(outTimezone, "(%s, %s%02d00)", tzname[daylight], tz >= 0 ? "+" : "-", abs(tz));
sprintf(outTimezoneStr, "%s (%s, %s%02d00)", buf, tzname[daylight], tz >= 0 ? "+" : "-", abs(tz));
*outDaylight = daylight;
#elif defined(_TD_DARWIN_64)
setenv("TZ", inTimezone, 1);
setenv("TZ", buf, 1);
tzset();
int32_t tz = (int32_t)((-timezone * MILLISECOND_PER_SECOND) / MILLISECOND_PER_HOUR);
*tsTimezone = tz;
tz += daylight;
sprintf(outTimezone, "(%s, %s%02d00)", tzname[daylight], tz >= 0 ? "+" : "-", abs(tz));
sprintf(outTimezoneStr, "%s (%s, %s%02d00)", buf, tzname[daylight], tz >= 0 ? "+" : "-", abs(tz));
*outDaylight = daylight;
#else
setenv("TZ", inTimezone, 1);
setenv("TZ", buf, 1);
tzset();
int32_t tz = (int32_t)((-timezone * MILLISECOND_PER_SECOND) / MILLISECOND_PER_HOUR);
*tsTimezone = tz;
tz += daylight;
sprintf(outTimezone, "(%s, %s%02d00)", tzname[daylight], tz >= 0 ? "+" : "-", abs(tz));
sprintf(outTimezoneStr, "%s (%s, %s%02d00)", buf, tzname[daylight], tz >= 0 ? "+" : "-", abs(tz));
*outDaylight = daylight;
#endif
taosMemoryFree(buf);
}
void taosGetSystemTimezone(char *outTimezone) {
void taosGetSystemTimezone(char *outTimezoneStr, enum TdTimezone *tsTimezone) {
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
char *tz = getenv("TZ");
if (tz == NULL || strlen(tz) == 0) {
strcpy(outTimezone, "not configured");
strcpy(outTimezoneStr, "not configured");
} else {
strcpy(outTimezone, tz);
strcpy(outTimezoneStr, tz);
}
#elif defined(_TD_DARWIN_64)
......@@ -153,7 +167,7 @@ void taosGetSystemTimezone(char *outTimezone) {
* Asia/Shanghai (CST, +0800)
* Europe/London (BST, +0100)
*/
snprintf(outTimezone, TD_TIMEZONE_LEN, "%s (%s, %+03ld00)", tz, tm1.tm_isdst ? tzname[daylight] : tzname[0],
snprintf(outTimezoneStr, TD_TIMEZONE_LEN, "%s (%s, %+03ld00)", tz, tm1.tm_isdst ? tzname[daylight] : tzname[0],
-timezone / 3600);
#else
......@@ -168,13 +182,14 @@ void taosGetSystemTimezone(char *outTimezone) {
/* load time zone string from /etc/timezone */
// FILE *f = fopen("/etc/timezone", "r");
errno = 0;
TdFilePtr pFile = taosOpenFile("/etc/timezone", TD_FILE_READ);
char buf[68] = {0};
if (pFile != NULL) {
int len = taosReadFile(pFile, buf, 64);
if (len < 64 && taosGetErrorFile(pFile)) {
taosCloseFile(&pFile);
// printf("read /etc/timezone error, reason:%s", strerror(errno));
printf("read /etc/timezone error, reason:%s", strerror(errno));
return;
}
......@@ -202,6 +217,7 @@ void taosGetSystemTimezone(char *outTimezone) {
* otherwise is GMT+00:00
*/
int32_t tz = (-timezone * MILLISECOND_PER_SECOND) / MILLISECOND_PER_HOUR;
*tsTimezone = tz;
tz += daylight;
/*
......@@ -210,7 +226,7 @@ void taosGetSystemTimezone(char *outTimezone) {
* Asia/Shanghai (CST, +0800)
* Europe/London (BST, +0100)
*/
snprintf(outTimezone, TD_TIMEZONE_LEN, "%s (%s, %s%02d00)", buf, tzname[daylight], tz >= 0 ? "+" : "-", abs(tz));
snprintf(outTimezoneStr, TD_TIMEZONE_LEN, "%s (%s, %s%02d00)", buf, tzname[daylight], tz >= 0 ? "+" : "-", abs(tz));
#endif
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册