未验证 提交 693e8784 编写于 作者: H Haojun Liao 提交者: GitHub

Merge pull request #10992 from taosdata/feature/3.0_liaohj

[td-14285] fix the taosd crash when both interval and sliding exist.
...@@ -661,7 +661,7 @@ TEST(testCase, agg_query_tables) { ...@@ -661,7 +661,7 @@ TEST(testCase, agg_query_tables) {
TAOS_RES* pRes = taos_query(pConn, "use abc1"); TAOS_RES* pRes = taos_query(pConn, "use abc1");
taos_free_result(pRes); taos_free_result(pRes);
pRes = taos_query(pConn, "select k from tm0"); pRes = taos_query(pConn, "select count(*) from tu");
if (taos_errno(pRes) != 0) { if (taos_errno(pRes) != 0) {
printf("failed to select from table, reason:%s\n", taos_errstr(pRes)); printf("failed to select from table, reason:%s\n", taos_errstr(pRes));
taos_free_result(pRes); taos_free_result(pRes);
......
...@@ -562,8 +562,7 @@ int64_t taosTimeTruncate(int64_t t, const SInterval* pInterval, int32_t precisio ...@@ -562,8 +562,7 @@ int64_t taosTimeTruncate(int64_t t, const SInterval* pInterval, int32_t precisio
// not enough time range // not enough time range
if (start < 0 || INT64_MAX - start > pInterval->interval - 1) { if (start < 0 || INT64_MAX - start > pInterval->interval - 1) {
end = start + pInterval->interval - 1; end = taosTimeAdd(start, pInterval->interval, pInterval->intervalUnit, precision) - 1;
while (end < t && ((start + pInterval->sliding) <= INT64_MAX)) { // move forward to the correct time window while (end < t && ((start + pInterval->sliding) <= INT64_MAX)) { // move forward to the correct time window
start += pInterval->sliding; start += pInterval->sliding;
......
...@@ -674,12 +674,7 @@ static void getInitialStartTimeWindow(SInterval* pInterval, int32_t precision, T ...@@ -674,12 +674,7 @@ static void getInitialStartTimeWindow(SInterval* pInterval, int32_t precision, T
int64_t key = w->skey; int64_t key = w->skey;
while(key < ts) { // moving towards end while(key < ts) { // moving towards end
if (pInterval->intervalUnit == 'n' || pInterval->intervalUnit == 'y') { key = taosTimeAdd(key, pInterval->sliding, pInterval->slidingUnit, precision);
key = taosTimeAdd(key, pInterval->sliding, pInterval->slidingUnit, precision);
} else {
key += pInterval->sliding;
}
if (key >= ts) { if (key >= ts) {
break; break;
} }
...@@ -695,12 +690,7 @@ static STimeWindow getActiveTimeWindow(SResultRowInfo * pResultRowInfo, int64_t ...@@ -695,12 +690,7 @@ static STimeWindow getActiveTimeWindow(SResultRowInfo * pResultRowInfo, int64_t
if (pResultRowInfo->curPos == -1) { // the first window, from the previous stored value if (pResultRowInfo->curPos == -1) { // the first window, from the previous stored value
getInitialStartTimeWindow(pInterval, precision, ts, &w, win->ekey, true); getInitialStartTimeWindow(pInterval, precision, ts, &w, win->ekey, true);
w.ekey = taosTimeAdd(w.skey, pInterval->interval, pInterval->intervalUnit, precision) - 1;
if (pInterval->intervalUnit == 'n' || pInterval->intervalUnit == 'y') {
w.ekey = taosTimeAdd(w.skey, pInterval->interval, pInterval->intervalUnit, precision) - 1;
} else {
w.ekey = w.skey + pInterval->interval - 1;
}
} else { } else {
w = getResultRow(pResultRowInfo, pResultRowInfo->curPos)->win; w = getResultRow(pResultRowInfo, pResultRowInfo->curPos)->win;
} }
...@@ -722,7 +712,7 @@ static STimeWindow getActiveTimeWindow(SResultRowInfo * pResultRowInfo, int64_t ...@@ -722,7 +712,7 @@ static STimeWindow getActiveTimeWindow(SResultRowInfo * pResultRowInfo, int64_t
} }
w.skey = st; w.skey = st;
w.ekey = w.skey + pInterval->interval - 1; w.ekey = taosTimeAdd(w.skey, pInterval->interval, pInterval->intervalUnit, precision) - 1;
} }
} }
return w; return w;
...@@ -2407,7 +2397,7 @@ static bool isCachedLastQuery(STaskAttr *pQueryAttr) { ...@@ -2407,7 +2397,7 @@ static bool isCachedLastQuery(STaskAttr *pQueryAttr) {
///////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////
//todo refactor : return window //todo refactor : return window
void getAlignQueryTimeWindow(SInterval* pInterval, int32_t precision, int64_t key, int64_t keyFirst, int64_t keyLast, STimeWindow *win) { void getAlignQueryTimeWindow(SInterval* pInterval, int32_t precision, int64_t key, int64_t keyFirst, int64_t keyLast, STimeWindow *win) {
assert(key >= keyFirst && key <= keyLast && pInterval->sliding <= pInterval->interval); ASSERT(key >= keyFirst && key <= keyLast);
win->skey = taosTimeTruncate(key, pInterval, precision); win->skey = taosTimeTruncate(key, pInterval, precision);
/* /*
...@@ -2417,10 +2407,8 @@ void getAlignQueryTimeWindow(SInterval* pInterval, int32_t precision, int64_t ke ...@@ -2417,10 +2407,8 @@ void getAlignQueryTimeWindow(SInterval* pInterval, int32_t precision, int64_t ke
if (keyFirst > (INT64_MAX - pInterval->interval)) { if (keyFirst > (INT64_MAX - pInterval->interval)) {
assert(keyLast - keyFirst < pInterval->interval); assert(keyLast - keyFirst < pInterval->interval);
win->ekey = INT64_MAX; win->ekey = INT64_MAX;
} else if (pInterval->intervalUnit == 'n' || pInterval->intervalUnit == 'y') {
win->ekey = taosTimeAdd(win->skey, pInterval->interval, pInterval->intervalUnit, precision) - 1;
} else { } else {
win->ekey = win->skey + pInterval->interval - 1; win->ekey = taosTimeAdd(win->skey, pInterval->interval, pInterval->intervalUnit, precision) - 1;
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册