Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
efa09d44
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看板
提交
efa09d44
编写于
1月 14, 2021
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more progress
上级
0a5200f0
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
135 addition
and
40 deletion
+135
-40
src/tsdb/inc/tsdbCommit.h
src/tsdb/inc/tsdbCommit.h
+7
-0
src/tsdb/inc/tsdbFS.h
src/tsdb/inc/tsdbFS.h
+9
-10
src/tsdb/src/tsdbCommit.c
src/tsdb/src/tsdbCommit.c
+119
-24
src/tsdb/src/tsdbStore.c
src/tsdb/src/tsdbStore.c
+0
-6
未找到文件。
src/tsdb/inc/tsdbCommit.h
浏览文件 @
efa09d44
...
@@ -19,7 +19,14 @@
...
@@ -19,7 +19,14 @@
#ifdef __cplusplus
#ifdef __cplusplus
extern
"C"
{
extern
"C"
{
#endif
#endif
typedef
struct
{
uint64_t
uid
;
int64_t
offset
;
int64_t
size
;
}
SKVRecord
;
int
tsdbEncodeKVRecord
(
void
**
buf
,
SKVRecord
*
pRecord
);
void
*
tsdbDecodeKVRecord
(
void
*
buf
,
SKVRecord
*
pRecord
);
void
*
tsdbCommitData
(
STsdbRepo
*
pRepo
);
void
*
tsdbCommitData
(
STsdbRepo
*
pRepo
);
#ifdef __cplusplus
#ifdef __cplusplus
...
...
src/tsdb/inc/tsdbFS.h
浏览文件 @
efa09d44
...
@@ -68,16 +68,15 @@ typedef struct {
...
@@ -68,16 +68,15 @@ typedef struct {
#define TSDB_FS_ITER_FORWARD TSDB_ORDER_ASC
#define TSDB_FS_ITER_FORWARD TSDB_ORDER_ASC
#define TSDB_FS_ITER_BACKWARD TSDB_ORDER_DESC
#define TSDB_FS_ITER_BACKWARD TSDB_ORDER_DESC
#if 0
STsdbFS
*
tsdbNewFS
(
int
keep
,
int
days
);
int tsdbOpenFS(STsdbRepo* pRepo);
void
*
tsdbFreeFS
(
STsdbFS
*
pfs
);
void tsdbCloseFS(STsdbRepo* pRepo);
int
tdbOpenFS
(
STsdbFS
*
pFs
,
int
keep
,
int
days
);
int tsdbFSNewTxn(STsdbRepo* pRepo);
void
tsdbCloseFS
(
STsdbFS
*
pFs
);
int tsdbFSEndTxn(STsdbRepo* pRepo, bool hasError);
int
tsdbStartTxn
(
STsdbFS
*
pfs
);
int tsdbUpdateMFile(STsdbRepo* pRepo, SMFile* pMFile);
int
tsdbEndTxn
(
STsdbFS
*
pfs
);
int tsdbUpdateDFileSet(STsdbRepo* pRepo, SDFileSet* pSet);
int
tsdbEndTxnWithError
(
STsdbFS
*
pfs
);
int tsdbInitFSIter(STsdbRepo* pRepo, SFSIter* pIter);
void
tsdbUpdateMFile
(
STsdbFS
*
pfs
,
const
SMFile
*
pMFile
);
SDFileSet* tsdbFSIterNext(SFSIter* pIter);
int
tsdbUpdateDFileSet
(
STsdbFS
*
pfs
,
const
SDFileSet
*
pSet
);
#endif
static
FORCE_INLINE
int
tsdbRLockFS
(
STsdbFS
*
pFs
)
{
static
FORCE_INLINE
int
tsdbRLockFS
(
STsdbFS
*
pFs
)
{
int
code
=
pthread_rwlock_rdlock
(
&
(
pFs
->
lock
));
int
code
=
pthread_rwlock_rdlock
(
&
(
pFs
->
lock
));
...
...
src/tsdb/src/tsdbCommit.c
浏览文件 @
efa09d44
...
@@ -85,56 +85,151 @@ _err:
...
@@ -85,56 +85,151 @@ _err:
// =================== Commit Meta Data
// =================== Commit Meta Data
static
int
tsdbCommitMeta
(
STsdbRepo
*
pRepo
)
{
static
int
tsdbCommitMeta
(
STsdbRepo
*
pRepo
)
{
STsdbFS
*
pfs
=
REPO_FS
(
pRepo
);
SMemTable
*
pMem
=
pRepo
->
imem
;
SMemTable
*
pMem
=
pRepo
->
imem
;
STsdbMeta
*
pMeta
=
pRepo
->
tsdbMeta
;
SMFile
*
pOMFile
=
pfs
->
cstatus
->
pmf
;
SMFile
mf
;
SActObj
*
pAct
=
NULL
;
SActObj
*
pAct
=
NULL
;
SActCont
*
pCont
=
NULL
;
SActCont
*
pCont
=
NULL
;
SListNode
*
pNode
=
NULL
;
if
(
listNEles
(
pMem
->
actList
)
<=
0
)
return
0
;
ASSERT
(
pOMFile
!=
NULL
||
listNEles
(
pMem
->
actList
)
>
0
)
;
if
(
tdKVStoreStartCommit
(
pMeta
->
pStore
)
<
0
)
{
if
(
listNEles
(
pMem
->
actList
)
<=
0
)
{
tsdbError
(
"vgId:%d failed to commit data while start commit meta since %s"
,
REPO_ID
(
pRepo
),
tstrerror
(
terrno
));
// no
goto
_err
;
tsdbUpdateMFile
(
pfs
,
pOMFile
);
}
return
0
;
}
else
{
// Create/Open a meta file or open the existing file
if
(
pOMFile
==
NULL
)
{
// Create a new meta file
tsdbInitMFile
(
&
mf
,
{.
level
=
TFS_PRIMARY_LEVEL
,
.
id
=
TFS_PRIMARY_ID
},
REPO_ID
(
pRepo
),
pfs
->
nstatus
->
meta
.
version
);
SListNode
*
pNode
=
NULL
;
if
(
tsdbCreateMFile
(
&
mf
)
<
0
)
{
return
-
1
;
}
}
else
{
tsdbInitMFile
(
&
mf
,
pOMFile
);
if
(
tsdbOpenMFile
(
&
mf
,
O_WRONLY
)
<
0
)
{
return
-
1
;
}
}
}
// Loop to write
while
((
pNode
=
tdListPopHead
(
pMem
->
actList
))
!=
NULL
)
{
while
((
pNode
=
tdListPopHead
(
pMem
->
actList
))
!=
NULL
)
{
pAct
=
(
SActObj
*
)
pNode
->
data
;
pAct
=
(
SActObj
*
)
pNode
->
data
;
if
(
pAct
->
act
==
TSDB_UPDATE_META
)
{
if
(
pAct
->
act
==
TSDB_UPDATE_META
)
{
pCont
=
(
SActCont
*
)
POINTER_SHIFT
(
pAct
,
sizeof
(
SActObj
));
pCont
=
(
SActCont
*
)
POINTER_SHIFT
(
pAct
,
sizeof
(
SActObj
));
if
(
tdUpdateKVStoreRecord
(
pMeta
->
pStore
,
pAct
->
uid
,
(
void
*
)(
pCont
->
cont
),
pCont
->
len
)
<
0
)
{
if
(
tsdbUpdateMetaRecord
(
pfs
,
&
mf
,
pAct
->
uid
,
(
void
*
)(
pCont
->
cont
),
pCont
->
len
)
<
0
)
{
tsdbError
(
"vgId:%d failed to update meta with uid %"
PRIu64
" since %s"
,
REPO_ID
(
pRepo
),
pAct
->
uid
,
tsdbCloseMFile
(
&
mf
);
tstrerror
(
terrno
));
return
-
1
;
tdKVStoreEndCommit
(
pMeta
->
pStore
);
goto
_err
;
}
}
}
else
if
(
pAct
->
act
==
TSDB_DROP_META
)
{
}
else
if
(
pAct
->
act
==
TSDB_DROP_META
)
{
if
(
tdDropKVStoreRecord
(
pMeta
->
pStore
,
pAct
->
uid
)
<
0
)
{
if
(
tsdbDropMetaRecord
(
pfs
,
&
mf
,
pAct
->
uid
)
<
0
)
{
tsdbError
(
"vgId:%d failed to drop meta with uid %"
PRIu64
" since %s"
,
REPO_ID
(
pRepo
),
pAct
->
uid
,
tsdbCloseMFile
(
&
mf
);
tstrerror
(
terrno
));
return
-
1
;
tdKVStoreEndCommit
(
pMeta
->
pStore
);
goto
_err
;
}
}
}
else
{
}
else
{
ASSERT
(
false
);
ASSERT
(
false
);
}
}
}
}
if
(
tdKVStoreEndCommit
(
pMeta
->
pStore
)
<
0
)
{
if
(
tsdbUpdateMFileHeader
(
&
mf
)
<
0
)
{
tsdbError
(
"vgId:%d failed to commit data while end commit meta since %s"
,
REPO_ID
(
pRepo
),
tstrerror
(
terrno
));
return
-
1
;
goto
_err
;
}
}
// TODO: update meta file
tsdbCloseMFile
(
&
mf
);
tsdbUpdateMFile
(
p
Repo
,
&
(
pMeta
->
pStore
.
f
)
);
tsdbUpdateMFile
(
p
fs
,
&
mf
);
return
0
;
return
0
;
}
_err:
int
tsdbEncodeKVRecord
(
void
**
buf
,
SKVRecord
*
pRecord
)
{
return
-
1
;
int
tlen
=
0
;
tlen
+=
taosEncodeFixedU64
(
buf
,
pRecord
->
uid
);
tlen
+=
taosEncodeFixedI64
(
buf
,
pRecord
->
offset
);
tlen
+=
taosEncodeFixedI64
(
buf
,
pRecord
->
size
);
return
tlen
;
}
void
*
tsdbDecodeKVRecord
(
void
*
buf
,
SKVRecord
*
pRecord
)
{
buf
=
taosDecodeFixedU64
(
buf
,
&
(
pRecord
->
uid
));
buf
=
taosDecodeFixedI64
(
buf
,
&
(
pRecord
->
offset
));
buf
=
taosDecodeFixedI64
(
buf
,
&
(
pRecord
->
size
));
return
buf
;
}
static
int
tsdbUpdateMetaRecord
(
STsdbFS
*
pfs
,
SMFile
*
pMFile
,
uint64_t
uid
,
void
*
cont
,
int
contLen
)
{
char
buf
[
64
]
=
"
\0
"
;
void
*
pBuf
=
buf
;
SKVRecord
rInfo
;
int64_t
offset
;
// Seek to end of meta file
offset
=
tsdbSeekMFile
(
pMFile
,
0
,
SEEK_END
);
if
(
offset
<
0
)
{
return
-
1
;
}
rInfo
.
offset
=
offset
;
rInfo
.
uid
=
uid
;
rInfo
.
size
=
contLen
;
tlen
=
tsdbEncodeKVRecord
((
void
**
)(
&
pBuf
),
pRInfo
);
if
(
tsdbAppendMFile
(
pMFile
,
buf
,
tlen
)
<
tlen
)
{
return
-
1
;
}
if
(
tsdbAppendMFile
(
pMFile
,
cont
,
contLen
)
<
contLen
)
{
return
-
1
;
}
tsdbUpdateMFileMagic
(
pMFile
,
POINTER_SHIFT
(
cont
,
contLen
-
sizeof
(
TSCKSUM
)));
SKVRecord
*
pRecord
=
taosHashGet
(
pfs
->
metaCache
,
(
void
*
)
&
uid
,
sizeof
(
uid
));
if
(
pRecord
!=
NULL
)
{
pMFile
->
info
.
tombSize
+=
pRecord
->
size
;
}
else
{
pMFile
->
info
.
nRecords
++
;
}
taosHashPut
(
pfs
->
metaCache
,
(
void
*
)(
&
uid
),
sizeof
(
uid
),
(
void
*
)(
&
rInfo
),
sizeof
(
rInfo
));
return
0
;
}
}
static
int
tsdbDropMetaRecord
(
STsdbFS
*
pfs
,
SMFile
*
pMFile
,
uint64_t
uid
)
{
SKVRecord
rInfo
=
{
0
};
char
buf
[
128
]
=
"
\0
"
;
SKVRecord
*
pRecord
=
taosHashGet
(
pfs
->
metaCache
,
(
void
*
)(
&
uid
),
sizeof
(
uid
));
if
(
pRecord
==
NULL
)
{
tsdbError
(
"failed to drop KV store record with key %"
PRIu64
" since not find"
,
uid
);
return
-
1
;
}
rInfo
.
offset
=
-
pRecord
->
offset
;
rInfo
.
uid
=
pRecord
->
uid
;
rInfo
.
size
=
pRecord
->
size
;
void
*
pBuf
=
buf
;
tdEncodeKVRecord
(
&
pBuf
,
&
rInfo
);
if
(
tsdbAppendMFile
(
pMFile
,
buf
,
POINTER_DISTANCE
(
pBuf
,
buf
),
NULL
)
<
0
)
{
return
-
1
;
}
pMFile
->
meta
.
magic
=
taosCalcChecksum
(
pStore
->
info
.
magic
,
(
uint8_t
*
)
buf
,
(
uint32_t
)
POINTER_DISTANCE
(
pBuf
,
buf
));
pMFile
->
meta
.
nDels
++
;
pMFile
->
meta
.
nRecords
--
;
pMFile
->
meta
.
tombSize
+=
(
rInfo
.
size
+
sizeof
(
SKVRecord
)
*
2
);
taosHashRemove
(
pfs
->
metaCache
,
(
void
*
)(
&
uid
),
sizeof
(
uid
));
return
0
;
}
// =================== Commit Time-Series Data
// =================== Commit Time-Series Data
static
int
tsdbCommitTSData
(
STsdbRepo
*
pRepo
)
{
static
int
tsdbCommitTSData
(
STsdbRepo
*
pRepo
)
{
SMemTable
*
pMem
=
pRepo
->
imem
;
SMemTable
*
pMem
=
pRepo
->
imem
;
...
...
src/tsdb/src/tsdbStore.c
浏览文件 @
efa09d44
...
@@ -18,12 +18,6 @@
...
@@ -18,12 +18,6 @@
#include "tsdbint.h"
#include "tsdbint.h"
typedef
struct
{
uint64_t
uid
;
int64_t
offset
;
int64_t
size
;
}
SKVRecord
;
static
int
tdInitKVStoreHeader
(
int
fd
,
char
*
fname
);
static
int
tdInitKVStoreHeader
(
int
fd
,
char
*
fname
);
static
int
tdEncodeStoreInfo
(
void
**
buf
,
SStoreInfo
*
pInfo
);
static
int
tdEncodeStoreInfo
(
void
**
buf
,
SStoreInfo
*
pInfo
);
static
void
*
tdDecodeStoreInfo
(
void
*
buf
,
SStoreInfo
*
pInfo
);
static
void
*
tdDecodeStoreInfo
(
void
*
buf
,
SStoreInfo
*
pInfo
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录