Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
2978f6b6
TDengine
项目概览
taosdata
/
TDengine
大约 2 年 前同步成功
通知
1192
Star
22018
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看板
提交
2978f6b6
编写于
10月 19, 2020
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor
上级
ab22af1d
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
34 addition
and
13 deletion
+34
-13
src/tsdb/inc/tsdbMain.h
src/tsdb/inc/tsdbMain.h
+2
-5
src/tsdb/src/tsdbMain.c
src/tsdb/src/tsdbMain.c
+1
-0
src/util/src/tkvstore.c
src/util/src/tkvstore.c
+31
-8
未找到文件。
src/tsdb/inc/tsdbMain.h
浏览文件 @
2978f6b6
...
...
@@ -14,18 +14,15 @@
*/
#ifndef _TD_TSDB_MAIN_H_
#define _TD_TSDB_MAIN_H_
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include "hash.h"
#include "os.h"
#include "hash.h"
#include "tcoding.h"
#include "tglobal.h"
#include "tkvstore.h"
#include "tlist.h"
#include "tlockfree.h"
#include "tlog.h"
#include "tlockfree.h"
#include "tsdb.h"
#include "tskiplist.h"
#include "tutil.h"
...
...
src/tsdb/src/tsdbMain.c
浏览文件 @
2978f6b6
...
...
@@ -12,6 +12,7 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// no test file errors here
#include "tsdbMain.h"
#include "os.h"
...
...
src/util/src/tkvstore.c
浏览文件 @
2978f6b6
...
...
@@ -94,7 +94,7 @@ SKVStore *tdOpenKVStore(char *fname, iterFunc iFunc, afterFunc aFunc, void *appH
SKVStore
*
pStore
=
tdNewKVStore
(
fname
,
iFunc
,
aFunc
,
appH
);
if
(
pStore
==
NULL
)
return
NULL
;
pStore
->
fd
=
open
(
pStore
->
fname
,
O_RD
WR
);
pStore
->
fd
=
open
(
pStore
->
fname
,
O_RD
ONLY
);
if
(
pStore
->
fd
<
0
)
{
uError
(
"failed to open file %s since %s"
,
pStore
->
fname
,
strerror
(
errno
));
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
...
...
@@ -118,7 +118,7 @@ SKVStore *tdOpenKVStore(char *fname, iterFunc iFunc, afterFunc aFunc, void *appH
return
pStore
;
_err:
if
(
pStore
->
fd
>
0
)
{
if
(
pStore
->
fd
>
=
0
)
{
close
(
pStore
->
fd
);
pStore
->
fd
=
-
1
;
}
...
...
@@ -168,6 +168,7 @@ int tdUpdateKVStoreRecord(SKVStore *pStore, uint64_t uid, void *cont, int contLe
rInfo
.
offset
=
lseek
(
pStore
->
fd
,
0
,
SEEK_CUR
);
if
(
rInfo
.
offset
<
0
)
{
uError
(
"failed to lseek file %s since %s"
,
pStore
->
fname
,
strerror
(
errno
));
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
return
-
1
;
}
...
...
@@ -194,7 +195,7 @@ int tdUpdateKVStoreRecord(SKVStore *pStore, uint64_t uid, void *cont, int contLe
pStore
->
ninfo
.
size
+=
(
sizeof
(
SKVRecord
)
+
contLen
);
SKVRecord
*
pRecord
=
taosHashGet
(
pStore
->
map
,
(
void
*
)
&
uid
,
sizeof
(
uid
));
if
(
pRecord
!=
NULL
)
{
// just to insert
pStore
->
ninfo
.
tombSize
+=
pRecord
->
size
;
pStore
->
ninfo
.
tombSize
+=
(
pRecord
->
size
+
sizeof
(
SKVRecord
))
;
}
else
{
pStore
->
ninfo
.
nRecords
++
;
}
...
...
@@ -380,7 +381,10 @@ static int tdInitKVStoreHeader(int fd, char *fname) {
static
SKVStore
*
tdNewKVStore
(
char
*
fname
,
iterFunc
iFunc
,
afterFunc
aFunc
,
void
*
appH
)
{
SKVStore
*
pStore
=
(
SKVStore
*
)
calloc
(
1
,
sizeof
(
SKVStore
));
if
(
pStore
==
NULL
)
goto
_err
;
if
(
pStore
==
NULL
)
{
terrno
=
TSDB_CODE_COM_OUT_OF_MEMORY
;
goto
_err
;
}
pStore
->
fname
=
strdup
(
fname
);
if
(
pStore
->
fname
==
NULL
)
{
...
...
@@ -459,12 +463,18 @@ static int tdRestoreKVStore(SKVStore *pStore) {
while
(
true
)
{
ssize_t
tsize
=
taosTRead
(
pStore
->
fd
,
tbuf
,
sizeof
(
SKVRecord
));
if
(
tsize
==
0
)
break
;
if
(
tsize
<
sizeof
(
SKVRecord
)
)
{
uError
(
"failed to read %"
PRIzu
" bytes from file %s at offset %"
PRId64
"since %s"
,
sizeof
(
SKVRecord
),
pStore
->
fname
,
pStore
->
info
.
size
,
strerror
(
errno
));
if
(
tsize
<
0
)
{
uError
(
"failed to read %"
PRIzu
" bytes from file %s at offset %"
PRId64
"since %s"
,
sizeof
(
SKVRecord
),
pStore
->
fname
,
pStore
->
info
.
size
,
strerror
(
errno
));
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
goto
_err
;
}
if
(
tsize
<
sizeof
(
SKVRecord
))
{
uError
(
"file %s is corrupted offset %"
PRId64
" len %"
PRIzu
,
pStore
->
fname
,
pStore
->
info
.
size
,
sizeof
(
SKVRecord
));
terrno
=
TSDB_CODE_COM_FILE_CORRUPTED
;
goto
_err
;
}
char
*
pBuf
=
tdDecodeKVRecord
(
tbuf
,
&
rInfo
);
ASSERT
(
POINTER_DISTANCE
(
pBuf
,
tbuf
)
==
sizeof
(
SKVRecord
));
...
...
@@ -478,6 +488,11 @@ static int tdRestoreKVStore(SKVStore *pStore) {
pStore
->
info
.
tombSize
+=
(
rInfo
.
size
+
sizeof
(
SKVRecord
)
*
2
);
}
else
{
ASSERT
(
rInfo
.
offset
>
0
&&
rInfo
.
size
>
0
);
SKVRecord
*
pRecord
=
taosHashGet
(
pStore
->
map
,
(
void
*
)(
&
rInfo
.
uid
),
sizeof
(
rInfo
.
uid
));
if
(
pRecord
!=
NULL
)
{
pStore
->
info
.
tombSize
+=
(
sizeof
(
SKVRecord
)
+
pRecord
->
size
);
}
if
(
taosHashPut
(
pStore
->
map
,
(
void
*
)(
&
rInfo
.
uid
),
sizeof
(
rInfo
.
uid
),
&
rInfo
,
sizeof
(
rInfo
))
<
0
)
{
uError
(
"failed to put record in KV store %s"
,
pStore
->
fname
);
terrno
=
TSDB_CODE_COM_OUT_OF_MEMORY
;
...
...
@@ -520,12 +535,20 @@ static int tdRestoreKVStore(SKVStore *pStore) {
goto
_err
;
}
if
(
taosTRead
(
pStore
->
fd
,
buf
,
(
size_t
)
pRecord
->
size
)
<
pRecord
->
size
)
{
ssize_t
tsize
=
taosTRead
(
pStore
->
fd
,
buf
,
(
size_t
)
pRecord
->
size
);
if
(
tsize
<
0
)
{
uError
(
"failed to read %"
PRId64
" bytes from file %s since %s, offset %"
PRId64
,
pRecord
->
size
,
pStore
->
fname
,
strerror
(
errno
),
pRecord
->
offset
);
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
goto
_err
;
}
if
(
tsize
<
pRecord
->
size
)
{
uError
(
"file %s is corrupted, offset %"
PRId64
" size %"
PRId64
,
pStore
->
fname
,
pRecord
->
offset
+
sizeof
(
SKVRecord
),
pRecord
->
size
);
terrno
=
TSDB_CODE_COM_FILE_CORRUPTED
;
goto
_err
;
}
if
(
pStore
->
iFunc
)
{
if
((
*
pStore
->
iFunc
)(
pStore
->
appH
,
buf
,
(
int
)
pRecord
->
size
)
<
0
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录