Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
f8d84036
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看板
提交
f8d84036
编写于
6月 08, 2020
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more
上级
7d7d4ddb
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
54 addition
and
8 deletion
+54
-8
src/util/src/tkvstore.c
src/util/src/tkvstore.c
+54
-8
未找到文件。
src/util/src/tkvstore.c
浏览文件 @
f8d84036
...
...
@@ -34,14 +34,21 @@
#define TD_KVSTORE_SNAP_SUFFIX ".snap"
#define TD_KVSTORE_NEW_SUFFIX ".new"
typedef
struct
{
uint64_t
uid
;
int64_t
offset
;
int32_t
size
;
}
SKVRecord
;
static
int
tdInitKVStoreHeader
(
int
fd
,
char
*
fname
);
static
void
*
tdEncodeStoreInfo
(
void
*
buf
,
SStoreInfo
*
pInfo
);
//
static void * tdDecodeStoreInfo(void *buf, SStoreInfo *pInfo);
static
void
*
tdDecodeStoreInfo
(
void
*
buf
,
SStoreInfo
*
pInfo
);
static
SKVStore
*
tdNewKVStore
(
char
*
fname
,
iterFunc
iFunc
,
afterFunc
aFunc
,
void
*
appH
);
static
char
*
tdGetKVStoreSnapshotFname
(
char
*
fdata
);
static
char
*
tdGetKVStoreNewFname
(
char
*
fdata
);
static
void
tdFreeKVStore
(
SKVStore
*
pStore
);
static
int
tdUpdateKVStoreHeader
(
int
fd
,
char
*
fname
,
SStoreInfo
*
pInfo
);
static
int
tdLoadKVStoreHeader
(
int
fd
,
char
*
fname
,
SStoreInfo
*
pInfo
);
int
tdCreateKVStore
(
char
*
fname
)
{
char
*
tname
=
strdup
(
fname
);
...
...
@@ -70,6 +77,7 @@ int tdCreateKVStore(char *fname) {
}
SKVStore
*
tdOpenKVStore
(
char
*
fname
,
iterFunc
iFunc
,
afterFunc
aFunc
,
void
*
appH
)
{
SStoreInfo
info
=
{
0
};
SKVStore
*
pStore
=
tdNewKVStore
(
fname
,
iFunc
,
aFunc
,
appH
);
if
(
pStore
==
NULL
)
return
NULL
;
...
...
@@ -90,6 +98,13 @@ SKVStore *tdOpenKVStore(char *fname, iterFunc iFunc, afterFunc aFunc, void *appH
}
// TODO: rewind the file
if
(
tdLoadKVStoreHeader
(
pStore
->
sfd
,
pStore
->
fsnap
,
&
info
)
<
0
)
goto
_err
;
if
(
ftruncate
(
pStore
->
fd
,
info
.
size
)
<
0
)
{
uError
(
"failed to truncate %s since %s"
,
pStore
->
fname
,
strerror
(
errno
));
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
goto
_err
;
}
close
(
pStore
->
sfd
);
pStore
->
sfd
=
-
1
;
...
...
@@ -97,6 +112,18 @@ SKVStore *tdOpenKVStore(char *fname, iterFunc iFunc, afterFunc aFunc, void *appH
}
// TODO: Recover from the file
terrno
=
tdUpdateKVStoreHeader
(
pStore
->
fd
,
pStore
->
fname
,
&
info
);
if
(
terrno
!=
TSDB_CODE_SUCCESS
)
goto
_err
;
if
(
lseek
(
pStore
->
fd
,
TD_KVSTORE_HEADER_SIZE
,
SEEK_SET
)
<
0
)
{
uError
(
"failed to lseek file %s since %s"
,
pStore
->
fname
,
strerror
(
errno
));
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
goto
_err
;
}
while
(
true
)
{
}
return
pStore
;
...
...
@@ -184,6 +211,25 @@ int tdKVStoreEndCommit(SKVStore *pStore) {
return
0
;
}
static
int
tdLoadKVStoreHeader
(
int
fd
,
char
*
fname
,
SStoreInfo
*
pInfo
)
{
char
buf
[
TD_KVSTORE_HEADER_SIZE
]
=
"
\0
"
;
if
(
tread
(
fd
,
buf
,
TD_KVSTORE_HEADER_SIZE
)
<
TD_KVSTORE_HEADER_SIZE
)
{
uError
(
"failed to read file %s since %s"
,
fname
,
strerror
(
errno
));
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
return
-
1
;
}
if
(
!
taosCheckChecksumWhole
((
uint8_t
*
)
buf
,
TD_KVSTORE_HEADER_SIZE
))
{
uError
(
"file %s is broken"
,
fname
);
return
-
1
;
}
tdDecodeStoreInfo
(
buf
,
pInfo
);
return
0
;
}
static
int
tdUpdateKVStoreHeader
(
int
fd
,
char
*
fname
,
SStoreInfo
*
pInfo
)
{
char
buf
[
TD_KVSTORE_HEADER_SIZE
]
=
"
\0
"
;
...
...
@@ -217,14 +263,14 @@ static void *tdEncodeStoreInfo(void *buf, SStoreInfo *pInfo) {
return
buf
;
}
//
static void *tdDecodeStoreInfo(void *buf, SStoreInfo *pInfo) {
//
buf = taosDecodeVariantI64(buf, &(pInfo->size));
//
buf = taosDecodeVariantI64(buf, &(pInfo->tombSize));
//
buf = taosDecodeVariantI64(buf, &(pInfo->nRecords));
//
buf = taosDecodeVariantI64(buf, &(pInfo->nDels));
static
void
*
tdDecodeStoreInfo
(
void
*
buf
,
SStoreInfo
*
pInfo
)
{
buf
=
taosDecodeVariantI64
(
buf
,
&
(
pInfo
->
size
));
buf
=
taosDecodeVariantI64
(
buf
,
&
(
pInfo
->
tombSize
));
buf
=
taosDecodeVariantI64
(
buf
,
&
(
pInfo
->
nRecords
));
buf
=
taosDecodeVariantI64
(
buf
,
&
(
pInfo
->
nDels
));
//
return buf;
//
}
return
buf
;
}
static
SKVStore
*
tdNewKVStore
(
char
*
fname
,
iterFunc
iFunc
,
afterFunc
aFunc
,
void
*
appH
)
{
SKVStore
*
pStore
=
(
SKVStore
*
)
malloc
(
sizeof
(
SKVStore
));
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录