Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
6413285b
T
TDengine
项目概览
慢慢CG
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
6413285b
编写于
6月 13, 2020
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
TD-353
上级
c2d352b9
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
60 addition
and
41 deletion
+60
-41
src/tsdb/inc/tsdbMain.h
src/tsdb/inc/tsdbMain.h
+4
-2
src/tsdb/src/tsdbMain.c
src/tsdb/src/tsdbMain.c
+4
-0
src/tsdb/src/tsdbMemTable.c
src/tsdb/src/tsdbMemTable.c
+52
-39
未找到文件。
src/tsdb/inc/tsdbMain.h
浏览文件 @
6413285b
...
...
@@ -254,7 +254,7 @@ typedef struct {
// ------------------ tsdbMain.c
typedef
struct
{
int8_t
state
;
int8_t
state
;
char
*
rootDir
;
STsdbCfg
config
;
...
...
@@ -265,9 +265,10 @@ typedef struct {
SMemTable
*
mem
;
SMemTable
*
imem
;
STsdbFileH
*
tsdbFileH
;
pthread_mutex_t
mutex
;
int
commit
;
pthread_t
commitThread
;
pthread_mutex_t
mutex
;
bool
repoLocked
;
}
STsdbRepo
;
// Operations
...
...
@@ -309,6 +310,7 @@ void tsdbFreeFileH(STsdbFileH* pFileH);
// ------------------ tsdbMain.c
#define REPO_ID(r) (r)->config.tsdbId
#define IS_REPO_LOCKED(r) (r)->repoLocked
char
*
tsdbGetMetaFileName
(
char
*
rootDir
);
int
tsdbLockRepo
(
STsdbRepo
*
pRepo
);
...
...
src/tsdb/src/tsdbMain.c
浏览文件 @
6413285b
...
...
@@ -337,10 +337,12 @@ int tsdbLockRepo(STsdbRepo *pRepo) {
terrno
=
TAOS_SYSTEM_ERROR
(
code
);
return
-
1
;
}
pRepo
->
repoLocked
=
true
;
return
0
;
}
int
tsdbUnlockRepo
(
STsdbRepo
*
pRepo
)
{
pRepo
->
repoLocked
=
false
;
int
code
=
pthread_mutex_unlock
(
&
pRepo
->
mutex
);
if
(
code
!=
0
)
{
tsdbError
(
"vgId:%d failed to unlock tsdb since %s"
,
REPO_ID
(
pRepo
),
strerror
(
errno
));
...
...
@@ -679,6 +681,8 @@ static STsdbRepo *tsdbNewRepo(char *rootDir, STsdbAppH *pAppH, STsdbCfg *pCfg) {
goto
_err
;
}
pRepo
->
repoLocked
=
false
;
pRepo
->
rootDir
=
strdup
(
rootDir
);
if
(
pRepo
->
rootDir
==
NULL
)
{
terrno
=
TSDB_CODE_TDB_OUT_OF_MEMORY
;
...
...
src/tsdb/src/tsdbMemTable.c
浏览文件 @
6413285b
...
...
@@ -20,60 +20,68 @@
// ---------------- INTERNAL FUNCTIONS ----------------
int
tsdbInsertRowToMem
(
STsdbRepo
*
pRepo
,
SDataRow
row
,
STable
*
pTable
)
{
STsdbCfg
*
pCfg
=
&
pRepo
->
config
;
int32_t
level
=
0
;
int32_t
headSize
=
0
;
TSKEY
key
=
dataRowKey
(
row
);
STsdbCfg
*
pCfg
=
&
pRepo
->
config
;
int32_t
level
=
0
;
int32_t
headSize
=
0
;
TSKEY
key
=
dataRowKey
(
row
);
SMemTable
*
pMemTable
=
pRepo
->
mem
;
STableData
*
pTableData
=
NULL
;
int
bytes
=
0
;
if
(
pMemTable
!=
NULL
&&
pMemTable
->
tData
[
TABLE_TID
(
pTable
)]
!=
NULL
&&
pMemTable
->
tData
[
TABLE_TID
(
pTable
)]
->
uid
==
TALBE_UID
(
pTable
))
{
pTableData
=
pMemTable
->
tData
[
TABLE_TID
(
pTable
)];
}
// TODO
tSkipListNewNodeInfo
(
pRepo
->
mem
->
tData
[
TABLE_TID
(
pTable
)]
->
pData
,
&
level
,
&
headSize
);
tSkipListNewNodeInfo
(
pTableData
,
&
level
,
&
headSize
);
// TODO: for duplicate keys, you do not need to allocate memory here
SSkipListNode
*
pNode
=
tsdbAllocBytes
(
pRepo
,
headSize
+
dataRowLen
(
row
)
);
bytes
=
headSize
+
dataRowLen
(
row
);
SSkipListNode
*
pNode
=
tsdbAllocBytes
(
pRepo
,
bytes
);
if
(
pNode
==
NULL
)
{
tsdbError
(
"vgId:%d failed to insert row with key %"
PRId64
" to table %s
since %s"
,
REPO_ID
(
pRepo
),
key
,
TABLE_CHAR_NAME
(
pTable
)
,
tstrerror
(
terrno
));
tsdbError
(
"vgId:%d failed to insert row with key %"
PRId64
" to table %s
while allocate %d bytes since %s"
,
REPO_ID
(
pRepo
),
key
,
TABLE_CHAR_NAME
(
pTable
),
bytes
,
tstrerror
(
terrno
));
return
-
1
;
}
SMemTable
*
pMemTable
=
pRepo
->
mem
;
ASSERT
(
pMemTable
!=
NULL
);
pNode
->
level
=
level
;
dataRowCpy
(
SL_GET_NODE_DATA
(
pNode
),
row
);
STableData
*
pTableData
=
pMemTable
->
tData
[
TABLE_TID
(
pTable
)];
if
(
pTableData
==
NULL
)
{
pTableData
=
tsdbNewTableData
(
pCfg
);
// Operations above may change pRepo->mem, retake those values
ASSERT
(
pRepo
->
mem
!=
NULL
);
pMemTable
=
pRepo
->
mem
;
pTableData
=
pMemTable
->
tData
[
TABLE_TID
(
pTable
)];
if
(
pTableData
==
NULL
||
pTableData
->
uid
!=
TALBE_UID
(
pTable
))
{
if
(
pTableData
!=
NULL
)
{
// destroy the table skiplist (may have race condition problem)
pMemTable
->
tData
[
TABLE_TID
(
pTable
)]
=
NULL
;
tsdbFreeTableData
(
pTableData
);
}
pTableData
=
tsdbNewTableData
(
pCfg
,
pTable
);
if
(
pTableData
==
NULL
)
{
tsdbError
(
"vgId:%d failed to insert row with key %"
PRId64
" to table %s since %s"
,
REPO_ID
(
pRepo
),
key
,
TABLE_CHAR_NAME
(
pTable
),
tstrerror
(
terrno
));
tsdbError
(
"vgId:%d failed to insert row with key %"
PRId64
" to table %s while create new table data object since %s"
,
REPO_ID
(
pRepo
),
key
,
TABLE_CHAR_NAME
(
pTable
),
tstrerror
(
terrno
));
tsdbFreeBytes
(
pRepo
,
(
void
*
)
pNode
,
bytes
);
return
-
1
;
}
pRepo
->
mem
->
tData
[
TABLE_TID
(
pTable
)]
=
pTableData
;
}
ASSERT
(
pTableData
!=
NULL
);
if
(
pTableData
->
uid
!=
TALBE_UID
(
pTable
))
{
// TODO
}
ASSERT
(
pTableData
!=
NULL
)
&&
pTableData
->
uid
==
TALBE_UID
(
pTable
);
if
(
tSkipListPut
(
pTableData
->
pData
,
pNode
)
==
NULL
)
{
tsdbFreeBytes
(
pRepo
,
(
void
*
)
pNode
,
headSize
+
dataRowLen
);
return
0
;
}
if
(
pMemTable
->
keyFirst
>
key
)
pMemTable
->
keyFirst
=
key
;
if
(
pMemTable
->
keyLast
<
key
)
pMemTable
->
keyLast
=
key
;
pMemTable
->
numOfRows
++
;
tsdbFreeBytes
(
pRepo
,
(
void
*
)
pNode
,
bytes
);
}
else
{
if
(
pMemTable
->
keyFirst
>
key
)
pMemTable
->
keyFirst
=
key
;
if
(
pMemTable
->
keyLast
<
key
)
pMemTable
->
keyLast
=
key
;
pMemTable
->
numOfRows
++
;
if
(
pTableData
->
keyFirst
>
key
)
pTableData
->
keyFirst
=
key
;
if
(
pTableData
->
keyLast
<
key
)
pTableData
->
keyLast
=
key
;
pTableData
->
numOfRows
++
;
if
(
pTableData
->
keyFirst
>
key
)
pTableData
->
keyFirst
=
key
;
if
(
pTableData
->
keyLast
<
key
)
pTableData
->
keyLast
=
key
;
pTableData
->
numOfRows
++
;
ASSERT
(
pTableData
->
numOfRows
==
tSkipListGetSize
(
pTableData
->
pData
));
ASSERT
(
pTableData
->
numOfRows
==
tSkipListGetSize
(
pTableData
->
pData
));
}
tsdbTrace
(
"vgId:%d a row is inserted to table %s tid %d uid %"
PRIu64
" key %"
PRIu64
,
REPO_ID
(
pRepo
),
TABLE_CHAR_NAME
(
pTable
),
TABLE_TID
(
pTable
),
TALBE_UID
(
pTable
),
key
);
...
...
@@ -82,12 +90,14 @@ int tsdbInsertRowToMem(STsdbRepo *pRepo, SDataRow row, STable *pTable) {
}
int
tsdbRefMemTable
(
STsdbRepo
*
pRepo
,
SMemTable
*
pMemTable
)
{
ASSERT
(
IS_REPO_LOCKED
(
pRepo
));
ASSERT
(
pMemTable
!=
NULL
);
T_REF_INC
(
pMemTable
);
}
// Need to lock the repository
int
tsdbUnRefMemTable
(
STsdbRepo
*
pRepo
,
SMemTable
*
pMemTable
)
{
ASSERT
(
IS_REPO_LOCKED
(
pRepo
));
ASSERT
(
pMemTable
!=
NULL
);
if
(
T_REF_DEC
(
pMemTable
)
==
0
)
{
...
...
@@ -117,7 +127,7 @@ int tsdbUnRefMemTable(STsdbRepo *pRepo, SMemTable *pMemTable) {
// ---------------- LOCAL FUNCTIONS ----------------
static
FORCE_INLINE
STsdbBufBlock
*
tsdbGetCurrBufBlock
(
STsdbRepo
*
pRepo
)
{
if
(
pRepo
->
mem
==
NULL
)
return
NULL
;
if
(
pRepo
==
NULL
||
pRepo
->
mem
==
NULL
)
return
NULL
;
SListNode
*
pNode
=
listTail
(
pRepo
->
mem
);
if
(
pNode
==
NULL
)
return
NULL
;
...
...
@@ -258,13 +268,14 @@ static STableData *tsdbNewTableData(STsdbCfg *pCfg, STable *pTable) {
pTableData
->
keyLast
=
0
;
pTableData
->
numOfRows
=
0
;
pTableData
->
pData
=
tSkipListCreate
(
TSDB_DATA_SKIPLIST_LEVEL
,
TSDB_DATA_TYPE_TIMESTAMP
,
TYPE_BYTES
[
TSDB_DATA_TYPE_TIMESTAMP
],
0
,
0
,
0
,
);
pTableData
->
pData
=
tSkipListCreate
(
TSDB_DATA_SKIPLIST_LEVEL
,
TSDB_DATA_TYPE_TIMESTAMP
,
TYPE_BYTES
[
TSDB_DATA_TYPE_TIMESTAMP
],
0
,
0
,
0
,
tsdbGetTsTupleKey
);
if
(
pTableData
->
pData
==
NULL
)
{
terrno
=
TSDB_CODE_TDB_OUT_OF_MEMORY
;
goto
_err
;
}
// TODO
// TODO
: operation here should not be here, remove it
pTableData
->
pData
->
level
=
1
;
return
pTableData
;
...
...
@@ -279,4 +290,6 @@ static void tsdbFreeTableData(STableData *pTableData) {
tSkipListDestroy
(
pTableData
->
pData
);
free
(
pTableData
);
}
}
\ No newline at end of file
}
static
char
*
tsdbGetTsTupleKey
(
const
void
*
data
)
{
return
dataRowTuple
(
data
);
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录