Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
m0_53320357
TDengine
提交
081e7120
TDengine
项目概览
m0_53320357
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
081e7120
编写于
8月 06, 2020
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
make action atomic
上级
cae5edea
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
112 addition
and
61 deletion
+112
-61
src/tsdb/inc/tsdbMain.h
src/tsdb/inc/tsdbMain.h
+17
-0
src/tsdb/src/tsdbMain.c
src/tsdb/src/tsdbMain.c
+17
-0
src/tsdb/src/tsdbMemTable.c
src/tsdb/src/tsdbMemTable.c
+59
-49
src/tsdb/src/tsdbMeta.c
src/tsdb/src/tsdbMeta.c
+19
-12
未找到文件。
src/tsdb/inc/tsdbMain.h
浏览文件 @
081e7120
...
...
@@ -123,6 +123,7 @@ typedef struct {
int32_t
maxTables
;
STableData
**
tData
;
SList
*
actList
;
SList
*
extraBuffList
;
SList
*
bufBlockList
;
}
SMemTable
;
...
...
@@ -392,6 +393,8 @@ static FORCE_INLINE STSchema *tsdbGetTableTagSchema(STable *pTable) {
}
// ------------------ tsdbBuffer.c
#define TSDB_BUFFER_RESERVE 1024 // Reseve 1K as commit threshold
STsdbBufPool
*
tsdbNewBufPool
();
void
tsdbFreeBufPool
(
STsdbBufPool
*
pBufPool
);
int
tsdbOpenBufPool
(
STsdbRepo
*
pRepo
);
...
...
@@ -425,6 +428,19 @@ static FORCE_INLINE TSKEY tsdbNextIterKey(SSkipListIterator* pIter) {
return
dataRowKey
(
row
);
}
static
FORCE_INLINE
STsdbBufBlock
*
tsdbGetCurrBufBlock
(
STsdbRepo
*
pRepo
)
{
ASSERT
(
pRepo
!=
NULL
);
if
(
pRepo
->
mem
==
NULL
)
return
NULL
;
SListNode
*
pNode
=
listTail
(
pRepo
->
mem
->
bufBlockList
);
if
(
pNode
==
NULL
)
return
NULL
;
STsdbBufBlock
*
pBufBlock
=
NULL
;
tdListNodeGetData
(
pRepo
->
mem
->
bufBlockList
,
pNode
,
(
void
*
)(
&
pBufBlock
));
return
pBufBlock
;
}
// ------------------ tsdbFile.c
#define TSDB_KEY_FILEID(key, daysPerFile, precision) ((key) / tsMsPerDay[(precision)] / (daysPerFile))
#define TSDB_MAX_FILE(keep, daysPerFile) ((keep) / (daysPerFile) + 3)
...
...
@@ -523,6 +539,7 @@ char* tsdbGetDataDirName(char* rootDir);
int
tsdbGetNextMaxTables
(
int
tid
);
STsdbMeta
*
tsdbGetMeta
(
TSDB_REPO_T
*
pRepo
);
STsdbFileH
*
tsdbGetFile
(
TSDB_REPO_T
*
pRepo
);
int
tsdbCheckCommit
(
STsdbRepo
*
pRepo
);
#ifdef __cplusplus
}
...
...
src/tsdb/src/tsdbMain.c
浏览文件 @
081e7120
...
...
@@ -192,6 +192,8 @@ int32_t tsdbInsertData(TSDB_REPO_T *repo, SSubmitMsg *pMsg, SShellSubmitRspMsg *
}
if
(
pRsp
!=
NULL
)
pRsp
->
affectedRows
=
htonl
(
affectedrows
);
if
(
tsdbCheckCommit
(
pRepo
)
<
0
)
return
-
1
;
return
0
;
}
...
...
@@ -387,6 +389,21 @@ int tsdbGetNextMaxTables(int tid) {
return
maxTables
+
1
;
}
int
tsdbCheckCommit
(
STsdbRepo
*
pRepo
)
{
ASSERT
(
pRepo
->
mem
!=
NULL
);
STsdbCfg
*
pCfg
=
&
(
pRepo
->
config
);
STsdbBufBlock
*
pBufBlock
=
tsdbGetCurrBufBlock
(
pRepo
);
ASSERT
(
pBufBlock
!=
NULL
);
if
((
pRepo
->
mem
->
extraBuffList
!=
NULL
)
||
((
listNEles
(
pRepo
->
mem
->
bufBlockList
)
>=
pCfg
->
totalBlocks
/
3
)
&&
(
pBufBlock
->
remain
<
TSDB_BUFFER_RESERVE
)))
{
// trigger commit
if
(
tsdbAsyncCommit
(
pRepo
)
<
0
)
return
-
1
;
}
return
0
;
}
STsdbMeta
*
tsdbGetMeta
(
TSDB_REPO_T
*
pRepo
)
{
return
((
STsdbRepo
*
)
pRepo
)
->
tsdbMeta
;
}
STsdbFileH
*
tsdbGetFile
(
TSDB_REPO_T
*
pRepo
)
{
return
((
STsdbRepo
*
)
pRepo
)
->
tsdbFileH
;
}
STsdbRepoInfo
*
tsdbGetStatus
(
TSDB_REPO_T
*
pRepo
)
{
return
NULL
;
}
...
...
src/tsdb/src/tsdbMemTable.c
浏览文件 @
081e7120
...
...
@@ -18,8 +18,6 @@
#define TSDB_DATA_SKIPLIST_LEVEL 5
static
FORCE_INLINE
STsdbBufBlock
*
tsdbGetCurrBufBlock
(
STsdbRepo
*
pRepo
);
static
void
tsdbFreeBytes
(
STsdbRepo
*
pRepo
,
void
*
ptr
,
int
bytes
);
static
SMemTable
*
tsdbNewMemTable
(
STsdbRepo
*
pRepo
);
static
void
tsdbFreeMemTable
(
SMemTable
*
pMemTable
);
...
...
@@ -202,44 +200,59 @@ void tsdbUnTakeMemSnapShot(STsdbRepo *pRepo, SMemTable *pMem, SMemTable *pIMem)
void
*
tsdbAllocBytes
(
STsdbRepo
*
pRepo
,
int
bytes
)
{
STsdbCfg
*
pCfg
=
&
pRepo
->
config
;
STsdbBufBlock
*
pBufBlock
=
tsdbGetCurrBufBlock
(
pRepo
);
if
(
pBufBlock
!=
NULL
&&
pBufBlock
->
remain
<
bytes
)
{
if
(
listNEles
(
pRepo
->
mem
->
bufBlockList
)
>=
pCfg
->
totalBlocks
/
3
)
{
// need to commit mem
if
(
tsdbAsyncCommit
(
pRepo
)
<
0
)
return
NULL
;
}
else
{
if
(
tsdbLockRepo
(
pRepo
)
<
0
)
return
NULL
;
SListNode
*
pNode
=
tsdbAllocBufBlockFromPool
(
pRepo
);
tdListAppendNode
(
pRepo
->
mem
->
bufBlockList
,
pNode
);
if
(
tsdbUnlockRepo
(
pRepo
)
<
0
)
return
NULL
;
}
}
STsdbBufBlock
*
pBufBlock
=
NULL
;
void
*
ptr
=
NULL
;
// Either allocate from buffer blocks or from SYSTEM memory pool
if
(
pRepo
->
mem
==
NULL
)
{
SMemTable
*
pMemTable
=
tsdbNewMemTable
(
pRepo
);
if
(
pMemTable
==
NULL
)
return
NULL
;
pRepo
->
mem
=
pMemTable
;
}
ASSERT
(
pRepo
->
mem
!=
NULL
);
if
(
tsdbLockRepo
(
pRepo
)
<
0
)
{
tsdbFreeMemTable
(
pMemTable
);
pBufBlock
=
tsdbGetCurrBufBlock
(
pRepo
);
if
((
pRepo
->
mem
->
extraBuffList
!=
NULL
)
||
((
listNEles
(
pRepo
->
mem
->
bufBlockList
)
>=
pCfg
->
totalBlocks
/
3
)
&&
(
pBufBlock
->
remain
<
bytes
)))
{
// allocate from SYSTEM buffer pool
if
(
pRepo
->
mem
->
extraBuffList
==
NULL
)
{
pRepo
->
mem
->
extraBuffList
=
tdListNew
(
0
);
if
(
pRepo
->
mem
->
extraBuffList
==
NULL
)
{
terrno
=
TSDB_CODE_TDB_OUT_OF_MEMORY
;
return
NULL
;
}
}
ASSERT
(
pRepo
->
mem
->
extraBuffList
!=
NULL
);
SListNode
*
pNode
=
(
SListNode
*
)
malloc
(
sizeof
(
SListNode
)
+
bytes
);
if
(
pNode
==
NULL
)
{
terrno
=
TSDB_CODE_TDB_OUT_OF_MEMORY
;
return
NULL
;
}
SListNode
*
pNode
=
tsdbAllocBufBlockFromPool
(
pRepo
);
tdListAppendNode
(
pMemTable
->
bufBlockList
,
pNode
);
pRepo
->
mem
=
pMemTable
;
pNode
->
next
=
pNode
->
prev
=
NULL
;
tdListAppend
(
pRepo
->
mem
->
extraBuffList
,
pNode
);
ptr
=
(
void
*
)(
pNode
->
data
);
tsdbTrace
(
"vgId:%d allocate %d bytes from SYSTEM buffer block"
,
REPO_ID
(
pRepo
),
bytes
);
}
else
{
// allocate from TSDB buffer pool
if
(
pBufBlock
==
NULL
||
pBufBlock
->
remain
<
bytes
)
{
ASSERT
(
listNEles
(
pRepo
->
mem
->
bufBlockList
)
<
pCfg
->
totalBlocks
/
3
);
if
(
tsdbLockRepo
(
pRepo
)
<
0
)
return
NULL
;
SListNode
*
pNode
=
tsdbAllocBufBlockFromPool
(
pRepo
);
tdListAppendNode
(
pRepo
->
mem
->
bufBlockList
,
pNode
);
if
(
tsdbUnlockRepo
(
pRepo
)
<
0
)
return
NULL
;
pBufBlock
=
tsdbGetCurrBufBlock
(
pRepo
);
}
if
(
tsdbUnlockRepo
(
pRepo
)
<
0
)
return
NULL
;
ASSERT
(
pBufBlock
->
remain
>=
bytes
);
ptr
=
POINTER_SHIFT
(
pBufBlock
->
data
,
pBufBlock
->
offset
);
pBufBlock
->
offset
+=
bytes
;
pBufBlock
->
remain
-=
bytes
;
tsdbTrace
(
"vgId:%d allocate %d bytes from TSDB buffer block, nBlocks %d offset %d remain %d"
,
REPO_ID
(
pRepo
),
bytes
,
listNEles
(
pRepo
->
mem
->
bufBlockList
),
pBufBlock
->
offset
,
pBufBlock
->
remain
);
}
pBufBlock
=
tsdbGetCurrBufBlock
(
pRepo
);
ASSERT
(
pBufBlock
->
remain
>=
bytes
);
void
*
ptr
=
POINTER_SHIFT
(
pBufBlock
->
data
,
pBufBlock
->
offset
);
pBufBlock
->
offset
+=
bytes
;
pBufBlock
->
remain
-=
bytes
;
tsdbTrace
(
"vgId:%d allocate %d bytes from buffer block, nBlocks %d offset %d remain %d"
,
REPO_ID
(
pRepo
),
bytes
,
listNEles
(
pRepo
->
mem
->
bufBlockList
),
pBufBlock
->
offset
,
pBufBlock
->
remain
);
return
ptr
;
}
...
...
@@ -340,27 +353,23 @@ int tsdbLoadDataFromCache(STable *pTable, SSkipListIterator *pIter, TSKEY maxKey
}
// ---------------- LOCAL FUNCTIONS ----------------
static
FORCE_INLINE
STsdbBufBlock
*
tsdbGetCurrBufBlock
(
STsdbRepo
*
pRepo
)
{
ASSERT
(
pRepo
!=
NULL
);
if
(
pRepo
->
mem
==
NULL
)
return
NULL
;
SListNode
*
pNode
=
listTail
(
pRepo
->
mem
->
bufBlockList
);
if
(
pNode
==
NULL
)
return
NULL
;
STsdbBufBlock
*
pBufBlock
=
NULL
;
tdListNodeGetData
(
pRepo
->
mem
->
bufBlockList
,
pNode
,
(
void
*
)(
&
pBufBlock
));
return
pBufBlock
;
}
static
void
tsdbFreeBytes
(
STsdbRepo
*
pRepo
,
void
*
ptr
,
int
bytes
)
{
STsdbBufBlock
*
pBufBlock
=
tsdbGetCurrBufBlock
(
pRepo
);
ASSERT
(
pBufBlock
!=
NULL
);
pBufBlock
->
offset
-=
bytes
;
pBufBlock
->
remain
+=
bytes
;
ASSERT
(
ptr
==
POINTER_SHIFT
(
pBufBlock
->
data
,
pBufBlock
->
offset
));
tsdbTrace
(
"vgId:%d return %d bytes to buffer block, nBlocks %d offset %d remain %d"
,
REPO_ID
(
pRepo
),
bytes
,
listNEles
(
pRepo
->
mem
->
bufBlockList
),
pBufBlock
->
offset
,
pBufBlock
->
remain
);
ASSERT
(
pRepo
->
mem
!=
NULL
);
if
(
pRepo
->
mem
->
extraBuffList
==
NULL
)
{
STsdbBufBlock
*
pBufBlock
=
tsdbGetCurrBufBlock
(
pRepo
);
ASSERT
(
pBufBlock
!=
NULL
);
pBufBlock
->
offset
-=
bytes
;
pBufBlock
->
remain
+=
bytes
;
ASSERT
(
ptr
==
POINTER_SHIFT
(
pBufBlock
->
data
,
pBufBlock
->
offset
));
tsdbTrace
(
"vgId:%d free %d bytes to TSDB buffer pool, nBlocks %d offset %d remain %d"
,
REPO_ID
(
pRepo
),
bytes
,
listNEles
(
pRepo
->
mem
->
bufBlockList
),
pBufBlock
->
offset
,
pBufBlock
->
remain
);
}
else
{
SListNode
*
pNode
=
(
SListNode
*
)
POINTER_SHIFT
(
ptr
,
-
sizeof
(
SListNode
));
ASSERT
(
listTail
(
pRepo
->
mem
->
extraBuffList
)
==
pNode
);
tdListPopNode
(
pRepo
->
mem
->
extraBuffList
,
pNode
);
free
(
pNode
);
tsdbTrace
(
"vgId:%d free %d bytes to SYSTEM buffer pool"
,
REPO_ID
(
pRepo
),
bytes
);
}
}
static
SMemTable
*
tsdbNewMemTable
(
STsdbRepo
*
pRepo
)
{
...
...
@@ -409,6 +418,7 @@ static void tsdbFreeMemTable(SMemTable* pMemTable) {
ASSERT
((
pMemTable
->
bufBlockList
==
NULL
)
?
true
:
(
listNEles
(
pMemTable
->
bufBlockList
)
==
0
));
ASSERT
((
pMemTable
->
actList
==
NULL
)
?
true
:
(
listNEles
(
pMemTable
->
actList
)
==
0
));
tdListFree
(
pMemTable
->
extraBuffList
);
tdListFree
(
pMemTable
->
bufBlockList
);
tdListFree
(
pMemTable
->
actList
);
taosTFree
(
pMemTable
->
tData
);
...
...
src/tsdb/src/tsdbMeta.c
浏览文件 @
081e7120
...
...
@@ -120,20 +120,23 @@ int tsdbCreateTable(TSDB_REPO_T *repo, STableCfg *pCfg) {
tsdbUnlockRepoMeta
(
pRepo
);
// Write to memtable action
int
tlen1
=
(
newSuper
)
?
tsdbGetTableEncodeSize
(
TSDB_UPDATE_META
,
super
)
:
0
;
int
tlen2
=
tsdbGetTableEncodeSize
(
TSDB_UPDATE_META
,
table
);
int
tlen
=
tlen1
+
tlen2
;
void
*
buf
=
tsdbAllocBytes
(
pRepo
,
tlen
);
if
(
buf
==
NULL
)
{
goto
_err
;
}
// TODO: refactor duplicate codes
int
tlen
=
0
;
void
*
pBuf
=
NULL
;
if
(
newSuper
)
{
void
*
pBuf
=
tsdbInsertTableAct
(
pRepo
,
TSDB_UPDATE_META
,
buf
,
super
);
ASSERT
(
POINTER_DISTANCE
(
pBuf
,
buf
)
==
tlen1
);
buf
=
pBuf
;
tlen
=
tsdbGetTableEncodeSize
(
TSDB_UPDATE_META
,
super
);
pBuf
=
tsdbAllocBytes
(
pRepo
,
tlen
);
if
(
pBuf
==
NULL
)
goto
_err
;
void
*
tBuf
=
tsdbInsertTableAct
(
pRepo
,
TSDB_UPDATE_META
,
pBuf
,
super
);
ASSERT
(
POINTER_DISTANCE
(
tBuf
,
pBuf
)
==
tlen
);
}
tsdbInsertTableAct
(
pRepo
,
TSDB_UPDATE_META
,
buf
,
table
);
tlen
=
tsdbGetTableEncodeSize
(
TSDB_UPDATE_META
,
table
);
pBuf
=
tsdbAllocBytes
(
pRepo
,
tlen
);
if
(
pBuf
==
NULL
)
goto
_err
;
void
*
tBuf
=
tsdbInsertTableAct
(
pRepo
,
TSDB_UPDATE_META
,
pBuf
,
table
);
ASSERT
(
POINTER_DISTANCE
(
tBuf
,
pBuf
)
==
tlen
);
if
(
tsdbCheckCommit
(
pRepo
)
<
0
)
return
-
1
;
return
0
;
...
...
@@ -182,6 +185,8 @@ int tsdbDropTable(TSDB_REPO_T *repo, STableId tableId) {
tsdbDebug
(
"vgId:%d, table %s is dropped! tid:%d, uid:%"
PRId64
,
pRepo
->
config
.
tsdbId
,
tbname
,
tid
,
uid
);
free
(
tbname
);
if
(
tsdbCheckCommit
(
pRepo
)
<
0
)
goto
_err
;
return
0
;
_err:
...
...
@@ -405,6 +410,8 @@ int tsdbUpdateTableTagValue(TSDB_REPO_T *repo, SUpdateTableTagValMsg *pMsg) {
}
tsdbInsertTableAct
(
pRepo
,
TSDB_UPDATE_META
,
buf
,
pTable
);
if
(
tsdbCheckCommit
(
pRepo
)
<
0
)
return
-
1
;
return
0
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录