Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
efa09d44
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
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 @@
#ifdef __cplusplus
extern
"C"
{
#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
);
#ifdef __cplusplus
...
...
src/tsdb/inc/tsdbFS.h
浏览文件 @
efa09d44
...
...
@@ -68,16 +68,15 @@ typedef struct {
#define TSDB_FS_ITER_FORWARD TSDB_ORDER_ASC
#define TSDB_FS_ITER_BACKWARD TSDB_ORDER_DESC
#if 0
int tsdbOpenFS(STsdbRepo* pRepo);
void tsdbCloseFS(STsdbRepo* pRepo);
int tsdbFSNewTxn(STsdbRepo* pRepo);
int tsdbFSEndTxn(STsdbRepo* pRepo, bool hasError);
int tsdbUpdateMFile(STsdbRepo* pRepo, SMFile* pMFile);
int tsdbUpdateDFileSet(STsdbRepo* pRepo, SDFileSet* pSet);
int tsdbInitFSIter(STsdbRepo* pRepo, SFSIter* pIter);
SDFileSet* tsdbFSIterNext(SFSIter* pIter);
#endif
STsdbFS
*
tsdbNewFS
(
int
keep
,
int
days
);
void
*
tsdbFreeFS
(
STsdbFS
*
pfs
);
int
tdbOpenFS
(
STsdbFS
*
pFs
,
int
keep
,
int
days
);
void
tsdbCloseFS
(
STsdbFS
*
pFs
);
int
tsdbStartTxn
(
STsdbFS
*
pfs
);
int
tsdbEndTxn
(
STsdbFS
*
pfs
);
int
tsdbEndTxnWithError
(
STsdbFS
*
pfs
);
void
tsdbUpdateMFile
(
STsdbFS
*
pfs
,
const
SMFile
*
pMFile
);
int
tsdbUpdateDFileSet
(
STsdbFS
*
pfs
,
const
SDFileSet
*
pSet
);
static
FORCE_INLINE
int
tsdbRLockFS
(
STsdbFS
*
pFs
)
{
int
code
=
pthread_rwlock_rdlock
(
&
(
pFs
->
lock
));
...
...
src/tsdb/src/tsdbCommit.c
浏览文件 @
efa09d44
...
...
@@ -85,56 +85,151 @@ _err:
// =================== Commit Meta Data
static
int
tsdbCommitMeta
(
STsdbRepo
*
pRepo
)
{
STsdbFS
*
pfs
=
REPO_FS
(
pRepo
);
SMemTable
*
pMem
=
pRepo
->
imem
;
STsdbMeta
*
pMeta
=
pRepo
->
tsdbMeta
;
SMFile
*
pOMFile
=
pfs
->
cstatus
->
pmf
;
SMFile
mf
;
SActObj
*
pAct
=
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
)
{
tsdbError
(
"vgId:%d failed to commit data while start commit meta since %s"
,
REPO_ID
(
pRepo
),
tstrerror
(
terrno
));
goto
_err
;
}
if
(
listNEles
(
pMem
->
actList
)
<=
0
)
{
// no
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
)
{
pAct
=
(
SActObj
*
)
pNode
->
data
;
if
(
pAct
->
act
==
TSDB_UPDATE_META
)
{
pCont
=
(
SActCont
*
)
POINTER_SHIFT
(
pAct
,
sizeof
(
SActObj
));
if
(
tdUpdateKVStoreRecord
(
pMeta
->
pStore
,
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
,
tstrerror
(
terrno
));
tdKVStoreEndCommit
(
pMeta
->
pStore
);
goto
_err
;
if
(
tsdbUpdateMetaRecord
(
pfs
,
&
mf
,
pAct
->
uid
,
(
void
*
)(
pCont
->
cont
),
pCont
->
len
)
<
0
)
{
tsdbCloseMFile
(
&
mf
);
return
-
1
;
}
}
else
if
(
pAct
->
act
==
TSDB_DROP_META
)
{
if
(
tdDropKVStoreRecord
(
pMeta
->
pStore
,
pAct
->
uid
)
<
0
)
{
tsdbError
(
"vgId:%d failed to drop meta with uid %"
PRIu64
" since %s"
,
REPO_ID
(
pRepo
),
pAct
->
uid
,
tstrerror
(
terrno
));
tdKVStoreEndCommit
(
pMeta
->
pStore
);
goto
_err
;
if
(
tsdbDropMetaRecord
(
pfs
,
&
mf
,
pAct
->
uid
)
<
0
)
{
tsdbCloseMFile
(
&
mf
);
return
-
1
;
}
}
else
{
ASSERT
(
false
);
}
}
if
(
tdKVStoreEndCommit
(
pMeta
->
pStore
)
<
0
)
{
tsdbError
(
"vgId:%d failed to commit data while end commit meta since %s"
,
REPO_ID
(
pRepo
),
tstrerror
(
terrno
));
goto
_err
;
if
(
tsdbUpdateMFileHeader
(
&
mf
)
<
0
)
{
return
-
1
;
}
// TODO: update meta file
tsdbUpdateMFile
(
p
Repo
,
&
(
pMeta
->
pStore
.
f
)
);
tsdbCloseMFile
(
&
mf
);
tsdbUpdateMFile
(
p
fs
,
&
mf
);
return
0
;
}
_err:
return
-
1
;
int
tsdbEncodeKVRecord
(
void
**
buf
,
SKVRecord
*
pRecord
)
{
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
static
int
tsdbCommitTSData
(
STsdbRepo
*
pRepo
)
{
SMemTable
*
pMem
=
pRepo
->
imem
;
...
...
src/tsdb/src/tsdbStore.c
浏览文件 @
efa09d44
...
...
@@ -18,12 +18,6 @@
#include "tsdbint.h"
typedef
struct
{
uint64_t
uid
;
int64_t
offset
;
int64_t
size
;
}
SKVRecord
;
static
int
tdInitKVStoreHeader
(
int
fd
,
char
*
fname
);
static
int
tdEncodeStoreInfo
(
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录