add STSma schema encode/decode
This commit is contained in:
parent
ffeba1b1d4
commit
5443bb0dae
|
@ -1833,7 +1833,20 @@ static FORCE_INLINE void* tDecodeSSchemaWrapper(void* buf, SSchemaWrapper* pSW)
|
||||||
}
|
}
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
typedef enum {
|
||||||
|
TD_TIME_UNIT_UNKNOWN = -1,
|
||||||
|
TD_TIME_UNIT_YEAR = 0,
|
||||||
|
TD_TIME_UNIT_SEASON = 1,
|
||||||
|
TD_TIME_UNIT_MONTH = 2,
|
||||||
|
TD_TIME_UNIT_WEEK = 3,
|
||||||
|
TD_TIME_UNIT_DAY = 4,
|
||||||
|
TD_TIME_UNIT_HOUR = 5,
|
||||||
|
TD_TIME_UNIT_MINUTE = 6,
|
||||||
|
TD_TIME_UNIT_SEC = 7,
|
||||||
|
TD_TIME_UNIT_MILLISEC = 8,
|
||||||
|
TD_TIME_UNIT_MICROSEC = 9,
|
||||||
|
TD_TIME_UNIT_NANOSEC = 10
|
||||||
|
} ETDTimeUnit;
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint8_t version; // for compatibility
|
uint8_t version; // for compatibility
|
||||||
uint8_t intervalUnit;
|
uint8_t intervalUnit;
|
||||||
|
@ -1863,6 +1876,15 @@ static FORCE_INLINE void tdDestroyTSma(STSma* pSma, bool releaseSelf) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static FORCE_INLINE void tdDestroyWrapper(STSmaWrapper* pSW) {
|
||||||
|
if (pSW && pSW->tSma) {
|
||||||
|
for (uint32_t i = 0; i < pSW->number; ++i) {
|
||||||
|
tdDestroyTSma(pSW->tSma + i, false);
|
||||||
|
}
|
||||||
|
tfree(pSW->tSma);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static FORCE_INLINE int32_t tEncodeTSma(void** buf, const STSma* pSma) {
|
static FORCE_INLINE int32_t tEncodeTSma(void** buf, const STSma* pSma) {
|
||||||
int32_t tlen = 0;
|
int32_t tlen = 0;
|
||||||
|
|
||||||
|
@ -1876,12 +1898,14 @@ static FORCE_INLINE int32_t tEncodeTSma(void** buf, const STSma* pSma) {
|
||||||
tlen += taosEncodeFixedI64(buf, pSma->interval);
|
tlen += taosEncodeFixedI64(buf, pSma->interval);
|
||||||
tlen += taosEncodeFixedI64(buf, pSma->sliding);
|
tlen += taosEncodeFixedI64(buf, pSma->sliding);
|
||||||
|
|
||||||
for (uint16_t i = 0; i < pSma->numOfColIds; ++i) {
|
for (col_id_t i = 0; i < pSma->numOfColIds; ++i) {
|
||||||
tlen += taosEncodeFixedU16(buf, *(pSma->colIds + i));
|
tlen += taosEncodeFixedU16(buf, *(pSma->colIds + i));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (uint16_t i = 0; i < pSma->numOfFuncIds; ++i) {
|
for (uint16_t i = 0; i < pSma->numOfFuncIds; ++i) {
|
||||||
tlen += taosEncodeFixedU16(buf, *(pSma->funcIds + i));
|
tlen += taosEncodeFixedU16(buf, *(pSma->funcIds + i));
|
||||||
}
|
}
|
||||||
|
|
||||||
return tlen;
|
return tlen;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1949,20 +1973,6 @@ static FORCE_INLINE void* tDecodeTSmaWrapper(void* buf, STSmaWrapper* pSW) {
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
// RSma: Time-range-wise Rollup SMA
|
|
||||||
typedef struct {
|
|
||||||
int64_t interval;
|
|
||||||
int32_t retention; // unit: day
|
|
||||||
uint16_t days; // unit: day
|
|
||||||
int8_t intervalUnit;
|
|
||||||
} SSmaParams;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
STSma tsma;
|
|
||||||
float xFilesFactor;
|
|
||||||
SArray* smaParams; // SSmaParams
|
|
||||||
} SRSma;
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int64_t uid;
|
int64_t uid;
|
||||||
int32_t numOfRows;
|
int32_t numOfRows;
|
||||||
|
|
|
@ -54,5 +54,5 @@ elseif(${META_DB_IMPL} STREQUAL "TDB")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(${BUILD_TEST})
|
if(${BUILD_TEST})
|
||||||
# add_subdirectory(test)
|
add_subdirectory(test)
|
||||||
endif(${BUILD_TEST})
|
endif(${BUILD_TEST})
|
||||||
|
|
|
@ -16,6 +16,10 @@
|
||||||
#ifndef _TD_TSDB_COMMIT_H_
|
#ifndef _TD_TSDB_COMMIT_H_
|
||||||
#define _TD_TSDB_COMMIT_H_
|
#define _TD_TSDB_COMMIT_H_
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int minFid;
|
int minFid;
|
||||||
int midFid;
|
int midFid;
|
||||||
|
@ -66,4 +70,8 @@ int tsdbApplyRtn(STsdbRepo *pRepo);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* _TD_TSDB_COMMIT_H_ */
|
#endif /* _TD_TSDB_COMMIT_H_ */
|
|
@ -18,6 +18,10 @@
|
||||||
|
|
||||||
#include "tsdbFile.h"
|
#include "tsdbFile.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
// ================== TSDB global config
|
// ================== TSDB global config
|
||||||
extern bool tsdbForceKeepFile;
|
extern bool tsdbForceKeepFile;
|
||||||
|
|
||||||
|
@ -111,4 +115,8 @@ static FORCE_INLINE int tsdbUnLockFS(STsdbFS *pFs) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* _TD_TSDB_FS_H_ */
|
#endif /* _TD_TSDB_FS_H_ */
|
||||||
|
|
|
@ -19,6 +19,10 @@
|
||||||
#include "tchecksum.h"
|
#include "tchecksum.h"
|
||||||
#include "tfs.h"
|
#include "tfs.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
#define TSDB_FILE_HEAD_SIZE 512
|
#define TSDB_FILE_HEAD_SIZE 512
|
||||||
#define TSDB_FILE_DELIMITER 0xF00AFA0F
|
#define TSDB_FILE_DELIMITER 0xF00AFA0F
|
||||||
#define TSDB_FILE_INIT_MAGIC 0xFFFFFFFF
|
#define TSDB_FILE_INIT_MAGIC 0xFFFFFFFF
|
||||||
|
@ -410,4 +414,8 @@ static FORCE_INLINE bool tsdbFSetIsOk(SDFileSet* pSet) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* _TS_TSDB_FILE_H_ */
|
#endif /* _TS_TSDB_FILE_H_ */
|
|
@ -18,6 +18,10 @@
|
||||||
|
|
||||||
#include "tlog.h"
|
#include "tlog.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
extern int32_t tsdbDebugFlag;
|
extern int32_t tsdbDebugFlag;
|
||||||
|
|
||||||
#define tsdbFatal(...) do { if (tsdbDebugFlag & DEBUG_FATAL) { taosPrintLog("TDB FATAL ", 255, __VA_ARGS__); }} while(0)
|
#define tsdbFatal(...) do { if (tsdbDebugFlag & DEBUG_FATAL) { taosPrintLog("TDB FATAL ", 255, __VA_ARGS__); }} while(0)
|
||||||
|
@ -27,4 +31,8 @@ extern int32_t tsdbDebugFlag;
|
||||||
#define tsdbDebug(...) do { if (tsdbDebugFlag & DEBUG_DEBUG) { taosPrintLog("TDB ", tsdbDebugFlag, __VA_ARGS__); }} while(0)
|
#define tsdbDebug(...) do { if (tsdbDebugFlag & DEBUG_DEBUG) { taosPrintLog("TDB ", tsdbDebugFlag, __VA_ARGS__); }} while(0)
|
||||||
#define tsdbTrace(...) do { if (tsdbDebugFlag & DEBUG_TRACE) { taosPrintLog("TDB ", tsdbDebugFlag, __VA_ARGS__); }} while(0)
|
#define tsdbTrace(...) do { if (tsdbDebugFlag & DEBUG_TRACE) { taosPrintLog("TDB ", tsdbDebugFlag, __VA_ARGS__); }} while(0)
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* _TD_TSDB_LOG_H_ */
|
#endif /* _TD_TSDB_LOG_H_ */
|
|
@ -16,6 +16,10 @@
|
||||||
#ifndef _TD_TSDB_MEMORY_H_
|
#ifndef _TD_TSDB_MEMORY_H_
|
||||||
#define _TD_TSDB_MEMORY_H_
|
#define _TD_TSDB_MEMORY_H_
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
static void * taosTMalloc(size_t size);
|
static void * taosTMalloc(size_t size);
|
||||||
static void * taosTCalloc(size_t nmemb, size_t size);
|
static void * taosTCalloc(size_t nmemb, size_t size);
|
||||||
static void * taosTRealloc(void *ptr, size_t size);
|
static void * taosTRealloc(void *ptr, size_t size);
|
||||||
|
@ -70,5 +74,8 @@ static FORCE_INLINE void* taosTZfree(void* ptr) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* _TD_TSDB_MEMORY_H_ */
|
#endif /* _TD_TSDB_MEMORY_H_ */
|
|
@ -24,6 +24,10 @@
|
||||||
#include "tsdbMemory.h"
|
#include "tsdbMemory.h"
|
||||||
#include "tcommon.h"
|
#include "tcommon.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef struct SReadH SReadH;
|
typedef struct SReadH SReadH;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -244,4 +248,8 @@ static FORCE_INLINE int tsdbMakeRoom(void **ppBuf, size_t size) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /*_TD_TSDB_READ_IMPL_H_*/
|
#endif /*_TD_TSDB_READ_IMPL_H_*/
|
||||||
|
|
|
@ -38,6 +38,7 @@ struct SMetaDB {
|
||||||
// DB
|
// DB
|
||||||
DB *pTbDB;
|
DB *pTbDB;
|
||||||
DB *pSchemaDB;
|
DB *pSchemaDB;
|
||||||
|
DB *pSmaDB;
|
||||||
|
|
||||||
// IDX
|
// IDX
|
||||||
DB *pNameIdx;
|
DB *pNameIdx;
|
||||||
|
@ -101,6 +102,11 @@ int metaOpenDB(SMeta *pMeta) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (metaOpenBDBDb(&(pDB->pSmaDB), pDB->pEvn, "sma.db", false) < 0) {
|
||||||
|
metaCloseDB(pMeta);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
// Open Indices
|
// Open Indices
|
||||||
if (metaOpenBDBIdx(&(pDB->pNameIdx), pDB->pEvn, "name.index", pDB->pTbDB, &metaNameIdxCb, false) < 0) {
|
if (metaOpenBDBIdx(&(pDB->pNameIdx), pDB->pEvn, "name.index", pDB->pTbDB, &metaNameIdxCb, false) < 0) {
|
||||||
metaCloseDB(pMeta);
|
metaCloseDB(pMeta);
|
||||||
|
@ -131,6 +137,7 @@ void metaCloseDB(SMeta *pMeta) {
|
||||||
metaCloseBDBIdx(pMeta->pDB->pNtbIdx);
|
metaCloseBDBIdx(pMeta->pDB->pNtbIdx);
|
||||||
metaCloseBDBIdx(pMeta->pDB->pStbIdx);
|
metaCloseBDBIdx(pMeta->pDB->pStbIdx);
|
||||||
metaCloseBDBIdx(pMeta->pDB->pNameIdx);
|
metaCloseBDBIdx(pMeta->pDB->pNameIdx);
|
||||||
|
metaCloseBDBDb(pMeta->pDB->pSmaDB);
|
||||||
metaCloseBDBDb(pMeta->pDB->pSchemaDB);
|
metaCloseBDBDb(pMeta->pDB->pSchemaDB);
|
||||||
metaCloseBDBDb(pMeta->pDB->pTbDB);
|
metaCloseBDBDb(pMeta->pDB->pTbDB);
|
||||||
metaCloseBDBEnv(pMeta->pDB->pEvn);
|
metaCloseBDBEnv(pMeta->pDB->pEvn);
|
||||||
|
|
|
@ -18,21 +18,85 @@
|
||||||
#include <tglobal.h>
|
#include <tglobal.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
#include <tmsg.h>
|
||||||
|
|
||||||
#pragma GCC diagnostic push
|
#pragma GCC diagnostic push
|
||||||
#pragma GCC diagnostic ignored "-Wwrite-strings"
|
#pragma GCC diagnostic ignored "-Wwrite-strings"
|
||||||
#pragma GCC diagnostic ignored "-Wunused-function"
|
#pragma GCC diagnostic ignored "-Wunused-function"
|
||||||
#pragma GCC diagnostic ignored "-Wunused-variable"
|
#pragma GCC diagnostic ignored "-Wunused-variable"
|
||||||
#pragma GCC diagnostic ignored "-Wsign-compare"
|
#pragma GCC diagnostic ignored "-Wsign-compare"
|
||||||
|
|
||||||
#include "tsdbDef.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
testing::InitGoogleTest(&argc, argv);
|
testing::InitGoogleTest(&argc, argv);
|
||||||
return RUN_ALL_TESTS();
|
return RUN_ALL_TESTS();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(testCase, tSmaEncodeDecodeTest) {
|
||||||
|
// encode
|
||||||
|
STSma tSma = {0};
|
||||||
|
tSma.version = 0;
|
||||||
|
tSma.intervalUnit = TD_TIME_UNIT_DAY;
|
||||||
|
tSma.interval = 1;
|
||||||
|
tSma.slidingUnit = TD_TIME_UNIT_HOUR;
|
||||||
|
tSma.sliding = 0;
|
||||||
|
tstrncpy(tSma.indexName, "sma_index_test", TSDB_INDEX_NAME_LEN);
|
||||||
|
tSma.tableUid = 1234567890;
|
||||||
|
tSma.numOfColIds = 2;
|
||||||
|
tSma.numOfFuncIds = 5; // sum/min/max/avg/last
|
||||||
|
tSma.colIds = (col_id_t *)calloc(tSma.numOfColIds, sizeof(col_id_t));
|
||||||
|
tSma.funcIds = (uint16_t *)calloc(tSma.numOfFuncIds, sizeof(uint16_t));
|
||||||
|
|
||||||
|
for (int32_t i = 0; i < tSma.numOfColIds; ++i) {
|
||||||
|
*(tSma.colIds + i) = (i + PRIMARYKEY_TIMESTAMP_COL_ID);
|
||||||
|
}
|
||||||
|
for (int32_t i = 0; i < tSma.numOfFuncIds; ++i) {
|
||||||
|
*(tSma.funcIds + i) = (i + 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
STSmaWrapper tSmaWrapper = {.number = 1, .tSma = &tSma};
|
||||||
|
uint32_t bufLen = tEncodeTSmaWrapper(NULL, &tSmaWrapper);
|
||||||
|
|
||||||
|
void *buf = calloc(bufLen, 1);
|
||||||
|
assert(buf != NULL);
|
||||||
|
|
||||||
|
STSmaWrapper *pSW = (STSmaWrapper *)buf;
|
||||||
|
uint32_t len = tEncodeTSmaWrapper(&buf, &tSmaWrapper);
|
||||||
|
|
||||||
|
EXPECT_EQ(len, bufLen);
|
||||||
|
|
||||||
|
// decode
|
||||||
|
STSmaWrapper dstTSmaWrapper = {0};
|
||||||
|
void * result = tDecodeTSmaWrapper(pSW, &dstTSmaWrapper);
|
||||||
|
assert(result != NULL);
|
||||||
|
|
||||||
|
EXPECT_EQ(tSmaWrapper.number, dstTSmaWrapper.number);
|
||||||
|
|
||||||
|
for (int i = 0; i < tSmaWrapper.number; ++i) {
|
||||||
|
STSma *pSma = tSmaWrapper.tSma + i;
|
||||||
|
STSma *qSma = dstTSmaWrapper.tSma + i;
|
||||||
|
|
||||||
|
EXPECT_EQ(pSma->version, qSma->version);
|
||||||
|
EXPECT_EQ(pSma->intervalUnit, qSma->intervalUnit);
|
||||||
|
EXPECT_EQ(pSma->slidingUnit, qSma->slidingUnit);
|
||||||
|
EXPECT_STRCASEEQ(pSma->indexName, qSma->indexName);
|
||||||
|
EXPECT_EQ(pSma->numOfColIds, qSma->numOfColIds);
|
||||||
|
EXPECT_EQ(pSma->numOfFuncIds, qSma->numOfFuncIds);
|
||||||
|
EXPECT_EQ(pSma->tableUid, qSma->tableUid);
|
||||||
|
EXPECT_EQ(pSma->interval, qSma->interval);
|
||||||
|
EXPECT_EQ(pSma->sliding, qSma->sliding);
|
||||||
|
for (uint32_t j = 0; j < pSma->numOfColIds; ++j) {
|
||||||
|
EXPECT_EQ(*(col_id_t *)(pSma->colIds + j), *(col_id_t *)(qSma->colIds + j));
|
||||||
|
}
|
||||||
|
for (uint32_t j = 0; j < pSma->numOfFuncIds; ++j) {
|
||||||
|
EXPECT_EQ(*(uint16_t *)(pSma->funcIds + j), *(uint16_t *)(qSma->funcIds + j));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// resource release
|
||||||
|
tdDestroyTSma(&tSma, false);
|
||||||
|
tdDestroyWrapper(&dstTSmaWrapper);
|
||||||
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
TEST(testCase, tSmaInsertTest) {
|
TEST(testCase, tSmaInsertTest) {
|
||||||
STSma tSma = {0};
|
STSma tSma = {0};
|
||||||
|
|
Loading…
Reference in New Issue