Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
1c135a69
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
1c135a69
编写于
3月 11, 2022
作者:
C
Cary Xu
提交者:
GitHub
3月 11, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #10709 from taosdata/feature/TD-11463-3.0
Feature/td 11463 3.0
上级
ba8d9a79
00f68071
变更
11
展开全部
显示空白变更内容
内联
并排
Showing
11 changed file
with
341 addition
and
392 deletion
+341
-392
include/common/tmsg.h
include/common/tmsg.h
+59
-81
source/dnode/vnode/inc/meta.h
source/dnode/vnode/inc/meta.h
+2
-2
source/dnode/vnode/inc/tsdb.h
source/dnode/vnode/inc/tsdb.h
+10
-13
source/dnode/vnode/src/inc/tsdbFS.h
source/dnode/vnode/src/inc/tsdbFS.h
+5
-8
source/dnode/vnode/src/inc/tsdbFile.h
source/dnode/vnode/src/inc/tsdbFile.h
+11
-0
source/dnode/vnode/src/inc/tsdbSma.h
source/dnode/vnode/src/inc/tsdbSma.h
+8
-6
source/dnode/vnode/src/meta/metaBDBImpl.c
source/dnode/vnode/src/meta/metaBDBImpl.c
+22
-13
source/dnode/vnode/src/tsdb/tsdbSma.c
source/dnode/vnode/src/tsdb/tsdbSma.c
+131
-184
source/dnode/vnode/src/tsdb/tsdbWrite.c
source/dnode/vnode/src/tsdb/tsdbWrite.c
+6
-6
source/dnode/vnode/test/tsdbSmaTest.cpp
source/dnode/vnode/test/tsdbSmaTest.cpp
+86
-78
source/os/src/osFile.c
source/os/src/osFile.c
+1
-1
未找到文件。
include/common/tmsg.h
浏览文件 @
1c135a69
...
...
@@ -1898,23 +1898,18 @@ typedef enum {
}
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
;
int8_t
version
;
// for compatibility(default 0)
int8_t
intervalUnit
;
int8_t
slidingUnit
;
char
indexName
[
TSDB_INDEX_NAME_LEN
];
char
timezone
[
TD_TIMEZONE_LEN
];
uint16_t
nFuncColIds
;
char
timezone
[
TD_TIMEZONE_LEN
];
// sma data is invalid if timezone change.
uint16_t
exprLen
;
uint16_t
tagsFilterLen
;
tb_uid_t
tableUid
;
// super/common table uid
int64_t
indexUid
;
tb_uid_t
tableUid
;
// super/child/common table uid
int64_t
interval
;
int64_t
sliding
;
SFuncColIds
*
funcColIds
;
// sorted funcIds
char
*
expr
;
// sma expression
char
*
tagsFilter
;
}
STSma
;
// Time-range-wise SMA
...
...
@@ -1944,24 +1939,30 @@ int32_t tSerializeSVDropTSmaReq(void** buf, SVDropTSmaReq* pReq);
void
*
tDeserializeSVDropTSmaReq
(
void
*
buf
,
SVDropTSmaReq
*
pReq
);
typedef
struct
{
STimeWindow
tsWindow
;
// [skey, ekey]
uint64_t
tableUid
;
// sub/common table uid
int32_t
numOfBlocks
;
// number of sma blocks for each column, total number is numOfBlocks*numOfColId
int32_t
dataLen
;
// total data length
col_id_t
*
colIds
;
// e.g. 2,4,9,10
col_id_t
numOfColIds
;
// e.g. 4
char
data
[];
// the sma blocks
}
STSmaData
;
// TODO: move to the final location afte schema of STSma/STSmaData defined
static
FORCE_INLINE
void
tdDestroySmaData
(
STSmaData
*
pSmaData
)
{
if
(
pSmaData
)
{
if
(
pSmaData
->
colIds
)
{
tfree
(
pSmaData
->
colIds
);
}
tfree
(
pSmaData
);
}
}
col_id_t
colId
;
uint16_t
blockSize
;
// sma data block size
char
data
[];
}
STSmaColData
;
typedef
struct
{
tb_uid_t
tableUid
;
// super/child/normal table uid
int32_t
dataLen
;
// not including head
char
data
[];
}
STSmaTbData
;
typedef
struct
{
int64_t
indexUid
;
TSKEY
skey
;
// startTS of one interval/sliding
int64_t
interval
;
int32_t
dataLen
;
// not including head
int8_t
intervalUnit
;
char
data
[];
}
STSmaDataWrapper
;
// sma data for a interval/sliding window
// interval/sliding => window
// => window->table->colId
// => 当一个window下所有的表均计算完成时,流计算告知tsdb清除window的过期标记
// RSma: Rollup SMA
typedef
struct
{
...
...
@@ -1984,13 +1985,7 @@ typedef struct {
static
FORCE_INLINE
void
tdDestroyTSma
(
STSma
*
pSma
)
{
if
(
pSma
)
{
if
(
pSma
->
funcColIds
!=
NULL
)
{
for
(
uint16_t
i
=
0
;
i
<
pSma
->
nFuncColIds
;
++
i
)
{
tfree
((
pSma
->
funcColIds
+
i
)
->
colIds
);
}
tfree
(
pSma
->
funcColIds
);
}
tfree
(
pSma
->
expr
);
tfree
(
pSma
->
tagsFilter
);
}
}
...
...
@@ -2009,24 +2004,20 @@ static FORCE_INLINE void tdDestroyTSmaWrapper(STSmaWrapper* pSW) {
static
FORCE_INLINE
int32_t
tEncodeTSma
(
void
**
buf
,
const
STSma
*
pSma
)
{
int32_t
tlen
=
0
;
tlen
+=
taosEncodeFixed
U
8
(
buf
,
pSma
->
version
);
tlen
+=
taosEncodeFixed
U
8
(
buf
,
pSma
->
intervalUnit
);
tlen
+=
taosEncodeFixed
U
8
(
buf
,
pSma
->
slidingUnit
);
tlen
+=
taosEncodeFixed
I
8
(
buf
,
pSma
->
version
);
tlen
+=
taosEncodeFixed
I
8
(
buf
,
pSma
->
intervalUnit
);
tlen
+=
taosEncodeFixed
I
8
(
buf
,
pSma
->
slidingUnit
);
tlen
+=
taosEncodeString
(
buf
,
pSma
->
indexName
);
tlen
+=
taosEncodeString
(
buf
,
pSma
->
timezone
);
tlen
+=
taosEncodeFixedU16
(
buf
,
pSma
->
nFuncColIds
);
tlen
+=
taosEncodeFixedU16
(
buf
,
pSma
->
exprLen
);
tlen
+=
taosEncodeFixedU16
(
buf
,
pSma
->
tagsFilterLen
);
tlen
+=
taosEncodeFixedI64
(
buf
,
pSma
->
indexUid
);
tlen
+=
taosEncodeFixedI64
(
buf
,
pSma
->
tableUid
);
tlen
+=
taosEncodeFixedI64
(
buf
,
pSma
->
interval
);
tlen
+=
taosEncodeFixedI64
(
buf
,
pSma
->
sliding
);
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
));
}
if
(
pSma
->
exprLen
>
0
)
{
tlen
+=
taosEncodeString
(
buf
,
pSma
->
expr
);
}
if
(
pSma
->
tagsFilterLen
>
0
)
{
...
...
@@ -2047,43 +2038,30 @@ static FORCE_INLINE int32_t tEncodeTSmaWrapper(void** buf, const STSmaWrapper* p
}
static
FORCE_INLINE
void
*
tDecodeTSma
(
void
*
buf
,
STSma
*
pSma
)
{
buf
=
taosDecodeFixed
U
8
(
buf
,
&
pSma
->
version
);
buf
=
taosDecodeFixed
U
8
(
buf
,
&
pSma
->
intervalUnit
);
buf
=
taosDecodeFixed
U
8
(
buf
,
&
pSma
->
slidingUnit
);
buf
=
taosDecodeFixed
I
8
(
buf
,
&
pSma
->
version
);
buf
=
taosDecodeFixed
I
8
(
buf
,
&
pSma
->
intervalUnit
);
buf
=
taosDecodeFixed
I
8
(
buf
,
&
pSma
->
slidingUnit
);
buf
=
taosDecodeStringTo
(
buf
,
pSma
->
indexName
);
buf
=
taosDecodeStringTo
(
buf
,
pSma
->
timezone
);
buf
=
taosDecodeFixedU16
(
buf
,
&
pSma
->
nFuncColIds
);
buf
=
taosDecodeFixedU16
(
buf
,
&
pSma
->
exprLen
);
buf
=
taosDecodeFixedU16
(
buf
,
&
pSma
->
tagsFilterLen
);
buf
=
taosDecodeFixedI64
(
buf
,
&
pSma
->
indexUid
);
buf
=
taosDecodeFixedI64
(
buf
,
&
pSma
->
tableUid
);
buf
=
taosDecodeFixedI64
(
buf
,
&
pSma
->
interval
);
buf
=
taosDecodeFixedI64
(
buf
,
&
pSma
->
sliding
);
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
->
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
);
}
if
(
pSma
->
exprLen
>
0
)
{
pSma
->
expr
=
(
char
*
)
calloc
(
pSma
->
exprLen
,
1
);
if
(
pSma
->
expr
!=
NULL
)
{
buf
=
taosDecodeStringTo
(
buf
,
pSma
->
expr
);
}
else
{
tdDestroyTSma
(
pSma
);
return
NULL
;
}
}
else
{
funcColIds
->
colIds
=
NULL
;
}
}
}
else
{
pSma
->
funcColIds
=
NULL
;
pSma
->
expr
=
NULL
;
}
if
(
pSma
->
tagsFilterLen
>
0
)
{
...
...
source/dnode/vnode/inc/meta.h
浏览文件 @
1c135a69
...
...
@@ -58,8 +58,8 @@ STbCfg * metaGetTbInfoByUid(SMeta *pMeta, tb_uid_t uid);
STbCfg
*
metaGetTbInfoByName
(
SMeta
*
pMeta
,
char
*
tbname
,
tb_uid_t
*
uid
);
SSchemaWrapper
*
metaGetTableSchema
(
SMeta
*
pMeta
,
tb_uid_t
uid
,
int32_t
sver
,
bool
isinline
);
STSchema
*
metaGetTbTSchema
(
SMeta
*
pMeta
,
tb_uid_t
uid
,
int32_t
sver
);
STSma
*
metaGetSmaInfoBy
Name
(
SMeta
*
pMeta
,
const
char
*
indexName
);
STSmaWrapper
*
metaGetSmaInfoBy
Uid
(
SMeta
*
pMeta
,
tb_uid_t
uid
);
STSma
*
metaGetSmaInfoBy
Index
(
SMeta
*
pMeta
,
int64_t
indexUid
);
STSmaWrapper
*
metaGetSmaInfoBy
Table
(
SMeta
*
pMeta
,
tb_uid_t
uid
);
SArray
*
metaGetSmaTbUids
(
SMeta
*
pMeta
,
bool
isDup
);
SMTbCursor
*
metaOpenTbCursor
(
SMeta
*
pMeta
);
...
...
source/dnode/vnode/inc/tsdb.h
浏览文件 @
1c135a69
...
...
@@ -91,22 +91,19 @@ int tsdbCommit(STsdb *pTsdb);
* @brief Insert tSma(Time-range-wise SMA) data from stream computing engine
*
* @param pTsdb
* @param param
* @param pData
* @param msg
* @return int32_t
*/
int32_t
tsdbInsertTSmaData
(
STsdb
*
pTsdb
,
STSma
*
param
,
STSmaData
*
pData
);
int32_t
tsdbInsertTSmaData
(
STsdb
*
pTsdb
,
char
*
msg
);
/**
* @brief Insert RSma(Time-range-wise Rollup SMA) data.
*
* @param pTsdb
* @param param
* @param pData
* @param msg
* @return int32_t
*/
int32_t
tsdbInsertRSmaData
(
STsdb
*
pTsdb
,
SRSma
*
param
,
STSmaData
*
pData
);
int32_t
tsdbInsertRSmaData
(
STsdb
*
pTsdb
,
char
*
msg
);
// STsdbCfg
int
tsdbOptionsInit
(
STsdbCfg
*
);
...
...
source/dnode/vnode/src/inc/tsdbFS.h
浏览文件 @
1c135a69
...
...
@@ -42,17 +42,14 @@ typedef struct {
typedef
struct
{
STsdbFSMeta
meta
;
// FS meta
SArray
*
df
;
// data file array
// SArray * v2t100.index_name
SArray
*
smaf
;
// sma data file array v2t1900.index_name
SArray
*
sf
;
// sma data file array v2(t|r)1900.index_name_1
}
SFSStatus
;
/**
* @brief Directory structure of .tsma data files.
*
*
root@cary /vnode2/tsdb $ tree .t
sma/
* .
t
sma/
*
/vnode2/tsdb $ tree .
sma/
* .sma/
* ├── v2t100.index_name_1
* ├── v2t101.index_name_1
* ├── v2t102.index_name_1
...
...
@@ -66,7 +63,7 @@ typedef struct {
* 0 directories, 9 files
*/
typedef
struct
{
typedef
struct
{
pthread_rwlock_t
lock
;
SFSStatus
*
cstatus
;
// current status
...
...
source/dnode/vnode/src/inc/tsdbFile.h
浏览文件 @
1c135a69
...
...
@@ -335,6 +335,17 @@ typedef struct {
SDFile
files
[
TSDB_FILE_MAX
];
}
SDFileSet
;
typedef
struct
{
int
fid
;
int8_t
state
;
uint8_t
ver
;
#if 0
SDFInfo info;
#endif
STfsFile
f
;
TdFilePtr
pFile
;
}
SSFile
;
// files split by days with fid
#define TSDB_LATEST_FSET_VER 0
#define TSDB_FSET_FID(s) ((s)->fid)
...
...
source/dnode/vnode/src/inc/tsdbSma.h
浏览文件 @
1c135a69
...
...
@@ -19,26 +19,28 @@
typedef
struct
SSmaStat
SSmaStat
;
// insert/update interface
int32_t
tsdbInsertTSmaDataImpl
(
STsdb
*
pTsdb
,
STSma
*
param
,
STSmaData
*
pData
);
int32_t
tsdbInsertRSmaDataImpl
(
STsdb
*
pTsdb
,
SRSma
*
param
,
STSmaData
*
pData
);
int32_t
tsdbInsertTSmaDataImpl
(
STsdb
*
pTsdb
,
char
*
msg
);
int32_t
tsdbInsertRSmaDataImpl
(
STsdb
*
pTsdb
,
char
*
msg
);
// query interface
// TODO: This is the basic params, and should wrap the params to a queryHandle.
int32_t
tsdbGetTSmaDataImpl
(
STsdb
*
pTsdb
,
STSma
*
param
,
STSmaData
*
pData
,
STimeWindow
*
queryWin
,
int32_t
nMaxResult
);
int32_t
tsdbGetTSmaDataImpl
(
STsdb
*
pTsdb
,
STSma
DataWrapper
*
pData
,
STimeWindow
*
queryWin
,
int32_t
nMaxResult
);
// management interface
int32_t
tsdbUpdateExpiredWindow
(
STsdb
*
pTsdb
,
char
*
msg
);
int32_t
tsdbDestroySmaState
(
SSmaStat
*
pSmaStat
);
#if 0
int32_t tsdbGetTSmaStatus(STsdb *pTsdb, STSma *param, void *result);
int32_t tsdbRemoveTSmaData(STsdb *pTsdb, STSma *param, STimeWindow *pWin);
int32_t
tsdbDestroySmaState
(
SSmaStat
*
pSmaStat
);
#endif
// internal func
static
FORCE_INLINE
int32_t
tsdbEncodeTSmaKey
(
uint64
_t
tableUid
,
col_id_t
colId
,
TSKEY
tsKey
,
void
**
pData
)
{
static
FORCE_INLINE
int32_t
tsdbEncodeTSmaKey
(
tb_uid
_t
tableUid
,
col_id_t
colId
,
TSKEY
tsKey
,
void
**
pData
)
{
int32_t
len
=
0
;
len
+=
taosEncodeFixed
U
64
(
pData
,
tableUid
);
len
+=
taosEncodeFixed
I
64
(
pData
,
tableUid
);
len
+=
taosEncodeFixedU16
(
pData
,
colId
);
len
+=
taosEncodeFixedI64
(
pData
,
tsKey
);
return
len
;
...
...
source/dnode/vnode/src/meta/metaBDBImpl.c
浏览文件 @
1c135a69
...
...
@@ -227,21 +227,27 @@ int metaRemoveTableFromDb(SMeta *pMeta, tb_uid_t uid) {
}
int
metaSaveSmaToDB
(
SMeta
*
pMeta
,
STSma
*
pSmaCfg
)
{
char
buf
[
512
]
=
{
0
};
// TODO: may overflow
void
*
pBuf
=
NULL
;
//
char buf[512] = {0}; // TODO: may overflow
void
*
pBuf
=
NULL
,
*
qBuf
=
NULL
;
DBT
key1
=
{
0
},
value1
=
{
0
};
{
// save sma info
pBuf
=
buf
;
int32_t
len
=
tEncodeTSma
(
NULL
,
pSmaCfg
);
pBuf
=
calloc
(
len
,
1
);
if
(
pBuf
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
}
key1
.
data
=
pSmaCfg
->
indexName
;
key1
.
size
=
s
trlen
(
key1
.
data
);
key1
.
data
=
(
void
*
)
&
pSmaCfg
->
indexUid
;
key1
.
size
=
s
izeof
(
pSmaCfg
->
indexUid
);
tEncodeTSma
(
&
pBuf
,
pSmaCfg
);
qBuf
=
pBuf
;
tEncodeTSma
(
&
qBuf
,
pSmaCfg
);
value1
.
data
=
b
uf
;
value1
.
size
=
POINTER_DISTANCE
(
pBuf
,
b
uf
);
value1
.
data
=
pB
uf
;
value1
.
size
=
POINTER_DISTANCE
(
qBuf
,
pB
uf
);
value1
.
app_data
=
pSmaCfg
;
}
...
...
@@ -609,7 +615,7 @@ STbCfg *metaGetTbInfoByName(SMeta *pMeta, char *tbname, tb_uid_t *uid) {
return
pTbCfg
;
}
STSma
*
metaGetSmaInfoBy
Name
(
SMeta
*
pMeta
,
const
char
*
indexName
)
{
STSma
*
metaGetSmaInfoBy
Index
(
SMeta
*
pMeta
,
int64_t
indexUid
)
{
STSma
*
pCfg
=
NULL
;
SMetaDB
*
pDB
=
pMeta
->
pDB
;
DBT
key
=
{
0
};
...
...
@@ -617,8 +623,8 @@ STSma *metaGetSmaInfoByName(SMeta *pMeta, const char *indexName) {
int
ret
;
// Set key/value
key
.
data
=
(
void
*
)
indexName
;
key
.
size
=
s
trlen
(
indexName
);
key
.
data
=
(
void
*
)
&
indexUid
;
key
.
size
=
s
izeof
(
indexUid
);
// Query
metaDBRLock
(
pDB
);
...
...
@@ -634,7 +640,10 @@ STSma *metaGetSmaInfoByName(SMeta *pMeta, const char *indexName) {
return
NULL
;
}
tDecodeTSma
(
value
.
data
,
pCfg
);
if
(
tDecodeTSma
(
value
.
data
,
pCfg
)
==
NULL
)
{
tfree
(
pCfg
);
return
NULL
;
}
return
pCfg
;
}
...
...
@@ -871,7 +880,7 @@ const char *metaSmaCursorNext(SMSmaCursor *pCur) {
}
}
STSmaWrapper
*
metaGetSmaInfoBy
Uid
(
SMeta
*
pMeta
,
tb_uid_t
uid
)
{
STSmaWrapper
*
metaGetSmaInfoBy
Table
(
SMeta
*
pMeta
,
tb_uid_t
uid
)
{
STSmaWrapper
*
pSW
=
NULL
;
pSW
=
calloc
(
sizeof
(
*
pSW
),
1
);
...
...
source/dnode/vnode/src/tsdb/tsdbSma.c
浏览文件 @
1c135a69
此差异已折叠。
点击以展开。
source/dnode/vnode/src/tsdb/tsdbWrite.c
浏览文件 @
1c135a69
...
...
@@ -39,13 +39,13 @@ int tsdbInsertData(STsdb *pTsdb, SSubmitReq *pMsg, SSubmitRsp *pRsp) {
*
* @param pTsdb
* @param param
* @param
pData
* @param
msg
* @return int32_t
* TODO: Who is responsible for resource allocate and release?
*/
int32_t
tsdbInsertTSmaData
(
STsdb
*
pTsdb
,
STSma
*
param
,
STSmaData
*
pData
)
{
int32_t
tsdbInsertTSmaData
(
STsdb
*
pTsdb
,
char
*
msg
)
{
int32_t
code
=
TSDB_CODE_SUCCESS
;
if
((
code
=
tsdbInsertTSmaDataImpl
(
pTsdb
,
param
,
pData
))
<
0
)
{
if
((
code
=
tsdbInsertTSmaDataImpl
(
pTsdb
,
msg
))
<
0
)
{
tsdbWarn
(
"vgId:%d insert tSma data failed since %s"
,
REPO_ID
(
pTsdb
),
tstrerror
(
terrno
));
}
return
code
;
...
...
@@ -56,12 +56,12 @@ int32_t tsdbInsertTSmaData(STsdb *pTsdb, STSma *param, STSmaData *pData) {
*
* @param pTsdb
* @param param
* @param
pData
* @param
msg
* @return int32_t
*/
int32_t
tsdbInsertRSmaData
(
STsdb
*
pTsdb
,
SRSma
*
param
,
STSmaData
*
pData
)
{
int32_t
tsdbInsertRSmaData
(
STsdb
*
pTsdb
,
char
*
msg
)
{
int32_t
code
=
TSDB_CODE_SUCCESS
;
if
((
code
=
tsdbInsertRSmaDataImpl
(
pTsdb
,
param
,
pData
))
<
0
)
{
if
((
code
=
tsdbInsertRSmaDataImpl
(
pTsdb
,
msg
))
<
0
)
{
tsdbWarn
(
"vgId:%d insert rSma data failed since %s"
,
REPO_ID
(
pTsdb
),
tstrerror
(
terrno
));
}
return
code
;
...
...
source/dnode/vnode/test/tsdbSmaTest.cpp
浏览文件 @
1c135a69
...
...
@@ -43,20 +43,8 @@ TEST(testCase, tSmaEncodeDecodeTest) {
tSma
.
sliding
=
0
;
tstrncpy
(
tSma
.
indexName
,
"sma_index_test"
,
TSDB_INDEX_NAME_LEN
);
tstrncpy
(
tSma
.
timezone
,
"Asia/Shanghai"
,
TD_TIMEZONE_LEN
);
tSma
.
indexUid
=
2345678910
;
tSma
.
tableUid
=
1234567890
;
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
};
uint32_t
bufLen
=
tEncodeTSmaWrapper
(
NULL
,
&
tSmaWrapper
);
...
...
@@ -85,35 +73,31 @@ TEST(testCase, tSmaEncodeDecodeTest) {
EXPECT_EQ
(
pSma
->
slidingUnit
,
qSma
->
slidingUnit
);
EXPECT_STRCASEEQ
(
pSma
->
indexName
,
qSma
->
indexName
);
EXPECT_STRCASEEQ
(
pSma
->
timezone
,
qSma
->
timezone
);
EXPECT_EQ
(
pSma
->
nFuncColIds
,
qSma
->
nFuncColIds
);
EXPECT_EQ
(
pSma
->
indexUid
,
qSma
->
indexUid
);
EXPECT_EQ
(
pSma
->
tableUid
,
qSma
->
tableUid
);
EXPECT_EQ
(
pSma
->
interval
,
qSma
->
interval
);
EXPECT_EQ
(
pSma
->
sliding
,
qSma
->
sliding
);
EXPECT_EQ
(
pSma
->
exprLen
,
qSma
->
exprLen
);
EXPECT_STRCASEEQ
(
pSma
->
expr
,
qSma
->
expr
);
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
));
}
}
}
// resource release
tdDestroyTSma
(
&
tSma
);
tdDestroyTSmaWrapper
(
&
dstTSmaWrapper
);
}
#if 1
TEST
(
testCase
,
tSma_DB_Put_Get_Del_Test
)
{
const
char
*
smaIndexName1
=
"sma_index_test_1"
;
const
char
*
smaIndexName2
=
"sma_index_test_2"
;
const
char
*
timeZone
=
"Asia/Shanghai"
;
const
char
*
timezone
=
"Asia/Shanghai"
;
const
char
*
expr
=
"select count(a,b, top 20), from table interval 1d, sliding 1h;"
;
const
char
*
tagsFilter
=
"I'm tags filter"
;
const
char
*
smaTestDir
=
"./smaTest"
;
const
uint64_t
tbUid
=
1234567890
;
const
tb_uid_t
tbUid
=
1234567890
;
const
int64_t
indexUid1
=
2000000001
;
const
int64_t
indexUid2
=
2000000002
;
const
uint32_t
nCntTSma
=
2
;
// encode
STSma
tSma
=
{
0
};
...
...
@@ -122,22 +106,15 @@ TEST(testCase, tSma_DB_Put_Get_Del_Test) {
tSma
.
interval
=
1
;
tSma
.
slidingUnit
=
TD_TIME_UNIT_HOUR
;
tSma
.
sliding
=
0
;
tSma
.
indexUid
=
indexUid1
;
tstrncpy
(
tSma
.
indexName
,
smaIndexName1
,
TSDB_INDEX_NAME_LEN
);
tstrncpy
(
tSma
.
timezone
,
time
Z
one
,
TD_TIMEZONE_LEN
);
tstrncpy
(
tSma
.
timezone
,
time
z
one
,
TD_TIMEZONE_LEN
);
tSma
.
tableUid
=
tbUid
;
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
.
exprLen
=
strlen
(
expr
);
tSma
.
expr
=
(
char
*
)
calloc
(
tSma
.
exprLen
+
1
,
1
);
tstrncpy
(
tSma
.
expr
,
expr
,
tSma
.
exprLen
+
1
);
tSma
.
tagsFilterLen
=
strlen
(
tagsFilter
);
tSma
.
tagsFilter
=
(
char
*
)
calloc
(
tSma
.
tagsFilterLen
+
1
,
1
);
tstrncpy
(
tSma
.
tagsFilter
,
tagsFilter
,
tSma
.
tagsFilterLen
+
1
);
...
...
@@ -151,8 +128,9 @@ TEST(testCase, tSma_DB_Put_Get_Del_Test) {
pMeta
=
metaOpen
(
smaTestDir
,
pMetaCfg
,
NULL
);
assert
(
pMeta
!=
NULL
);
// save index 1
metaSaveSmaToDB
(
pMeta
,
pSmaCfg
);
EXPECT_EQ
(
metaSaveSmaToDB
(
pMeta
,
pSmaCfg
),
0
);
pSmaCfg
->
indexUid
=
indexUid2
;
tstrncpy
(
pSmaCfg
->
indexName
,
smaIndexName2
,
TSDB_INDEX_NAME_LEN
);
pSmaCfg
->
version
=
1
;
pSmaCfg
->
intervalUnit
=
TD_TIME_UNIT_HOUR
;
...
...
@@ -161,24 +139,26 @@ TEST(testCase, tSma_DB_Put_Get_Del_Test) {
pSmaCfg
->
sliding
=
5
;
// save index 2
metaSaveSmaToDB
(
pMeta
,
pSmaCfg
);
EXPECT_EQ
(
metaSaveSmaToDB
(
pMeta
,
pSmaCfg
),
0
);
// get value by indexName
STSma
*
qSmaCfg
=
NULL
;
qSmaCfg
=
metaGetSmaInfoBy
Name
(
pMeta
,
smaIndexName
1
);
qSmaCfg
=
metaGetSmaInfoBy
Index
(
pMeta
,
indexUid
1
);
assert
(
qSmaCfg
!=
NULL
);
printf
(
"name1 = %s
\n
"
,
qSmaCfg
->
indexName
);
printf
(
"timezone1 = %s
\n
"
,
qSmaCfg
->
timezone
);
printf
(
"expr1 = %s
\n
"
,
qSmaCfg
->
expr
!=
NULL
?
qSmaCfg
->
expr
:
""
);
printf
(
"tagsFilter1 = %s
\n
"
,
qSmaCfg
->
tagsFilter
!=
NULL
?
qSmaCfg
->
tagsFilter
:
""
);
EXPECT_STRCASEEQ
(
qSmaCfg
->
indexName
,
smaIndexName1
);
EXPECT_EQ
(
qSmaCfg
->
tableUid
,
tSma
.
tableUid
);
tdDestroyTSma
(
qSmaCfg
);
tfree
(
qSmaCfg
);
qSmaCfg
=
metaGetSmaInfoBy
Name
(
pMeta
,
smaIndexName
2
);
qSmaCfg
=
metaGetSmaInfoBy
Index
(
pMeta
,
indexUid
2
);
assert
(
qSmaCfg
!=
NULL
);
printf
(
"name2 = %s
\n
"
,
qSmaCfg
->
indexName
);
printf
(
"timezone2 = %s
\n
"
,
qSmaCfg
->
timezone
);
printf
(
"expr2 = %s
\n
"
,
qSmaCfg
->
expr
!=
NULL
?
qSmaCfg
->
expr
:
""
);
printf
(
"tagsFilter2 = %s
\n
"
,
qSmaCfg
->
tagsFilter
!=
NULL
?
qSmaCfg
->
tagsFilter
:
""
);
EXPECT_STRCASEEQ
(
qSmaCfg
->
indexName
,
smaIndexName2
);
EXPECT_EQ
(
qSmaCfg
->
interval
,
tSma
.
interval
);
...
...
@@ -201,17 +181,21 @@ TEST(testCase, tSma_DB_Put_Get_Del_Test) {
metaCloseSmaCurosr
(
pSmaCur
);
// get wrapper by table uid
STSmaWrapper
*
pSW
=
metaGetSmaInfoBy
Uid
(
pMeta
,
tbUid
);
STSmaWrapper
*
pSW
=
metaGetSmaInfoBy
Table
(
pMeta
,
tbUid
);
assert
(
pSW
!=
NULL
);
EXPECT_EQ
(
pSW
->
number
,
nCntTSma
);
EXPECT_STRCASEEQ
(
pSW
->
tSma
->
indexName
,
smaIndexName1
);
EXPECT_STRCASEEQ
(
pSW
->
tSma
->
timezone
,
timeZone
);
EXPECT_STRCASEEQ
(
pSW
->
tSma
->
timezone
,
timezone
);
EXPECT_STRCASEEQ
(
pSW
->
tSma
->
expr
,
expr
);
EXPECT_STRCASEEQ
(
pSW
->
tSma
->
tagsFilter
,
tagsFilter
);
EXPECT_EQ
(
pSW
->
tSma
->
tableUid
,
tSma
.
tableUid
);
EXPECT_EQ
(
pSW
->
tSma
->
indexUid
,
indexUid1
);
EXPECT_EQ
(
pSW
->
tSma
->
tableUid
,
tbUid
);
EXPECT_STRCASEEQ
((
pSW
->
tSma
+
1
)
->
indexName
,
smaIndexName2
);
EXPECT_STRCASEEQ
((
pSW
->
tSma
+
1
)
->
timezone
,
timeZone
);
EXPECT_STRCASEEQ
((
pSW
->
tSma
+
1
)
->
timezone
,
timezone
);
EXPECT_STRCASEEQ
((
pSW
->
tSma
+
1
)
->
expr
,
expr
);
EXPECT_STRCASEEQ
((
pSW
->
tSma
+
1
)
->
tagsFilter
,
tagsFilter
);
EXPECT_EQ
((
pSW
->
tSma
+
1
)
->
tableUid
,
tSma
.
tableUid
);
EXPECT_EQ
((
pSW
->
tSma
+
1
)
->
indexUid
,
indexUid2
);
EXPECT_EQ
((
pSW
->
tSma
+
1
)
->
tableUid
,
tbUid
);
tdDestroyTSmaWrapper
(
pSW
);
tfree
(
pSW
);
...
...
@@ -233,44 +217,68 @@ TEST(testCase, tSma_DB_Put_Get_Del_Test) {
tdDestroyTSma
(
&
tSma
);
metaClose
(
pMeta
);
}
#endif
#if
0
#if
1
TEST
(
testCase
,
tSmaInsertTest
)
{
STSma tSma = {0}
;
STSmaData *pSmaData = NULL;
const
int64_t
indexUid
=
2000000002
;
STSmaData
Wrapper
*
pSmaData
=
NULL
;
STsdb
tsdb
=
{
0
};
STsdbCfg
*
pCfg
=
&
tsdb
.
config
;
pCfg
->
daysPerFile
=
1
;
// init
tSma.intervalUnit = TD_TIME_UNIT_DAY;
tSma.interval = 1;
tSma.numOfFuncIds = 5; // sum/min/max/avg/last
int32_t blockSize = tSma.numOfFuncIds * sizeof(int64_t);
int32_t numOfColIds = 3;
int32_t numOfBlocks = 10;
int32_t dataLen = numOfColIds * numOfBlocks * blockSize;
pSmaData = (STSmaData *)malloc(sizeof(STSmaData) + dataLen);
ASSERT_EQ(pSmaData != NULL, true);
pSmaData->tableUid = 3232329230;
pSmaData->numOfColIds = numOfColIds;
pSmaData->numOfBlocks = numOfBlocks;
pSmaData->dataLen = dataLen;
pSmaData->tsWindow.skey = 1640000000;
pSmaData->tsWindow.ekey = 1645788649;
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) {
*(pSmaData->colIds + i) = (i + PRIMARYKEY_TIMESTAMP_COL_ID);
int32_t
allocCnt
=
0
;
int32_t
allocStep
=
40960
;
int32_t
buffer
=
4096
;
void
*
buf
=
NULL
;
EXPECT_EQ
(
tsdbMakeRoom
(
&
buf
,
allocStep
),
0
);
int32_t
bufSize
=
taosTSizeof
(
buf
);
int32_t
numOfTables
=
25
;
col_id_t
numOfCols
=
4096
;
EXPECT_GT
(
numOfCols
,
0
);
pSmaData
=
(
STSmaDataWrapper
*
)
buf
;
printf
(
">> allocate [%d] time to %d and addr is %p
\n
"
,
++
allocCnt
,
bufSize
,
pSmaData
);
pSmaData
->
skey
=
1646987196
;
pSmaData
->
interval
=
10
;
pSmaData
->
intervalUnit
=
TD_TIME_UNIT_MINUTE
;
pSmaData
->
indexUid
=
indexUid
;
int32_t
len
=
sizeof
(
STSmaDataWrapper
);
for
(
int32_t
t
=
0
;
t
<
numOfTables
;
++
t
)
{
STSmaTbData
*
pTbData
=
(
STSmaTbData
*
)
POINTER_SHIFT
(
pSmaData
,
len
);
pTbData
->
tableUid
=
t
;
int32_t
tableDataLen
=
sizeof
(
STSmaTbData
);
for
(
col_id_t
c
=
0
;
c
<
numOfCols
;
++
c
)
{
if
(
bufSize
-
len
-
tableDataLen
<
buffer
)
{
EXPECT_EQ
(
tsdbMakeRoom
(
&
buf
,
bufSize
+
allocStep
),
0
);
pSmaData
=
(
STSmaDataWrapper
*
)
buf
;
pTbData
=
(
STSmaTbData
*
)
POINTER_SHIFT
(
pSmaData
,
len
);
bufSize
=
taosTSizeof
(
buf
);
printf
(
">> allocate [%d] time to %d and addr is %p
\n
"
,
++
allocCnt
,
bufSize
,
pSmaData
);
}
STSmaColData
*
pColData
=
(
STSmaColData
*
)
POINTER_SHIFT
(
pSmaData
,
len
+
tableDataLen
);
pColData
->
colId
=
c
+
PRIMARYKEY_TIMESTAMP_COL_ID
;
pColData
->
blockSize
=
((
c
&
1
)
==
0
)
?
8
:
16
;
// TODO: fill col data
tableDataLen
+=
(
sizeof
(
STSmaColData
)
+
pColData
->
blockSize
);
}
pTbData
->
dataLen
=
(
tableDataLen
-
sizeof
(
STSmaTbData
));
len
+=
tableDataLen
;
// printf("bufSize=%d, len=%d, len of table[%d]=%d\n", bufSize, len, t, tableDataLen);
}
pSmaData
->
dataLen
=
(
len
-
sizeof
(
STSmaDataWrapper
));
EXPECT_GE
(
bufSize
,
pSmaData
->
dataLen
);
// execute
EXPECT_EQ(tsdbInsertTSmaData(&tsdb,
&tSma,
pSmaData), TSDB_CODE_SUCCESS);
EXPECT_EQ
(
tsdbInsertTSmaData
(
&
tsdb
,
(
char
*
)
pSmaData
),
TSDB_CODE_SUCCESS
);
// release
t
dDestroySmaData(pSmaData
);
t
aosTZfree
(
buf
);
}
#endif
...
...
source/os/src/osFile.c
浏览文件 @
1c135a69
...
...
@@ -265,7 +265,7 @@ TdFilePtr taosOpenFile(const char *path, int32_t tdFileOptions) {
return
NULL
;
}
#if FILE_WITH_LOCK
pthread_rwlock_init
(
&
(
pFile
->
rwlock
),
NULL
);
pthread_rwlock_init
(
&
(
pFile
->
rwlock
),
NULL
);
#endif
pFile
->
fd
=
fd
;
pFile
->
fp
=
fp
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录