Merge branch 'feature/TD-2354' of https://github.com/taosdata/TDengine into feature/TD-2354

This commit is contained in:
Minglei Jin 2020-12-22 15:44:15 +08:00
commit 8a8fca3f15
9 changed files with 48 additions and 138 deletions

View File

@ -1266,8 +1266,10 @@ static int32_t syncForwardToPeerImpl(SSyncNode *pNode, void *data, void *mhandle
} }
} }
if (pNode->replica != 1) {
return TSDB_CODE_SYN_INVALID_VERSION; return TSDB_CODE_SYN_INVALID_VERSION;
} }
}
// always update version // always update version
sTrace("vgId:%d, update version, replica:%d role:%s qtype:%s hver:%" PRIu64, pNode->vgId, pNode->replica, sTrace("vgId:%d, update version, replica:%d role:%s qtype:%s hver:%" PRIu64, pNode->vgId, pNode->replica,

View File

@ -66,10 +66,8 @@ typedef struct STable {
SSkipList* pIndex; // For TSDB_SUPER_TABLE, it is the skiplist index SSkipList* pIndex; // For TSDB_SUPER_TABLE, it is the skiplist index
void* eventHandler; // TODO void* eventHandler; // TODO
void* streamHandler; // TODO void* streamHandler; // TODO
union {
TSKEY lastKey; TSKEY lastKey;
SDataRow lastRow; SDataRow lastRow;
};
char* sql; char* sql;
void* cqhandle; void* cqhandle;
SRWLatch latch; // TODO: implementa latch functions SRWLatch latch; // TODO: implementa latch functions
@ -439,17 +437,10 @@ static FORCE_INLINE STSchema *tsdbGetTableTagSchema(STable *pTable) {
} }
} }
static FORCE_INLINE TSKEY tsdbGetTableLastKeyImpl(STable* pTable, bool cacheLastRow) { static FORCE_INLINE TSKEY tsdbGetTableLastKeyImpl(STable* pTable) {
if (cacheLastRow) { ASSERT(pTable->lastRow == NULL || pTable->lastKey == dataRowKey(pTable->lastRow));
if (pTable->lastRow == NULL) {
return TSKEY_INITIAL_VAL;
} else {
return dataRowKey(pTable->lastRow);
}
} else {
return pTable->lastKey; return pTable->lastKey;
} }
}
// ------------------ tsdbBuffer.c // ------------------ tsdbBuffer.c
#define TSDB_BUFFER_RESERVE 1024 // Reseve 1K as commit threshold #define TSDB_BUFFER_RESERVE 1024 // Reseve 1K as commit threshold

View File

@ -722,8 +722,9 @@ static int tsdbRestoreInfo(STsdbRepo *pRepo) { // TODO
if (tsdbSetHelperTable(&rhelper, pTable, pRepo) < 0) goto _err; if (tsdbSetHelperTable(&rhelper, pTable, pRepo) < 0) goto _err;
SCompIdx *pIdx = &(rhelper.curCompIdx); SCompIdx *pIdx = &(rhelper.curCompIdx);
TSKEY lastKey = tsdbGetTableLastKeyImpl(pTable, pCfg->cacheLastRow); TSKEY lastKey = tsdbGetTableLastKeyImpl(pTable);
if (pIdx->offset > 0 && lastKey < pIdx->maxKey) { if (pIdx->offset > 0 && lastKey < pIdx->maxKey) {
pTable->lastKey = pIdx->maxKey;
if (pCfg->cacheLastRow) { // load the block of data if (pCfg->cacheLastRow) { // load the block of data
if (tsdbLoadCompInfo(&rhelper, NULL) < 0) goto _err; if (tsdbLoadCompInfo(&rhelper, NULL) < 0) goto _err;
@ -745,8 +746,6 @@ static int tsdbRestoreInfo(STsdbRepo *pRepo) { // TODO
tdAppendColVal(pTable->lastRow, tdGetColDataOfRow(pDataCol, pBlock->numOfRows - 1), pCol->type, pCol->bytes, tdAppendColVal(pTable->lastRow, tdGetColDataOfRow(pDataCol, pBlock->numOfRows - 1), pCol->type, pCol->bytes,
pCol->offset); pCol->offset);
} }
} else {
pTable->lastKey = pIdx->maxKey;
} }
} }
} }

View File

@ -664,7 +664,7 @@ static int tsdbCopyRowToMem(STsdbRepo *pRepo, SDataRow row, STable *pTable, void
return -1; return -1;
} }
TSKEY lastKey = tsdbGetTableLastKeyImpl(pTable, pCfg->cacheLastRow); TSKEY lastKey = tsdbGetTableLastKeyImpl(pTable);
if (key > lastKey) { if (key > lastKey) {
tsdbTrace("vgId:%d skip to delete row key %" PRId64 " which is larger than table lastKey %" PRId64, tsdbTrace("vgId:%d skip to delete row key %" PRId64 " which is larger than table lastKey %" PRId64,
REPO_ID(pRepo), key, lastKey); REPO_ID(pRepo), key, lastKey);
@ -898,8 +898,9 @@ static void tsdbFreeRows(STsdbRepo *pRepo, void **rows, int rowCounter) {
static int tsdbUpdateTableLatestInfo(STsdbRepo *pRepo, STable *pTable, SDataRow row) { static int tsdbUpdateTableLatestInfo(STsdbRepo *pRepo, STable *pTable, SDataRow row) {
STsdbCfg *pCfg = &pRepo->config; STsdbCfg *pCfg = &pRepo->config;
if (tsdbGetTableLastKeyImpl(pTable, pCfg->cacheLastRow) < dataRowKey(row)) { if (tsdbGetTableLastKeyImpl(pTable) < dataRowKey(row)) {
if (pCfg->cacheLastRow) { pTable->lastKey = dataRowKey(row);
if (pCfg->cacheLastRow || pTable->lastRow != NULL) {
SDataRow nrow = pTable->lastRow; SDataRow nrow = pTable->lastRow;
if (taosTSizeof(nrow) < dataRowLen(row)) { if (taosTSizeof(nrow) < dataRowLen(row)) {
SDataRow orow = nrow; SDataRow orow = nrow;
@ -919,8 +920,6 @@ static int tsdbUpdateTableLatestInfo(STsdbRepo *pRepo, STable *pTable, SDataRow
dataRowCpy(nrow, row); dataRowCpy(nrow, row);
TSDB_WUNLOCK_TABLE(pTable); TSDB_WUNLOCK_TABLE(pTable);
} }
} else {
pTable->lastKey = dataRowKey(row);
} }
} }

View File

@ -663,7 +663,7 @@ static STable *tsdbNewTable() {
return NULL; return NULL;
} }
// pTable->lastKey = TSKEY_INITIAL_VAL; pTable->lastKey = TSKEY_INITIAL_VAL;
return pTable; return pTable;
} }
@ -775,6 +775,7 @@ static void tsdbFreeTable(STable *pTable) {
kvRowFree(pTable->tagVal); kvRowFree(pTable->tagVal);
tSkipListDestroy(pTable->pIndex); tSkipListDestroy(pTable->pIndex);
taosTZfree(pTable->lastRow);
tfree(pTable->sql); tfree(pTable->sql);
free(pTable); free(pTable);
} }
@ -782,13 +783,6 @@ static void tsdbFreeTable(STable *pTable) {
static int tsdbAddTableToMeta(STsdbRepo *pRepo, STable *pTable, bool addIdx, bool lock) { static int tsdbAddTableToMeta(STsdbRepo *pRepo, STable *pTable, bool addIdx, bool lock) {
STsdbMeta *pMeta = pRepo->tsdbMeta; STsdbMeta *pMeta = pRepo->tsdbMeta;
STsdbCfg * pCfg = &(pRepo->config);
if (pCfg->cacheLastRow) {
pTable->lastRow = NULL;
} else {
pTable->lastKey = TSKEY_INITIAL_VAL;
}
if (lock && tsdbWLockRepoMeta(pRepo) < 0) { if (lock && tsdbWLockRepoMeta(pRepo) < 0) {
tsdbError("vgId:%d failed to add table %s to meta since %s", REPO_ID(pRepo), TABLE_CHAR_NAME(pTable), tsdbError("vgId:%d failed to add table %s to meta since %s", REPO_ID(pRepo), TABLE_CHAR_NAME(pTable),

View File

@ -215,7 +215,7 @@ python3 ./test.py -f functions/function_spread.py -r 1
python3 ./test.py -f functions/function_stddev.py -r 1 python3 ./test.py -f functions/function_stddev.py -r 1
python3 ./test.py -f functions/function_sum.py -r 1 python3 ./test.py -f functions/function_sum.py -r 1
python3 ./test.py -f functions/function_top.py -r 1 python3 ./test.py -f functions/function_top.py -r 1
#python3 ./test.py -f functions/function_twa.py -r 1 python3 ./test.py -f functions/function_twa.py -r 1
python3 ./test.py -f functions/function_twa_test2.py python3 ./test.py -f functions/function_twa_test2.py
python3 queryCount.py python3 queryCount.py
python3 ./test.py -f query/queryGroupbyWithInterval.py python3 ./test.py -f query/queryGroupbyWithInterval.py

View File

@ -47,22 +47,16 @@ class TDTestCase:
tdSql.error("select twa(ts) from test1") tdSql.error("select twa(ts) from test1")
tdSql.error("select twa(col1) from test") tdSql.error("select twa(col1) from test")
tdSql.error("select twa(col1) from test1")
tdSql.error("select twa(col2) from test") tdSql.error("select twa(col2) from test")
tdSql.error("select twa(col2) from test1")
tdSql.error("select twa(col3) from test") tdSql.error("select twa(col3) from test")
tdSql.error("select twa(col3) from test1")
tdSql.error("select twa(col4) from test") tdSql.error("select twa(col4) from test")
tdSql.error("select twa(col4) from test1")
tdSql.error("select twa(col5) from test") tdSql.error("select twa(col5) from test")
tdSql.error("select twa(col5) from test1")
tdSql.error("select twa(col6) from test") tdSql.error("select twa(col6) from test")
tdSql.error("select twa(col6) from test1")
tdSql.error("select twa(col7) from test") tdSql.error("select twa(col7) from test")
tdSql.error("select twa(col7) from test1") tdSql.error("select twa(col7) from test1")
@ -73,58 +67,22 @@ class TDTestCase:
tdSql.error("select twa(col9) from test") tdSql.error("select twa(col9) from test")
tdSql.error("select twa(col9) from test1") tdSql.error("select twa(col9) from test1")
tdSql.error("select twa(col1) from test where ts > %d" % self.ts) tdSql.error("select twa(col1) from test where ts > %d and ts < %d" % (self.ts, self.ts + self.rowNum))
tdSql.error("select twa(col1) from test1 where ts > %d" % self.ts)
tdSql.error("select twa(col2) from test where ts > %d" % self.ts)
tdSql.error("select twa(col2) from test1 where ts > %d" % self.ts)
tdSql.error("select twa(col3) from test where ts > %d" % self.ts)
tdSql.error("select twa(col3) from test1 where ts > %d" % self.ts)
tdSql.error("select twa(col4) from test where ts > %d" % self.ts)
tdSql.error("select twa(col4) from test1 where ts > %d" % self.ts)
tdSql.error("select twa(col5) from test where ts > %d" % self.ts)
tdSql.error("select twa(col5) from test1 where ts > %d" % self.ts)
tdSql.error("select twa(col6) from test where ts > %d" % self.ts)
tdSql.error("select twa(col6) from test1 where ts > %d" % self.ts)
tdSql.error("select twa(col1) from test where ts < %d" % (self.ts + self.rowNum))
tdSql.error("select twa(col1) from test1 where ts < %d" % (self.ts + self.rowNum))
tdSql.error("select twa(col2) from test where ts < %d" % (self.ts + self.rowNum))
tdSql.error("select twa(col2) from test1 where ts < %d" % (self.ts + self.rowNum))
tdSql.error("select twa(col3) from test where ts < %d" % (self.ts + self.rowNum))
tdSql.error("select twa(col3) from test1 where ts < %d" % (self.ts + self.rowNum))
tdSql.error("select twa(col4) from test where ts < %d" % (self.ts + self.rowNum))
tdSql.error("select twa(col4) from test1 where ts < %d" % (self.ts + self.rowNum))
tdSql.error("select twa(col5) from test where ts < %d" % (self.ts + self.rowNum))
tdSql.error("select twa(col5) from test1 where ts < %d" % (self.ts + self.rowNum))
tdSql.error("select twa(col6) from test where ts < %d" % (self.ts + self.rowNum))
tdSql.error("select twa(col6) from test1 where ts < %d" % (self.ts + self.rowNum))
tdSql.query("select twa(col1) from test where ts > %d and ts < %d" % (self.ts, self.ts + self.rowNum))
tdSql.query("select twa(col1) from test1 where ts > %d and ts < %d" % (self.ts, self.ts + self.rowNum)) tdSql.query("select twa(col1) from test1 where ts > %d and ts < %d" % (self.ts, self.ts + self.rowNum))
tdSql.query("select twa(col2) from test where ts > %d and ts < %d" % (self.ts, self.ts + self.rowNum)) tdSql.error("select twa(col2) from test where ts > %d and ts < %d" % (self.ts, self.ts + self.rowNum))
tdSql.query("select twa(col2) from test1 where ts > %d and ts < %d" % (self.ts, self.ts + self.rowNum)) tdSql.query("select twa(col2) from test1 where ts > %d and ts < %d" % (self.ts, self.ts + self.rowNum))
tdSql.query("select twa(col3) from test where ts > %d and ts < %d" % (self.ts, self.ts + self.rowNum)) tdSql.error("select twa(col3) from test where ts > %d and ts < %d" % (self.ts, self.ts + self.rowNum))
tdSql.query("select twa(col3) from test1 where ts > %d and ts < %d" % (self.ts, self.ts + self.rowNum)) tdSql.query("select twa(col3) from test1 where ts > %d and ts < %d" % (self.ts, self.ts + self.rowNum))
tdSql.query("select twa(col4) from test where ts > %d and ts < %d" % (self.ts, self.ts + self.rowNum)) tdSql.error("select twa(col4) from test where ts > %d and ts < %d" % (self.ts, self.ts + self.rowNum))
tdSql.query("select twa(col4) from test1 where ts > %d and ts < %d" % (self.ts, self.ts + self.rowNum)) tdSql.query("select twa(col4) from test1 where ts > %d and ts < %d" % (self.ts, self.ts + self.rowNum))
tdSql.query("select twa(col5) from test where ts > %d and ts < %d" % (self.ts, self.ts + self.rowNum)) tdSql.error("select twa(col5) from test where ts > %d and ts < %d" % (self.ts, self.ts + self.rowNum))
tdSql.query("select twa(col5) from test1 where ts > %d and ts < %d" % (self.ts, self.ts + self.rowNum)) tdSql.query("select twa(col5) from test1 where ts > %d and ts < %d" % (self.ts, self.ts + self.rowNum))
tdSql.query("select twa(col6) from test where ts > %d and ts < %d" % (self.ts, self.ts + self.rowNum)) tdSql.error("select twa(col6) from test where ts > %d and ts < %d" % (self.ts, self.ts + self.rowNum))
tdSql.query("select twa(col6) from test1 where ts > %d and ts < %d" % (self.ts, self.ts + self.rowNum)) tdSql.query("select twa(col6) from test1 where ts > %d and ts < %d" % (self.ts, self.ts + self.rowNum))
def stop(self): def stop(self):

View File

@ -28,12 +28,17 @@ class TDTestCase:
self.ts = 1537146000000 self.ts = 1537146000000
def run(self): def run(self):
tdSql.execute("use db") tdSql.prepare()
intData = [] intData = []
floatData = [] floatData = []
tdSql.execute('''create table test(ts timestamp, col1 tinyint, col2 smallint, col3 int, col4 bigint, col5 float, col6 double,
col7 bool, col8 binary(20), col9 nchar(20)) tags(loc nchar(20))''')
tdSql.execute("create table test1 using test tags('beijing')")
for i in range(self.rowNum): for i in range(self.rowNum):
tdSql.execute("insert into test1 values(%d, %d, %d, %d, %d, %f, %f, %d, 'taosdata%d', '涛思数据%d')"
% (self.ts + i, i + 1, i + 1, i + 1, i + 1, i + 0.1, i + 0.1, i % 2, i + 1, i + 1))
intData.append(i + 1) intData.append(i + 1)
floatData.append(i + 0.1) floatData.append(i + 0.1)
@ -42,22 +47,16 @@ class TDTestCase:
tdSql.error("select twa(ts) from test1") tdSql.error("select twa(ts) from test1")
tdSql.error("select twa(col1) from test") tdSql.error("select twa(col1) from test")
tdSql.error("select twa(col1) from test1")
tdSql.error("select twa(col2) from test") tdSql.error("select twa(col2) from test")
tdSql.error("select twa(col2) from test1")
tdSql.error("select twa(col3) from test") tdSql.error("select twa(col3) from test")
tdSql.error("select twa(col3) from test1")
tdSql.error("select twa(col4) from test") tdSql.error("select twa(col4) from test")
tdSql.error("select twa(col4) from test1")
tdSql.error("select twa(col5) from test") tdSql.error("select twa(col5) from test")
tdSql.error("select twa(col5) from test1")
tdSql.error("select twa(col6) from test") tdSql.error("select twa(col6) from test")
tdSql.error("select twa(col6) from test1")
tdSql.error("select twa(col7) from test") tdSql.error("select twa(col7) from test")
tdSql.error("select twa(col7) from test1") tdSql.error("select twa(col7) from test1")
@ -68,58 +67,22 @@ class TDTestCase:
tdSql.error("select twa(col9) from test") tdSql.error("select twa(col9) from test")
tdSql.error("select twa(col9) from test1") tdSql.error("select twa(col9) from test1")
tdSql.error("select twa(col1) from test where ts > %d" % self.ts) tdSql.error("select twa(col1) from test where ts > %d and ts < %d" % (self.ts, self.ts + self.rowNum))
tdSql.error("select twa(col1) from test1 where ts > %d" % self.ts)
tdSql.error("select twa(col2) from test where ts > %d" % self.ts)
tdSql.error("select twa(col2) from test1 where ts > %d" % self.ts)
tdSql.error("select twa(col3) from test where ts > %d" % self.ts)
tdSql.error("select twa(col3) from test1 where ts > %d" % self.ts)
tdSql.error("select twa(col4) from test where ts > %d" % self.ts)
tdSql.error("select twa(col4) from test1 where ts > %d" % self.ts)
tdSql.error("select twa(col5) from test where ts > %d" % self.ts)
tdSql.error("select twa(col5) from test1 where ts > %d" % self.ts)
tdSql.error("select twa(col6) from test where ts > %d" % self.ts)
tdSql.error("select twa(col6) from test1 where ts > %d" % self.ts)
tdSql.error("select twa(col1) from test where ts < %d" % (self.ts + self.rowNum))
tdSql.error("select twa(col1) from test1 where ts < %d" % (self.ts + self.rowNum))
tdSql.error("select twa(col2) from test where ts < %d" % (self.ts + self.rowNum))
tdSql.error("select twa(col2) from test1 where ts < %d" % (self.ts + self.rowNum))
tdSql.error("select twa(col3) from test where ts < %d" % (self.ts + self.rowNum))
tdSql.error("select twa(col3) from test1 where ts < %d" % (self.ts + self.rowNum))
tdSql.error("select twa(col4) from test where ts < %d" % (self.ts + self.rowNum))
tdSql.error("select twa(col4) from test1 where ts < %d" % (self.ts + self.rowNum))
tdSql.error("select twa(col5) from test where ts < %d" % (self.ts + self.rowNum))
tdSql.error("select twa(col5) from test1 where ts < %d" % (self.ts + self.rowNum))
tdSql.error("select twa(col6) from test where ts < %d" % (self.ts + self.rowNum))
tdSql.error("select twa(col6) from test1 where ts < %d" % (self.ts + self.rowNum))
tdSql.query("select twa(col1) from test where ts > %d and ts < %d" % (self.ts, self.ts + self.rowNum))
tdSql.query("select twa(col1) from test1 where ts > %d and ts < %d" % (self.ts, self.ts + self.rowNum)) tdSql.query("select twa(col1) from test1 where ts > %d and ts < %d" % (self.ts, self.ts + self.rowNum))
tdSql.query("select twa(col2) from test where ts > %d and ts < %d" % (self.ts, self.ts + self.rowNum)) tdSql.error("select twa(col2) from test where ts > %d and ts < %d" % (self.ts, self.ts + self.rowNum))
tdSql.query("select twa(col2) from test1 where ts > %d and ts < %d" % (self.ts, self.ts + self.rowNum)) tdSql.query("select twa(col2) from test1 where ts > %d and ts < %d" % (self.ts, self.ts + self.rowNum))
tdSql.query("select twa(col3) from test where ts > %d and ts < %d" % (self.ts, self.ts + self.rowNum)) tdSql.error("select twa(col3) from test where ts > %d and ts < %d" % (self.ts, self.ts + self.rowNum))
tdSql.query("select twa(col3) from test1 where ts > %d and ts < %d" % (self.ts, self.ts + self.rowNum)) tdSql.query("select twa(col3) from test1 where ts > %d and ts < %d" % (self.ts, self.ts + self.rowNum))
tdSql.query("select twa(col4) from test where ts > %d and ts < %d" % (self.ts, self.ts + self.rowNum)) tdSql.error("select twa(col4) from test where ts > %d and ts < %d" % (self.ts, self.ts + self.rowNum))
tdSql.query("select twa(col4) from test1 where ts > %d and ts < %d" % (self.ts, self.ts + self.rowNum)) tdSql.query("select twa(col4) from test1 where ts > %d and ts < %d" % (self.ts, self.ts + self.rowNum))
tdSql.query("select twa(col5) from test where ts > %d and ts < %d" % (self.ts, self.ts + self.rowNum)) tdSql.error("select twa(col5) from test where ts > %d and ts < %d" % (self.ts, self.ts + self.rowNum))
tdSql.query("select twa(col5) from test1 where ts > %d and ts < %d" % (self.ts, self.ts + self.rowNum)) tdSql.query("select twa(col5) from test1 where ts > %d and ts < %d" % (self.ts, self.ts + self.rowNum))
tdSql.query("select twa(col6) from test where ts > %d and ts < %d" % (self.ts, self.ts + self.rowNum)) tdSql.error("select twa(col6) from test where ts > %d and ts < %d" % (self.ts, self.ts + self.rowNum))
tdSql.query("select twa(col6) from test1 where ts > %d and ts < %d" % (self.ts, self.ts + self.rowNum)) tdSql.query("select twa(col6) from test1 where ts > %d and ts < %d" % (self.ts, self.ts + self.rowNum))
def stop(self): def stop(self):

View File

@ -39,6 +39,10 @@ class TDTestCase:
tdSql.checkRows(1) tdSql.checkRows(1)
tdSql.checkData(0, 0, 5.5) tdSql.checkData(0, 0, 5.5)
tdSql.query("select twa(c) from t1")
tdSql.checkRows(1)
tdSql.checkData(0, 0, 5.5)
tdSql.query("select twa(c) from t1 where ts >= '2018-09-17 09:00:00.000' and ts <= '2018-09-17 09:01:30.000' interval(10s)") tdSql.query("select twa(c) from t1 where ts >= '2018-09-17 09:00:00.000' and ts <= '2018-09-17 09:01:30.000' interval(10s)")
tdSql.checkRows(10) tdSql.checkRows(10)
tdSql.checkData(0, 1, 1.49995) tdSql.checkData(0, 1, 1.49995)