Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
156b0cfe
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看板
提交
156b0cfe
编写于
5月 17, 2022
作者:
C
Cary Xu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: tsma logic optimization
上级
b74c0cf1
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
89 addition
and
99 deletion
+89
-99
include/common/tmsg.h
include/common/tmsg.h
+13
-0
source/dnode/vnode/src/inc/sma.h
source/dnode/vnode/src/inc/sma.h
+1
-1
source/dnode/vnode/src/inc/tsdb.h
source/dnode/vnode/src/inc/tsdb.h
+1
-1
source/dnode/vnode/src/meta/metaEntry.c
source/dnode/vnode/src/meta/metaEntry.c
+4
-4
source/dnode/vnode/src/meta/metaQuery.c
source/dnode/vnode/src/meta/metaQuery.c
+0
-7
source/dnode/vnode/src/sma/smaTDBImpl.c
source/dnode/vnode/src/sma/smaTDBImpl.c
+8
-6
source/dnode/vnode/src/sma/smaTimeRange.c
source/dnode/vnode/src/sma/smaTimeRange.c
+50
-69
source/dnode/vnode/src/tsdb/tsdbOpen.c
source/dnode/vnode/src/tsdb/tsdbOpen.c
+3
-2
source/dnode/vnode/src/tsdb/tsdbRead.c
source/dnode/vnode/src/tsdb/tsdbRead.c
+3
-3
source/dnode/vnode/src/tsdb/tsdbSma.c
source/dnode/vnode/src/tsdb/tsdbSma.c
+5
-5
source/dnode/vnode/src/vnd/vnodeOpen.c
source/dnode/vnode/src/vnd/vnodeOpen.c
+1
-1
未找到文件。
include/common/tmsg.h
浏览文件 @
156b0cfe
...
...
@@ -403,6 +403,19 @@ static FORCE_INLINE int32_t tDecodeSSchemaWrapper(SDecoder* pDecoder, SSchemaWra
return
0
;
}
static
FORCE_INLINE
int32_t
tDecodeSSchemaWrapperEx
(
SDecoder
*
pDecoder
,
SSchemaWrapper
*
pSW
)
{
if
(
tDecodeI32v
(
pDecoder
,
&
pSW
->
nCols
)
<
0
)
return
-
1
;
if
(
tDecodeI32v
(
pDecoder
,
&
pSW
->
sver
)
<
0
)
return
-
1
;
pSW
->
pSchema
=
(
SSchema
*
)
tDecoderMalloc
(
pDecoder
,
pSW
->
nCols
*
sizeof
(
SSchema
));
if
(
pSW
->
pSchema
==
NULL
)
return
-
1
;
for
(
int32_t
i
=
0
;
i
<
pSW
->
nCols
;
i
++
)
{
if
(
tDecodeSSchema
(
pDecoder
,
&
pSW
->
pSchema
[
i
])
<
0
)
return
-
1
;
}
return
0
;
}
STSchema
*
tdGetSTSChemaFromSSChema
(
SSchema
**
pSchema
,
int32_t
nCols
);
typedef
struct
{
...
...
source/dnode/vnode/src/inc/sma.h
浏览文件 @
156b0cfe
...
...
@@ -70,7 +70,7 @@ struct SSmaStatItem {
* N.B. only applicable to tsma
*/
int8_t
state
;
// ETsdbSmaStat
SHashObj
*
expiredWindows
;
// key: skey of time window, value:
N/A
SHashObj
*
expiredWindows
;
// key: skey of time window, value:
version
STSma
*
pTSma
;
// cache schema
};
...
...
source/dnode/vnode/src/inc/tsdb.h
浏览文件 @
156b0cfe
...
...
@@ -60,7 +60,7 @@ typedef struct {
TSKEY
minKey
;
}
SRtn
;
#define TSDB_DATA_DIR_LEN 6
#define TSDB_DATA_DIR_LEN 6
// adapt accordingly
struct
STsdb
{
char
*
path
;
SVnode
*
pVnode
;
...
...
source/dnode/vnode/src/meta/metaEntry.c
浏览文件 @
156b0cfe
...
...
@@ -56,8 +56,8 @@ int metaDecodeEntry(SDecoder *pCoder, SMetaEntry *pME) {
if
(
tDecodeCStr
(
pCoder
,
&
pME
->
name
)
<
0
)
return
-
1
;
if
(
pME
->
type
==
TSDB_SUPER_TABLE
)
{
if
(
tDecodeSSchemaWrapper
(
pCoder
,
&
pME
->
stbEntry
.
schema
)
<
0
)
return
-
1
;
if
(
tDecodeSSchemaWrapper
(
pCoder
,
&
pME
->
stbEntry
.
schemaTag
)
<
0
)
return
-
1
;
if
(
tDecodeSSchemaWrapper
Ex
(
pCoder
,
&
pME
->
stbEntry
.
schema
)
<
0
)
return
-
1
;
if
(
tDecodeSSchemaWrapper
Ex
(
pCoder
,
&
pME
->
stbEntry
.
schemaTag
)
<
0
)
return
-
1
;
}
else
if
(
pME
->
type
==
TSDB_CHILD_TABLE
)
{
if
(
tDecodeI64
(
pCoder
,
&
pME
->
ctbEntry
.
ctime
)
<
0
)
return
-
1
;
if
(
tDecodeI32
(
pCoder
,
&
pME
->
ctbEntry
.
ttlDays
)
<
0
)
return
-
1
;
...
...
@@ -67,9 +67,9 @@ int metaDecodeEntry(SDecoder *pCoder, SMetaEntry *pME) {
if
(
tDecodeI64
(
pCoder
,
&
pME
->
ntbEntry
.
ctime
)
<
0
)
return
-
1
;
if
(
tDecodeI32
(
pCoder
,
&
pME
->
ntbEntry
.
ttlDays
)
<
0
)
return
-
1
;
if
(
tDecodeI32v
(
pCoder
,
&
pME
->
ntbEntry
.
ncid
)
<
0
)
return
-
1
;
if
(
tDecodeSSchemaWrapper
(
pCoder
,
&
pME
->
ntbEntry
.
schema
)
<
0
)
return
-
1
;
if
(
tDecodeSSchemaWrapper
Ex
(
pCoder
,
&
pME
->
ntbEntry
.
schema
)
<
0
)
return
-
1
;
}
else
if
(
pME
->
type
==
TSDB_TSMA_TABLE
)
{
pME
->
smaEntry
.
tsma
=
t
aosMemoryCalloc
(
1
,
sizeof
(
STSma
));
pME
->
smaEntry
.
tsma
=
t
DecoderMalloc
(
pCoder
,
sizeof
(
STSma
));
if
(
!
pME
->
smaEntry
.
tsma
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
...
...
source/dnode/vnode/src/meta/metaQuery.c
浏览文件 @
156b0cfe
...
...
@@ -394,11 +394,6 @@ STSmaWrapper *metaGetSmaInfoByTable(SMeta *pMeta, tb_uid_t uid, bool deepCopy) {
goto
_err
;
}
SMSmaCursor
*
pCur
=
metaOpenSmaCursor
(
pMeta
,
uid
);
if
(
pCur
==
NULL
)
{
goto
_err
;
}
SMetaReader
mr
=
{
0
};
metaReaderInit
(
&
mr
,
pMeta
,
0
);
int64_t
smaId
;
...
...
@@ -442,12 +437,10 @@ STSmaWrapper *metaGetSmaInfoByTable(SMeta *pMeta, tb_uid_t uid, bool deepCopy) {
metaReaderClear
(
&
mr
);
taosArrayDestroy
(
pSmaIds
);
metaCloseSmaCursor
(
pCur
);
return
pSW
;
_err:
metaReaderClear
(
&
mr
);
taosArrayDestroy
(
pSmaIds
);
metaCloseSmaCursor
(
pCur
);
tdFreeTSmaWrapper
(
pSW
,
deepCopy
);
return
NULL
;
}
...
...
source/dnode/vnode/src/sma/smaTDBImpl.c
浏览文件 @
156b0cfe
...
...
@@ -55,12 +55,13 @@ static inline int tdSmaKeyCmpr(const void *arg1, int len1, const void *arg2, int
}
static
int32_t
smaOpenDBDb
(
TDB
**
ppDB
,
TENV
*
pEnv
,
const
char
*
pFName
)
{
int
ret
;
tdb_cmpr_fn_t
compFunc
;
// Create a database
compFunc
=
tdSmaKeyCmpr
;
ret
=
tdbDbOpen
(
pFName
,
-
1
,
-
1
,
compFunc
,
pEnv
,
ppDB
);
if
(
tdbDbOpen
(
pFName
,
-
1
,
-
1
,
compFunc
,
pEnv
,
ppDB
)
<
0
)
{
return
-
1
;
}
return
0
;
}
...
...
@@ -76,7 +77,7 @@ int32_t smaOpenDBF(TENV *pEnv, SDBFile *pDBF) {
// Open DBF
if
(
smaOpenDBDb
(
&
(
pDBF
->
pDB
),
pEnv
,
pDBF
->
path
)
<
0
)
{
terrno
=
TSDB_CODE_TDB_INIT_FAILED
;
smaError
(
"failed to open DBF: %s"
,
pDBF
->
path
)
;
smaCloseDBDb
(
pDBF
->
pDB
);
return
-
1
;
}
...
...
@@ -97,9 +98,10 @@ int32_t smaCloseDBF(SDBFile *pDBF) {
int32_t
smaSaveSmaToDB
(
SDBFile
*
pDBF
,
void
*
pKey
,
int32_t
keyLen
,
void
*
pVal
,
int32_t
valLen
,
TXN
*
txn
)
{
int32_t
ret
;
ret
=
tdbDbInsert
(
pDBF
->
pDB
,
pKey
,
keyLen
,
pVal
,
valLen
,
txn
);
printf
(
"save tsma data into %s, keyLen:%d valLen:%d txn:%p
\n
"
,
pDBF
->
path
,
keyLen
,
valLen
,
txn
);
ret
=
tdbDbUpsert
(
pDBF
->
pDB
,
pKey
,
keyLen
,
pVal
,
valLen
,
txn
);
if
(
ret
<
0
)
{
smaError
(
"failed to
create insert
sma data into db, ret = %d"
,
ret
);
smaError
(
"failed to
upsert t
sma data into db, ret = %d"
,
ret
);
return
-
1
;
}
...
...
@@ -113,7 +115,7 @@ void *smaGetSmaDataByKey(SDBFile *pDBF, const void *pKey, int32_t keyLen, int32_
ret
=
tdbDbGet
(
pDBF
->
pDB
,
pKey
,
keyLen
,
&
pVal
,
valLen
);
if
(
ret
<
0
)
{
smaError
(
"failed to get sma data from db, ret = %d"
,
ret
);
smaError
(
"failed to get
t
sma data from db, ret = %d"
,
ret
);
return
NULL
;
}
...
...
source/dnode/vnode/src/sma/smaTimeRange.c
浏览文件 @
156b0cfe
...
...
@@ -16,21 +16,22 @@
#include "sma.h"
#include "tsdb.h"
typedef
STsdbCfg
STSmaKeepCfg
;
#undef _TEST_SMA_PRINT_DEBUG_LOG_
#define SMA_STORAGE_TSDB_
DAYS 3
0
#define SMA_STORAGE_TSDB_TIMES 10
#define SMA_STORAGE_SPLIT_
HOURS 24
#define SMA_KEY_LEN
16
// TSKEY+groupId 8+8
#define SMA_DROP_EXPIRED_TIME
10
// default is 10 seconds
#define SMA_STORAGE_TSDB_
MINUTES 8640
0
#define SMA_STORAGE_TSDB_TIMES
10
#define SMA_STORAGE_SPLIT_
FACTOR 144 // least records in tsma file
#define SMA_KEY_LEN
16
// TSKEY+groupId 8+8
#define SMA_DROP_EXPIRED_TIME
10
// default is 10 seconds
#define SMA_STATE_ITEM_HASH_SLOT 32
typedef
struct
{
SSma
*
pSma
;
SDBFile
dFile
;
const
SArray
*
pDataBlocks
;
// sma data
int
32
_t
interval
;
// interval with the precision of DB
int
64
_t
interval
;
// interval with the precision of DB
}
STSmaWriteH
;
typedef
struct
{
...
...
@@ -42,10 +43,10 @@ typedef struct {
STsdb
*
pTsdb
;
SSma
*
pSma
;
SDBFile
dFile
;
int
32
_t
interval
;
// interval with the precision of DB
int
64
_t
interval
;
// interval with the precision of DB
int32_t
blockSize
;
// size of SMA block item
int32_t
days
;
int8_t
storageLevel
;
int8_t
days
;
SmaFsIter
smaFsIter
;
}
STSmaReadH
;
...
...
@@ -58,9 +59,9 @@ typedef enum {
// static func
static
int64_t
tdGetIntervalByPrecision
(
int64_t
interval
,
uint8_t
intervalUnit
,
int8_t
precision
,
bool
adjusted
);
static
int32_t
tdGetSmaStorageLevel
(
int64_t
interval
,
int8_t
intervalUnit
);
static
int32_t
tdGetSmaStorageLevel
(
STSmaKeepCfg
*
pCfg
,
int64_t
interval
);
static
int32_t
tdInitTSmaWriteH
(
STSmaWriteH
*
pSmaH
,
SSma
*
pSma
,
const
SArray
*
pDataBlocks
,
int64_t
interval
,
int8_t
intervalUnit
);
int8_t
intervalUnit
);
static
int32_t
tdInitTSmaReadH
(
STSmaReadH
*
pSmaH
,
SSma
*
pSma
,
int64_t
interval
,
int8_t
intervalUnit
);
static
void
tdDestroyTSmaWriteH
(
STSmaWriteH
*
pSmaH
);
static
int32_t
tdGetTSmaDays
(
SSma
*
pSma
,
int64_t
interval
,
int32_t
storageLevel
);
...
...
@@ -92,9 +93,10 @@ static int32_t tdDropTSmaDataImpl(SSma *pSma, int64_t indexUid);
* @return int32_t
*/
static
int32_t
tdInitTSmaReadH
(
STSmaReadH
*
pSmaH
,
SSma
*
pSma
,
int64_t
interval
,
int8_t
intervalUnit
)
{
STSmaKeepCfg
*
pCfg
=
SMA_TSDB_CFG
(
pSma
);
pSmaH
->
pSma
=
pSma
;
pSmaH
->
interval
=
tdGetIntervalByPrecision
(
interval
,
intervalUnit
,
SMA_TSDB_CFG
(
pSma
)
->
precision
,
true
);
pSmaH
->
storageLevel
=
tdGetSmaStorageLevel
(
interval
,
intervalUnit
);
pSmaH
->
storageLevel
=
tdGetSmaStorageLevel
(
pCfg
,
interval
);
pSmaH
->
days
=
tdGetTSmaDays
(
pSma
,
pSmaH
->
interval
,
pSmaH
->
storageLevel
);
return
TSDB_CODE_SUCCESS
;
}
...
...
@@ -275,11 +277,13 @@ static int32_t tdSetTSmaDataFile(STSmaWriteH *pSmaH, int64_t indexUid, int32_t f
*/
static
int32_t
tdGetTSmaDays
(
SSma
*
pSma
,
int64_t
interval
,
int32_t
storageLevel
)
{
STsdbCfg
*
pCfg
=
SMA_TSDB_CFG
(
pSma
);
int32_t
daysPerFile
=
pCfg
->
days
;
int32_t
daysPerFile
=
pCfg
->
days
;
// unit is minute
if
(
storageLevel
==
SMA_STORAGE_LEVEL_TSDB
)
{
int32_t
days
=
SMA_STORAGE_TSDB_TIMES
*
(
interval
/
tsTickPerMin
[
pCfg
->
precision
]);
daysPerFile
=
days
>
SMA_STORAGE_TSDB_DAYS
?
days
:
SMA_STORAGE_TSDB_DAYS
;
int32_t
minutes
=
SMA_STORAGE_TSDB_TIMES
*
(
interval
/
tsTickPerMin
[
pCfg
->
precision
]);
if
(
minutes
>
SMA_STORAGE_TSDB_MINUTES
)
{
daysPerFile
=
SMA_STORAGE_TSDB_MINUTES
;
}
}
return
daysPerFile
;
...
...
@@ -288,45 +292,14 @@ static int32_t tdGetTSmaDays(SSma *pSma, int64_t interval, int32_t storageLevel)
/**
* @brief Judge the tSma storage level
*
* @param pCfg
* @param interval
* @param intervalUnit
* @return int32_t
*/
static
int32_t
tdGetSmaStorageLevel
(
int64_t
interval
,
int8_t
intervalUnit
)
{
// TODO: configurable for SMA_STORAGE_SPLIT_HOURS?
switch
(
intervalUnit
)
{
case
TIME_UNIT_HOUR
:
if
(
interval
<
SMA_STORAGE_SPLIT_HOURS
)
{
return
SMA_STORAGE_LEVEL_DFILESET
;
}
break
;
case
TIME_UNIT_MINUTE
:
if
(
interval
<
60
*
SMA_STORAGE_SPLIT_HOURS
)
{
return
SMA_STORAGE_LEVEL_DFILESET
;
}
break
;
case
TIME_UNIT_SECOND
:
if
(
interval
<
3600
*
SMA_STORAGE_SPLIT_HOURS
)
{
return
SMA_STORAGE_LEVEL_DFILESET
;
}
break
;
case
TIME_UNIT_MILLISECOND
:
if
(
interval
<
3600
*
1e3
*
SMA_STORAGE_SPLIT_HOURS
)
{
return
SMA_STORAGE_LEVEL_DFILESET
;
}
break
;
case
TIME_UNIT_MICROSECOND
:
if
(
interval
<
3600
*
1e6
*
SMA_STORAGE_SPLIT_HOURS
)
{
return
SMA_STORAGE_LEVEL_DFILESET
;
}
break
;
case
TIME_UNIT_NANOSECOND
:
if
(
interval
<
3600
*
1e9
*
SMA_STORAGE_SPLIT_HOURS
)
{
return
SMA_STORAGE_LEVEL_DFILESET
;
}
break
;
default:
break
;
static
int32_t
tdGetSmaStorageLevel
(
STSmaKeepCfg
*
pCfg
,
int64_t
interval
)
{
int64_t
mInterval
=
convertTimeFromPrecisionToUnit
(
interval
,
pCfg
->
precision
,
TIME_UNIT_MINUTE
);
if
(
pCfg
->
days
/
mInterval
>=
SMA_STORAGE_SPLIT_FACTOR
)
{
return
SMA_STORAGE_LEVEL_DFILESET
;
}
return
SMA_STORAGE_LEVEL_TSDB
;
}
...
...
@@ -346,6 +319,7 @@ static int32_t tdGetSmaStorageLevel(int64_t interval, int8_t intervalUnit) {
int32_t
tdProcessTSmaInsertImpl
(
SSma
*
pSma
,
int64_t
indexUid
,
const
char
*
msg
)
{
STsdbCfg
*
pCfg
=
SMA_TSDB_CFG
(
pSma
);
const
SArray
*
pDataBlocks
=
(
const
SArray
*
)
msg
;
int64_t
testSkey
=
TSKEY_INITIAL_VAL
;
// TODO: destroy SSDataBlocks(msg)
...
...
@@ -403,8 +377,8 @@ int32_t tdProcessTSmaInsertImpl(SSma *pSma, int64_t indexUid, const char *msg) {
}
// Step 1: Judge the storage level and days
int32_t
storageLevel
=
tdGetSmaStorageLevel
(
p
TSma
->
interval
,
pTSma
->
intervalUnit
);
int32_t
days
PerFile
=
tdGetTSmaDays
(
pSma
,
tSmaH
.
interval
,
storageLevel
);
int32_t
storageLevel
=
tdGetSmaStorageLevel
(
p
Cfg
,
tSmaH
.
interval
);
int32_t
minute
PerFile
=
tdGetTSmaDays
(
pSma
,
tSmaH
.
interval
,
storageLevel
);
char
smaKey
[
SMA_KEY_LEN
]
=
{
0
};
// key: skey + groupId
char
dataBuf
[
512
]
=
{
0
};
// val: aggr data // TODO: handle 512 buffer?
...
...
@@ -432,6 +406,7 @@ int32_t tdProcessTSmaInsertImpl(SSma *pSma, int64_t indexUid, const char *msg) {
if
(
!
isStartKey
)
{
isStartKey
=
true
;
skey
=
*
(
TSKEY
*
)
var
;
testSkey
=
skey
;
printf
(
"= skey %"
PRIi64
" groupId = %"
PRIi64
"|"
,
skey
,
groupId
);
tdEncodeTSmaKey
(
groupId
,
skey
,
&
pSmaKey
);
}
else
{
...
...
@@ -503,9 +478,10 @@ int32_t tdProcessTSmaInsertImpl(SSma *pSma, int64_t indexUid, const char *msg) {
break
;
}
}
printf
(
"
\n
"
);
// if ((tlen > 0) && (skey != TSKEY_INITIAL_VAL)) {
if
(
tlen
>
0
)
{
int32_t
fid
=
(
int32_t
)(
TSDB_KEY_FID
(
skey
,
days
PerFile
,
pCfg
->
precision
));
int32_t
fid
=
(
int32_t
)(
TSDB_KEY_FID
(
skey
,
minute
PerFile
,
pCfg
->
precision
));
// Step 2: Set the DFile for storage of SMA index, and iterate/split the TSma data and store to B+Tree index
// file
...
...
@@ -517,6 +493,8 @@ int32_t tdProcessTSmaInsertImpl(SSma *pSma, int64_t indexUid, const char *msg) {
smaCloseDBF
(
&
tSmaH
.
dFile
);
}
tdSetTSmaDataFile
(
&
tSmaH
,
indexUid
,
fid
);
smaDebug
(
"@@@ vgId:%d write to DBF %s, days:%d, interval:%"
PRIi64
", storageLevel:%"
PRIi32
" queryKey:%"
PRIi64
,
SMA_VID
(
pSma
),
tSmaH
.
dFile
.
path
,
minutePerFile
,
tSmaH
.
interval
,
storageLevel
,
testSkey
);
if
(
smaOpenDBF
(
pEnv
->
dbEnv
,
&
tSmaH
.
dFile
)
!=
0
)
{
smaWarn
(
"vgId:%d open DB file %s failed since %s"
,
SMA_VID
(
pSma
),
tSmaH
.
dFile
.
path
?
tSmaH
.
dFile
.
path
:
"path is NULL"
,
tstrerror
(
terrno
));
...
...
@@ -528,16 +506,17 @@ int32_t tdProcessTSmaInsertImpl(SSma *pSma, int64_t indexUid, const char *msg) {
}
if
(
tdInsertTSmaBlocks
(
&
tSmaH
,
&
smaKey
,
SMA_KEY_LEN
,
dataBuf
,
tlen
,
&
pEnv
->
txn
)
!=
0
)
{
smaWarn
(
"vgId:%d insert t
S
ma data blocks fail for index %"
PRIi64
", skey %"
PRIi64
", groupId %"
PRIi64
" since %s"
,
SMA_VID
(
pSma
),
indexUid
,
skey
,
groupId
,
tstrerror
(
terrno
));
smaWarn
(
"vgId:%d insert t
s
ma data blocks fail for index %"
PRIi64
", skey %"
PRIi64
", groupId %"
PRIi64
" since %s"
,
SMA_VID
(
pSma
),
indexUid
,
skey
,
groupId
,
tstrerror
(
terrno
));
tdSmaEndCommit
(
pEnv
);
tdDestroyTSmaWriteH
(
&
tSmaH
);
tdUnRefSmaStat
(
pSma
,
pStat
);
return
TSDB_CODE_FAILED
;
}
smaDebug
(
"vgId:%d insert tSma data blocks success for index %"
PRIi64
", skey %"
PRIi64
", groupId %"
PRIi64
,
SMA_VID
(
pSma
),
indexUid
,
skey
,
groupId
);
smaDebug
(
"vgId:%d insert tsma data blocks success for index %"
PRIi64
", skey %"
PRIi64
", groupId %"
PRIi64
,
SMA_VID
(
pSma
),
indexUid
,
skey
,
groupId
);
// TODO:tsdbEndTSmaCommit();
// Step 3: reset the SSmaStat
...
...
@@ -547,7 +526,6 @@ int32_t tdProcessTSmaInsertImpl(SSma *pSma, int64_t indexUid, const char *msg) {
SMA_VID
(
pSma
),
skey
,
tlen
,
indexUid
);
}
printf
(
"
\n
"
);
}
}
tdSmaEndCommit
(
pEnv
);
// TODO: not commit for every insert
...
...
@@ -579,14 +557,14 @@ static int32_t tdInsertTSmaBlocks(STSmaWriteH *pSmaH, void *smaKey, int32_t keyL
TXN
*
txn
)
{
SDBFile
*
pDBFile
=
&
pSmaH
->
dFile
;
// TODO: insert sma data blocks into B+Tree(TDB)
// TODO: insert
t
sma data blocks into B+Tree(TDB)
if
(
smaSaveSmaToDB
(
pDBFile
,
smaKey
,
keyLen
,
pData
,
dataLen
,
txn
)
!=
0
)
{
smaWarn
(
"vgId:%d insert sma data blocks into %s: smaKey %"
PRIx64
"-%"
PRIx64
", dataLen %"
PRIu32
" fail"
,
SMA_VID
(
pSmaH
->
pSma
),
pDBFile
->
path
,
*
(
int64_t
*
)
smaKey
,
*
(
int64_t
*
)
POINTER_SHIFT
(
smaKey
,
8
),
dataLen
);
smaWarn
(
"vgId:%d insert
t
sma data blocks into %s: smaKey %"
PRIx64
"-%"
PRIx64
", dataLen %"
PRIu32
" fail"
,
SMA_VID
(
pSmaH
->
pSma
),
pDBFile
->
path
,
*
(
int64_t
*
)
smaKey
,
*
(
int64_t
*
)
POINTER_SHIFT
(
smaKey
,
8
),
dataLen
);
return
TSDB_CODE_FAILED
;
}
smaDebug
(
"vgId:%d insert sma data blocks into %s: smaKey %"
PRIx64
"-%"
PRIx64
", dataLen %"
PRIu32
" succeed"
,
SMA_VID
(
pSmaH
->
pSma
),
pDBFile
->
path
,
*
(
int64_t
*
)
smaKey
,
*
(
int64_t
*
)
POINTER_SHIFT
(
smaKey
,
8
),
dataLen
);
smaDebug
(
"vgId:%d insert
t
sma data blocks into %s: smaKey %"
PRIx64
"-%"
PRIx64
", dataLen %"
PRIu32
" succeed"
,
SMA_VID
(
pSmaH
->
pSma
),
pDBFile
->
path
,
*
(
int64_t
*
)
smaKey
,
*
(
int64_t
*
)
POINTER_SHIFT
(
smaKey
,
8
),
dataLen
);
#ifdef _TEST_SMA_PRINT_DEBUG_LOG_
uint32_t
valueSize
=
0
;
...
...
@@ -776,6 +754,8 @@ int32_t tdGetTSmaDataImpl(SSma *pSma, char *pData, int64_t indexUid, TSKEY query
tdUnRefSmaStat
(
pSma
,
pStat
);
tdInitTSmaFile
(
&
tReadH
,
indexUid
,
querySKey
);
smaDebug
(
"### vgId:%d read from DBF %s days:%d, interval:%"
PRIi64
", storageLevel:%"
PRIi8
" queryKey:%"
PRIi64
,
SMA_VID
(
pSma
),
tReadH
.
dFile
.
path
,
tReadH
.
days
,
tReadH
.
interval
,
tReadH
.
storageLevel
,
querySKey
);
if
(
smaOpenDBF
(
pEnv
->
dbEnv
,
&
tReadH
.
dFile
)
!=
0
)
{
smaWarn
(
"vgId:%d open DBF %s failed since %s"
,
SMA_VID
(
pSma
),
tReadH
.
dFile
.
path
,
tstrerror
(
terrno
));
return
TSDB_CODE_FAILED
;
...
...
@@ -783,7 +763,7 @@ int32_t tdGetTSmaDataImpl(SSma *pSma, char *pData, int64_t indexUid, TSKEY query
char
smaKey
[
SMA_KEY_LEN
]
=
{
0
};
void
*
pSmaKey
=
&
smaKey
;
int64_t
queryGroupId
=
1
;
int64_t
queryGroupId
=
0
;
tdEncodeTSmaKey
(
queryGroupId
,
querySKey
,
(
void
**
)
&
pSmaKey
);
smaDebug
(
"vgId:%d get sma data from %s: smaKey %"
PRIx64
"-%"
PRIx64
", keyLen %d"
,
SMA_VID
(
pSma
),
...
...
@@ -915,8 +895,8 @@ static int32_t tdSetExpiredWindow(SSma *pSma, SHashObj *pItemsHash, int64_t inde
terrno
=
TSDB_CODE_TDB_NO_SMA_INDEX_IN_META
;
taosHashCleanup
(
pItem
->
expiredWindows
);
taosMemoryFree
(
pItem
);
smaWarn
(
"vgId:%d
update expired window failed for smaIndex %"
PRIi64
" since %s"
,
SMA_VID
(
pSma
),
indexUid
,
tstrerror
(
terrno
));
smaWarn
(
"vgId:%d
set expire window, get tsma meta failed for smaIndex %"
PRIi64
" since %s"
,
SMA_VID
(
pSma
)
,
indexUid
,
tstrerror
(
terrno
));
return
TSDB_CODE_FAILED
;
}
pItem
->
pTSma
=
pTSma
;
...
...
@@ -1021,7 +1001,7 @@ int32_t tdUpdateExpiredWindowImpl(SSma *pSma, SSubmitReq *pMsg, int64_t version)
pSW
=
tdFreeTSmaWrapper
(
pSW
,
false
);
break
;
}
if
(
!
pSW
||
(
pTSma
->
tableUid
!=
msgIter
.
suid
))
{
if
(
!
pSW
||
(
pTSma
&&
(
pTSma
->
tableUid
!=
msgIter
.
suid
)
))
{
if
(
pSW
)
{
pSW
=
tdFreeTSmaWrapper
(
pSW
,
false
);
}
...
...
@@ -1043,6 +1023,7 @@ int32_t tdUpdateExpiredWindowImpl(SSma *pSma, SSubmitReq *pMsg, int64_t version)
interval
.
slidingUnit
=
pTSma
->
slidingUnit
;
}
// TODO: process multiple tsma for one table uid
TSKEY
winSKey
=
taosTimeTruncate
(
TD_ROW_KEY
(
row
),
&
interval
,
interval
.
precision
);
if
(
lastWinSKey
!=
winSKey
)
{
...
...
source/dnode/vnode/src/tsdb/tsdbOpen.c
浏览文件 @
156b0cfe
...
...
@@ -42,7 +42,7 @@ int tsdbOpen(SVnode *pVnode, STsdb **ppTsdb, const char *dir, STsdbKeepCfg *pKee
int
slen
=
0
;
*
ppTsdb
=
NULL
;
slen
=
strlen
(
tfsGetPrimaryPath
(
pVnode
->
pTfs
))
+
strlen
(
pVnode
->
path
)
+
strlen
(
dir
)
+
TSDB_DATA_DIR_LEN
+
3
;
slen
=
strlen
(
tfsGetPrimaryPath
(
pVnode
->
pTfs
))
+
strlen
(
pVnode
->
path
)
+
3
;
// create handle
pTsdb
=
(
STsdb
*
)
taosMemoryCalloc
(
1
,
sizeof
(
*
pTsdb
)
+
slen
);
...
...
@@ -73,7 +73,8 @@ int tsdbOpen(SVnode *pVnode, STsdb **ppTsdb, const char *dir, STsdbKeepCfg *pKee
goto
_err
;
}
tsdbDebug
(
"vgId:%d tsdb is opened for %s"
,
TD_VID
(
pVnode
),
pTsdb
->
path
);
tsdbDebug
(
"vgId:%d tsdb is opened for %s, days:%d, keep:%d,%d,%d"
,
TD_VID
(
pVnode
),
pTsdb
->
path
,
pTsdb
->
keepCfg
.
days
,
pTsdb
->
keepCfg
.
keep0
,
pTsdb
->
keepCfg
.
keep1
,
pTsdb
->
keepCfg
.
keep2
);
*
ppTsdb
=
pTsdb
;
return
0
;
...
...
source/dnode/vnode/src/tsdb/tsdbRead.c
浏览文件 @
156b0cfe
...
...
@@ -372,13 +372,13 @@ static STsdb* getTsdbByRetentions(SVnode* pVnode, STsdbReadHandle* pReadHandle,
}
if
(
level
==
TSDB_RETENTION_L0
)
{
tsdbDebug
(
"
%p rsma level %d is selected to query"
,
pReadHandle
,
TSDB_RETENTION_L0
);
tsdbDebug
(
"
vgId:%d read handle %p rsma level %d is selected to query"
,
TD_VID
(
pVnode
)
,
pReadHandle
,
TSDB_RETENTION_L0
);
return
VND_RSMA0
(
pVnode
);
}
else
if
(
level
==
TSDB_RETENTION_L1
)
{
tsdbDebug
(
"
%p rsma level %d is selected to query"
,
pReadHandle
,
TSDB_RETENTION_L1
);
tsdbDebug
(
"
vgId:%d read handle %p rsma level %d is selected to query"
,
TD_VID
(
pVnode
)
,
pReadHandle
,
TSDB_RETENTION_L1
);
return
VND_RSMA1
(
pVnode
);
}
else
{
tsdbDebug
(
"
%p rsma level %d is selected to query"
,
pReadHandle
,
TSDB_RETENTION_L2
);
tsdbDebug
(
"
vgId:%d read handle %p rsma level %d is selected to query"
,
TD_VID
(
pVnode
)
,
pReadHandle
,
TSDB_RETENTION_L2
);
return
VND_RSMA2
(
pVnode
);
}
}
...
...
source/dnode/vnode/src/tsdb/tsdbSma.c
浏览文件 @
156b0cfe
...
...
@@ -876,13 +876,13 @@ static int32_t tsdbInsertTSmaBlocks(STSmaWriteH *pSmaH, void *smaKey, int32_t ke
TXN
*
txn
)
{
SDBFile
*
pDBFile
=
&
pSmaH
->
dFile
;
// TODO: insert sma data blocks into B+Tree(TDB)
// TODO: insert
t
sma data blocks into B+Tree(TDB)
if
(
tsdbSaveSmaToDB
(
pDBFile
,
smaKey
,
keyLen
,
pData
,
dataLen
,
txn
)
!=
0
)
{
tsdbWarn
(
"vgId:%d insert sma data blocks into %s: smaKey %"
PRIx64
"-%"
PRIx64
", dataLen %"
PRIu32
" fail"
,
tsdbWarn
(
"vgId:%d insert
t
sma data blocks into %s: smaKey %"
PRIx64
"-%"
PRIx64
", dataLen %"
PRIu32
" fail"
,
REPO_ID
(
pSmaH
->
pTsdb
),
pDBFile
->
path
,
*
(
int64_t
*
)
smaKey
,
*
(
int64_t
*
)
POINTER_SHIFT
(
smaKey
,
8
),
dataLen
);
return
TSDB_CODE_FAILED
;
}
tsdbDebug
(
"vgId:%d insert sma data blocks into %s: smaKey %"
PRIx64
"-%"
PRIx64
", dataLen %"
PRIu32
" succeed"
,
tsdbDebug
(
"vgId:%d insert
t
sma data blocks into %s: smaKey %"
PRIx64
"-%"
PRIx64
", dataLen %"
PRIu32
" succeed"
,
REPO_ID
(
pSmaH
->
pTsdb
),
pDBFile
->
path
,
*
(
int64_t
*
)
smaKey
,
*
(
int64_t
*
)
POINTER_SHIFT
(
smaKey
,
8
),
dataLen
);
#ifdef _TEST_SMA_PRINT_DEBUG_LOG_
...
...
@@ -1245,7 +1245,7 @@ static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, int64_t indexUid, const char
}
if
(
tsdbInsertTSmaBlocks
(
&
tSmaH
,
&
smaKey
,
SMA_KEY_LEN
,
dataBuf
,
tlen
,
&
pEnv
->
txn
)
!=
0
)
{
tsdbWarn
(
"vgId:%d insert t
S
ma data blocks fail for index %"
PRIi64
", skey %"
PRIi64
", groupId %"
PRIi64
tsdbWarn
(
"vgId:%d insert t
s
ma data blocks fail for index %"
PRIi64
", skey %"
PRIi64
", groupId %"
PRIi64
" since %s"
,
REPO_ID
(
pTsdb
),
indexUid
,
skey
,
groupId
,
tstrerror
(
terrno
));
tsdbSmaEndCommit
(
pEnv
);
...
...
@@ -1253,7 +1253,7 @@ static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, int64_t indexUid, const char
tsdbUnRefSmaStat
(
pTsdb
,
pStat
);
return
TSDB_CODE_FAILED
;
}
tsdbDebug
(
"vgId:%d insert t
S
ma data blocks success for index %"
PRIi64
", skey %"
PRIi64
", groupId %"
PRIi64
,
tsdbDebug
(
"vgId:%d insert t
s
ma data blocks success for index %"
PRIi64
", skey %"
PRIi64
", groupId %"
PRIi64
,
REPO_ID
(
pTsdb
),
indexUid
,
skey
,
groupId
);
// TODO:tsdbEndTSmaCommit();
...
...
source/dnode/vnode/src/vnd/vnodeOpen.c
浏览文件 @
156b0cfe
...
...
@@ -103,7 +103,7 @@ SVnode *vnodeOpen(const char *path, STfs *pTfs, SMsgCb msgCb) {
// open sma
if
(
smaOpen
(
pVnode
))
{
vError
(
"vgId:%d failed to open vnode
tsdb
since %s"
,
TD_VID
(
pVnode
),
tstrerror
(
terrno
));
vError
(
"vgId:%d failed to open vnode
sma
since %s"
,
TD_VID
(
pVnode
),
tstrerror
(
terrno
));
goto
_err
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录