Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lzh_me
TDengine
提交
e54e1bae
TDengine
项目概览
lzh_me
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
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,发现更多精彩内容 >>
未验证
提交
e54e1bae
编写于
3月 14, 2020
作者:
S
slguan
提交者:
GitHub
3月 14, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1367 from taosdata/feature/2.0tsdb
Feature/2.0tsdb
上级
a126b12f
9c8cf5e4
变更
9
显示空白变更内容
内联
并排
Showing
9 changed file
with
109 addition
and
19 deletion
+109
-19
src/util/src/tskiplist.c
src/util/src/tskiplist.c
+1
-0
src/vnode/tsdb/inc/tsdb.h
src/vnode/tsdb/inc/tsdb.h
+1
-0
src/vnode/tsdb/inc/tsdbFile.h
src/vnode/tsdb/inc/tsdbFile.h
+23
-11
src/vnode/tsdb/inc/tsdbMeta.h
src/vnode/tsdb/inc/tsdbMeta.h
+1
-0
src/vnode/tsdb/src/tsdbFile.c
src/vnode/tsdb/src/tsdbFile.c
+67
-0
src/vnode/tsdb/src/tsdbMain.c
src/vnode/tsdb/src/tsdbMain.c
+0
-1
src/vnode/tsdb/src/tsdbMeta.c
src/vnode/tsdb/src/tsdbMeta.c
+9
-2
src/vnode/tsdb/src/tsdbMetaFile.c
src/vnode/tsdb/src/tsdbMetaFile.c
+4
-4
src/vnode/tsdb/tests/tsdbTests.cpp
src/vnode/tsdb/tests/tsdbTests.cpp
+3
-1
未找到文件。
src/util/src/tskiplist.c
浏览文件 @
e54e1bae
...
...
@@ -253,6 +253,7 @@ static __compar_fn_t getKeyComparator(int32_t keyType) {
comparFn
=
compareInt32Val
;
break
;
case
TSDB_DATA_TYPE_BIGINT
:
case
TSDB_DATA_TYPE_TIMESTAMP
:
comparFn
=
compareInt64Val
;
break
;
case
TSDB_DATA_TYPE_BOOL
:
...
...
src/vnode/tsdb/inc/tsdb.h
浏览文件 @
e54e1bae
...
...
@@ -75,6 +75,7 @@ typedef struct {
typedef
struct
{
TSDB_TABLE_TYPE
type
;
STableId
tableId
;
int32_t
sversion
;
int64_t
superUid
;
STSchema
*
schema
;
STSchema
*
tagSchema
;
...
...
src/vnode/tsdb/inc/tsdbFile.h
浏览文件 @
e54e1bae
...
...
@@ -23,8 +23,6 @@
extern
"C"
{
#endif
typedef
int32_t
file_id_t
;
typedef
enum
{
TSDB_FILE_TYPE_HEAD
,
// .head file type
TSDB_FILE_TYPE_DATA
,
// .data file type
...
...
@@ -40,19 +38,33 @@ typedef struct {
}
SFileInfo
;
typedef
struct
{
char
*
fname
;
SFileInfo
fInfo
;
}
SFILE
;
int
fd
;
int64_t
size
;
// total size of the file
int64_t
tombSize
;
// unused file size
}
SFile
;
// typedef struct {
// int64_t offset;
// int64_t skey;
// int64_t ekey;
// int16_t numOfBlocks;
// } SDataBlock;
typedef
struct
{
int32_t
fileId
;
SFile
fhead
;
SFile
fdata
;
SFile
flast
;
}
SFileGroup
;
// TSDB file handle
typedef
struct
{
int32_t
daysPerFile
;
int32_t
keep
;
int32_t
minRowPerFBlock
;
int32_t
maxRowsPerFBlock
;
SFileGroup
fGroup
[];
}
STsdbFileH
;
#define IS_VALID_TSDB_FILE_TYPE(type) ((type) >= TSDB_FILE_TYPE_HEAD && (type) <= TSDB_FILE_TYPE_META)
STsdbFileH
*
tsdbInitFile
(
char
*
dataDir
,
int32_t
daysPerFile
,
int32_t
keep
,
int32_t
minRowsPerFBlock
,
int32_t
maxRowsPerFBlock
);
void
tsdbCloseFile
(
STsdbFileH
*
pFileH
);
char
*
tsdbGetFileName
(
char
*
dirName
,
char
*
fname
,
TSDB_FILE_TYPE
type
);
#ifdef __cplusplus
...
...
src/vnode/tsdb/inc/tsdbMeta.h
浏览文件 @
e54e1bae
...
...
@@ -38,6 +38,7 @@ typedef struct STable {
TSDB_TABLE_TYPE
type
;
STableId
tableId
;
int32_t
superUid
;
// Super table UID
int32_t
sversion
;
STSchema
*
schema
;
STSchema
*
tagSchema
;
SDataRow
tagVal
;
...
...
src/vnode/tsdb/src/tsdbFile.c
浏览文件 @
e54e1bae
...
...
@@ -14,9 +14,21 @@
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <dirent.h>
#include "tsdbFile.h"
#include "tglobalcfg.h"
// int64_t tsMsPerDay[] = {
// 86400000L, // TSDB_PRECISION_MILLI
// 86400000000L, // TSDB_PRECISION_MICRO
// 86400000000000L // TSDB_PRECISION_NANO
// };
#define tsdbGetKeyFileId(key, daysPerFile, precision) ((key) / tsMsPerDay[(precision)] / (daysPerFile))
#define tsdbGetMaxNumOfFiles(keep, daysPerFile) ((keep) / (daysPerFile) + 3)
typedef
struct
{
int64_t
offset
;
...
...
@@ -71,6 +83,55 @@ const char *tsdbFileSuffix[] = {
".meta"
// TSDB_FILE_TYPE_META
};
/**
* Initialize the TSDB file handle
*/
STsdbFileH
*
tsdbInitFile
(
char
*
dataDir
,
int32_t
daysPerFile
,
int32_t
keep
,
int32_t
minRowsPerFBlock
,
int32_t
maxRowsPerFBlock
)
{
STsdbFileH
*
pTsdbFileH
=
(
STsdbFileH
*
)
calloc
(
1
,
sizeof
(
STsdbFileH
)
+
sizeof
(
SFileGroup
)
*
tsdbGetMaxNumOfFiles
(
keep
,
daysPerFile
));
if
(
pTsdbFileH
==
NULL
)
return
NULL
;
pTsdbFileH
->
daysPerFile
=
daysPerFile
;
pTsdbFileH
->
keep
=
keep
;
pTsdbFileH
->
minRowPerFBlock
=
minRowsPerFBlock
;
pTsdbFileH
->
maxRowsPerFBlock
=
maxRowsPerFBlock
;
// Open the directory to read information of each file
DIR
*
dir
=
opendir
(
dataDir
);
if
(
dir
==
NULL
)
{
free
(
pTsdbFileH
);
return
NULL
;
}
struct
dirent
*
dp
;
char
fname
[
256
];
while
((
dp
=
readdir
(
dir
))
!=
NULL
)
{
if
(
strncmp
(
dp
->
d_name
,
"."
,
1
)
==
0
||
strncmp
(
dp
->
d_name
,
".."
,
2
)
==
0
)
continue
;
if
(
true
/* check if the file is the .head file */
)
{
int
fileId
=
0
;
int
vgId
=
0
;
sscanf
(
dp
->
d_name
,
"v%df%d.head"
,
&
vgId
,
&
fileId
);
// TODO
// Open head file
// Open data file
// Open last file
}
}
return
pTsdbFileH
;
}
/**
* Closet the file handle
*/
void
tsdbCloseFile
(
STsdbFileH
*
pFileH
)
{
// TODO
}
char
*
tsdbGetFileName
(
char
*
dirName
,
char
*
fname
,
TSDB_FILE_TYPE
type
)
{
if
(
!
IS_VALID_TSDB_FILE_TYPE
(
type
))
return
NULL
;
...
...
@@ -80,3 +141,9 @@ char *tsdbGetFileName(char *dirName, char *fname, TSDB_FILE_TYPE type) {
sprintf
(
fileName
,
"%s/%s%s"
,
dirName
,
fname
,
tsdbFileSuffix
[
type
]);
return
fileName
;
}
static
void
tsdbGetKeyRangeOfFileId
(
int32_t
daysPerFile
,
int8_t
precision
,
int32_t
fileId
,
TSKEY
*
minKey
,
TSKEY
*
maxKey
)
{
*
minKey
=
fileId
*
daysPerFile
*
tsMsPerDay
[
precision
];
*
maxKey
=
*
minKey
+
daysPerFile
*
tsMsPerDay
[
precision
]
-
1
;
}
\ No newline at end of file
src/vnode/tsdb/src/tsdbMain.c
浏览文件 @
e54e1bae
...
...
@@ -308,7 +308,6 @@ int tsdbAlterTable(tsdb_repo_t *pRepo, STableCfg *pCfg) {
}
int
tsdbDropTable
(
tsdb_repo_t
*
repo
,
STableId
tableId
)
{
// TODO
if
(
repo
==
NULL
)
return
-
1
;
STsdbRepo
*
pRepo
=
(
STsdbRepo
*
)
repo
;
...
...
src/vnode/tsdb/src/tsdbMeta.c
浏览文件 @
e54e1bae
...
...
@@ -18,6 +18,7 @@ static int tsdbAddTableIntoMap(STsdbMeta *pMeta, STable *pTable);
static
int
tsdbAddTableIntoIndex
(
STsdbMeta
*
pMeta
,
STable
*
pTable
);
static
int
tsdbRemoveTableFromIndex
(
STsdbMeta
*
pMeta
,
STable
*
pTable
);
static
int
tsdbEstimateTableEncodeSize
(
STable
*
pTable
);
static
char
*
getTupleKey
(
const
void
*
data
);
/**
* Encode a TSDB table object as a binary content
...
...
@@ -153,7 +154,7 @@ int32_t tsdbCreateTableImpl(STsdbMeta *pMeta, STableCfg *pCfg) {
super
->
tagSchema
=
tdDupSchema
(
pCfg
->
tagSchema
);
super
->
tagVal
=
tdDataRowDup
(
pCfg
->
tagValues
);
super
->
content
.
pIndex
=
tSkipListCreate
(
TSDB_SUPER_TABLE_SL_LEVEL
,
TSDB_DATA_TYPE_TIMESTAMP
,
sizeof
(
int64_t
),
1
,
0
,
NULL
);
// Allow duplicate key, no lock
0
,
getTupleKey
);
// Allow duplicate key, no lock
if
(
super
->
content
.
pIndex
==
NULL
)
{
tdFreeSchema
(
super
->
schema
);
...
...
@@ -183,7 +184,7 @@ int32_t tsdbCreateTableImpl(STsdbMeta *pMeta, STableCfg *pCfg) {
table
->
superUid
=
-
1
;
table
->
schema
=
tdDupSchema
(
pCfg
->
schema
);
}
table
->
content
.
pData
=
tSkipListCreate
(
TSDB_SUPER_TABLE_SL_LEVEL
,
0
,
8
,
0
,
0
,
NULL
);
table
->
content
.
pData
=
tSkipListCreate
(
TSDB_SUPER_TABLE_SL_LEVEL
,
TSDB_DATA_TYPE_TIMESTAMP
,
TYPE_BYTES
[
TSDB_DATA_TYPE_TIMESTAMP
],
0
,
0
,
getTupleKey
);
if
(
newSuper
)
tsdbAddTableToMeta
(
pMeta
,
super
);
tsdbAddTableToMeta
(
pMeta
,
table
);
...
...
@@ -320,3 +321,9 @@ static int tsdbEstimateTableEncodeSize(STable *pTable) {
// TODO
return
0
;
}
static
char
*
getTupleKey
(
const
void
*
data
)
{
SDataRow
row
=
(
SDataRow
)
data
;
return
dataRowAt
(
row
,
TD_DATA_ROW_HEAD_SIZE
);
}
\ No newline at end of file
src/vnode/tsdb/src/tsdbMetaFile.c
浏览文件 @
e54e1bae
...
...
@@ -83,7 +83,7 @@ int32_t tsdbInsertMetaRecord(SMetaFile *mfh, int64_t uid, void *cont, int32_t co
}
// TODO: make below a function to implement
if
(
f
seek
(
mfh
->
fd
,
info
.
offset
,
SEEK_CUR
)
<
0
)
{
if
(
l
seek
(
mfh
->
fd
,
info
.
offset
,
SEEK_CUR
)
<
0
)
{
return
-
1
;
}
...
...
@@ -114,7 +114,7 @@ int32_t tsdbDeleteMetaRecord(SMetaFile *mfh, int64_t uid) {
// Remove record from file
info
.
offset
=
-
info
.
offset
;
if
(
f
seek
(
mfh
->
fd
,
-
info
.
offset
,
SEEK_CUR
)
<
0
)
{
if
(
l
seek
(
mfh
->
fd
,
-
info
.
offset
,
SEEK_CUR
)
<
0
)
{
return
-
1
;
}
...
...
@@ -149,7 +149,7 @@ int32_t tsdbUpdateMetaRecord(SMetaFile *mfh, int64_t uid, void *cont, int32_t co
mfh
->
size
+=
contLen
;
}
if
(
f
seek
(
mfh
->
fd
,
-
info
.
offset
,
SEEK_CUR
)
<
0
)
{
if
(
l
seek
(
mfh
->
fd
,
-
info
.
offset
,
SEEK_CUR
)
<
0
)
{
return
-
1
;
}
...
...
@@ -212,7 +212,7 @@ static int tsdbRestoreFromMetaFile(char *fname, SMetaFile *mfh) {
return
-
1
;
}
if
(
f
seek
(
fd
,
TSDB_META_FILE_HEADER_SIZE
,
SEEK_SET
)
<
0
)
{
if
(
l
seek
(
fd
,
TSDB_META_FILE_HEADER_SIZE
,
SEEK_SET
)
<
0
)
{
// TODO: deal with the error
close
(
fd
);
return
-
1
;
...
...
src/vnode/tsdb/tests/tsdbTests.cpp
浏览文件 @
e54e1bae
...
...
@@ -48,7 +48,7 @@ TEST(TsdbTest, createRepo) {
for
(
int
j
=
0
;
j
<
schemaNCols
(
schema
);
j
++
)
{
if
(
j
==
0
)
{
// Just for timestamp
tdAppendColVal
(
row
,
(
void
*
)(
&
time
),
schemaColAt
(
schema
,
j
));
tdAppendColVal
(
row
,
(
void
*
)(
&
t
t
ime
),
schemaColAt
(
schema
,
j
));
}
else
{
// For int
int
val
=
10
;
tdAppendColVal
(
row
,
(
void
*
)(
&
val
),
schemaColAt
(
schema
,
j
));
...
...
@@ -61,5 +61,7 @@ TEST(TsdbTest, createRepo) {
pMsg
->
length
=
pMsg
->
length
+
sizeof
(
SSubmitBlk
)
+
pBlock
->
len
;
tsdbInsertData
(
pRepo
,
pMsg
);
int
k
=
0
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录