Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
b03c73c9
T
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1185
Star
22015
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看板
未验证
提交
b03c73c9
编写于
7月 15, 2020
作者:
S
Shengliang Guan
提交者:
GitHub
7月 15, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #2665 from taosdata/feature/2.0tsdb
Feature/2.0tsdb
上级
67a04744
849dd43e
变更
4
展开全部
显示空白变更内容
内联
并排
Showing
4 changed file
with
611 addition
and
454 deletion
+611
-454
src/tsdb/inc/tsdbMain.h
src/tsdb/inc/tsdbMain.h
+55
-21
src/tsdb/src/tsdbMemTable.c
src/tsdb/src/tsdbMemTable.c
+75
-88
src/tsdb/src/tsdbMeta.c
src/tsdb/src/tsdbMeta.c
+2
-2
src/tsdb/src/tsdbRWHelper.c
src/tsdb/src/tsdbRWHelper.c
+479
-343
未找到文件。
src/tsdb/inc/tsdbMain.h
浏览文件 @
b03c73c9
...
...
@@ -96,6 +96,11 @@ typedef struct {
}
STsdbBufPool
;
// ------------------ tsdbMemTable.c
typedef
struct
{
STable
*
pTable
;
SSkipListIterator
*
pIter
;
}
SCommitIter
;
typedef
struct
{
uint64_t
uid
;
TSKEY
keyFirst
;
...
...
@@ -206,10 +211,10 @@ typedef struct {
int64_t
offset
:
63
;
int32_t
algorithm
:
8
;
int32_t
numOfRows
:
24
;
int32_t
sversion
;
int32_t
len
;
int32_t
keyLen
;
// key column length, keyOffset = offset+sizeof(SCompData)+sizeof(SCompCol)*numOfCols
int16_t
numOfSubBlocks
;
int16_t
numOfCols
;
int16_t
numOfCols
;
// not including timestamp column
TSKEY
keyFirst
;
TSKEY
keyLast
;
}
SCompBlock
;
...
...
@@ -377,6 +382,24 @@ int tsdbUnRefMemTable(STsdbRepo* pRepo, SMemTable* pMemTable);
int
tsdbTakeMemSnapshot
(
STsdbRepo
*
pRepo
,
SMemTable
**
pMem
,
SMemTable
**
pIMem
);
void
*
tsdbAllocBytes
(
STsdbRepo
*
pRepo
,
int
bytes
);
int
tsdbAsyncCommit
(
STsdbRepo
*
pRepo
);
int
tsdbLoadDataFromCache
(
STable
*
pTable
,
SSkipListIterator
*
pIter
,
TSKEY
maxKey
,
int
maxRowsToRead
,
SDataCols
*
pCols
,
TSKEY
*
filterKeys
,
int
nFilterKeys
);
static
FORCE_INLINE
SDataRow
tsdbNextIterRow
(
SSkipListIterator
*
pIter
)
{
if
(
pIter
==
NULL
)
return
NULL
;
SSkipListNode
*
node
=
tSkipListIterGet
(
pIter
);
if
(
node
==
NULL
)
return
NULL
;
return
SL_GET_NODE_DATA
(
node
);
}
static
FORCE_INLINE
TSKEY
tsdbNextIterKey
(
SSkipListIterator
*
pIter
)
{
SDataRow
row
=
tsdbNextIterRow
(
pIter
);
if
(
row
==
NULL
)
return
-
1
;
return
dataRowKey
(
row
);
}
// ------------------ tsdbFile.c
#define TSDB_KEY_FILEID(key, daysPerFile, precision) ((key) / tsMsPerDay[(precision)] / (daysPerFile))
...
...
@@ -421,6 +444,7 @@ void tsdbRemoveFileGroup(STsdbRepo* pRepo, SFileGroup* pFGroup);
#define helperType(h) (h)->type
#define helperRepo(h) (h)->pRepo
#define helperState(h) (h)->state
#define TSDB_NLAST_FILE_OPENED(h) ((h)->files.nLastF.fd > 0)
int
tsdbInitReadHelper
(
SRWHelper
*
pHelper
,
STsdbRepo
*
pRepo
);
int
tsdbInitWriteHelper
(
SRWHelper
*
pHelper
,
STsdbRepo
*
pRepo
);
...
...
@@ -429,7 +453,7 @@ void tsdbResetHelper(SRWHelper* pHelper);
int
tsdbSetAndOpenHelperFile
(
SRWHelper
*
pHelper
,
SFileGroup
*
pGroup
);
int
tsdbCloseHelperFile
(
SRWHelper
*
pHelper
,
bool
hasError
);
void
tsdbSetHelperTable
(
SRWHelper
*
pHelper
,
STable
*
pTable
,
STsdbRepo
*
pRepo
);
int
tsdbWriteDataBlock
(
SRWHelper
*
pHelper
,
SDataCols
*
pDataCols
);
int
tsdbCommitTableData
(
SRWHelper
*
pHelper
,
SCommitIter
*
pCommitIter
,
SDataCols
*
pDataCols
,
TSKEY
maxKey
);
int
tsdbMoveLastBlockIfNeccessary
(
SRWHelper
*
pHelper
);
int
tsdbWriteCompInfo
(
SRWHelper
*
pHelper
);
int
tsdbWriteCompIdx
(
SRWHelper
*
pHelper
);
...
...
@@ -441,6 +465,16 @@ int tsdbLoadBlockDataCols(SRWHelper* pHelper, SCompBlock* pCompBlock, SCompInf
int
numOfColIds
);
int
tsdbLoadBlockData
(
SRWHelper
*
pHelper
,
SCompBlock
*
pCompBlock
,
SCompInfo
*
pCompInfo
);
static
FORCE_INLINE
int
compTSKEY
(
const
void
*
key1
,
const
void
*
key2
)
{
if
(
*
(
TSKEY
*
)
key1
>
*
(
TSKEY
*
)
key2
)
{
return
1
;
}
else
if
(
*
(
TSKEY
*
)
key1
==
*
(
TSKEY
*
)
key2
)
{
return
0
;
}
else
{
return
-
1
;
}
}
// ------------------ tsdbMain.c
#define REPO_ID(r) (r)->config.tsdbId
#define IS_REPO_LOCKED(r) (r)->repoLocked
...
...
src/tsdb/src/tsdbMemTable.c
浏览文件 @
b03c73c9
...
...
@@ -18,11 +18,6 @@
#define TSDB_DATA_SKIPLIST_LEVEL 5
typedef
struct
{
STable
*
pTable
;
SSkipListIterator
*
pIter
;
}
SCommitIter
;
static
FORCE_INLINE
STsdbBufBlock
*
tsdbGetCurrBufBlock
(
STsdbRepo
*
pRepo
);
static
void
tsdbFreeBytes
(
STsdbRepo
*
pRepo
,
void
*
ptr
,
int
bytes
);
...
...
@@ -34,14 +29,11 @@ static char * tsdbGetTsTupleKey(const void *data);
static
void
*
tsdbCommitData
(
void
*
arg
);
static
int
tsdbCommitMeta
(
STsdbRepo
*
pRepo
);
static
void
tsdbEndCommit
(
STsdbRepo
*
pRepo
);
static
TSKEY
tsdbNextIterKey
(
SCommitIter
*
pIter
);
static
int
tsdbHasDataToCommit
(
SCommitIter
*
iters
,
int
nIters
,
TSKEY
minKey
,
TSKEY
maxKey
);
static
int
tsdbCommitToFile
(
STsdbRepo
*
pRepo
,
int
fid
,
SCommitIter
*
iters
,
SRWHelper
*
pHelper
,
SDataCols
*
pDataCols
);
static
void
tsdbGetFidKeyRange
(
int
daysPerFile
,
int8_t
precision
,
int
fileId
,
TSKEY
*
minKey
,
TSKEY
*
maxKey
);
static
SCommitIter
*
tsdbCreateTableIters
(
STsdbRepo
*
pRepo
);
static
void
tsdbDestroyTableIters
(
SCommitIter
*
iters
,
int
maxTables
);
static
int
tsdbReadRowsFromCache
(
STsdbMeta
*
pMeta
,
STable
*
pTable
,
SSkipListIterator
*
pIter
,
TSKEY
maxKey
,
int
maxRowsToRead
,
SDataCols
*
pCols
);
static
SCommitIter
*
tsdbCreateCommitIters
(
STsdbRepo
*
pRepo
);
static
void
tsdbDestroyCommitIters
(
SCommitIter
*
iters
,
int
maxTables
);
// ---------------- INTERNAL FUNCTIONS ----------------
int
tsdbInsertRowToMem
(
STsdbRepo
*
pRepo
,
SDataRow
row
,
STable
*
pTable
)
{
...
...
@@ -252,6 +244,66 @@ int tsdbAsyncCommit(STsdbRepo *pRepo) {
return
0
;
}
int
tsdbLoadDataFromCache
(
STable
*
pTable
,
SSkipListIterator
*
pIter
,
TSKEY
maxKey
,
int
maxRowsToRead
,
SDataCols
*
pCols
,
TSKEY
*
filterKeys
,
int
nFilterKeys
)
{
ASSERT
(
maxRowsToRead
>
0
&&
nFilterKeys
>=
0
);
if
(
pIter
==
NULL
)
return
0
;
STSchema
*
pSchema
=
NULL
;
int
numOfRows
=
0
;
TSKEY
keyNext
=
0
;
int
filterIter
=
0
;
if
(
nFilterKeys
!=
0
)
{
// for filter purpose
ASSERT
(
filterKeys
!=
NULL
);
keyNext
=
tsdbNextIterKey
(
pIter
);
if
(
keyNext
<
0
||
keyNext
>
maxKey
)
return
numOfRows
;
void
*
ptr
=
taosbsearch
((
void
*
)(
&
keyNext
),
(
void
*
)
filterKeys
,
nFilterKeys
,
sizeof
(
TSKEY
),
compTSKEY
,
TD_GE
);
filterIter
=
(
ptr
==
NULL
)
?
nFilterKeys
:
(
POINTER_DISTANCE
(
ptr
,
filterKeys
)
/
sizeof
(
TSKEY
));
}
do
{
if
(
numOfRows
>=
maxRowsToRead
)
break
;
SDataRow
row
=
tsdbNextIterRow
(
pIter
);
if
(
row
==
NULL
)
break
;
keyNext
=
dataRowKey
(
row
);
if
(
keyNext
<
0
||
keyNext
>
maxKey
)
break
;
bool
keyFiltered
=
false
;
if
(
nFilterKeys
!=
0
)
{
while
(
true
)
{
if
(
filterIter
>=
nFilterKeys
)
break
;
if
(
keyNext
==
filterKeys
[
filterIter
])
{
keyFiltered
=
true
;
filterIter
++
;
break
;
}
else
if
(
keyNext
<
filterKeys
[
filterIter
])
{
break
;
}
else
{
filterIter
++
;
}
}
}
if
(
!
keyFiltered
)
{
if
(
pCols
)
{
if
(
pSchema
==
NULL
||
schemaVersion
(
pSchema
)
!=
dataRowVersion
(
row
))
{
pSchema
=
tsdbGetTableSchemaImpl
(
pTable
,
false
,
false
,
dataRowVersion
(
row
));
if
(
pSchema
==
NULL
)
{
ASSERT
(
0
);
}
}
tdAppendDataRowToDataCol
(
row
,
pSchema
,
pCols
);
}
numOfRows
++
;
}
}
while
(
tSkipListIterNext
(
pIter
));
return
numOfRows
;
}
// ---------------- LOCAL FUNCTIONS ----------------
static
FORCE_INLINE
STsdbBufBlock
*
tsdbGetCurrBufBlock
(
STsdbRepo
*
pRepo
)
{
ASSERT
(
pRepo
!=
NULL
);
...
...
@@ -378,7 +430,7 @@ static void *tsdbCommitData(void *arg) {
// Create the iterator to read from cache
if
(
pMem
->
numOfRows
>
0
)
{
iters
=
tsdbCreate
Table
Iters
(
pRepo
);
iters
=
tsdbCreate
Commit
Iters
(
pRepo
);
if
(
iters
==
NULL
)
{
tsdbError
(
"vgId:%d failed to create commit iterator since %s"
,
REPO_ID
(
pRepo
),
tstrerror
(
terrno
));
goto
_exit
;
...
...
@@ -418,7 +470,7 @@ static void *tsdbCommitData(void *arg) {
_exit:
tdFreeDataCols
(
pDataCols
);
tsdbDestroy
Table
Iters
(
iters
,
pCfg
->
maxTables
);
tsdbDestroy
Commit
Iters
(
iters
,
pCfg
->
maxTables
);
tsdbDestroyHelper
(
&
whelper
);
tsdbEndCommit
(
pRepo
);
tsdbInfo
(
"vgId:%d commit over"
,
pRepo
->
config
.
tsdbId
);
...
...
@@ -479,19 +531,9 @@ static void tsdbEndCommit(STsdbRepo *pRepo) {
if
(
pRepo
->
appH
.
notifyStatus
)
pRepo
->
appH
.
notifyStatus
(
pRepo
->
appH
.
appH
,
TSDB_STATUS_COMMIT_OVER
);
}
static
TSKEY
tsdbNextIterKey
(
SCommitIter
*
pIter
)
{
if
(
pIter
==
NULL
)
return
-
1
;
SSkipListNode
*
node
=
tSkipListIterGet
(
pIter
->
pIter
);
if
(
node
==
NULL
)
return
-
1
;
SDataRow
row
=
SL_GET_NODE_DATA
(
node
);
return
dataRowKey
(
row
);
}
static
int
tsdbHasDataToCommit
(
SCommitIter
*
iters
,
int
nIters
,
TSKEY
minKey
,
TSKEY
maxKey
)
{
for
(
int
i
=
0
;
i
<
nIters
;
i
++
)
{
TSKEY
nextKey
=
tsdbNextIterKey
(
iters
+
i
);
TSKEY
nextKey
=
tsdbNextIterKey
(
(
iters
+
i
)
->
pIter
);
if
(
nextKey
>
0
&&
(
nextKey
>=
minKey
&&
nextKey
<=
maxKey
))
return
1
;
}
return
0
;
...
...
@@ -504,7 +546,6 @@ static void tsdbGetFidKeyRange(int daysPerFile, int8_t precision, int fileId, TS
static
int
tsdbCommitToFile
(
STsdbRepo
*
pRepo
,
int
fid
,
SCommitIter
*
iters
,
SRWHelper
*
pHelper
,
SDataCols
*
pDataCols
)
{
char
*
dataDir
=
NULL
;
STsdbMeta
*
pMeta
=
pRepo
->
tsdbMeta
;
STsdbCfg
*
pCfg
=
&
pRepo
->
config
;
STsdbFileH
*
pFileH
=
pRepo
->
tsdbFileH
;
SFileGroup
*
pGroup
=
NULL
;
...
...
@@ -549,33 +590,13 @@ static int tsdbCommitToFile(STsdbRepo *pRepo, int fid, SCommitIter *iters, SRWHe
if
(
pIter
->
pIter
!=
NULL
)
{
tdInitDataCols
(
pDataCols
,
tsdbGetTableSchemaImpl
(
pIter
->
pTable
,
false
,
false
,
-
1
));
int
maxRowsToRead
=
pCfg
->
maxRowsPerFileBlock
*
4
/
5
;
int
nLoop
=
0
;
while
(
true
)
{
int
rowsRead
=
tsdbReadRowsFromCache
(
pMeta
,
pIter
->
pTable
,
pIter
->
pIter
,
maxKey
,
maxRowsToRead
,
pDataCols
);
ASSERT
(
rowsRead
>=
0
);
if
(
pDataCols
->
numOfRows
==
0
)
break
;
nLoop
++
;
ASSERT
(
dataColsKeyFirst
(
pDataCols
)
>=
minKey
&&
dataColsKeyFirst
(
pDataCols
)
<=
maxKey
);
ASSERT
(
dataColsKeyLast
(
pDataCols
)
>=
minKey
&&
dataColsKeyLast
(
pDataCols
)
<=
maxKey
);
int
rowsWritten
=
tsdbWriteDataBlock
(
pHelper
,
pDataCols
);
ASSERT
(
rowsWritten
!=
0
);
if
(
rowsWritten
<
0
)
{
if
(
tsdbCommitTableData
(
pHelper
,
pIter
,
pDataCols
,
maxKey
)
<
0
)
{
taosRUnLockLatch
(
&
(
pIter
->
pTable
->
latch
));
tsdbError
(
"vgId:%d failed to write data block to
table %s tid %d uid %"
PRIu64
" since %s"
,
REPO_ID
(
pRepo
),
tsdbError
(
"vgId:%d failed to write data of
table %s tid %d uid %"
PRIu64
" since %s"
,
REPO_ID
(
pRepo
),
TABLE_CHAR_NAME
(
pIter
->
pTable
),
TABLE_TID
(
pIter
->
pTable
),
TABLE_UID
(
pIter
->
pTable
),
tstrerror
(
terrno
));
goto
_err
;
}
ASSERT
(
rowsWritten
<=
pDataCols
->
numOfRows
);
tdPopDataColsPoints
(
pDataCols
,
rowsWritten
);
maxRowsToRead
=
pCfg
->
maxRowsPerFileBlock
*
4
/
5
-
pDataCols
->
numOfRows
;
}
ASSERT
(
pDataCols
->
numOfRows
==
0
);
}
taosRUnLockLatch
(
&
(
pIter
->
pTable
->
latch
));
...
...
@@ -615,7 +636,7 @@ _err:
return
-
1
;
}
static
SCommitIter
*
tsdbCreate
Table
Iters
(
STsdbRepo
*
pRepo
)
{
static
SCommitIter
*
tsdbCreate
Commit
Iters
(
STsdbRepo
*
pRepo
)
{
STsdbCfg
*
pCfg
=
&
(
pRepo
->
config
);
SMemTable
*
pMem
=
pRepo
->
imem
;
STsdbMeta
*
pMeta
=
pRepo
->
tsdbMeta
;
...
...
@@ -645,21 +666,18 @@ static SCommitIter *tsdbCreateTableIters(STsdbRepo *pRepo) {
goto
_err
;
}
if
(
!
tSkipListIterNext
(
iters
[
i
].
pIter
))
{
terrno
=
TSDB_CODE_TDB_NO_TABLE_DATA_IN_MEM
;
goto
_err
;
}
tSkipListIterNext
(
iters
[
i
].
pIter
);
}
}
return
iters
;
_err:
tsdbDestroy
Table
Iters
(
iters
,
pCfg
->
maxTables
);
tsdbDestroy
Commit
Iters
(
iters
,
pCfg
->
maxTables
);
return
NULL
;
}
static
void
tsdbDestroy
Table
Iters
(
SCommitIter
*
iters
,
int
maxTables
)
{
static
void
tsdbDestroy
Commit
Iters
(
SCommitIter
*
iters
,
int
maxTables
)
{
if
(
iters
==
NULL
)
return
;
for
(
int
i
=
1
;
i
<
maxTables
;
i
++
)
{
...
...
@@ -671,34 +689,3 @@ static void tsdbDestroyTableIters(SCommitIter *iters, int maxTables) {
free
(
iters
);
}
\ No newline at end of file
static
int
tsdbReadRowsFromCache
(
STsdbMeta
*
pMeta
,
STable
*
pTable
,
SSkipListIterator
*
pIter
,
TSKEY
maxKey
,
int
maxRowsToRead
,
SDataCols
*
pCols
)
{
ASSERT
(
maxRowsToRead
>
0
);
if
(
pIter
==
NULL
)
return
0
;
STSchema
*
pSchema
=
NULL
;
int
numOfRows
=
0
;
do
{
if
(
numOfRows
>=
maxRowsToRead
)
break
;
SSkipListNode
*
node
=
tSkipListIterGet
(
pIter
);
if
(
node
==
NULL
)
break
;
SDataRow
row
=
SL_GET_NODE_DATA
(
node
);
if
(
dataRowKey
(
row
)
>
maxKey
)
break
;
if
(
pSchema
==
NULL
||
schemaVersion
(
pSchema
)
!=
dataRowVersion
(
row
))
{
pSchema
=
tsdbGetTableSchemaImpl
(
pTable
,
true
,
false
,
dataRowVersion
(
row
));
if
(
pSchema
==
NULL
)
{
// TODO: deal with the error here
ASSERT
(
0
);
}
}
tdAppendDataRowToDataCol
(
row
,
pSchema
,
pCols
);
numOfRows
++
;
}
while
(
tSkipListIterNext
(
pIter
));
return
numOfRows
;
}
\ No newline at end of file
src/tsdb/src/tsdbMeta.c
浏览文件 @
b03c73c9
...
...
@@ -727,7 +727,7 @@ static STable *tsdbNewTable(STableCfg *pCfg, bool isSuper) {
T_REF_INC
(
pTable
);
tsdb
Debug
(
"table %s tid %d uid %"
PRIu64
" is created"
,
TABLE_CHAR_NAME
(
pTable
),
TABLE_TID
(
pTable
),
tsdb
Trace
(
"table %s tid %d uid %"
PRIu64
" is created"
,
TABLE_CHAR_NAME
(
pTable
),
TABLE_TID
(
pTable
),
TABLE_UID
(
pTable
));
return
pTable
;
...
...
@@ -740,7 +740,7 @@ _err:
static
void
tsdbFreeTable
(
STable
*
pTable
)
{
if
(
pTable
)
{
if
(
pTable
->
name
!=
NULL
)
tsdb
Debug
(
"table %s tid %d uid %"
PRIu64
" is destroy
ed"
,
TABLE_CHAR_NAME
(
pTable
),
TABLE_TID
(
pTable
),
tsdb
Trace
(
"table %s tid %d uid %"
PRIu64
" is fre
ed"
,
TABLE_CHAR_NAME
(
pTable
),
TABLE_TID
(
pTable
),
TABLE_UID
(
pTable
));
tfree
(
TABLE_NAME
(
pTable
));
if
(
TABLE_TYPE
(
pTable
)
!=
TSDB_CHILD_TABLE
)
{
...
...
src/tsdb/src/tsdbRWHelper.c
浏览文件 @
b03c73c9
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录