Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
0e7cfbb0
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看板
未验证
提交
0e7cfbb0
编写于
7月 22, 2020
作者:
S
Shengliang Guan
提交者:
GitHub
7月 22, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #2728 from taosdata/feature/2.0tsdb
Feature/2.0tsdb
上级
dd703941
946f6cb8
变更
9
展开全部
隐藏空白更改
内联
并排
Showing
9 changed file
with
422 addition
and
270 deletion
+422
-270
src/common/src/tdataformat.c
src/common/src/tdataformat.c
+1
-1
src/tsdb/inc/tsdbMain.h
src/tsdb/inc/tsdbMain.h
+43
-17
src/tsdb/src/tsdbFile.c
src/tsdb/src/tsdbFile.c
+19
-12
src/tsdb/src/tsdbMain.c
src/tsdb/src/tsdbMain.c
+17
-14
src/tsdb/src/tsdbMemTable.c
src/tsdb/src/tsdbMemTable.c
+6
-3
src/tsdb/src/tsdbRWHelper.c
src/tsdb/src/tsdbRWHelper.c
+300
-209
src/tsdb/src/tsdbRead.c
src/tsdb/src/tsdbRead.c
+21
-9
src/util/inc/tkvstore.h
src/util/inc/tkvstore.h
+7
-4
src/util/src/tkvstore.c
src/util/src/tkvstore.c
+8
-1
未找到文件。
src/common/src/tdataformat.c
浏览文件 @
0e7cfbb0
...
...
@@ -318,7 +318,7 @@ SDataCols *tdNewDataCols(int maxRowSize, int maxCols, int maxRows) {
pCols
->
maxPoints
=
maxRows
;
pCols
->
bufSize
=
maxRowSize
*
maxRows
;
pCols
->
buf
=
calloc
(
1
,
pCols
->
bufSize
);
pCols
->
buf
=
malloc
(
pCols
->
bufSize
);
if
(
pCols
->
buf
==
NULL
)
{
free
(
pCols
);
return
NULL
;
...
...
src/tsdb/inc/tsdbMain.h
浏览文件 @
0e7cfbb0
...
...
@@ -42,6 +42,7 @@ extern int tsdbDebugFlag;
#define TSDB_MAX_TABLE_SCHEMAS 16
#define TSDB_FILE_HEAD_SIZE 512
#define TSDB_FILE_DELIMITER 0xF00AFA0F
#define TSDB_FILE_INIT_MAGIC 0xFFFFFFFF
// Definitions
// ------------------ tsdbMeta.c
...
...
@@ -132,21 +133,30 @@ typedef struct {
// ------------------ tsdbFile.c
extern
const
char
*
tsdbFileSuffix
[];
typedef
enum
{
#ifdef TSDB_IDX
TSDB_FILE_TYPE_IDX
=
0
,
TSDB_FILE_TYPE_HEAD
,
#else
TSDB_FILE_TYPE_HEAD
=
0
,
#endif
TSDB_FILE_TYPE_DATA
,
TSDB_FILE_TYPE_LAST
,
TSDB_FILE_TYPE_MAX
,
#ifdef TSDB_IDX
TSDB_FILE_TYPE_NIDX
,
#endif
TSDB_FILE_TYPE_NHEAD
,
TSDB_FILE_TYPE_NLAST
}
TSDB_FILE_TYPE
;
typedef
struct
{
uint32_t
offset
;
uint32_t
magic
;
uint32_t
len
;
uint64_t
size
;
// total size of the file
uint64_t
tombSize
;
// unused file size
uint32_t
totalBlocks
;
uint32_t
totalSubBlocks
;
uint32_t
offset
;
uint64_t
size
;
// total size of the file
uint64_t
tombSize
;
// unused file size
}
STsdbFileInfo
;
typedef
struct
{
...
...
@@ -197,6 +207,7 @@ typedef struct {
// ------------------ tsdbRWHelper.c
typedef
struct
{
int32_t
tid
;
uint32_t
len
;
uint32_t
offset
;
uint32_t
hasLast
:
2
;
...
...
@@ -220,7 +231,7 @@ typedef struct {
typedef
struct
{
int32_t
delimiter
;
// For recovery usage
int32_t
checksum
;
// TODO: decide if checksum logic in this file or make it one API
int32_t
tid
;
uint64_t
uid
;
SCompBlock
blocks
[];
}
SCompInfo
;
...
...
@@ -249,24 +260,27 @@ typedef struct {
typedef
enum
{
TSDB_WRITE_HELPER
,
TSDB_READ_HELPER
}
tsdb_rw_helper_t
;
typedef
struct
{
int
fid
;
TSKEY
minKey
;
TSKEY
maxKey
;
// For read/write purpose
SFile
headF
;
SFile
dataF
;
SFile
lastF
;
// For write purpose only
SFile
nHeadF
;
SFile
nLastF
;
TSKEY
minKey
;
TSKEY
maxKey
;
SFileGroup
fGroup
;
#ifdef TSDB_IDX
SFile
nIdxF
;
#endif
SFile
nHeadF
;
SFile
nLastF
;
}
SHelperFile
;
typedef
struct
{
uint64_t
uid
;
int32_t
tid
;
int32_t
sversion
;
}
SHelperTable
;
typedef
struct
{
SCompIdx
*
pIdxArray
;
int
numOfIdx
;
int
curIdx
;
}
SIdxH
;
typedef
struct
{
tsdb_rw_helper_t
type
;
...
...
@@ -274,7 +288,9 @@ typedef struct {
int8_t
state
;
// For file set usage
SHelperFile
files
;
SCompIdx
*
pCompIdx
;
SIdxH
idxH
;
SCompIdx
curCompIdx
;
void
*
pWIdx
;
// For table set usage
SHelperTable
tableInfo
;
SCompInfo
*
pCompInfo
;
...
...
@@ -286,7 +302,6 @@ typedef struct {
void
*
compBuffer
;
// Buffer for temperary compress/decompress purpose
}
SRWHelper
;
// Operations
// ------------------ tsdbMeta.c
#define TABLE_TYPE(t) (t)->type
...
...
@@ -296,6 +311,7 @@ typedef struct {
#define TABLE_TID(t) (t)->tableId.tid
#define TABLE_SUID(t) (t)->suid
#define TABLE_LASTKEY(t) (t)->lastKey
#define TSDB_META_FILE_MAGIC(m) KVSTORE_MAGIC((m)->pStore)
STsdbMeta
*
tsdbNewMeta
(
STsdbCfg
*
pCfg
);
void
tsdbFreeMeta
(
STsdbMeta
*
pMeta
);
...
...
@@ -445,6 +461,16 @@ void tsdbGetFidKeyRange(int daysPerFile, int8_t precision, int fileId, TS
#define helperRepo(h) (h)->pRepo
#define helperState(h) (h)->state
#define TSDB_NLAST_FILE_OPENED(h) ((h)->files.nLastF.fd > 0)
#define helperFileId(h) ((h)->files.fGroup.fileId)
#ifdef TSDB_IDX
#define helperIdxF(h) (&((h)->files.fGroup.files[TSDB_FILE_TYPE_IDX]))
#define helperNewIdxF(h) (&((h)->files.nIdxF))
#endif
#define helperHeadF(h) (&((h)->files.fGroup.files[TSDB_FILE_TYPE_HEAD]))
#define helperDataF(h) (&((h)->files.fGroup.files[TSDB_FILE_TYPE_DATA]))
#define helperLastF(h) (&((h)->files.fGroup.files[TSDB_FILE_TYPE_LAST]))
#define helperNewHeadF(h) (&((h)->files.nHeadF))
#define helperNewLastF(h) (&((h)->files.nLastF))
int
tsdbInitReadHelper
(
SRWHelper
*
pHelper
,
STsdbRepo
*
pRepo
);
int
tsdbInitWriteHelper
(
SRWHelper
*
pHelper
,
STsdbRepo
*
pRepo
);
...
...
src/tsdb/src/tsdbFile.c
浏览文件 @
0e7cfbb0
...
...
@@ -30,7 +30,11 @@
#include "ttime.h"
#include "tfile.h"
#ifdef TSDB_IDX
const
char
*
tsdbFileSuffix
[]
=
{
".idx"
,
".head"
,
".data"
,
".last"
,
""
,
".i"
,
".h"
,
".l"
};
#else
const
char
*
tsdbFileSuffix
[]
=
{
".head"
,
".data"
,
".last"
,
""
,
".h"
,
".l"
};
#endif
static
int
tsdbInitFile
(
SFile
*
pFile
,
STsdbRepo
*
pRepo
,
int
fid
,
int
type
);
static
void
tsdbDestroyFile
(
SFile
*
pFile
);
...
...
@@ -108,7 +112,7 @@ int tsdbOpenFileH(STsdbRepo *pRepo) {
memset
((
void
*
)(
&
fileGroup
),
0
,
sizeof
(
SFileGroup
));
fileGroup
.
fileId
=
fid
;
for
(
int
type
=
TSDB_FILE_TYPE_HEAD
;
type
<
TSDB_FILE_TYPE_MAX
;
type
++
)
{
for
(
int
type
=
0
;
type
<
TSDB_FILE_TYPE_MAX
;
type
++
)
{
if
(
tsdbInitFile
(
&
fileGroup
.
files
[
type
],
pRepo
,
fid
,
type
)
<
0
)
{
tsdbError
(
"vgId:%d failed to init file fid %d type %d"
,
REPO_ID
(
pRepo
),
fid
,
type
);
goto
_err
;
...
...
@@ -126,7 +130,7 @@ int tsdbOpenFileH(STsdbRepo *pRepo) {
return
0
;
_err:
for
(
int
type
=
TSDB_FILE_TYPE_HEAD
;
type
<
TSDB_FILE_TYPE_MAX
;
type
++
)
tsdbDestroyFile
(
&
fileGroup
.
files
[
type
]);
for
(
int
type
=
0
;
type
<
TSDB_FILE_TYPE_MAX
;
type
++
)
tsdbDestroyFile
(
&
fileGroup
.
files
[
type
]);
tfree
(
tDataDir
);
if
(
dir
!=
NULL
)
closedir
(
dir
);
...
...
@@ -139,7 +143,7 @@ void tsdbCloseFileH(STsdbRepo *pRepo) {
for
(
int
i
=
0
;
i
<
pFileH
->
nFGroups
;
i
++
)
{
SFileGroup
*
pFGroup
=
pFileH
->
pFGroup
+
i
;
for
(
int
type
=
TSDB_FILE_TYPE_HEAD
;
type
<
TSDB_FILE_TYPE_MAX
;
type
++
)
{
for
(
int
type
=
0
;
type
<
TSDB_FILE_TYPE_MAX
;
type
++
)
{
tsdbDestroyFile
(
&
pFGroup
->
files
[
type
]);
}
}
...
...
@@ -156,7 +160,7 @@ SFileGroup *tsdbCreateFGroupIfNeed(STsdbRepo *pRepo, char *dataDir, int fid, int
SFileGroup
*
pGroup
=
tsdbSearchFGroup
(
pFileH
,
fid
,
TD_EQ
);
if
(
pGroup
==
NULL
)
{
// if not exists, create one
pFGroup
->
fileId
=
fid
;
for
(
int
type
=
TSDB_FILE_TYPE_HEAD
;
type
<
TSDB_FILE_TYPE_MAX
;
type
++
)
{
for
(
int
type
=
0
;
type
<
TSDB_FILE_TYPE_MAX
;
type
++
)
{
if
(
tsdbCreateFile
(
&
pFGroup
->
files
[
type
],
pRepo
,
fid
,
type
)
<
0
)
goto
_err
;
}
...
...
@@ -169,7 +173,7 @@ SFileGroup *tsdbCreateFGroupIfNeed(STsdbRepo *pRepo, char *dataDir, int fid, int
return
pGroup
;
_err:
for
(
int
type
=
TSDB_FILE_TYPE_HEAD
;
type
<
TSDB_FILE_TYPE_MAX
;
type
++
)
tsdbDestroyFile
(
&
pGroup
->
files
[
type
]);
for
(
int
type
=
0
;
type
<
TSDB_FILE_TYPE_MAX
;
type
++
)
tsdbDestroyFile
(
&
pGroup
->
files
[
type
]);
return
NULL
;
}
...
...
@@ -260,6 +264,7 @@ int tsdbCreateFile(SFile *pFile, STsdbRepo *pRepo, int fid, int type) {
}
pFile
->
info
.
size
=
TSDB_FILE_HEAD_SIZE
;
pFile
->
info
.
magic
=
TSDB_FILE_INIT_MAGIC
;
if
(
tsdbUpdateFileHeader
(
pFile
,
0
)
<
0
)
{
tsdbCloseFile
(
pFile
);
...
...
@@ -323,23 +328,25 @@ int tsdbUpdateFileHeader(SFile *pFile, uint32_t version) {
int
tsdbEncodeSFileInfo
(
void
**
buf
,
const
STsdbFileInfo
*
pInfo
)
{
int
tlen
=
0
;
tlen
+=
taosEncodeFixedU32
(
buf
,
pInfo
->
offset
);
tlen
+=
taosEncodeFixedU32
(
buf
,
pInfo
->
magic
);
tlen
+=
taosEncodeFixedU32
(
buf
,
pInfo
->
len
);
tlen
+=
taosEncodeFixedU64
(
buf
,
pInfo
->
size
);
tlen
+=
taosEncodeFixedU64
(
buf
,
pInfo
->
tombSize
);
tlen
+=
taosEncodeFixedU32
(
buf
,
pInfo
->
totalBlocks
);
tlen
+=
taosEncodeFixedU32
(
buf
,
pInfo
->
totalSubBlocks
);
tlen
+=
taosEncodeFixedU32
(
buf
,
pInfo
->
offset
);
tlen
+=
taosEncodeFixedU64
(
buf
,
pInfo
->
size
);
tlen
+=
taosEncodeFixedU64
(
buf
,
pInfo
->
tombSize
);
return
tlen
;
}
void
*
tsdbDecodeSFileInfo
(
void
*
buf
,
STsdbFileInfo
*
pInfo
)
{
buf
=
taosDecodeFixedU32
(
buf
,
&
(
pInfo
->
offset
));
buf
=
taosDecodeFixedU32
(
buf
,
&
(
pInfo
->
magic
));
buf
=
taosDecodeFixedU32
(
buf
,
&
(
pInfo
->
len
));
buf
=
taosDecodeFixedU64
(
buf
,
&
(
pInfo
->
size
));
buf
=
taosDecodeFixedU64
(
buf
,
&
(
pInfo
->
tombSize
));
buf
=
taosDecodeFixedU32
(
buf
,
&
(
pInfo
->
totalBlocks
));
buf
=
taosDecodeFixedU32
(
buf
,
&
(
pInfo
->
totalSubBlocks
));
buf
=
taosDecodeFixedU32
(
buf
,
&
(
pInfo
->
offset
));
buf
=
taosDecodeFixedU64
(
buf
,
&
(
pInfo
->
size
));
buf
=
taosDecodeFixedU64
(
buf
,
&
(
pInfo
->
tombSize
));
return
buf
;
}
...
...
@@ -358,7 +365,7 @@ void tsdbRemoveFileGroup(STsdbRepo *pRepo, SFileGroup *pFGroup) {
pFileH
->
nFGroups
--
;
ASSERT
(
pFileH
->
nFGroups
>=
0
);
for
(
int
type
=
TSDB_FILE_TYPE_HEAD
;
type
<
TSDB_FILE_TYPE_MAX
;
type
++
)
{
for
(
int
type
=
0
;
type
<
TSDB_FILE_TYPE_MAX
;
type
++
)
{
if
(
remove
(
fileGroup
.
files
[
type
].
fname
)
<
0
)
{
tsdbError
(
"vgId:%d failed to remove file %s"
,
REPO_ID
(
pRepo
),
fileGroup
.
files
[
type
].
fname
);
}
...
...
src/tsdb/src/tsdbMain.c
浏览文件 @
0e7cfbb0
...
...
@@ -212,59 +212,61 @@ uint32_t tsdbGetFileInfo(TSDB_REPO_T *repo, char *name, uint32_t *index, uint32_
char
*
sdup
=
strdup
(
pRepo
->
rootDir
);
char
*
prefix
=
dirname
(
sdup
);
int
prefixLen
=
strlen
(
prefix
);
tfree
(
sdup
);
if
(
name
[
0
]
==
0
)
{
// get the file from index or after, but not larger than eindex
int
fid
=
(
*
index
)
/
3
;
int
fid
=
(
*
index
)
/
TSDB_FILE_TYPE_MAX
;
if
(
pFileH
->
nFGroups
==
0
||
fid
>
pFileH
->
pFGroup
[
pFileH
->
nFGroups
-
1
].
fileId
)
{
if
(
*
index
<=
TSDB_META_FILE_INDEX
&&
TSDB_META_FILE_INDEX
<=
eindex
)
{
fname
=
tsdbGetMetaFileName
(
pRepo
->
rootDir
);
*
index
=
TSDB_META_FILE_INDEX
;
magic
=
TSDB_META_FILE_MAGIC
(
pRepo
->
tsdbMeta
);
}
else
{
tfree
(
sdup
);
return
0
;
}
}
else
{
SFileGroup
*
pFGroup
=
taosbsearch
(
&
fid
,
pFileH
->
pFGroup
,
pFileH
->
nFGroups
,
sizeof
(
SFileGroup
),
keyFGroupCompFunc
,
TD_GE
);
if
(
pFGroup
->
fileId
==
fid
)
{
fname
=
strdup
(
pFGroup
->
files
[(
*
index
)
%
3
].
fname
);
fname
=
strdup
(
pFGroup
->
files
[(
*
index
)
%
TSDB_FILE_TYPE_MAX
].
fname
);
magic
=
pFGroup
->
files
[(
*
index
)
%
TSDB_FILE_TYPE_MAX
].
info
.
magic
;
}
else
{
if
(
pFGroup
->
fileId
*
3
+
2
<
eindex
)
{
if
(
(
pFGroup
->
fileId
+
1
)
*
TSDB_FILE_TYPE_MAX
-
1
<
eindex
)
{
fname
=
strdup
(
pFGroup
->
files
[
0
].
fname
);
*
index
=
pFGroup
->
fileId
*
3
;
*
index
=
pFGroup
->
fileId
*
TSDB_FILE_TYPE_MAX
;
magic
=
pFGroup
->
files
[
0
].
info
.
magic
;
}
else
{
tfree
(
sdup
);
return
0
;
}
}
}
strcpy
(
name
,
fname
+
strlen
(
prefix
)
);
strcpy
(
name
,
fname
+
prefixLen
);
}
else
{
// get the named file at the specified index. If not there, return 0
if
(
*
index
==
TSDB_META_FILE_INDEX
)
{
// get meta file
fname
=
tsdbGetMetaFileName
(
pRepo
->
rootDir
);
magic
=
TSDB_META_FILE_MAGIC
(
pRepo
->
tsdbMeta
);
}
else
{
int
fid
=
(
*
index
)
/
3
;
int
fid
=
(
*
index
)
/
TSDB_FILE_TYPE_MAX
;
SFileGroup
*
pFGroup
=
tsdbSearchFGroup
(
pFileH
,
fid
,
TD_EQ
);
if
(
pFGroup
==
NULL
)
{
// not found
tfree
(
sdup
);
return
0
;
}
SFile
*
pFile
=
&
pFGroup
->
files
[(
*
index
)
%
3
];
SFile
*
pFile
=
&
pFGroup
->
files
[(
*
index
)
%
TSDB_FILE_TYPE_MAX
];
fname
=
strdup
(
pFile
->
fname
);
magic
=
pFile
->
info
.
magic
;
}
}
if
(
stat
(
fname
,
&
fState
)
<
0
)
{
tfree
(
sdup
);
tfree
(
fname
);
return
0
;
}
tfree
(
sdup
);
*
size
=
fState
.
st_size
;
magic
=
*
size
;
//
magic = *size;
tfree
(
fname
);
return
magic
;
...
...
@@ -793,7 +795,8 @@ static int tsdbRestoreInfo(STsdbRepo *pRepo) {
for
(
int
i
=
1
;
i
<
pRepo
->
config
.
maxTables
;
i
++
)
{
STable
*
pTable
=
pMeta
->
tables
[
i
];
if
(
pTable
==
NULL
)
continue
;
SCompIdx
*
pIdx
=
&
rhelper
.
pCompIdx
[
i
];
tsdbSetHelperTable
(
&
rhelper
,
pTable
,
pRepo
);
SCompIdx
*
pIdx
=
&
(
rhelper
.
curCompIdx
);
if
(
pIdx
->
offset
>
0
&&
pTable
->
lastKey
<
pIdx
->
maxKey
)
pTable
->
lastKey
=
pIdx
->
maxKey
;
}
...
...
src/tsdb/src/tsdbMemTable.c
浏览文件 @
0e7cfbb0
...
...
@@ -627,9 +627,12 @@ static int tsdbCommitToFile(STsdbRepo *pRepo, int fid, SCommitIter *iters, SRWHe
tsdbCloseHelperFile
(
pHelper
,
0
);
pthread_rwlock_wrlock
(
&
(
pFileH
->
fhlock
));
pGroup
->
files
[
TSDB_FILE_TYPE_HEAD
]
=
pHelper
->
files
.
headF
;
pGroup
->
files
[
TSDB_FILE_TYPE_DATA
]
=
pHelper
->
files
.
dataF
;
pGroup
->
files
[
TSDB_FILE_TYPE_LAST
]
=
pHelper
->
files
.
lastF
;
#ifdef TSDB_IDX
pGroup
->
files
[
TSDB_FILE_TYPE_IDX
]
=
*
(
helperIdxF
(
pHelper
));
#endif
pGroup
->
files
[
TSDB_FILE_TYPE_HEAD
]
=
*
(
helperHeadF
(
pHelper
));
pGroup
->
files
[
TSDB_FILE_TYPE_DATA
]
=
*
(
helperDataF
(
pHelper
));
pGroup
->
files
[
TSDB_FILE_TYPE_LAST
]
=
*
(
helperLastF
(
pHelper
));
pthread_rwlock_unlock
(
&
(
pFileH
->
fhlock
));
return
0
;
...
...
src/tsdb/src/tsdbRWHelper.c
浏览文件 @
0e7cfbb0
此差异已折叠。
点击以展开。
src/tsdb/src/tsdbRead.c
浏览文件 @
0e7cfbb0
...
...
@@ -126,12 +126,13 @@ typedef struct STsdbQueryHandle {
SIOCostSummary
cost
;
}
STsdbQueryHandle
;
static
void
changeQueryHandleForLastrowQuery
(
TsdbQueryHandleT
pqHandle
);
static
void
changeQueryHandleForInterpQuery
(
TsdbQueryHandleT
pHandle
);
static
void
doMergeTwoLevelData
(
STsdbQueryHandle
*
pQueryHandle
,
STableCheckInfo
*
pCheckInfo
,
SCompBlock
*
pBlock
);
static
void
changeQueryHandleForLastrowQuery
(
TsdbQueryHandleT
pqHandle
);
static
void
changeQueryHandleForInterpQuery
(
TsdbQueryHandleT
pHandle
);
static
void
doMergeTwoLevelData
(
STsdbQueryHandle
*
pQueryHandle
,
STableCheckInfo
*
pCheckInfo
,
SCompBlock
*
pBlock
);
static
int32_t
binarySearchForKey
(
char
*
pValue
,
int
num
,
TSKEY
key
,
int
order
);
static
int
tsdbReadRowsFromCache
(
STableCheckInfo
*
pCheckInfo
,
TSKEY
maxKey
,
int
maxRowsToRead
,
STimeWindow
*
win
,
STsdbQueryHandle
*
pQueryHandle
);
static
int
tsdbReadRowsFromCache
(
STableCheckInfo
*
pCheckInfo
,
TSKEY
maxKey
,
int
maxRowsToRead
,
STimeWindow
*
win
,
STsdbQueryHandle
*
pQueryHandle
);
static
int
tsdbCheckInfoCompar
(
const
void
*
key1
,
const
void
*
key2
);
static
void
tsdbInitDataBlockLoadInfo
(
SDataBlockLoadInfo
*
pBlockLoadInfo
)
{
pBlockLoadInfo
->
slot
=
-
1
;
...
...
@@ -236,7 +237,8 @@ TsdbQueryHandleT* tsdbQueryTables(TSDB_REPO_T* tsdb, STsdbQueryCond* pCond, STab
taosArrayPush
(
pQueryHandle
->
pTableCheckInfo
,
&
info
);
}
}
taosArraySort
(
pQueryHandle
->
pTableCheckInfo
,
tsdbCheckInfoCompar
);
pQueryHandle
->
defaultLoadColumn
=
getDefaultLoadColumns
(
pQueryHandle
,
true
);
tsdbDebug
(
"%p total numOfTable:%zu in query, %p"
,
pQueryHandle
,
taosArrayGetSize
(
pQueryHandle
->
pTableCheckInfo
),
pQueryHandle
->
qinfo
);
...
...
@@ -554,7 +556,9 @@ static int32_t getFileCompInfo(STsdbQueryHandle* pQueryHandle, int32_t* numOfBlo
STableCheckInfo
*
pCheckInfo
=
taosArrayGet
(
pQueryHandle
->
pTableCheckInfo
,
i
);
pCheckInfo
->
numOfBlocks
=
0
;
SCompIdx
*
compIndex
=
&
pQueryHandle
->
rhelper
.
pCompIdx
[
pCheckInfo
->
tableId
.
tid
];
tsdbSetHelperTable
(
&
pQueryHandle
->
rhelper
,
pCheckInfo
->
pTableObj
,
pQueryHandle
->
pTsdb
);
SCompIdx
*
compIndex
=
&
pQueryHandle
->
rhelper
.
curCompIdx
;
// no data block in this file, try next file
if
(
compIndex
->
len
==
0
||
compIndex
->
numOfBlocks
==
0
||
compIndex
->
uid
!=
pCheckInfo
->
tableId
.
uid
)
{
...
...
@@ -571,8 +575,6 @@ static int32_t getFileCompInfo(STsdbQueryHandle* pQueryHandle, int32_t* numOfBlo
pCheckInfo
->
compSize
=
compIndex
->
len
;
}
tsdbSetHelperTable
(
&
pQueryHandle
->
rhelper
,
pCheckInfo
->
pTableObj
,
pQueryHandle
->
pTsdb
);
tsdbLoadCompInfo
(
&
(
pQueryHandle
->
rhelper
),
(
void
*
)(
pCheckInfo
->
pCompInfo
));
SCompInfo
*
pCompInfo
=
pCheckInfo
->
pCompInfo
;
...
...
@@ -2431,3 +2433,13 @@ void tsdbDestroyTableGroup(STableGroupInfo *pGroupList) {
taosArrayDestroy
(
pGroupList
->
pGroupList
);
}
static
int
tsdbCheckInfoCompar
(
const
void
*
key1
,
const
void
*
key2
)
{
if
(((
STableCheckInfo
*
)
key1
)
->
tableId
.
tid
<
((
STableCheckInfo
*
)
key2
)
->
tableId
.
tid
)
{
return
-
1
;
}
else
if
(((
STableCheckInfo
*
)
key1
)
->
tableId
.
tid
>
((
STableCheckInfo
*
)
key2
)
->
tableId
.
tid
)
{
return
1
;
}
else
{
ASSERT
(
false
);
return
0
;
}
}
\ No newline at end of file
src/util/inc/tkvstore.h
浏览文件 @
0e7cfbb0
...
...
@@ -25,10 +25,11 @@ typedef int (*iterFunc)(void *, void *cont, int contLen);
typedef
void
(
*
afterFunc
)(
void
*
);
typedef
struct
{
int64_t
size
;
// including 512 bytes of header size
int64_t
tombSize
;
int64_t
nRecords
;
int64_t
nDels
;
int64_t
size
;
// including 512 bytes of header size
int64_t
tombSize
;
int64_t
nRecords
;
int64_t
nDels
;
uint32_t
magic
;
}
SStoreInfo
;
typedef
struct
{
...
...
@@ -45,6 +46,8 @@ typedef struct {
SStoreInfo
info
;
}
SKVStore
;
#define KVSTORE_MAGIC(s) (s)->info.magic
int
tdCreateKVStore
(
char
*
fname
);
int
tdDestroyKVStore
(
char
*
fname
);
SKVStore
*
tdOpenKVStore
(
char
*
fname
,
iterFunc
iFunc
,
afterFunc
aFunc
,
void
*
appH
);
...
...
src/util/src/tkvstore.c
浏览文件 @
0e7cfbb0
...
...
@@ -34,6 +34,7 @@
#define TD_KVSTORE_MAINOR_VERSION 0
#define TD_KVSTORE_SNAP_SUFFIX ".snap"
#define TD_KVSTORE_NEW_SUFFIX ".new"
#define TD_KVSTORE_INIT_MAGIC 0xFFFFFFFF
typedef
struct
{
uint64_t
uid
;
...
...
@@ -140,6 +141,7 @@ SKVStore *tdOpenKVStore(char *fname, iterFunc iFunc, afterFunc aFunc, void *appH
if
(
tdLoadKVStoreHeader
(
pStore
->
fd
,
pStore
->
fname
,
&
info
)
<
0
)
goto
_err
;
pStore
->
info
.
size
=
TD_KVSTORE_HEADER_SIZE
;
pStore
->
info
.
magic
=
info
.
magic
;
if
(
tdRestoreKVStore
(
pStore
)
<
0
)
goto
_err
;
...
...
@@ -251,6 +253,8 @@ int tdUpdateKVStoreRecord(SKVStore *pStore, uint64_t uid, void *cont, int contLe
return
-
1
;
}
pStore
->
info
.
magic
=
taosCalcChecksum
(
pStore
->
info
.
magic
,
(
uint8_t
*
)
POINTER_SHIFT
(
cont
,
contLen
-
sizeof
(
TSCKSUM
)),
sizeof
(
TSCKSUM
));
pStore
->
info
.
size
+=
(
sizeof
(
SKVRecord
)
+
contLen
);
SKVRecord
*
pRecord
=
taosHashGet
(
pStore
->
map
,
(
void
*
)
&
uid
,
sizeof
(
uid
));
if
(
pRecord
!=
NULL
)
{
// just to insert
...
...
@@ -288,6 +292,7 @@ int tdDropKVStoreRecord(SKVStore *pStore, uint64_t uid) {
return
-
1
;
}
pStore
->
info
.
magic
=
taosCalcChecksum
(
pStore
->
info
.
magic
,
(
uint8_t
*
)
buf
,
POINTER_DISTANCE
(
pBuf
,
buf
));
pStore
->
info
.
size
+=
POINTER_DISTANCE
(
pBuf
,
buf
);
pStore
->
info
.
nDels
++
;
pStore
->
info
.
nRecords
--
;
...
...
@@ -371,7 +376,7 @@ static int tdUpdateKVStoreHeader(int fd, char *fname, SStoreInfo *pInfo) {
}
static
int
tdInitKVStoreHeader
(
int
fd
,
char
*
fname
)
{
SStoreInfo
info
=
{
TD_KVSTORE_HEADER_SIZE
,
0
,
0
,
0
};
SStoreInfo
info
=
{
TD_KVSTORE_HEADER_SIZE
,
0
,
0
,
0
,
TD_KVSTORE_INIT_MAGIC
};
return
tdUpdateKVStoreHeader
(
fd
,
fname
,
&
info
);
}
...
...
@@ -382,6 +387,7 @@ static int tdEncodeStoreInfo(void **buf, SStoreInfo *pInfo) {
tlen
+=
taosEncodeVariantI64
(
buf
,
pInfo
->
tombSize
);
tlen
+=
taosEncodeVariantI64
(
buf
,
pInfo
->
nRecords
);
tlen
+=
taosEncodeVariantI64
(
buf
,
pInfo
->
nDels
);
tlen
+=
taosEncodeFixedU32
(
buf
,
pInfo
->
magic
);
return
tlen
;
}
...
...
@@ -391,6 +397,7 @@ static void *tdDecodeStoreInfo(void *buf, SStoreInfo *pInfo) {
buf
=
taosDecodeVariantI64
(
buf
,
&
(
pInfo
->
tombSize
));
buf
=
taosDecodeVariantI64
(
buf
,
&
(
pInfo
->
nRecords
));
buf
=
taosDecodeVariantI64
(
buf
,
&
(
pInfo
->
nDels
));
buf
=
taosDecodeFixedU32
(
buf
,
&
(
pInfo
->
magic
));
return
buf
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录