Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
4b33695f
T
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1184
Star
22015
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
4b33695f
编写于
6月 23, 2022
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more work
上级
4d8d1df2
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
245 addition
and
114 deletion
+245
-114
source/dnode/vnode/src/inc/tsdb.h
source/dnode/vnode/src/inc/tsdb.h
+9
-21
source/dnode/vnode/src/tsdb/tsdbFS.c
source/dnode/vnode/src/tsdb/tsdbFS.c
+182
-57
source/dnode/vnode/src/tsdb/tsdbFile.c
source/dnode/vnode/src/tsdb/tsdbFile.c
+33
-14
source/dnode/vnode/src/tsdb/tsdbMemTable.c
source/dnode/vnode/src/tsdb/tsdbMemTable.c
+9
-7
source/dnode/vnode/src/tsdb/tsdbOpen.c
source/dnode/vnode/src/tsdb/tsdbOpen.c
+4
-6
source/dnode/vnode/src/tsdb/tsdbReaderWriter.c
source/dnode/vnode/src/tsdb/tsdbReaderWriter.c
+8
-9
未找到文件。
source/dnode/vnode/src/inc/tsdb.h
浏览文件 @
4b33695f
...
...
@@ -67,6 +67,7 @@ typedef struct STsdbFS STsdbFS;
typedef
struct
SRowMerger
SRowMerger
;
#define TSDB_MAX_SUBBLOCKS 8
#define TSDB_FHDR_SIZE 512
#define HAS_NONE ((int8_t)0x1)
#define HAS_NULL ((int8_t)0x2)
...
...
@@ -165,15 +166,8 @@ void tsdbTbDataIterOpen(STbData *pTbData, TSDBKEY *pFrom, int8_t backward, S
TSDBROW
*
tsdbTbDataIterGet
(
STbDataIter
*
pIter
);
bool
tsdbTbDataIterNext
(
STbDataIter
*
pIter
);
// tsdbFile.c ==============================================================================================
// SDataFSet
// SHeadFile
void
tsdbHeadFileName
(
STsdb
*
pTsdb
,
SHeadFile
*
pFile
,
char
fname
[]);
// SDataFile
void
tsdbDataFileName
(
STsdb
*
pTsdb
,
SDataFile
*
pFile
,
char
fname
[]);
// SLastFile
void
tsdbLastFileName
(
STsdb
*
pTsdb
,
SLastFile
*
pFile
,
char
fname
[]);
// SSmaFile
void
tsdbSmaFileName
(
STsdb
*
pTsdb
,
SSmaFile
*
pFile
,
char
fname
[]);
enum
{
TSDB_HEAD_FILE
=
0
,
TSDB_DATA_FILE
,
TSDB_LAST_FILE
,
TSDB_SMA_FILE
};
void
tsdbDataFileName
(
STsdb
*
pTsdb
,
SDFileSet
*
pDFileSet
,
int8_t
ftype
,
char
fname
[]);
// SDelFile
#define tsdbDelFileCreate() \
((SDelFile){ \
...
...
@@ -230,12 +224,10 @@ typedef struct {
TSKEY
minKey
;
}
SRtn
;
#define TSDB_DATA_DIR_LEN 6 // adapt accordingly
struct
STsdb
{
char
*
path
;
SVnode
*
pVnode
;
TdThreadMutex
mutex
;
char
dir
[
TSDB_DATA_DIR_LEN
];
bool
repoLocked
;
STsdbKeepCfg
keepCfg
;
SMemTable
*
mem
;
...
...
@@ -487,16 +479,12 @@ struct SSmaFile {
};
struct
SDFileSet
{
SDiskID
diskId
;
int32_t
fid
;
SHeadFile
*
pHeadFile
;
SDataFile
*
pDataFile
;
SLastFile
*
pLastFile
;
SSmaFile
*
pSmaFile
;
// SHeadFile headFile;
// SDataFile dataFile;
// SLastFile lastFile;
// SSmaFile smaFile;
SDiskID
diskId
;
int32_t
fid
;
SHeadFile
fHead
;
SDataFile
fData
;
SLastFile
fLast
;
SSmaFile
fSma
;
};
struct
SRowIter
{
...
...
source/dnode/vnode/src/tsdb/tsdbFS.c
浏览文件 @
4b33695f
...
...
@@ -17,7 +17,8 @@
typedef
struct
{
SDelFile
*
pDelFile
;
SArray
*
aDFileSet
;
// SArray<aDFileSet *>
SArray
*
aDFileSet
;
// SArray<aDFileSet>
SDelFile
delFile
;
}
STsdbFSState
;
struct
STsdbFS
{
...
...
@@ -105,10 +106,10 @@ static int32_t tsdbDFileSetToJson(const void *pObj, SJson *pJson) {
if
(
tjsonAddIntegerToObject
(
pJson
,
"level"
,
pDFileSet
->
diskId
.
level
)
<
0
)
goto
_err
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"id"
,
pDFileSet
->
diskId
.
id
)
<
0
)
goto
_err
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"fid"
,
pDFileSet
->
fid
)
<
0
)
goto
_err
;
if
(
tjsonAddObject
(
pJson
,
"head"
,
tsdbHeadFileToJson
,
pDFileSet
->
pHeadFile
)
<
0
)
goto
_err
;
if
(
tjsonAddObject
(
pJson
,
"data"
,
tsdbDataFileToJson
,
pDFileSet
->
pDataFile
)
<
0
)
goto
_err
;
if
(
tjsonAddObject
(
pJson
,
"last"
,
tsdbLastFileToJson
,
pDFileSet
->
pLastFile
)
<
0
)
goto
_err
;
if
(
tjsonAddObject
(
pJson
,
"sma"
,
tsdbSmaFileToJson
,
pDFileSet
->
pSmaFile
)
<
0
)
goto
_err
;
//
if (tjsonAddObject(pJson, "head", tsdbHeadFileToJson, pDFileSet->pHeadFile) < 0) goto _err;
//
if (tjsonAddObject(pJson, "data", tsdbDataFileToJson, pDFileSet->pDataFile) < 0) goto _err;
//
if (tjsonAddObject(pJson, "last", tsdbLastFileToJson, pDFileSet->pLastFile) < 0) goto _err;
//
if (tjsonAddObject(pJson, "sma", tsdbSmaFileToJson, pDFileSet->pSmaFile) < 0) goto _err;
return
code
;
...
...
@@ -273,7 +274,8 @@ static int32_t tsdbLoadCurrentState(STsdbFS *pFS, STsdbFSState *pState) {
char
*
pData
=
NULL
;
TdFilePtr
pFD
;
snprintf
(
fname
,
TSDB_FILENAME_LEN
-
1
,
"%s/CURRENT"
,
pFS
->
pTsdb
->
path
);
snprintf
(
fname
,
TSDB_FILENAME_LEN
-
1
,
"%s%s%s%sCURRENT"
,
tfsGetPrimaryPath
(
pFS
->
pTsdb
->
pVnode
->
pTfs
),
TD_DIRSEP
,
pFS
->
pTsdb
->
path
,
TD_DIRSEP
);
if
(
!
taosCheckExistFile
(
fname
))
{
// create an empry CURRENT file if not exists
...
...
@@ -321,38 +323,6 @@ _err:
return
code
;
}
static
int32_t
tsdbFSOpenImpl
(
STsdbFS
*
pFS
)
{
int32_t
code
=
0
;
int64_t
size
;
int64_t
n
;
// read CURRENT file
code
=
tsdbLoadCurrentState
(
pFS
,
pFS
->
cState
);
if
(
code
)
goto
_err
;
// decode the statue file
// code = tsdbDecodeFSState(pData, pFS->cState);
// if (code) goto _err;
// // scan and fix invalid tsdb FS
// code = tsdbScanAndFixFS(pFS);
// if (code) goto _err;
// if (pData) taosMemoryFree(pData);
return
code
;
_err:
// if (pData) taosMemoryFree(pData);
tsdbError
(
"vgId:%d tsdb fs open impl failed since %s"
,
TD_VID
(
pFS
->
pTsdb
->
pVnode
),
tstrerror
(
code
));
return
code
;
}
static
int32_t
tsdbFSCloseImpl
(
STsdbFS
*
pFS
)
{
int32_t
code
=
0
;
// TODO
return
code
;
}
static
int32_t
tsdbApplyDFileSetChange
(
STsdbFS
*
pFS
,
SDFileSet
*
pFrom
,
SDFileSet
*
pTo
)
{
int32_t
code
=
0
;
// TODO
...
...
@@ -448,8 +418,25 @@ _err:
return
code
;
}
// EXPOSED APIS ====================================================================================
int32_t
tsdbFSOpen
(
STsdb
*
pTsdb
,
STsdbFS
**
ppFS
)
{
static
void
tsdbFSDestroy
(
STsdbFS
*
pFS
)
{
if
(
pFS
)
{
if
(
pFS
->
nState
)
{
taosArrayDestroy
(
pFS
->
nState
->
aDFileSet
);
taosMemoryFree
(
pFS
->
nState
);
}
if
(
pFS
->
cState
)
{
taosArrayDestroy
(
pFS
->
cState
->
aDFileSet
);
taosMemoryFree
(
pFS
->
cState
);
}
taosThreadRwlockDestroy
(
&
pFS
->
lock
);
taosMemoryFree
(
pFS
);
}
// TODO
}
static
int32_t
tsdbFSCreate
(
STsdb
*
pTsdb
,
STsdbFS
**
ppFS
)
{
int32_t
code
=
0
;
STsdbFS
*
pFS
=
NULL
;
...
...
@@ -462,6 +449,7 @@ int32_t tsdbFSOpen(STsdb *pTsdb, STsdbFS **ppFS) {
code
=
taosThreadRwlockInit
(
&
pFS
->
lock
,
NULL
);
if
(
code
)
{
taosMemoryFree
(
pFS
);
code
=
TAOS_SYSTEM_ERROR
(
code
);
goto
_err
;
}
...
...
@@ -473,7 +461,7 @@ int32_t tsdbFSOpen(STsdb *pTsdb, STsdbFS **ppFS) {
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_err
;
}
pFS
->
cState
->
aDFileSet
=
taosArrayInit
(
0
,
sizeof
(
SDFileSet
*
));
pFS
->
cState
->
aDFileSet
=
taosArrayInit
(
0
,
sizeof
(
SDFileSet
));
if
(
pFS
->
cState
->
aDFileSet
==
NULL
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_err
;
...
...
@@ -484,43 +472,180 @@ int32_t tsdbFSOpen(STsdb *pTsdb, STsdbFS **ppFS) {
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_err
;
}
pFS
->
nState
->
aDFileSet
=
taosArrayInit
(
0
,
sizeof
(
SDFileSet
*
));
pFS
->
nState
->
aDFileSet
=
taosArrayInit
(
0
,
sizeof
(
SDFileSet
));
if
(
pFS
->
nState
->
aDFileSet
==
NULL
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_err
;
}
code
=
tsdbFSOpenImpl
(
pFS
);
if
(
code
)
goto
_err
;
*
ppFS
=
pFS
;
return
code
;
_err:
tsdbError
(
"vgId:%d tsdb fs create failed since %s"
,
TD_VID
(
pTsdb
->
pVnode
),
tstrerror
(
code
));
tsdbFSDestroy
(
pFS
);
*
ppFS
=
NULL
;
tsdbError
(
"vgId:%d tsdb fs open failed since %s"
,
TD_VID
(
pTsdb
->
pVnode
),
tstrerror
(
code
));
return
code
;
}
int32_t
tsdbFSClose
(
STsdbFS
*
pFS
)
{
static
int32_t
tsdbScanAndTryFixFS
(
STsdbFS
*
pFS
,
int8_t
deepScan
)
{
int32_t
code
=
0
;
STsdb
*
pTsdb
=
pFS
->
pTsdb
;
STfs
*
pTfs
=
pTsdb
->
pVnode
->
pTfs
;
int64_t
size
;
char
fname
[
TSDB_FILENAME_LEN
];
char
pHdr
[
TSDB_FHDR_SIZE
];
TdFilePtr
pFD
;
// SDelFile
if
(
pFS
->
cState
->
pDelFile
)
{
tsdbDelFileName
(
pTsdb
,
pFS
->
cState
->
pDelFile
,
fname
);
if
(
taosStatFile
(
fname
,
&
size
,
NULL
))
{
code
=
TAOS_SYSTEM_ERROR
(
errno
);
goto
_err
;
}
if
(
size
!=
pFS
->
cState
->
pDelFile
->
size
)
{
code
=
TSDB_CODE_FILE_CORRUPTED
;
goto
_err
;
}
if
(
deepScan
)
{
// TODO
}
}
// SArray<SDFileSet>
for
(
int32_t
iSet
=
0
;
iSet
<
taosArrayGetSize
(
pFS
->
cState
->
aDFileSet
);
iSet
++
)
{
SDFileSet
*
pDFileSet
=
(
SDFileSet
*
)
taosArrayGet
(
pFS
->
cState
->
aDFileSet
,
iSet
);
// head =========
tsdbDataFileName
(
pTsdb
,
pDFileSet
,
TSDB_HEAD_FILE
,
fname
);
if
(
taosStatFile
(
fname
,
&
size
,
NULL
))
{
code
=
TAOS_SYSTEM_ERROR
(
errno
);
goto
_err
;
}
if
(
deepScan
)
{
// TODO
}
// data =========
tsdbDataFileName
(
pTsdb
,
pDFileSet
,
TSDB_DATA_FILE
,
fname
);
if
(
taosStatFile
(
fname
,
&
size
,
NULL
))
{
code
=
TAOS_SYSTEM_ERROR
(
errno
);
goto
_err
;
}
if
(
size
<
pDFileSet
->
fData
.
size
)
{
code
=
TSDB_CODE_FILE_CORRUPTED
;
goto
_err
;
}
else
if
(
size
>
pDFileSet
->
fData
.
size
)
{
ASSERT
(
0
);
// need to rollback the file
}
if
(
deepScan
)
{
// TODO
}
// last ===========
tsdbDataFileName
(
pTsdb
,
pDFileSet
,
TSDB_LAST_FILE
,
fname
);
if
(
taosStatFile
(
fname
,
&
size
,
NULL
))
{
code
=
TAOS_SYSTEM_ERROR
(
errno
);
goto
_err
;
}
if
(
size
<
pDFileSet
->
fLast
.
size
)
{
code
=
TSDB_CODE_FILE_CORRUPTED
;
goto
_err
;
}
else
if
(
size
>
pDFileSet
->
fLast
.
size
)
{
ASSERT
(
0
);
// need to rollback the file
}
if
(
deepScan
)
{
// TODO
}
// sma =============
tsdbDataFileName
(
pTsdb
,
pDFileSet
,
TSDB_SMA_FILE
,
fname
);
if
(
taosStatFile
(
fname
,
&
size
,
NULL
))
{
code
=
TAOS_SYSTEM_ERROR
(
errno
);
goto
_err
;
}
if
(
size
<
pDFileSet
->
fSma
.
size
)
{
code
=
TSDB_CODE_FILE_CORRUPTED
;
goto
_err
;
}
else
if
(
size
>
pDFileSet
->
fSma
.
size
)
{
ASSERT
(
0
);
// need to rollback the file
}
if
(
deepScan
)
{
// TODO
}
}
// remove those invalid files (todo)
#if 0
STfsDir *tdir;
const STfsFile *pf;
tdir = tfsOpendir(pTfs, pTsdb->path);
if (tdir == NULL) {
code = TAOS_SYSTEM_ERROR(errno);
goto _err;
}
while ((pf = tfsReaddir(tdir))) {
tfsBasename(pf, fname);
}
tfsClosedir(tdir);
#endif
return
code
;
_err:
tsdbError
(
"vgId:%d tsdb can and try fix fs failed since %s"
,
TD_VID
(
pTsdb
->
pVnode
),
tstrerror
(
code
));
return
code
;
}
// EXPOSED APIS ====================================================================================
int32_t
tsdbFSOpen
(
STsdb
*
pTsdb
,
STsdbFS
**
ppFS
)
{
int32_t
code
=
0
;
if
(
pFS
)
{
code
=
tsdbFSCloseImpl
(
pFS
);
if
(
code
)
goto
_err
;
// create handle
code
=
tsdbFSCreate
(
pTsdb
,
p
pFS
);
if
(
code
)
goto
_err
;
taosArrayDestroy
(
pFS
->
nState
->
aDFileSet
);
taosMemoryFree
(
pFS
->
nState
);
taosArrayDestroy
(
pFS
->
cState
->
aDFileSet
);
taosMemoryFree
(
pFS
->
cState
);
taosThreadRwlockDestroy
(
&
pFS
->
lock
);
taosMemoryFree
(
pFS
);
// load current state
code
=
tsdbLoadCurrentState
(
*
ppFS
,
(
*
ppFS
)
->
cState
);
if
(
code
)
{
tsdbFSDestroy
(
*
ppFS
);
goto
_err
;
}
// scan and fix FS
code
=
tsdbScanAndTryFixFS
(
*
ppFS
,
0
);
if
(
code
)
{
tsdbFSDestroy
(
*
ppFS
);
goto
_err
;
}
return
code
;
_err:
tsdbError
(
"vgId:%d tsdb fs close failed since %s"
,
TD_VID
(
pFS
->
pTsdb
->
pVnode
),
tstrerror
(
code
));
*
ppFS
=
NULL
;
tsdbError
(
"vgId:%d tsdb fs open failed since %s"
,
TD_VID
(
pTsdb
->
pVnode
),
tstrerror
(
code
));
return
code
;
}
int32_t
tsdbFSClose
(
STsdbFS
*
pFS
)
{
int32_t
code
=
0
;
tsdbFSDestroy
(
pFS
);
return
code
;
}
...
...
source/dnode/vnode/src/tsdb/tsdbFile.c
浏览文件 @
4b33695f
...
...
@@ -15,29 +15,48 @@
#include "tsdb.h"
static
const
char
*
tsdbFileSuffix
[]
=
{
".del"
,
".cache"
,
".head"
,
".data"
,
".last"
,
".sma"
,
""
};
void
tsdbDataFileName
(
STsdb
*
pTsdb
,
SDFileSet
*
pDFileSet
,
int8_t
ftype
,
char
fname
[])
{
STfs
*
pTfs
=
pTsdb
->
pVnode
->
pTfs
;
// SHeadFile ===============================================
void
tsdbHeadFileName
(
STsdb
*
pTsdb
,
SHeadFile
*
pFile
,
char
fname
[])
{
// snprintf(fname, TSDB_FILENAME_LEN - 1, "%s/v%df%dver%18d.head", );
switch
(
ftype
)
{
case
TSDB_HEAD_FILE
:
snprintf
(
fname
,
TSDB_FILENAME_LEN
-
1
,
"%s%s%s%sv%df%dver%"
PRId64
"%s"
,
tfsGetDiskPath
(
pTfs
,
pDFileSet
->
diskId
),
TD_DIRSEP
,
pTsdb
->
path
,
TD_DIRSEP
,
TD_VID
(
pTsdb
->
pVnode
),
pDFileSet
->
fid
,
pDFileSet
->
fHead
.
commitID
,
".head"
);
break
;
case
TSDB_DATA_FILE
:
snprintf
(
fname
,
TSDB_FILENAME_LEN
-
1
,
"%s%s%s%sv%df%dver%"
PRId64
"%s"
,
tfsGetDiskPath
(
pTfs
,
pDFileSet
->
diskId
),
TD_DIRSEP
,
pTsdb
->
path
,
TD_DIRSEP
,
TD_VID
(
pTsdb
->
pVnode
),
pDFileSet
->
fid
,
pDFileSet
->
fData
.
commitID
,
".data"
);
break
;
case
TSDB_LAST_FILE
:
snprintf
(
fname
,
TSDB_FILENAME_LEN
-
1
,
"%s%s%s%sv%df%dver%"
PRId64
"%s"
,
tfsGetDiskPath
(
pTfs
,
pDFileSet
->
diskId
),
TD_DIRSEP
,
pTsdb
->
path
,
TD_DIRSEP
,
TD_VID
(
pTsdb
->
pVnode
),
pDFileSet
->
fid
,
pDFileSet
->
fLast
.
commitID
,
".last"
);
break
;
case
TSDB_SMA_FILE
:
snprintf
(
fname
,
TSDB_FILENAME_LEN
-
1
,
"%s%s%s%sv%df%dver%"
PRId64
"%s"
,
tfsGetDiskPath
(
pTfs
,
pDFileSet
->
diskId
),
TD_DIRSEP
,
pTsdb
->
path
,
TD_DIRSEP
,
TD_VID
(
pTsdb
->
pVnode
),
pDFileSet
->
fid
,
pDFileSet
->
fSma
.
commitID
,
".sma"
);
break
;
default:
ASSERT
(
0
);
break
;
}
}
// SHeadFile ===============================================
// SDataFile ===============================================
void
tsdbDataFileName
(
STsdb
*
pTsdb
,
SDataFile
*
pFile
,
char
fname
[])
{
// TODO
}
// SLastFile ===============================================
void
tsdbLastFileName
(
STsdb
*
pTsdb
,
SLastFile
*
pFile
,
char
fname
[])
{
// TODO
}
// SSmaFile ===============================================
void
tsdbSmaFileName
(
STsdb
*
pTsdb
,
SSmaFile
*
pFile
,
char
fname
[])
{
// TODO
}
// SDelFile ===============================================
void
tsdbDelFileName
(
STsdb
*
pTsdb
,
SDelFile
*
pFile
,
char
fname
[])
{
// snprintf(fname, TSDB_FILENAME_LEN, "", pTsdb->path);
STfs
*
pTfs
=
pTsdb
->
pVnode
->
pTfs
;
snprintf
(
fname
,
TSDB_FILENAME_LEN
-
1
,
"%s%s%s%sv%dver%"
PRId64
"%s"
,
tfsGetPrimaryPath
(
pTfs
),
TD_DIRSEP
,
pTsdb
->
path
,
TD_DIRSEP
,
TD_VID
(
pTsdb
->
pVnode
),
pFile
->
commitID
,
".del"
);
}
\ No newline at end of file
source/dnode/vnode/src/tsdb/tsdbMemTable.c
浏览文件 @
4b33695f
...
...
@@ -175,6 +175,8 @@ int32_t tsdbDeleteTableData(STsdb *pTsdb, int64_t version, tb_uid_t suid, tb_uid
// update the state of pMemTable and other (todo)
pMemTable
->
minVersion
=
TMIN
(
pMemTable
->
minVersion
,
version
);
pMemTable
->
maxVersion
=
TMAX
(
pMemTable
->
maxVersion
,
version
);
pMemTable
->
nDel
++
;
if
(
tsdbKeyCmprFn
(
&
lastKey
,
&
pTbData
->
maxKey
)
>=
0
)
{
...
...
@@ -521,7 +523,7 @@ static int32_t tsdbInsertTableDataImpl(SMemTable *pMemTable, STbData *pTbData, i
goto
_err
;
}
if
(
pTbData
->
minKey
>
key
.
ts
)
pTbData
->
minKey
=
key
.
ts
;
pTbData
->
minKey
=
TMIN
(
pTbData
->
minKey
,
key
.
ts
)
;
pLastRow
=
row
.
pTSRow
;
...
...
@@ -553,14 +555,14 @@ static int32_t tsdbInsertTableDataImpl(SMemTable *pMemTable, STbData *pTbData, i
tsdbCacheInsertLastrow
(
pMemTable
->
pTsdb
->
lruCache
,
pTbData
->
uid
,
pLastRow
);
}
}
if
(
pTbData
->
minVersion
>
version
)
pTbData
->
minVersion
=
version
;
if
(
pTbData
->
maxVersion
<
version
)
pTbData
->
maxVersion
=
version
;
pTbData
->
minVersion
=
TMIN
(
pTbData
->
minVersion
,
version
)
;
pTbData
->
maxVersion
=
TMAX
(
pTbData
->
maxVersion
,
version
)
;
// SMemTable
if
(
pMemTable
->
minKey
>
pTbData
->
minKey
)
pMemTable
->
minKey
=
pTbData
->
minKey
;
if
(
pMemTable
->
maxKey
<
pTbData
->
maxKey
)
pMemTable
->
maxKey
=
pTbData
->
maxKey
;
if
(
pMemTable
->
minVersion
>
pTbData
->
minVersion
)
pMemTable
->
minVersion
=
pTbData
->
minVersion
;
if
(
pMemTable
->
maxVersion
<
pTbData
->
maxVersion
)
pMemTable
->
maxVersion
=
pTbData
->
maxVersion
;
pMemTable
->
minKey
=
TMIN
(
pMemTable
->
minKey
,
pTbData
->
minKey
)
;
pMemTable
->
maxKey
=
TMAX
(
pMemTable
->
maxKey
,
pTbData
->
maxKey
)
;
pMemTable
->
minVersion
=
TMIN
(
pMemTable
->
minVersion
,
pTbData
->
minVersion
)
;
pMemTable
->
maxVersion
=
TMAX
(
pMemTable
->
maxVersion
,
pTbData
->
maxVersion
)
;
pMemTable
->
nRow
+=
nRow
;
pRsp
->
numOfRows
=
nRow
;
...
...
source/dnode/vnode/src/tsdb/tsdbOpen.c
浏览文件 @
4b33695f
...
...
@@ -41,7 +41,7 @@ int tsdbOpen(SVnode *pVnode, STsdb **ppTsdb, const char *dir, STsdbKeepCfg *pKee
int
slen
=
0
;
*
ppTsdb
=
NULL
;
slen
=
strlen
(
tfsGetPrimaryPath
(
pVnode
->
pTfs
))
+
strlen
(
pVnode
->
path
)
+
strlen
(
dir
)
+
3
;
slen
=
strlen
(
pVnode
->
path
)
+
strlen
(
dir
)
+
2
;
// create handle
pTsdb
=
(
STsdb
*
)
taosMemoryCalloc
(
1
,
sizeof
(
*
pTsdb
)
+
slen
);
...
...
@@ -50,10 +50,8 @@ int tsdbOpen(SVnode *pVnode, STsdb **ppTsdb, const char *dir, STsdbKeepCfg *pKee
return
-
1
;
}
ASSERT
(
strlen
(
dir
)
<
TSDB_DATA_DIR_LEN
);
memcpy
(
pTsdb
->
dir
,
dir
,
strlen
(
dir
));
pTsdb
->
path
=
(
char
*
)
&
pTsdb
[
1
];
sprintf
(
pTsdb
->
path
,
"%s%s%s
%s%s"
,
tfsGetPrimaryPath
(
pVnode
->
pTfs
),
TD_DIRSEP
,
pVnode
->
path
,
TD_DIRSEP
,
dir
);
sprintf
(
pTsdb
->
path
,
"%s%s%s
"
,
pVnode
->
path
,
TD_DIRSEP
,
dir
);
taosRealPath
(
pTsdb
->
path
,
NULL
,
slen
);
pTsdb
->
pVnode
=
pVnode
;
pTsdb
->
repoLocked
=
false
;
...
...
@@ -65,8 +63,8 @@ int tsdbOpen(SVnode *pVnode, STsdb **ppTsdb, const char *dir, STsdbKeepCfg *pKee
}
// pTsdb->fs = tsdbNewFS(REPO_KEEP_CFG(pTsdb));
// create dir
(TODO: use tfsMkdir)
t
aosMkDir
(
pTsdb
->
path
);
// create dir
t
fsMkdir
(
pVnode
->
pTfs
,
pTsdb
->
path
);
// open tsdb
if
(
tsdbFSOpen
(
pTsdb
,
&
pTsdb
->
fs
)
<
0
)
{
...
...
source/dnode/vnode/src/tsdb/tsdbReaderWriter.c
浏览文件 @
4b33695f
...
...
@@ -15,7 +15,6 @@
#include "tsdb.h"
#define TSDB_FHDR_SIZE 512
#define TSDB_FILE_DLMT ((uint32_t)0xF00AFA0F)
// SDelFWriter ====================================================
...
...
@@ -443,8 +442,8 @@ _err:
int32_t
tsdbReadBlockIdx
(
SDataFReader
*
pReader
,
SMapData
*
mBlockIdx
,
uint8_t
**
ppBuf
)
{
int32_t
code
=
0
;
int64_t
offset
=
pReader
->
pSet
->
pHeadFile
->
offset
;
int64_t
size
=
pReader
->
pSet
->
pHeadFile
->
size
;
int64_t
offset
=
pReader
->
pSet
->
fHead
.
offset
;
int64_t
size
=
pReader
->
pSet
->
fHead
.
size
-
offset
;
int64_t
n
;
uint32_t
delimiter
;
...
...
@@ -629,10 +628,10 @@ int32_t tsdbUpdateDFileSetHeader(SDataFWriter *pWriter, uint8_t **ppBuf) {
int64_t
size
=
TSDB_FHDR_SIZE
;
int64_t
n
;
uint8_t
*
pBuf
=
NULL
;
SHeadFile
*
pHeadFile
=
pWriter
->
pSet
->
pHeadFile
;
SDataFile
*
pDataFile
=
pWriter
->
pSet
->
pDataFile
;
SLastFile
*
pLastFile
=
pWriter
->
pSet
->
pLastFile
;
SSmaFile
*
pSmaFile
=
pWriter
->
pSet
->
pSmaFile
;
SHeadFile
*
pHeadFile
=
&
pWriter
->
pSet
->
fHead
;
SDataFile
*
pDataFile
=
&
pWriter
->
pSet
->
fData
;
SLastFile
*
pLastFile
=
&
pWriter
->
pSet
->
fLast
;
SSmaFile
*
pSmaFile
=
&
pWriter
->
pSet
->
fSma
;
// alloc
if
(
!
ppBuf
)
ppBuf
=
&
pBuf
;
...
...
@@ -724,7 +723,7 @@ _err:
int32_t
tsdbWriteBlockIdx
(
SDataFWriter
*
pWriter
,
SMapData
*
mBlockIdx
,
uint8_t
**
ppBuf
)
{
int32_t
code
=
0
;
int64_t
size
=
0
;
SHeadFile
*
pHeadFile
=
pWriter
->
pSet
->
pHeadFile
;
SHeadFile
*
pHeadFile
=
&
pWriter
->
pSet
->
fHead
;
int64_t
n
=
0
;
uint8_t
*
pBuf
=
NULL
;
...
...
@@ -766,7 +765,7 @@ _err:
int32_t
tsdbWriteBlock
(
SDataFWriter
*
pWriter
,
SMapData
*
mBlock
,
uint8_t
**
ppBuf
,
SBlockIdx
*
pBlockIdx
)
{
int32_t
code
=
0
;
SHeadFile
*
pHeadFile
=
pWriter
->
pSet
->
pHeadFile
;
SHeadFile
*
pHeadFile
=
&
pWriter
->
pSet
->
fHead
;
uint8_t
*
pBuf
=
NULL
;
int64_t
size
;
int64_t
n
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录