Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
f2f353c0
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看板
提交
f2f353c0
编写于
1月 16, 2021
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
finish refact
上级
c29b78d3
变更
8
展开全部
隐藏空白更改
内联
并排
Showing
8 changed file
with
322 addition
and
619 deletion
+322
-619
src/inc/tsdb.h
src/inc/tsdb.h
+3
-4
src/tsdb/CMakeLists.txt
src/tsdb/CMakeLists.txt
+0
-1
src/tsdb/inc/tsdbFS.h
src/tsdb/inc/tsdbFS.h
+3
-3
src/tsdb/inc/tsdbint.h
src/tsdb/inc/tsdbint.h
+12
-5
src/tsdb/src/tsdbFS.c
src/tsdb/src/tsdbFS.c
+31
-12
src/tsdb/src/tsdbMain.c
src/tsdb/src/tsdbMain.c
+250
-570
src/tsdb/src/tsdbMeta.c
src/tsdb/src/tsdbMeta.c
+3
-0
src/vnode/src/vnodeMain.c
src/vnode/src/vnodeMain.c
+20
-24
未找到文件。
src/inc/tsdb.h
浏览文件 @
f2f353c0
...
...
@@ -81,9 +81,9 @@ typedef void TSDB_REPO_T; // use void to hide implementation details from outsi
STsdbCfg
*
tsdbGetCfg
(
const
TSDB_REPO_T
*
repo
);
// --------- TSDB REPOSITORY DEFINITION
int
tsdbCreateRepo
(
char
*
rootDir
,
STsdbCfg
*
pCfg
);
int32_t
tsdbDropRepo
(
char
*
rootDir
);
TSDB_REPO_T
*
tsdbOpenRepo
(
char
*
rootDir
,
STsdbAppH
*
pAppH
);
int
32_t
tsdbCreateRepo
(
int
repoid
);
int32_t
tsdbDropRepo
(
int
repoid
);
TSDB_REPO_T
*
tsdbOpenRepo
(
STsdbCfg
*
pCfg
,
STsdbAppH
*
pAppH
);
int
tsdbCloseRepo
(
TSDB_REPO_T
*
repo
,
int
toCommit
);
int32_t
tsdbConfigRepo
(
TSDB_REPO_T
*
repo
,
STsdbCfg
*
pCfg
);
int
tsdbGetState
(
TSDB_REPO_T
*
repo
);
...
...
@@ -120,7 +120,6 @@ STableCfg *tsdbCreateTableCfgFromMsg(SMDCreateTableMsg *pMsg);
int
tsdbCreateTable
(
TSDB_REPO_T
*
repo
,
STableCfg
*
pCfg
);
int
tsdbDropTable
(
TSDB_REPO_T
*
pRepo
,
STableId
tableId
);
int
tsdbUpdateTableTagValue
(
TSDB_REPO_T
*
repo
,
SUpdateTableTagValMsg
*
pMsg
);
// TSKEY tsdbGetTableLastKey(TSDB_REPO_T *repo, uint64_t uid);
uint32_t
tsdbGetFileInfo
(
TSDB_REPO_T
*
repo
,
char
*
name
,
uint32_t
*
index
,
uint32_t
eindex
,
int64_t
*
size
);
...
...
src/tsdb/CMakeLists.txt
浏览文件 @
f2f353c0
...
...
@@ -3,7 +3,6 @@ PROJECT(TDengine)
INCLUDE_DIRECTORIES
(
inc
)
AUX_SOURCE_DIRECTORY
(
src SRC
)
list
(
REMOVE_ITEM SRC
"src/tsdbFS.c"
)
ADD_LIBRARY
(
tsdb
${
SRC
}
)
TARGET_LINK_LIBRARIES
(
tsdb tfs common tutil
)
...
...
src/tsdb/inc/tsdbFS.h
浏览文件 @
f2f353c0
...
...
@@ -69,10 +69,10 @@ typedef struct {
#define TSDB_FS_ITER_FORWARD TSDB_ORDER_ASC
#define TSDB_FS_ITER_BACKWARD TSDB_ORDER_DESC
STsdbFS
*
tsdbNewFS
(
int
keep
,
int
days
);
STsdbFS
*
tsdbNewFS
(
STsdbCfg
*
pCfg
);
void
*
tsdbFreeFS
(
STsdbFS
*
pfs
);
int
tsdbOpenFS
(
STsdb
FS
*
pFs
,
int
keep
,
int
days
);
void
tsdbCloseFS
(
STsdb
FS
*
pFs
);
int
tsdbOpenFS
(
STsdb
Repo
*
pRepo
);
void
tsdbCloseFS
(
STsdb
Repo
*
pRepo
);
void
tsdbStartFSTxn
(
STsdbFS
*
pfs
,
int64_t
pointsAdd
,
int64_t
storageAdd
);
int
tsdbEndFSTxn
(
STsdbFS
*
pfs
);
int
tsdbEndFSTxnWithError
(
STsdbFS
*
pfs
);
...
...
src/tsdb/inc/tsdbint.h
浏览文件 @
f2f353c0
...
...
@@ -71,7 +71,6 @@ typedef struct STsdbRepo STsdbRepo;
struct
STsdbRepo
{
int8_t
state
;
char
*
rootDir
;
STsdbCfg
config
;
STsdbAppH
appH
;
STsdbStat
stat
;
...
...
@@ -92,12 +91,8 @@ struct STsdbRepo {
#define IS_REPO_LOCKED(r) (r)->repoLocked
#define TSDB_SUBMIT_MSG_HEAD_SIZE sizeof(SSubmitMsg)
char
*
tsdbGetMetaFileName
(
char
*
rootDir
);
void
tsdbGetDataFileName
(
char
*
rootDir
,
int
vid
,
int
fid
,
int
type
,
char
*
fname
);
int
tsdbLockRepo
(
STsdbRepo
*
pRepo
);
int
tsdbUnlockRepo
(
STsdbRepo
*
pRepo
);
char
*
tsdbGetDataDirName
(
char
*
rootDir
);
int
tsdbGetNextMaxTables
(
int
tid
);
STsdbMeta
*
tsdbGetMeta
(
TSDB_REPO_T
*
pRepo
);
int
tsdbCheckCommit
(
STsdbRepo
*
pRepo
);
...
...
@@ -114,6 +109,18 @@ static FORCE_INLINE STsdbBufBlock* tsdbGetCurrBufBlock(STsdbRepo* pRepo) {
return
pBufBlock
;
}
static
FORCE_INLINE
int
tsdbGetNextMaxTables
(
int
tid
)
{
ASSERT
(
tid
>=
1
&&
tid
<=
TSDB_MAX_TABLES
);
int
maxTables
=
TSDB_INIT_NTABLES
;
while
(
true
)
{
maxTables
=
MIN
(
maxTables
,
TSDB_MAX_TABLES
);
if
(
tid
<=
maxTables
)
break
;
maxTables
*=
2
;
}
return
maxTables
+
1
;
}
#ifdef __cplusplus
}
#endif
...
...
src/tsdb/src/tsdbFS.c
浏览文件 @
f2f353c0
...
...
@@ -19,6 +19,11 @@
#define TSDB_FS_TEMP_FNAME "current.t"
#define TSDB_MAX_FSETS(keep, days) ((keep) / (days) + 3)
static
int
tsdbComparFidFSet
(
const
void
*
arg1
,
const
void
*
arg2
);
static
void
tsdbResetFSStatus
(
SFSStatus
*
pStatus
);
static
int
tsdbApplyFSTxn
(
STsdbFS
*
pfs
);
static
void
tsdbApplyFSTxnOnDisk
(
SFSStatus
*
pFrom
,
SFSStatus
*
pTo
);
// ================== CURRENT file header info
static
int
tsdbEncodeFSHeader
(
void
**
buf
,
SFSHeader
*
pHeader
)
{
int
tlen
=
0
;
...
...
@@ -29,7 +34,7 @@ static int tsdbEncodeFSHeader(void **buf, SFSHeader *pHeader) {
return
tlen
;
}
static
void
*
tsdbDecodeFSHeader
(
void
*
buf
,
SFSHeader
*
pHeader
)
{
static
UNUSED_FUNC
void
*
tsdbDecodeFSHeader
(
void
*
buf
,
SFSHeader
*
pHeader
)
{
buf
=
taosDecodeFixedU32
(
buf
,
&
(
pHeader
->
version
));
buf
=
taosDecodeFixedU32
(
buf
,
&
(
pHeader
->
len
));
...
...
@@ -47,7 +52,7 @@ static int tsdbEncodeFSMeta(void **buf, STsdbFSMeta *pMeta) {
return
tlen
;
}
static
void
*
tsdbDecodeFSMeta
(
void
*
buf
,
STsdbFSMeta
*
pMeta
)
{
static
UNUSED_FUNC
void
*
tsdbDecodeFSMeta
(
void
*
buf
,
STsdbFSMeta
*
pMeta
)
{
buf
=
taosDecodeFixedU32
(
buf
,
&
(
pMeta
->
version
));
buf
=
taosDecodeFixedI64
(
buf
,
&
(
pMeta
->
totalPoints
));
buf
=
taosDecodeFixedI64
(
buf
,
&
(
pMeta
->
totalStorage
));
...
...
@@ -95,7 +100,7 @@ static int tsdbEncodeFSStatus(void **buf, SFSStatus *pStatus) {
return
tlen
;
}
static
void
*
tsdbDecodeFSStatus
(
void
*
buf
,
SFSStatus
*
pStatus
)
{
static
UNUSED_FUNC
void
*
tsdbDecodeFSStatus
(
void
*
buf
,
SFSStatus
*
pStatus
)
{
tsdbResetFSStatus
(
pStatus
);
pStatus
->
pmf
=
&
(
pStatus
->
mf
);
...
...
@@ -113,7 +118,7 @@ static SFSStatus *tsdbNewFSStatus(int maxFSet) {
return
NULL
;
}
TSDB_F
SET
_SET_CLOSED
(
&
(
pStatus
->
mf
));
TSDB_F
ILE
_SET_CLOSED
(
&
(
pStatus
->
mf
));
pStatus
->
df
=
taosArrayInit
(
maxFSet
,
sizeof
(
SDFileSet
));
if
(
pStatus
->
df
==
NULL
)
{
...
...
@@ -139,7 +144,7 @@ static void tsdbResetFSStatus(SFSStatus *pStatus) {
return
;
}
TSDB_F
SET
_SET_CLOSED
(
&
(
pStatus
->
mf
));
TSDB_F
ILE
_SET_CLOSED
(
&
(
pStatus
->
mf
));
pStatus
->
pmf
=
NULL
;
taosArrayClear
(
pStatus
->
df
);
...
...
@@ -167,7 +172,9 @@ static int tsdbAddDFileSetToStatus(SFSStatus *pStatus, const SDFileSet *pSet) {
// ================== STsdbFS
// TODO
STsdbFS
*
tsdbNewFS
(
int
keep
,
int
days
)
{
STsdbFS
*
tsdbNewFS
(
STsdbCfg
*
pCfg
)
{
int
keep
=
pCfg
->
keep
;
int
days
=
pCfg
->
daysPerFile
;
int
maxFSet
=
TSDB_MAX_FSETS
(
keep
,
days
);
STsdbFS
*
pfs
;
...
...
@@ -220,14 +227,13 @@ void *tsdbFreeFS(STsdbFS *pfs) {
}
// TODO
int
tsdbOpenFS
(
STsdb
FS
*
pFs
,
int
keep
,
int
days
)
{
int
tsdbOpenFS
(
STsdb
Repo
*
pRepo
)
{
// TODO
return
0
;
}
// TODO
void
tsdbCloseFS
(
STsdb
FS
*
pFs
)
{
void
tsdbCloseFS
(
STsdb
Repo
*
pRepo
)
{
// TODO
}
...
...
@@ -298,7 +304,7 @@ static int tsdbApplyFSTxn(STsdbFS *pfs) {
ASSERT
(
taosArrayGetSize
(
pfs
->
nstatus
->
df
)
==
0
);
fsheader
.
len
=
0
;
}
else
{
fsheader
.
len
=
tsdbEncodeFSHeader
(
NULL
,
pfs
->
nstatus
)
+
sizeof
(
TSCKSUM
);
fsheader
.
len
=
tsdbEncodeFSHeader
(
NULL
,
&
fsheader
)
+
sizeof
(
TSCKSUM
);
}
// Encode header part and write
...
...
@@ -325,7 +331,7 @@ static int tsdbApplyFSTxn(STsdbFS *pfs) {
ptr
=
pBuf
;
tsdbEncodeFSStatus
(
&
ptr
,
pfs
->
nstatus
);
taosCalcChecksumAppend
(
0
,
(
uint8_t
*
)
pBuf
,
fsheader
.
len
)
taosCalcChecksumAppend
(
0
,
(
uint8_t
*
)
pBuf
,
fsheader
.
len
)
;
if
(
taosWrite
(
fd
,
pBuf
,
fsheader
.
len
)
<
fsheader
.
len
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
...
...
@@ -455,7 +461,7 @@ void tsdbFSIterSeek(SFSIter *pIter, int fid) {
flags
=
TD_LE
;
}
void
*
ptr
=
taosbsearch
(
&
fid
,
pfs
->
cstatus
->
df
->
pData
,
size
,
sizeof
(
SDFileSet
),
,
flags
);
void
*
ptr
=
taosbsearch
(
&
fid
,
pfs
->
cstatus
->
df
->
pData
,
size
,
sizeof
(
SDFileSet
),
tsdbComparFidFSet
,
flags
);
if
(
ptr
==
NULL
)
{
pIter
->
index
=
-
1
;
pIter
->
fid
=
TSDB_IVLD_FID
;
...
...
@@ -503,4 +509,17 @@ SDFileSet *tsdbFSIterNext(SFSIter *pIter) {
}
return
pSet
;
}
static
int
tsdbComparFidFSet
(
const
void
*
arg1
,
const
void
*
arg2
)
{
int
fid
=
*
(
int
*
)
arg1
;
SDFileSet
*
pSet
=
(
SDFileSet
*
)
arg2
;
if
(
fid
<
pSet
->
fid
)
{
return
-
1
;
}
else
if
(
fid
==
pSet
->
fid
)
{
return
0
;
}
else
{
return
1
;
}
}
\ No newline at end of file
src/tsdb/src/tsdbMain.c
浏览文件 @
f2f353c0
此差异已折叠。
点击以展开。
src/tsdb/src/tsdbMeta.c
浏览文件 @
f2f353c0
...
...
@@ -463,6 +463,8 @@ void tsdbFreeMeta(STsdbMeta *pMeta) {
}
int
tsdbOpenMeta
(
STsdbRepo
*
pRepo
)
{
return
0
;
#if 0
char * fname = NULL;
STsdbMeta *pMeta = pRepo->tsdbMeta;
ASSERT(pMeta != NULL);
...
...
@@ -486,6 +488,7 @@ int tsdbOpenMeta(STsdbRepo *pRepo) {
_err:
tfree(fname);
return -1;
#endif
}
int
tsdbCloseMeta
(
STsdbRepo
*
pRepo
)
{
...
...
src/vnode/src/vnodeMain.c
浏览文件 @
f2f353c0
...
...
@@ -62,24 +62,24 @@ int32_t vnodeCreate(SCreateVnodeMsg *pVnodeCfg) {
return
code
;
}
STsdbCfg
tsdbCfg
=
{
0
};
tsdbCfg
.
tsdbId
=
pVnodeCfg
->
cfg
.
vgId
;
tsdbCfg
.
cacheBlockSize
=
pVnodeCfg
->
cfg
.
cacheBlockSize
;
tsdbCfg
.
totalBlocks
=
pVnodeCfg
->
cfg
.
totalBlocks
;
tsdbCfg
.
daysPerFile
=
pVnodeCfg
->
cfg
.
daysPerFile
;
tsdbCfg
.
keep
=
pVnodeCfg
->
cfg
.
daysToKeep
;
tsdbCfg
.
keep1
=
pVnodeCfg
->
cfg
.
daysToKeep1
;
tsdbCfg
.
keep2
=
pVnodeCfg
->
cfg
.
daysToKeep2
;
tsdbCfg
.
minRowsPerFileBlock
=
pVnodeCfg
->
cfg
.
minRowsPerFileBlock
;
tsdbCfg
.
maxRowsPerFileBlock
=
pVnodeCfg
->
cfg
.
maxRowsPerFileBlock
;
tsdbCfg
.
precision
=
pVnodeCfg
->
cfg
.
precision
;
tsdbCfg
.
compression
=
pVnodeCfg
->
cfg
.
compression
;
tsdbCfg
.
update
=
pVnodeCfg
->
cfg
.
update
;
tsdbCfg
.
cacheLastRow
=
pVnodeCfg
->
cfg
.
cacheLastRow
;
char
tsdbDir
[
TSDB_FILENAME_LEN
]
=
{
0
};
sprintf
(
tsdbDir
,
"vnode/vnode%d/tsdb"
,
pVnodeCfg
->
cfg
.
vgId
);
if
(
tsdbCreateRepo
(
tsdbDir
,
&
tsdbCfg
)
<
0
)
{
//
STsdbCfg tsdbCfg = {0};
//
tsdbCfg.tsdbId = pVnodeCfg->cfg.vgId;
//
tsdbCfg.cacheBlockSize = pVnodeCfg->cfg.cacheBlockSize;
//
tsdbCfg.totalBlocks = pVnodeCfg->cfg.totalBlocks;
//
tsdbCfg.daysPerFile = pVnodeCfg->cfg.daysPerFile;
//
tsdbCfg.keep = pVnodeCfg->cfg.daysToKeep;
//
tsdbCfg.keep1 = pVnodeCfg->cfg.daysToKeep1;
//
tsdbCfg.keep2 = pVnodeCfg->cfg.daysToKeep2;
//
tsdbCfg.minRowsPerFileBlock = pVnodeCfg->cfg.minRowsPerFileBlock;
//
tsdbCfg.maxRowsPerFileBlock = pVnodeCfg->cfg.maxRowsPerFileBlock;
//
tsdbCfg.precision = pVnodeCfg->cfg.precision;
//
tsdbCfg.compression = pVnodeCfg->cfg.compression;
//
tsdbCfg.update = pVnodeCfg->cfg.update;
//
tsdbCfg.cacheLastRow = pVnodeCfg->cfg.cacheLastRow;
//
char tsdbDir[TSDB_FILENAME_LEN] = {0};
//
sprintf(tsdbDir, "vnode/vnode%d/tsdb", pVnodeCfg->cfg.vgId);
if
(
tsdbCreateRepo
(
pVnodeCfg
->
cfg
.
vgId
)
<
0
)
{
vError
(
"vgId:%d, failed to create tsdb in vnode, reason:%s"
,
pVnodeCfg
->
cfg
.
vgId
,
tstrerror
(
terrno
));
return
TSDB_CODE_VND_INIT_FAILED
;
}
...
...
@@ -234,10 +234,9 @@ int32_t vnodeOpen(int32_t vgId) {
appH
.
cqH
=
pVnode
->
cq
;
appH
.
cqCreateFunc
=
cqCreate
;
appH
.
cqDropFunc
=
cqDrop
;
sprintf
(
temp
,
"vnode/vnode%d/tsdb"
,
vgId
);
terrno
=
0
;
pVnode
->
tsdb
=
tsdbOpenRepo
(
temp
,
&
appH
);
pVnode
->
tsdb
=
tsdbOpenRepo
(
&
(
pVnode
->
tsdbCfg
)
,
&
appH
);
if
(
pVnode
->
tsdb
==
NULL
)
{
vnodeCleanUp
(
pVnode
);
return
terrno
;
...
...
@@ -456,9 +455,6 @@ static int32_t vnodeProcessTsdbStatus(void *arg, int32_t status, int32_t eno) {
}
int32_t
vnodeReset
(
SVnodeObj
*
pVnode
)
{
char
rootDir
[
128
]
=
"
\0
"
;
sprintf
(
rootDir
,
"vnode/vnode%d/tsdb"
,
pVnode
->
vgId
);
if
(
!
vnodeSetResetStatus
(
pVnode
))
{
return
-
1
;
}
...
...
@@ -481,7 +477,7 @@ int32_t vnodeReset(SVnodeObj *pVnode) {
appH
.
cqH
=
pVnode
->
cq
;
appH
.
cqCreateFunc
=
cqCreate
;
appH
.
cqDropFunc
=
cqDrop
;
pVnode
->
tsdb
=
tsdbOpenRepo
(
rootDir
,
&
appH
);
pVnode
->
tsdb
=
tsdbOpenRepo
(
&
(
pVnode
->
tsdbCfg
)
,
&
appH
);
vnodeSetReadyStatus
(
pVnode
);
vnodeRelease
(
pVnode
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录