Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
7bef44aa
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
7bef44aa
编写于
3月 10, 2022
作者:
C
Cary Xu
提交者:
GitHub
3月 10, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #10662 from taosdata/feature/TD-11463-3.0
reset smsStatWindow
上级
13e1d70e
7ad5e742
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
197 addition
and
91 deletion
+197
-91
include/common/tmsg.h
include/common/tmsg.h
+77
-39
include/util/tdef.h
include/util/tdef.h
+1
-1
source/dnode/vnode/src/inc/tsdbFS.h
source/dnode/vnode/src/inc/tsdbFS.h
+21
-3
source/dnode/vnode/src/inc/tsdbFile.h
source/dnode/vnode/src/inc/tsdbFile.h
+4
-3
source/dnode/vnode/src/inc/tsdbSma.h
source/dnode/vnode/src/inc/tsdbSma.h
+1
-1
source/dnode/vnode/src/tsdb/tsdbFile.c
source/dnode/vnode/src/tsdb/tsdbFile.c
+2
-2
source/dnode/vnode/src/tsdb/tsdbMain.c
source/dnode/vnode/src/tsdb/tsdbMain.c
+1
-1
source/dnode/vnode/src/tsdb/tsdbSma.c
source/dnode/vnode/src/tsdb/tsdbSma.c
+27
-3
source/dnode/vnode/test/tsdbSmaTest.cpp
source/dnode/vnode/test/tsdbSmaTest.cpp
+63
-38
未找到文件。
include/common/tmsg.h
浏览文件 @
7bef44aa
...
...
@@ -1856,19 +1856,27 @@ typedef enum {
TD_TIME_UNIT_MICROSEC
=
9
,
TD_TIME_UNIT_NANOSEC
=
10
}
ETDTimeUnit
;
typedef
struct
{
uint16_t
funcId
;
uint16_t
nColIds
;
col_id_t
*
colIds
;
// sorted colIds
}
SFuncColIds
;
typedef
struct
{
uint8_t
version
;
// for compatibility
uint8_t
intervalUnit
;
uint8_t
slidingUnit
;
char
indexName
[
TSDB_INDEX_NAME_LEN
+
1
];
col_id_t
numOfColIds
;
uint16_t
numOfFuncIds
;
uint64_t
tableUid
;
// super/common table uid
int64_t
interval
;
int64_t
sliding
;
col_id_t
*
colIds
;
// sorted column ids
uint16_t
*
funcIds
;
// sorted sma function ids
}
STSma
;
// Time-range-wise SMA
uint8_t
version
;
// for compatibility
uint8_t
intervalUnit
;
uint8_t
slidingUnit
;
char
indexName
[
TSDB_INDEX_NAME_LEN
];
char
timezone
[
TD_TIMEZONE_LEN
];
uint16_t
nFuncColIds
;
uint16_t
tagsFilterLen
;
tb_uid_t
tableUid
;
// super/common table uid
int64_t
interval
;
int64_t
sliding
;
SFuncColIds
*
funcColIds
;
// sorted funcIds
char
*
tagsFilter
;
}
STSma
;
// Time-range-wise SMA
typedef
struct
{
int64_t
ver
;
// use a general definition
...
...
@@ -1877,13 +1885,13 @@ typedef struct {
typedef
struct
{
int8_t
type
;
// 0 status report, 1 update data
char
indexName
[
TSDB_INDEX_NAME_LEN
+
1
];
//
char
indexName
[
TSDB_INDEX_NAME_LEN
];
//
STimeWindow
windows
;
}
STSmaMsg
;
typedef
struct
{
int64_t
ver
;
// use a general definition
char
indexName
[
TSDB_INDEX_NAME_LEN
+
1
];
char
indexName
[
TSDB_INDEX_NAME_LEN
];
}
SVDropTSmaReq
;
typedef
struct
{
}
SVCreateTSmaRsp
,
SVDropTSmaRsp
;
...
...
@@ -1934,8 +1942,14 @@ typedef struct {
static
FORCE_INLINE
void
tdDestroyTSma
(
STSma
*
pSma
)
{
if
(
pSma
)
{
tfree
(
pSma
->
colIds
);
tfree
(
pSma
->
funcIds
);
if
(
pSma
->
funcColIds
!=
NULL
)
{
for
(
uint16_t
i
=
0
;
i
<
pSma
->
nFuncColIds
;
++
i
)
{
tfree
((
pSma
->
funcColIds
+
i
)
->
colIds
);
}
tfree
(
pSma
->
funcColIds
);
}
tfree
(
pSma
->
tagsFilter
);
}
}
...
...
@@ -1957,18 +1971,24 @@ static FORCE_INLINE int32_t tEncodeTSma(void** buf, const STSma* pSma) {
tlen
+=
taosEncodeFixedU8
(
buf
,
pSma
->
intervalUnit
);
tlen
+=
taosEncodeFixedU8
(
buf
,
pSma
->
slidingUnit
);
tlen
+=
taosEncodeString
(
buf
,
pSma
->
indexName
);
tlen
+=
taosEncodeFixedU16
(
buf
,
pSma
->
numOfColIds
);
tlen
+=
taosEncodeFixedU16
(
buf
,
pSma
->
numOfFuncIds
);
tlen
+=
taosEncodeFixedU64
(
buf
,
pSma
->
tableUid
);
tlen
+=
taosEncodeString
(
buf
,
pSma
->
timezone
);
tlen
+=
taosEncodeFixedU16
(
buf
,
pSma
->
nFuncColIds
);
tlen
+=
taosEncodeFixedU16
(
buf
,
pSma
->
tagsFilterLen
);
tlen
+=
taosEncodeFixedI64
(
buf
,
pSma
->
tableUid
);
tlen
+=
taosEncodeFixedI64
(
buf
,
pSma
->
interval
);
tlen
+=
taosEncodeFixedI64
(
buf
,
pSma
->
sliding
);
for
(
col_id_t
i
=
0
;
i
<
pSma
->
numOfColIds
;
++
i
)
{
tlen
+=
taosEncodeFixedU16
(
buf
,
*
(
pSma
->
colIds
+
i
));
for
(
uint16_t
i
=
0
;
i
<
pSma
->
nFuncColIds
;
++
i
)
{
SFuncColIds
*
funcColIds
=
pSma
->
funcColIds
+
i
;
tlen
+=
taosEncodeFixedU16
(
buf
,
funcColIds
->
funcId
);
tlen
+=
taosEncodeFixedU16
(
buf
,
funcColIds
->
nColIds
);
for
(
uint16_t
j
=
0
;
j
<
funcColIds
->
nColIds
;
++
j
)
{
tlen
+=
taosEncodeFixedU16
(
buf
,
*
(
funcColIds
->
colIds
+
j
));
}
}
for
(
uint16_t
i
=
0
;
i
<
pSma
->
numOfFuncIds
;
++
i
)
{
tlen
+=
taosEncode
FixedU16
(
buf
,
*
(
pSma
->
funcIds
+
i
)
);
if
(
pSma
->
tagsFilterLen
>
0
)
{
tlen
+=
taosEncode
String
(
buf
,
pSma
->
tagsFilter
);
}
return
tlen
;
...
...
@@ -1989,34 +2009,52 @@ static FORCE_INLINE void* tDecodeTSma(void* buf, STSma* pSma) {
buf
=
taosDecodeFixedU8
(
buf
,
&
pSma
->
intervalUnit
);
buf
=
taosDecodeFixedU8
(
buf
,
&
pSma
->
slidingUnit
);
buf
=
taosDecodeStringTo
(
buf
,
pSma
->
indexName
);
buf
=
taosDecodeFixedU16
(
buf
,
&
pSma
->
numOfColIds
);
buf
=
taosDecodeFixedU16
(
buf
,
&
pSma
->
numOfFuncIds
);
buf
=
taosDecodeFixedU64
(
buf
,
&
pSma
->
tableUid
);
buf
=
taosDecodeStringTo
(
buf
,
pSma
->
timezone
);
buf
=
taosDecodeFixedU16
(
buf
,
&
pSma
->
nFuncColIds
);
buf
=
taosDecodeFixedU16
(
buf
,
&
pSma
->
tagsFilterLen
);
buf
=
taosDecodeFixedI64
(
buf
,
&
pSma
->
tableUid
);
buf
=
taosDecodeFixedI64
(
buf
,
&
pSma
->
interval
);
buf
=
taosDecodeFixedI64
(
buf
,
&
pSma
->
sliding
);
if
(
pSma
->
numOfColIds
>
0
)
{
pSma
->
colIds
=
(
col_id_t
*
)
calloc
(
pSma
->
numOfColIds
,
sizeof
(
STSma
));
if
(
pSma
->
colIds
==
NULL
)
{
if
(
pSma
->
nFuncColIds
>
0
)
{
pSma
->
funcColIds
=
(
SFuncColIds
*
)
calloc
(
pSma
->
nFuncColIds
,
sizeof
(
SFuncColIds
));
if
(
pSma
->
funcColIds
==
NULL
)
{
tdDestroyTSma
(
pSma
);
return
NULL
;
}
for
(
uint16_t
i
=
0
;
i
<
pSma
->
numOfColIds
;
++
i
)
{
buf
=
taosDecodeFixedU16
(
buf
,
pSma
->
colIds
+
i
);
for
(
uint16_t
i
=
0
;
i
<
pSma
->
nFuncColIds
;
++
i
)
{
SFuncColIds
*
funcColIds
=
pSma
->
funcColIds
+
i
;
buf
=
taosDecodeFixedU16
(
buf
,
&
funcColIds
->
funcId
);
buf
=
taosDecodeFixedU16
(
buf
,
&
funcColIds
->
nColIds
);
if
(
funcColIds
->
nColIds
>
0
)
{
funcColIds
->
colIds
=
(
col_id_t
*
)
calloc
(
funcColIds
->
nColIds
,
sizeof
(
col_id_t
));
if
(
funcColIds
->
colIds
!=
NULL
)
{
for
(
uint16_t
j
=
0
;
j
<
funcColIds
->
nColIds
;
++
j
)
{
buf
=
taosDecodeFixedU16
(
buf
,
funcColIds
->
colIds
+
j
);
}
}
else
{
tdDestroyTSma
(
pSma
);
return
NULL
;
}
}
else
{
funcColIds
->
colIds
=
NULL
;
}
}
}
else
{
pSma
->
c
olIds
=
NULL
;
pSma
->
funcC
olIds
=
NULL
;
}
if
(
pSma
->
numOfFuncIds
>
0
)
{
pSma
->
funcIds
=
(
uint16_t
*
)
calloc
(
pSma
->
numOfFuncIds
,
sizeof
(
STSma
));
if
(
pSma
->
funcIds
==
NULL
)
{
if
(
pSma
->
tagsFilterLen
>
0
)
{
pSma
->
tagsFilter
=
(
char
*
)
calloc
(
pSma
->
tagsFilterLen
,
1
);
if
(
pSma
->
tagsFilter
!=
NULL
)
{
buf
=
taosDecodeStringTo
(
buf
,
pSma
->
tagsFilter
);
}
else
{
tdDestroyTSma
(
pSma
);
return
NULL
;
}
for
(
uint16_t
i
=
0
;
i
<
pSma
->
numOfFuncIds
;
++
i
)
{
buf
=
taosDecodeFixedU16
(
buf
,
pSma
->
funcIds
+
i
);
}
}
else
{
pSma
->
funcIds
=
NULL
;
pSma
->
tagsFilter
=
NULL
;
}
return
buf
;
...
...
include/util/tdef.h
浏览文件 @
7bef44aa
...
...
@@ -207,7 +207,7 @@ typedef enum ELogicConditionType {
#define TSDB_FUNC_TYPE_AGGREGATE 2
#define TSDB_FUNC_MAX_RETRIEVE 1024
#define TSDB_INDEX_NAME_LEN 3
2
#define TSDB_INDEX_NAME_LEN 3
3 // 32 + 1 '\0'
#define TSDB_TYPE_STR_MAX_LEN 32
#define TSDB_TABLE_FNAME_LEN (TSDB_DB_FNAME_LEN + TSDB_TABLE_NAME_LEN + TSDB_NAME_DELIMITER_LEN)
#define TSDB_TOPIC_FNAME_LEN TSDB_TABLE_FNAME_LEN
...
...
source/dnode/vnode/src/inc/tsdbFS.h
浏览文件 @
7bef44aa
...
...
@@ -43,12 +43,30 @@ typedef struct {
STsdbFSMeta
meta
;
// FS meta
SArray
*
df
;
// data file array
// SArray * v2
f100.tsma
.index_name
// SArray * v2
t100
.index_name
SArray
*
smaf
;
// sma data file array v2
f1900.tsma
.index_name
SArray
*
smaf
;
// sma data file array v2
t1900
.index_name
}
SFSStatus
;
typedef
struct
{
/**
* @brief Directory structure of .tsma data files.
*
* root@cary /vnode2/tsdb $ tree .tsma/
* .tsma/
* ├── v2t100.index_name_1
* ├── v2t101.index_name_1
* ├── v2t102.index_name_1
* ├── v2t1900.index_name_3
* ├── v2t1901.index_name_3
* ├── v2t1902.index_name_3
* ├── v2t200.index_name_2
* ├── v2t201.index_name_2
* └── v2t202.index_name_2
*
* 0 directories, 9 files
*/
typedef
struct
{
pthread_rwlock_t
lock
;
SFSStatus
*
cstatus
;
// current status
...
...
source/dnode/vnode/src/inc/tsdbFile.h
浏览文件 @
7bef44aa
...
...
@@ -56,10 +56,11 @@ typedef enum {
TSDB_FILE_SMAL
,
// .smal(Block-wise SMA)
TSDB_FILE_MAX
,
//
TSDB_FILE_META
,
// meta
TSDB_FILE_TSMA
,
//
.tsma
.${sma_index_name}, Time-range-wise SMA
TSDB_FILE_RSMA
,
//
.rsma
.${sma_index_name}, Time-range-wise Rollup SMA
}
TSDB_FILE_T
;
TSDB_FILE_TSMA
,
//
v2t100
.${sma_index_name}, Time-range-wise SMA
TSDB_FILE_RSMA
,
//
v2r100
.${sma_index_name}, Time-range-wise Rollup SMA
}
E_
TSDB_FILE_T
;
typedef
int32_t
TSDB_FILE_T
;
typedef
enum
{
TSDB_FS_VER_0
=
0
,
TSDB_FS_VER_MAX
,
...
...
source/dnode/vnode/src/inc/tsdbSma.h
浏览文件 @
7bef44aa
...
...
@@ -31,7 +31,7 @@ int32_t tsdbGetTSmaDataImpl(STsdb *pTsdb, STSma *param, STSmaData *pData, STimeW
int32_t
tsdbUpdateExpiredWindow
(
STsdb
*
pTsdb
,
char
*
msg
);
int32_t
tsdbGetTSmaStatus
(
STsdb
*
pTsdb
,
STSma
*
param
,
void
*
result
);
int32_t
tsdbRemoveTSmaData
(
STsdb
*
pTsdb
,
STSma
*
param
,
STimeWindow
*
pWin
);
int32_t
tsdb
Free
SmaState
(
SSmaStat
*
pSmaStat
);
int32_t
tsdb
Destroy
SmaState
(
SSmaStat
*
pSmaStat
);
// internal func
...
...
source/dnode/vnode/src/tsdb/tsdbFile.c
浏览文件 @
7bef44aa
...
...
@@ -23,8 +23,8 @@ static const char *TSDB_FNAME_SUFFIX[] = {
"smal"
,
// TSDB_FILE_SMAL
""
,
// TSDB_FILE_MAX
"meta"
,
// TSDB_FILE_META
"
tsma"
,
// TSDB_FILE_TSMA
"
rsma"
,
// TSDB_FILE_RSMA
"
sma"
,
// TSDB_FILE_TSMA(directory name)
"
sma"
,
// TSDB_FILE_RSMA(directory name)
};
static
void
tsdbGetFilename
(
int
vid
,
int
fid
,
uint32_t
ver
,
TSDB_FILE_T
ftype
,
char
*
fname
);
...
...
source/dnode/vnode/src/tsdb/tsdbMain.c
浏览文件 @
7bef44aa
...
...
@@ -89,7 +89,7 @@ static STsdb *tsdbNew(const char *path, int32_t vgId, const STsdbCfg *pTsdbCfg,
static
void
tsdbFree
(
STsdb
*
pTsdb
)
{
if
(
pTsdb
)
{
tsdbFreeFS
(
pTsdb
->
fs
);
tsdb
Free
SmaState
(
pTsdb
->
pSmaStat
);
tsdb
Destroy
SmaState
(
pTsdb
->
pSmaStat
);
tfree
(
pTsdb
->
path
);
free
(
pTsdb
);
}
...
...
source/dnode/vnode/src/tsdb/tsdbSma.c
浏览文件 @
7bef44aa
...
...
@@ -128,7 +128,7 @@ static SSmaStatItem *tsdbNewSmaStatItem(int8_t state) {
return
pItem
;
}
int32_t
tsdb
Free
SmaState
(
SSmaStat
*
pSmaStat
)
{
int32_t
tsdb
Destroy
SmaState
(
SSmaStat
*
pSmaStat
)
{
if
(
pSmaStat
)
{
// TODO: use taosHashSetFreeFp when taosHashSetFreeFp is ready.
SSmaStatItem
*
item
=
taosHashIterate
(
pSmaStat
->
smaStatItems
,
NULL
);
...
...
@@ -203,6 +203,23 @@ int32_t tsdbUpdateExpiredWindow(STsdb *pTsdb, char *msg) {
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
tsdbResetExpiredWindow
(
STsdb
*
pTsdb
,
const
char
*
indexName
,
void
*
timeWindow
)
{
SSmaStatItem
*
pItem
=
NULL
;
if
(
pTsdb
->
pSmaStat
&&
pTsdb
->
pSmaStat
->
smaStatItems
)
{
pItem
=
(
SSmaStatItem
*
)
taosHashGet
(
pTsdb
->
pSmaStat
->
smaStatItems
,
indexName
,
strlen
(
indexName
));
}
if
(
pItem
!=
NULL
)
{
// TODO: reset time windows for the sma data blocks
while
(
true
)
{
TSKEY
thisWindow
=
0
;
taosHashRemove
(
pItem
->
expiredWindows
,
&
thisWindow
,
sizeof
(
thisWindow
));
}
}
return
TSDB_CODE_SUCCESS
;
}
/**
* @brief Judge the tSma storage level
*
...
...
@@ -387,7 +404,7 @@ static int32_t tsdbInsertTSmaDataSection(STSmaWriteH *pSmaH, STSmaData *pData, i
static
int32_t
tsdbInitTSmaWriteH
(
STSmaWriteH
*
pSmaH
,
STsdb
*
pTsdb
,
STSma
*
param
,
STSmaData
*
pData
)
{
pSmaH
->
pTsdb
=
pTsdb
;
pSmaH
->
interval
=
tsdbGetIntervalByPrecision
(
param
->
interval
,
param
->
intervalUnit
,
REPO_CFG
(
pTsdb
)
->
precision
);
pSmaH
->
blockSize
=
param
->
numOfFuncIds
*
sizeof
(
int64_t
);
//
pSmaH->blockSize = param->numOfFuncIds * sizeof(int64_t);
}
static
int32_t
tsdbSetTSmaDataFile
(
STSmaWriteH
*
pSmaH
,
STSma
*
param
,
STSmaData
*
pData
,
int32_t
storageLevel
,
...
...
@@ -495,6 +512,9 @@ int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, STSma *param, STSmaData *pData) {
return
terrno
;
}
// reset the SSmaStat
tsdbResetExpiredWindow
(
pTsdb
,
param
->
indexName
,
&
pData
->
tsWindow
);
return
TSDB_CODE_SUCCESS
;
}
...
...
@@ -542,6 +562,10 @@ int32_t tsdbInsertRSmaDataImpl(STsdb *pTsdb, SRSma *param, STSmaData *pData) {
TASSERT
(
0
);
return
TSDB_CODE_INVALID_PARA
;
}
// reset the SSmaStat
tsdbResetExpiredWindow
(
pTsdb
,
param
->
tsma
.
indexName
,
&
pData
->
tsWindow
);
// Step 4: finish
return
TSDB_CODE_SUCCESS
;
}
...
...
@@ -558,7 +582,7 @@ int32_t tsdbInsertRSmaDataImpl(STsdb *pTsdb, SRSma *param, STSmaData *pData) {
static
int32_t
tsdbInitTSmaReadH
(
STSmaReadH
*
pSmaH
,
STsdb
*
pTsdb
,
STSma
*
param
,
STSmaData
*
pData
)
{
pSmaH
->
pTsdb
=
pTsdb
;
pSmaH
->
interval
=
tsdbGetIntervalByPrecision
(
param
->
interval
,
param
->
intervalUnit
,
REPO_CFG
(
pTsdb
)
->
precision
);
pSmaH
->
blockSize
=
param
->
numOfFuncIds
*
sizeof
(
int64_t
);
//
pSmaH->blockSize = param->numOfFuncIds * sizeof(int64_t);
}
/**
...
...
source/dnode/vnode/test/tsdbSmaTest.cpp
浏览文件 @
7bef44aa
...
...
@@ -20,6 +20,7 @@
#include <metaDef.h>
#include <tmsg.h>
#include <tsdbDef.h>
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wwrite-strings"
...
...
@@ -41,17 +42,20 @@ TEST(testCase, tSmaEncodeDecodeTest) {
tSma
.
slidingUnit
=
TD_TIME_UNIT_HOUR
;
tSma
.
sliding
=
0
;
tstrncpy
(
tSma
.
indexName
,
"sma_index_test"
,
TSDB_INDEX_NAME_LEN
);
tstrncpy
(
tSma
.
timezone
,
"Asia/Shanghai"
,
TD_TIMEZONE_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
);
tSma
.
nFuncColIds
=
5
;
tSma
.
funcColIds
=
(
SFuncColIds
*
)
calloc
(
tSma
.
nFuncColIds
,
sizeof
(
SFuncColIds
));
ASSERT
(
tSma
.
funcColIds
!=
NULL
);
for
(
int32_t
n
=
0
;
n
<
tSma
.
nFuncColIds
;
++
n
)
{
SFuncColIds
*
funcColIds
=
tSma
.
funcColIds
+
n
;
funcColIds
->
funcId
=
n
;
funcColIds
->
nColIds
=
10
;
funcColIds
->
colIds
=
(
col_id_t
*
)
calloc
(
funcColIds
->
nColIds
,
sizeof
(
col_id_t
));
ASSERT
(
funcColIds
->
colIds
!=
NULL
);
for
(
int32_t
i
=
0
;
i
<
funcColIds
->
nColIds
;
++
i
)
{
*
(
funcColIds
->
colIds
+
i
)
=
(
i
+
PRIMARYKEY_TIMESTAMP_COL_ID
);
}
}
STSmaWrapper
tSmaWrapper
=
{.
number
=
1
,
.
tSma
=
&
tSma
};
...
...
@@ -80,16 +84,21 @@ TEST(testCase, tSmaEncodeDecodeTest) {
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
->
n
umOfFuncIds
,
qSma
->
numOfFunc
Ids
);
EXPECT_
STRCASEEQ
(
pSma
->
timezone
,
qSma
->
timezone
);
EXPECT_EQ
(
pSma
->
n
FuncColIds
,
qSma
->
nFuncCol
Ids
);
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
));
EXPECT_EQ
(
pSma
->
tagsFilterLen
,
qSma
->
tagsFilterLen
);
EXPECT_STRCASEEQ
(
pSma
->
tagsFilter
,
qSma
->
tagsFilter
);
for
(
uint32_t
j
=
0
;
j
<
pSma
->
nFuncColIds
;
++
j
)
{
SFuncColIds
*
pFuncColIds
=
pSma
->
funcColIds
+
j
;
SFuncColIds
*
qFuncColIds
=
qSma
->
funcColIds
+
j
;
EXPECT_EQ
(
pFuncColIds
->
funcId
,
qFuncColIds
->
funcId
);
EXPECT_EQ
(
pFuncColIds
->
nColIds
,
qFuncColIds
->
nColIds
);
for
(
uint32_t
k
=
0
;
k
<
pFuncColIds
->
nColIds
;
++
k
)
{
EXPECT_EQ
(
*
(
pFuncColIds
->
colIds
+
k
),
*
(
qFuncColIds
->
colIds
+
k
));
}
}
}
...
...
@@ -99,9 +108,11 @@ TEST(testCase, tSmaEncodeDecodeTest) {
}
TEST
(
testCase
,
tSma_DB_Put_Get_Del_Test
)
{
const
char
*
smaIndexName1
=
"sma_index_test_1"
;
const
char
*
smaIndexName2
=
"sma_index_test_2"
;
const
char
*
smaTestDir
=
"./smaTest"
;
const
char
*
smaIndexName1
=
"sma_index_test_1"
;
const
char
*
smaIndexName2
=
"sma_index_test_2"
;
const
char
*
timeZone
=
"Asia/Shanghai"
;
const
char
*
tagsFilter
=
"I'm tags filter"
;
const
char
*
smaTestDir
=
"./smaTest"
;
const
uint64_t
tbUid
=
1234567890
;
const
uint32_t
nCntTSma
=
2
;
// encode
...
...
@@ -112,21 +123,27 @@ TEST(testCase, tSma_DB_Put_Get_Del_Test) {
tSma
.
slidingUnit
=
TD_TIME_UNIT_HOUR
;
tSma
.
sliding
=
0
;
tstrncpy
(
tSma
.
indexName
,
smaIndexName1
,
TSDB_INDEX_NAME_LEN
);
tstrncpy
(
tSma
.
timezone
,
timeZone
,
TD_TIMEZONE_LEN
);
tSma
.
tableUid
=
tbUid
;
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
);
tSma
.
nFuncColIds
=
5
;
tSma
.
funcColIds
=
(
SFuncColIds
*
)
calloc
(
tSma
.
nFuncColIds
,
sizeof
(
SFuncColIds
));
ASSERT
(
tSma
.
funcColIds
!=
NULL
);
for
(
int32_t
n
=
0
;
n
<
tSma
.
nFuncColIds
;
++
n
)
{
SFuncColIds
*
funcColIds
=
tSma
.
funcColIds
+
n
;
funcColIds
->
funcId
=
n
;
funcColIds
->
nColIds
=
10
;
funcColIds
->
colIds
=
(
col_id_t
*
)
calloc
(
funcColIds
->
nColIds
,
sizeof
(
col_id_t
));
ASSERT
(
funcColIds
->
colIds
!=
NULL
);
for
(
int32_t
i
=
0
;
i
<
funcColIds
->
nColIds
;
++
i
)
{
*
(
funcColIds
->
colIds
+
i
)
=
(
i
+
PRIMARYKEY_TIMESTAMP_COL_ID
);
}
}
tSma
.
tagsFilterLen
=
strlen
(
tagsFilter
);
tSma
.
tagsFilter
=
(
char
*
)
calloc
(
tSma
.
tagsFilterLen
+
1
,
1
);
tstrncpy
(
tSma
.
tagsFilter
,
tagsFilter
,
tSma
.
tagsFilterLen
+
1
);
SMeta
*
pMeta
=
NULL
;
STSma
*
pSmaCfg
=
&
tSma
;
STSma
*
pSmaCfg
=
&
tSma
;
const
SMetaCfg
*
pMetaCfg
=
&
defaultMetaOptions
;
taosRemoveDir
(
smaTestDir
);
...
...
@@ -151,6 +168,8 @@ TEST(testCase, tSma_DB_Put_Get_Del_Test) {
qSmaCfg
=
metaGetSmaInfoByName
(
pMeta
,
smaIndexName1
);
assert
(
qSmaCfg
!=
NULL
);
printf
(
"name1 = %s
\n
"
,
qSmaCfg
->
indexName
);
printf
(
"timezone1 = %s
\n
"
,
qSmaCfg
->
timezone
);
printf
(
"tagsFilter1 = %s
\n
"
,
qSmaCfg
->
tagsFilter
!=
NULL
?
qSmaCfg
->
tagsFilter
:
""
);
EXPECT_STRCASEEQ
(
qSmaCfg
->
indexName
,
smaIndexName1
);
EXPECT_EQ
(
qSmaCfg
->
tableUid
,
tSma
.
tableUid
);
tdDestroyTSma
(
qSmaCfg
);
...
...
@@ -159,6 +178,8 @@ TEST(testCase, tSma_DB_Put_Get_Del_Test) {
qSmaCfg
=
metaGetSmaInfoByName
(
pMeta
,
smaIndexName2
);
assert
(
qSmaCfg
!=
NULL
);
printf
(
"name2 = %s
\n
"
,
qSmaCfg
->
indexName
);
printf
(
"timezone2 = %s
\n
"
,
qSmaCfg
->
timezone
);
printf
(
"tagsFilter2 = %s
\n
"
,
qSmaCfg
->
tagsFilter
!=
NULL
?
qSmaCfg
->
tagsFilter
:
""
);
EXPECT_STRCASEEQ
(
qSmaCfg
->
indexName
,
smaIndexName2
);
EXPECT_EQ
(
qSmaCfg
->
interval
,
tSma
.
interval
);
tdDestroyTSma
(
qSmaCfg
);
...
...
@@ -169,7 +190,7 @@ TEST(testCase, tSma_DB_Put_Get_Del_Test) {
assert
(
pSmaCur
!=
NULL
);
uint32_t
indexCnt
=
0
;
while
(
1
)
{
const
char
*
indexName
=
metaSmaCursorNext
(
pSmaCur
);
const
char
*
indexName
=
metaSmaCursorNext
(
pSmaCur
);
if
(
indexName
==
NULL
)
{
break
;
}
...
...
@@ -184,10 +205,14 @@ TEST(testCase, tSma_DB_Put_Get_Del_Test) {
assert
(
pSW
!=
NULL
);
EXPECT_EQ
(
pSW
->
number
,
nCntTSma
);
EXPECT_STRCASEEQ
(
pSW
->
tSma
->
indexName
,
smaIndexName1
);
EXPECT_STRCASEEQ
(
pSW
->
tSma
->
timezone
,
timeZone
);
EXPECT_STRCASEEQ
(
pSW
->
tSma
->
tagsFilter
,
tagsFilter
);
EXPECT_EQ
(
pSW
->
tSma
->
tableUid
,
tSma
.
tableUid
);
EXPECT_STRCASEEQ
((
pSW
->
tSma
+
1
)
->
indexName
,
smaIndexName2
);
EXPECT_STRCASEEQ
((
pSW
->
tSma
+
1
)
->
timezone
,
timeZone
);
EXPECT_STRCASEEQ
((
pSW
->
tSma
+
1
)
->
tagsFilter
,
tagsFilter
);
EXPECT_EQ
((
pSW
->
tSma
+
1
)
->
tableUid
,
tSma
.
tableUid
);
tdDestroyTSmaWrapper
(
pSW
);
tfree
(
pSW
);
...
...
@@ -211,9 +236,9 @@ TEST(testCase, tSma_DB_Put_Get_Del_Test) {
#if 0
TEST(testCase, tSmaInsertTest) {
STSma tSma = {0};
STSmaData
*
pSmaData = NULL;
STsdb tsdb = {0};
STSma
tSma = {0};
STSmaData
*
pSmaData = NULL;
STsdb
tsdb = {0};
// init
tSma.intervalUnit = TD_TIME_UNIT_DAY;
...
...
@@ -226,7 +251,7 @@ TEST(testCase, tSmaInsertTest) {
int32_t dataLen = numOfColIds * numOfBlocks * blockSize;
pSmaData = (STSmaData*)malloc(sizeof(STSmaData) + dataLen);
pSmaData = (STSmaData
*)malloc(sizeof(STSmaData) + dataLen);
ASSERT_EQ(pSmaData != NULL, true);
pSmaData->tableUid = 3232329230;
pSmaData->numOfColIds = numOfColIds;
...
...
@@ -234,7 +259,7 @@ TEST(testCase, tSmaInsertTest) {
pSmaData->dataLen = dataLen;
pSmaData->tsWindow.skey = 1640000000;
pSmaData->tsWindow.ekey = 1645788649;
pSmaData->colIds = (col_id_t*)malloc(sizeof(col_id_t) * numOfColIds);
pSmaData->colIds = (col_id_t
*)malloc(sizeof(col_id_t) * numOfColIds);
ASSERT_EQ(pSmaData->colIds != NULL, true);
for (int32_t i = 0; i < numOfColIds; ++i) {
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录