minor changes
This commit is contained in:
parent
4fe44df5b8
commit
26adff1fa5
|
@ -43,14 +43,12 @@
|
|||
* An encoding of midnight at the end of the day as 24:00:00 - ie. midnight
|
||||
* tomorrow - (allowable under ISO 8601) is supported.
|
||||
*/
|
||||
static int64_t user_mktime64(const unsigned int year0, const unsigned int mon0,
|
||||
const unsigned int day, const unsigned int hour,
|
||||
const unsigned int min, const unsigned int sec, int64_t time_zone)
|
||||
{
|
||||
unsigned int mon = mon0, year = year0;
|
||||
static int64_t user_mktime64(const uint32_t year0, const uint32_t mon0, const uint32_t day, const uint32_t hour,
|
||||
const uint32_t min, const uint32_t sec, int64_t time_zone) {
|
||||
uint32_t mon = mon0, year = year0;
|
||||
|
||||
/* 1..12 -> 11,12,1..10 */
|
||||
if (0 >= (int) (mon -= 2)) {
|
||||
if (0 >= (int32_t)(mon -= 2)) {
|
||||
mon += 12; /* Puts Feb last since it has leap day */
|
||||
year -= 1;
|
||||
}
|
||||
|
@ -83,10 +81,8 @@ static int32_t parseLocaltimeDst(char* timestr, int64_t* time, int32_t timePrec)
|
|||
static char* forwardToTimeStringEnd(char* str);
|
||||
static bool checkTzPresent(const char* str, int32_t len);
|
||||
|
||||
static int32_t (*parseLocaltimeFp[]) (char* timestr, int64_t* time, int32_t timePrec) = {
|
||||
parseLocaltime,
|
||||
parseLocaltimeDst
|
||||
};
|
||||
static int32_t (*parseLocaltimeFp[])(char* timestr, int64_t* time, int32_t timePrec) = {parseLocaltime,
|
||||
parseLocaltimeDst};
|
||||
|
||||
int32_t taosParseTime(const char* timestr, int64_t* time, int32_t len, int32_t timePrec, int8_t day_light) {
|
||||
/* parse datatime string in with tz */
|
||||
|
@ -104,7 +100,7 @@ bool checkTzPresent(const char* str, int32_t len) {
|
|||
int32_t seg_len = len - (int32_t)(seg - str);
|
||||
|
||||
char* c = &seg[seg_len - 1];
|
||||
for (int i = 0; i < seg_len; ++i) {
|
||||
for (int32_t i = 0; i < seg_len; ++i) {
|
||||
if (*c == 'Z' || *c == 'z' || *c == '+' || *c == '-') {
|
||||
return true;
|
||||
}
|
||||
|
@ -205,7 +201,6 @@ int32_t parseTimezone(char* str, int64_t* tzOffset) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
|
||||
int64_t minute = strnatoi(&str[i], 2);
|
||||
if (minute > 59) {
|
||||
return -1;
|
||||
|
@ -233,9 +228,8 @@ int32_t parseTimezone(char* str, int64_t* tzOffset) {
|
|||
* 2013-04-12T15:52:01.123+0800
|
||||
*/
|
||||
int32_t parseTimeWithTz(const char* timestr, int64_t* time, int32_t timePrec, char delim) {
|
||||
|
||||
int64_t factor = (timePrec == TSDB_TIME_PRECISION_MILLI) ? 1000 :
|
||||
(timePrec == TSDB_TIME_PRECISION_MICRO ? 1000000 : 1000000000);
|
||||
int64_t factor =
|
||||
(timePrec == TSDB_TIME_PRECISION_MILLI) ? 1000 : (timePrec == TSDB_TIME_PRECISION_MICRO ? 1000000 : 1000000000);
|
||||
int64_t tzOffset = 0;
|
||||
|
||||
struct tm tm = {0};
|
||||
|
@ -320,7 +314,8 @@ int32_t parseLocaltime(char* timestr, int64_t* time, int32_t timePrec) {
|
|||
#endif
|
||||
#endif
|
||||
|
||||
int64_t seconds = user_mktime64(tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, timezone);
|
||||
int64_t seconds =
|
||||
user_mktime64(tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, timezone);
|
||||
|
||||
int64_t fraction = 0;
|
||||
|
||||
|
@ -331,8 +326,8 @@ int32_t parseLocaltime(char* timestr, int64_t* time, int32_t timePrec) {
|
|||
}
|
||||
}
|
||||
|
||||
int64_t factor = (timePrec == TSDB_TIME_PRECISION_MILLI) ? 1000 :
|
||||
(timePrec == TSDB_TIME_PRECISION_MICRO ? 1000000 : 1000000000);
|
||||
int64_t factor =
|
||||
(timePrec == TSDB_TIME_PRECISION_MILLI) ? 1000 : (timePrec == TSDB_TIME_PRECISION_MICRO ? 1000000 : 1000000000);
|
||||
*time = factor * seconds + fraction;
|
||||
|
||||
return 0;
|
||||
|
@ -360,27 +355,22 @@ int32_t parseLocaltimeDst(char* timestr, int64_t* time, int32_t timePrec) {
|
|||
}
|
||||
}
|
||||
|
||||
int64_t factor = (timePrec == TSDB_TIME_PRECISION_MILLI) ? 1000 :
|
||||
(timePrec == TSDB_TIME_PRECISION_MICRO ? 1000000 : 1000000000);
|
||||
int64_t factor =
|
||||
(timePrec == TSDB_TIME_PRECISION_MILLI) ? 1000 : (timePrec == TSDB_TIME_PRECISION_MICRO ? 1000000 : 1000000000);
|
||||
*time = factor * seconds + fraction;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int64_t convertTimePrecision(int64_t time, int32_t fromPrecision, int32_t toPrecision) {
|
||||
assert(fromPrecision == TSDB_TIME_PRECISION_MILLI ||
|
||||
fromPrecision == TSDB_TIME_PRECISION_MICRO ||
|
||||
assert(fromPrecision == TSDB_TIME_PRECISION_MILLI || fromPrecision == TSDB_TIME_PRECISION_MICRO ||
|
||||
fromPrecision == TSDB_TIME_PRECISION_NANO);
|
||||
assert(toPrecision == TSDB_TIME_PRECISION_MILLI ||
|
||||
toPrecision == TSDB_TIME_PRECISION_MICRO ||
|
||||
assert(toPrecision == TSDB_TIME_PRECISION_MILLI || toPrecision == TSDB_TIME_PRECISION_MICRO ||
|
||||
toPrecision == TSDB_TIME_PRECISION_NANO);
|
||||
static double factors[3][3] = { {1., 1000., 1000000.},
|
||||
{1.0 / 1000, 1., 1000.},
|
||||
{1.0 / 1000000, 1.0 / 1000, 1.} };
|
||||
static double factors[3][3] = {{1., 1000., 1000000.}, {1.0 / 1000, 1., 1000.}, {1.0 / 1000000, 1.0 / 1000, 1.}};
|
||||
return (int64_t)((double)time * factors[fromPrecision][toPrecision]);
|
||||
}
|
||||
|
||||
static int32_t getDuration(int64_t val, char unit, int64_t* result, int32_t timePrecision) {
|
||||
|
||||
switch (unit) {
|
||||
case 's':
|
||||
(*result) = convertTimePrecision(val * MILLISECOND_PER_SECOND, TSDB_TIME_PRECISION_MILLI, timePrecision);
|
||||
|
@ -427,7 +417,8 @@ static int32_t getDuration(int64_t val, char unit, int64_t* result, int32_t time
|
|||
* d - Days (24 hours)
|
||||
* w - Weeks (7 days)
|
||||
*/
|
||||
int32_t parseAbsoluteDuration(const char* token, int32_t tokenlen, int64_t* duration, char* unit, int32_t timePrecision) {
|
||||
int32_t parseAbsoluteDuration(const char* token, int32_t tokenlen, int64_t* duration, char* unit,
|
||||
int32_t timePrecision) {
|
||||
errno = 0;
|
||||
char* endPtr = NULL;
|
||||
|
||||
|
@ -476,7 +467,7 @@ int64_t taosTimeAdd(int64_t t, int64_t duration, char unit, int32_t precision) {
|
|||
struct tm tm;
|
||||
time_t tt = (time_t)(t / TSDB_TICK_PER_SECOND(precision));
|
||||
localtime_r(&tt, &tm);
|
||||
int mon = tm.tm_year * 12 + tm.tm_mon + (int)duration;
|
||||
int32_t mon = tm.tm_year * 12 + tm.tm_mon + (int32_t)duration;
|
||||
tm.tm_year = mon / 12;
|
||||
tm.tm_mon = mon % 12;
|
||||
|
||||
|
@ -499,11 +490,11 @@ int32_t taosTimeCountInterval(int64_t skey, int64_t ekey, int64_t interval, char
|
|||
struct tm tm;
|
||||
time_t t = (time_t)skey;
|
||||
localtime_r(&t, &tm);
|
||||
int smon = tm.tm_year * 12 + tm.tm_mon;
|
||||
int32_t smon = tm.tm_year * 12 + tm.tm_mon;
|
||||
|
||||
t = (time_t)ekey;
|
||||
localtime_r(&t, &tm);
|
||||
int emon = tm.tm_year * 12 + tm.tm_mon;
|
||||
int32_t emon = tm.tm_year * 12 + tm.tm_mon;
|
||||
|
||||
if (unit == 'y') {
|
||||
interval *= 12;
|
||||
|
@ -531,10 +522,10 @@ int64_t taosTimeTruncate(int64_t t, const SInterval* pInterval, int32_t precisio
|
|||
|
||||
if (pInterval->slidingUnit == 'y') {
|
||||
tm.tm_mon = 0;
|
||||
tm.tm_year = (int)(tm.tm_year / pInterval->sliding * pInterval->sliding);
|
||||
tm.tm_year = (int32_t)(tm.tm_year / pInterval->sliding * pInterval->sliding);
|
||||
} else {
|
||||
int mon = tm.tm_year * 12 + tm.tm_mon;
|
||||
mon = (int)(mon / pInterval->sliding * pInterval->sliding);
|
||||
int32_t mon = tm.tm_year * 12 + tm.tm_mon;
|
||||
mon = (int32_t)(mon / pInterval->sliding * pInterval->sliding);
|
||||
tm.tm_year = mon / 12;
|
||||
tm.tm_mon = mon % 12;
|
||||
}
|
||||
|
@ -619,7 +610,7 @@ const char* fmtts(int64_t ts) {
|
|||
buf[pos++] = ' ';
|
||||
}
|
||||
pos += strftime(buf + pos, sizeof(buf), "ms=%Y-%m-%d %H:%M:%S", &tm);
|
||||
pos += sprintf(buf + pos, ".%03d", (int)(ts % 1000));
|
||||
pos += sprintf(buf + pos, ".%03d", (int32_t)(ts % 1000));
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -631,7 +622,7 @@ const char* fmtts(int64_t ts) {
|
|||
buf[pos++] = ' ';
|
||||
}
|
||||
pos += strftime(buf + pos, sizeof(buf), "us=%Y-%m-%d %H:%M:%S", &tm);
|
||||
pos += sprintf(buf + pos, ".%06d", (int)(ts % 1000000));
|
||||
pos += sprintf(buf + pos, ".%06d", (int32_t)(ts % 1000000));
|
||||
}
|
||||
|
||||
return buf;
|
||||
|
|
|
@ -154,7 +154,8 @@ STSBuf* tsBufCreateFromFile(const char* path, bool autoDelete) {
|
|||
// ascending by default
|
||||
pTSBuf->cur.order = TSDB_ORDER_ASC;
|
||||
|
||||
// tscDebug("create tsBuf from file:%s, fd:%d, size:%d, numOfGroups:%d, autoDelete:%d", pTSBuf->path, fileno(pTSBuf->pFile),
|
||||
// tscDebug("create tsBuf from file:%s, fd:%d, size:%d, numOfGroups:%d, autoDelete:%d", pTSBuf->path,
|
||||
// fileno(pTSBuf->pFile),
|
||||
// pTSBuf->fileSize, pTSBuf->numOfGroups, pTSBuf->autoDelete);
|
||||
|
||||
return pTSBuf;
|
||||
|
@ -265,9 +266,8 @@ static void writeDataToDisk(STSBuf* pTSBuf) {
|
|||
STSList* pTsData = &pTSBuf->tsData;
|
||||
|
||||
pBlock->numOfElem = pTsData->len / TSDB_KEYSIZE;
|
||||
pBlock->compLen =
|
||||
tsCompressTimestamp(pTsData->rawBuf, pTsData->len, pTsData->len/TSDB_KEYSIZE, pBlock->payload, pTsData->allocSize,
|
||||
TWO_STAGE_COMP, pTSBuf->assistBuf, pTSBuf->bufSize);
|
||||
pBlock->compLen = tsCompressTimestamp(pTsData->rawBuf, pTsData->len, pTsData->len / TSDB_KEYSIZE, pBlock->payload,
|
||||
pTsData->allocSize, TWO_STAGE_COMP, pTSBuf->assistBuf, pTSBuf->bufSize);
|
||||
|
||||
int64_t r = taosLSeekFile(pTSBuf->pFile, pTSBuf->fileSize, SEEK_SET);
|
||||
assert(r == 0);
|
||||
|
@ -666,7 +666,8 @@ int32_t STSBufUpdateHeader(STSBuf* pTSBuf, STSBufFileHeader* pHeader) {
|
|||
|
||||
size_t ws = taosWriteFile(pTSBuf->pFile, pHeader, sizeof(STSBufFileHeader));
|
||||
if (ws != 1) {
|
||||
// qError("ts update header fwrite failed, size:%d, expected size:%d", (int32_t)ws, (int32_t)sizeof(STSBufFileHeader));
|
||||
// qError("ts update header fwrite failed, size:%d, expected size:%d", (int32_t)ws,
|
||||
// (int32_t)sizeof(STSBufFileHeader));
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
|
@ -1089,14 +1090,14 @@ int32_t dumpFileBlockByGroupId(STSBuf* pTSBuf, int32_t groupIndex, void* buf, in
|
|||
*numOfBlocks = 0;
|
||||
|
||||
if (taosLSeekFile(pTSBuf->pFile, pBlockInfo->offset, SEEK_SET) != 0) {
|
||||
int code = TAOS_SYSTEM_ERROR(taosEOFFile(pTSBuf->pFile));
|
||||
int32_t code = TAOS_SYSTEM_ERROR(taosEOFFile(pTSBuf->pFile));
|
||||
// qError("%p: fseek failed: %s", pSql, tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
|
||||
size_t s = taosReadFile(pTSBuf->pFile, buf, pBlockInfo->compLen);
|
||||
if (s != pBlockInfo->compLen) {
|
||||
int code = TAOS_SYSTEM_ERROR(taosEOFFile(pTSBuf->pFile));
|
||||
int32_t code = TAOS_SYSTEM_ERROR(taosEOFFile(pTSBuf->pFile));
|
||||
// tscError("%p: fread didn't return expected data: %s", pSql, tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
|
@ -1120,6 +1121,4 @@ STSElem tsBufFindElemStartPosByTag(STSBuf* pTSBuf, SVariant* pTag) {
|
|||
return el;
|
||||
}
|
||||
|
||||
bool tsBufIsValidElem(STSElem* pElem) {
|
||||
return pElem->id >= 0;
|
||||
}
|
||||
bool tsBufIsValidElem(STSElem* pElem) { return pElem->id >= 0; }
|
||||
|
|
Loading…
Reference in New Issue