Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
6dfca928
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看板
未验证
提交
6dfca928
编写于
3月 30, 2020
作者:
H
haojun Liao
提交者:
GitHub
3月 30, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1467 from taosdata/feature/2.0tsdb
Feature/2.0tsdb
上级
fd6c41eb
d8c7cdf1
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
138 addition
and
9 deletion
+138
-9
src/util/src/tskiplist.c
src/util/src/tskiplist.c
+1
-1
src/vnode/tsdb/inc/tsdbFile.h
src/vnode/tsdb/inc/tsdbFile.h
+13
-0
src/vnode/tsdb/src/tsdbFile.c
src/vnode/tsdb/src/tsdbFile.c
+80
-2
src/vnode/tsdb/src/tsdbMain.c
src/vnode/tsdb/src/tsdbMain.c
+33
-1
src/vnode/tsdb/tests/tsdbTests.cpp
src/vnode/tsdb/tests/tsdbTests.cpp
+11
-5
未找到文件。
src/util/src/tskiplist.c
浏览文件 @
6dfca928
...
...
@@ -472,7 +472,7 @@ void tSkipListDoInsert(SSkipList *pSkipList, SSkipListNode **forward, int32_t le
SL_GET_FORWARD_POINTER
(
x
,
i
)
=
pNode
;
}
else
{
SL_GET_FORWARD_POINTER
(
pSkipList
->
pHead
,
i
)
=
pNode
;
SL_GET_BACKWARD_POINTER
(
pSkipList
->
pHead
,
i
)
=
(
pSkipList
->
pHead
);
//
SL_GET_BACKWARD_POINTER(pSkipList->pHead, i) = (pSkipList->pHead);
}
}
}
...
...
src/vnode/tsdb/inc/tsdbFile.h
浏览文件 @
6dfca928
...
...
@@ -82,6 +82,19 @@ int tsdbOpenFile(SFile *pFile, int oflag);
int
tsdbCloseFile
(
SFile
*
pFile
);
SFileGroup
*
tsdbOpenFilesForCommit
(
STsdbFileH
*
pFileH
,
int
fid
);
int
tsdbRemoveFileGroup
(
STsdbFileH
*
pFile
,
int
fid
);
#define TSDB_FGROUP_ITER_FORWARD 0
#define TSDB_FGROUP_ITER_BACKWARD 1
typedef
struct
{
int
numOfFGroups
;
SFileGroup
*
base
;
SFileGroup
*
pFileGroup
;
int
direction
;
}
SFileGroupIter
;
void
tsdbInitFileGroupIter
(
STsdbFileH
*
pFileH
,
SFileGroupIter
*
pIter
,
int
direction
);
void
tsdbSeekFileGroupIter
(
SFileGroupIter
*
pIter
,
int
fid
);
SFileGroup
*
tsdbGetFileGroupNext
(
SFileGroupIter
*
pIter
);
typedef
struct
{
int32_t
len
;
int32_t
offset
;
...
...
src/vnode/tsdb/src/tsdbFile.c
浏览文件 @
6dfca928
...
...
@@ -22,6 +22,7 @@
#include <sys/types.h>
#include <unistd.h>
#include "tutil.h"
#include "tsdbFile.h"
const
char
*
tsdbFileSuffix
[]
=
{
...
...
@@ -35,6 +36,7 @@ static int compFGroup(const void *arg1, const void *arg2);
static
int
tsdbGetFileName
(
char
*
dataDir
,
int
fileId
,
char
*
suffix
,
char
*
fname
);
static
int
tsdbWriteFileHead
(
SFile
*
pFile
);
static
int
tsdbWriteHeadFileIdx
(
SFile
*
pFile
,
int
maxTables
);
static
int
tsdbOpenFGroup
(
STsdbFileH
*
pFileH
,
char
*
dataDir
,
int
fid
);
STsdbFileH
*
tsdbInitFileH
(
char
*
dataDir
,
int
maxFiles
)
{
STsdbFileH
*
pFileH
=
(
STsdbFileH
*
)
calloc
(
1
,
sizeof
(
STsdbFileH
)
+
sizeof
(
SFileGroup
)
*
maxFiles
);
...
...
@@ -50,10 +52,17 @@ STsdbFileH *tsdbInitFileH(char *dataDir, int maxFiles) {
return
NULL
;
}
struct
dirent
*
dp
;
struct
dirent
*
dp
=
NULL
;
int
fid
=
0
;
SFileGroup
fGroup
=
{
0
};
while
((
dp
=
readdir
(
dir
))
!=
NULL
)
{
if
(
strncmp
(
dp
->
d_name
,
"."
,
1
)
==
0
||
strncmp
(
dp
->
d_name
,
".."
,
1
)
==
0
)
continue
;
// TODO
int
fid
=
0
;
sscanf
(
dp
->
d_name
,
"f%d"
,
&
fid
);
if
(
tsdbOpenFGroup
(
pFileH
,
dataDir
,
fid
)
<
0
)
{
break
;
// TODO
}
}
return
pFileH
;
...
...
@@ -61,6 +70,30 @@ STsdbFileH *tsdbInitFileH(char *dataDir, int maxFiles) {
void
tsdbCloseFileH
(
STsdbFileH
*
pFileH
)
{
free
(
pFileH
);
}
static
int
tsdbInitFile
(
char
*
dataDir
,
int
fid
,
char
*
suffix
,
SFile
*
pFile
)
{
tsdbGetFileName
(
dataDir
,
fid
,
suffix
,
pFile
->
fname
);
if
(
access
(
pFile
->
fname
,
F_OK
|
R_OK
|
W_OK
)
<
0
)
return
-
1
;
pFile
->
fd
=
-
1
;
// TODO: recover the file info
// pFile->info = {0};
return
0
;
}
static
int
tsdbOpenFGroup
(
STsdbFileH
*
pFileH
,
char
*
dataDir
,
int
fid
)
{
if
(
tsdbSearchFGroup
(
pFileH
,
fid
)
!=
NULL
)
return
0
;
char
fname
[
128
]
=
"
\0
"
;
SFileGroup
fGroup
=
{
0
};
fGroup
.
fileId
=
fid
;
for
(
int
type
=
TSDB_FILE_TYPE_HEAD
;
type
<
TSDB_FILE_TYPE_MAX
;
type
++
)
{
if
(
tsdbInitFile
(
dataDir
,
fid
,
tsdbFileSuffix
[
type
],
&
fGroup
.
files
[
type
])
<
0
)
return
-
1
;
}
pFileH
->
fGroup
[
pFileH
->
numOfFGroups
++
]
=
fGroup
;
qsort
((
void
*
)(
pFileH
->
fGroup
),
pFileH
->
numOfFGroups
,
sizeof
(
SFileGroup
),
compFGroup
);
return
0
;
}
int
tsdbCreateFGroup
(
STsdbFileH
*
pFileH
,
char
*
dataDir
,
int
fid
,
int
maxTables
)
{
if
(
pFileH
->
numOfFGroups
>=
pFileH
->
maxFGroups
)
return
-
1
;
...
...
@@ -101,6 +134,51 @@ int tsdbRemoveFileGroup(STsdbFileH *pFileH, int fid) {
return
0
;
}
void
tsdbInitFileGroupIter
(
STsdbFileH
*
pFileH
,
SFileGroupIter
*
pIter
,
int
direction
)
{
pIter
->
direction
=
direction
;
pIter
->
base
=
pFileH
->
fGroup
;
pIter
->
numOfFGroups
=
pFileH
->
numOfFGroups
;
if
(
pFileH
->
numOfFGroups
==
0
){
pIter
->
pFileGroup
=
NULL
;
}
else
{
if
(
direction
==
TSDB_FGROUP_ITER_FORWARD
)
{
pIter
->
pFileGroup
=
pFileH
->
fGroup
;
}
else
{
pIter
->
pFileGroup
=
pFileH
->
fGroup
+
pFileH
->
numOfFGroups
-
1
;
}
}
}
void
tsdbSeekFileGroupIter
(
SFileGroupIter
*
pIter
,
int
fid
)
{
int
flags
=
(
pIter
->
direction
==
TSDB_FGROUP_ITER_FORWARD
)
?
TD_GE
:
TD_LE
;
void
*
ptr
=
taosbsearch
(
&
fid
,
pIter
->
base
,
sizeof
(
SFileGroup
),
pIter
->
numOfFGroups
,
compFGroupKey
,
flags
);
if
(
ptr
==
NULL
)
{
pIter
->
pFileGroup
=
NULL
;
}
else
{
pIter
->
pFileGroup
=
(
SFileGroup
*
)
ptr
;
}
}
SFileGroup
*
tsdbGetFileGroupNext
(
SFileGroupIter
*
pIter
)
{
SFileGroup
*
ret
=
pIter
->
pFileGroup
;
if
(
ret
==
NULL
)
return
NULL
;
if
(
pIter
->
direction
=
TSDB_FGROUP_ITER_FORWARD
)
{
if
(
pIter
->
pFileGroup
+
1
==
pIter
->
base
+
pIter
->
numOfFGroups
)
{
pIter
->
pFileGroup
=
NULL
;
}
else
{
pIter
->
pFileGroup
+=
1
;
}
}
else
{
if
(
pIter
->
pFileGroup
-
1
==
pIter
->
base
)
{
pIter
->
pFileGroup
=
NULL
;
}
else
{
pIter
->
pFileGroup
-=
1
;
}
}
return
ret
;
}
int
tsdbLoadDataBlock
(
SFile
*
pFile
,
SCompBlock
*
pStartBlock
,
int
numOfBlocks
,
SDataCols
*
pCols
,
SCompData
*
pCompData
)
{
SCompBlock
*
pBlock
=
pStartBlock
;
for
(
int
i
=
0
;
i
<
numOfBlocks
;
i
++
)
{
...
...
src/vnode/tsdb/src/tsdbMain.c
浏览文件 @
6dfca928
...
...
@@ -237,6 +237,7 @@ int32_t tsdbDropRepo(tsdb_repo_t *repo) {
* @return a TSDB repository handle on success, NULL for failure and the error number is set
*/
tsdb_repo_t
*
tsdbOpenRepo
(
char
*
tsdbDir
)
{
char
dataDir
[
128
]
=
"
\0
"
;
if
(
access
(
tsdbDir
,
F_OK
|
W_OK
|
R_OK
)
<
0
)
{
return
NULL
;
}
...
...
@@ -265,6 +266,16 @@ tsdb_repo_t *tsdbOpenRepo(char *tsdbDir) {
return
NULL
;
}
tsdbGetDataDirName
(
pRepo
,
dataDir
);
pRepo
->
tsdbFileH
=
tsdbInitFileH
(
dataDir
,
pRepo
->
config
.
maxTables
);
if
(
pRepo
->
tsdbFileH
==
NULL
)
{
tsdbFreeCache
(
pRepo
->
tsdbCache
);
tsdbFreeMeta
(
pRepo
->
tsdbMeta
);
free
(
pRepo
->
rootDir
);
free
(
pRepo
);
return
NULL
;
}
pRepo
->
state
=
TSDB_REPO_STATE_ACTIVE
;
return
(
tsdb_repo_t
*
)
pRepo
;
...
...
@@ -287,8 +298,29 @@ int32_t tsdbCloseRepo(tsdb_repo_t *repo) {
if
(
pRepo
==
NULL
)
return
0
;
pRepo
->
state
=
TSDB_REPO_STATE_CLOSED
;
tsdbLockRepo
(
repo
);
if
(
pRepo
->
commit
)
{
tsdbUnLockRepo
(
repo
);
return
-
1
;
}
pRepo
->
commit
=
1
;
// Loop to move pData to iData
for
(
int
i
=
0
;
i
<
pRepo
->
config
.
maxTables
;
i
++
)
{
STable
*
pTable
=
pRepo
->
tsdbMeta
->
tables
[
i
];
if
(
pTable
!=
NULL
&&
pTable
->
mem
!=
NULL
)
{
pTable
->
imem
=
pTable
->
mem
;
pTable
->
mem
=
NULL
;
}
}
// TODO: Loop to move mem to imem
pRepo
->
tsdbCache
->
imem
=
pRepo
->
tsdbCache
->
mem
;
pRepo
->
tsdbCache
->
mem
=
NULL
;
pRepo
->
tsdbCache
->
curBlock
=
NULL
;
tsdbUnLockRepo
(
repo
);
tsdbCommitData
((
void
*
)
repo
);
tsdb
FlushCache
(
pRepo
);
tsdb
CloseFileH
(
pRepo
->
tsdbFileH
);
tsdbFreeMeta
(
pRepo
->
tsdbMeta
);
...
...
src/vnode/tsdb/tests/tsdbTests.cpp
浏览文件 @
6dfca928
...
...
@@ -49,6 +49,7 @@ TEST(TsdbTest, DISABLED_tableEncodeDecode) {
ASSERT_EQ
(
memcmp
(
pTable
->
schema
,
tTable
->
schema
,
sizeof
(
STSchema
)
+
sizeof
(
STColumn
)
*
nCols
),
0
);
}
// TEST(TsdbTest, DISABLED_createRepo) {
TEST
(
TsdbTest
,
createRepo
)
{
STsdbCfg
config
;
...
...
@@ -87,6 +88,7 @@ TEST(TsdbTest, createRepo) {
double
stime
=
getCurTime
();
for
(
int
k
=
0
;
k
<
nRows
/
rowsPerSubmit
;
k
++
)
{
memset
((
void
*
)
pMsg
,
0
,
sizeof
(
SSubmitMsg
));
SSubmitBlk
*
pBlock
=
pMsg
->
blocks
;
pBlock
->
uid
=
987607499877672L
;
pBlock
->
tid
=
0
;
...
...
@@ -108,6 +110,9 @@ TEST(TsdbTest, createRepo) {
}
pBlock
->
len
+=
dataRowLen
(
row
);
}
pMsg
->
length
=
pMsg
->
length
+
sizeof
(
SSubmitBlk
)
+
pBlock
->
len
;
pMsg
->
numOfBlocks
=
1
;
pBlock
->
len
=
htonl
(
pBlock
->
len
);
pBlock
->
numOfRows
=
htonl
(
pBlock
->
numOfRows
);
pBlock
->
uid
=
htobe64
(
pBlock
->
uid
);
...
...
@@ -116,7 +121,6 @@ TEST(TsdbTest, createRepo) {
pBlock
->
sversion
=
htonl
(
pBlock
->
sversion
);
pBlock
->
padding
=
htonl
(
pBlock
->
padding
);
pMsg
->
length
=
pMsg
->
length
+
sizeof
(
SSubmitBlk
)
+
pBlock
->
len
;
pMsg
->
length
=
htonl
(
pMsg
->
length
);
pMsg
->
numOfBlocks
=
htonl
(
pMsg
->
numOfBlocks
);
pMsg
->
compressed
=
htonl
(
pMsg
->
numOfBlocks
);
...
...
@@ -126,15 +130,17 @@ TEST(TsdbTest, createRepo) {
double
etime
=
getCurTime
();
printf
(
"Spent %f seconds to write %d records
\n
"
,
etime
-
stime
,
nRows
);
void
*
ptr
=
malloc
(
150000
);
free
(
ptr
);
printf
(
"Spent %f seconds to write %d records
\n
"
,
etime
-
stime
,
nRows
);
// tsdbTriggerCommit
(pRepo);
tsdbCloseRepo
(
pRepo
);
}
TEST
(
TsdbTest
,
DISABLED_openRepo
)
{
// TEST(TsdbTest, DISABLED_openRepo) {
TEST
(
TsdbTest
,
openRepo
)
{
tsdb_repo_t
*
pRepo
=
tsdbOpenRepo
(
"/home/ubuntu/work/ttest/vnode0"
);
ASSERT_NE
(
pRepo
,
nullptr
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录