Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
055aed43
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看板
提交
055aed43
编写于
5月 18, 2020
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
TD-185
上级
714d8ea9
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
162 addition
and
62 deletion
+162
-62
src/tsdb/inc/tsdbMain.h
src/tsdb/inc/tsdbMain.h
+18
-11
src/tsdb/src/tsdbFile.c
src/tsdb/src/tsdbFile.c
+3
-35
src/tsdb/src/tsdbMain.c
src/tsdb/src/tsdbMain.c
+9
-1
src/tsdb/src/tsdbMeta.c
src/tsdb/src/tsdbMeta.c
+0
-1
src/tsdb/src/tsdbRWHelper.c
src/tsdb/src/tsdbRWHelper.c
+122
-14
src/util/inc/tcoding.h
src/util/inc/tcoding.h
+10
-0
未找到文件。
src/tsdb/inc/tsdbMain.h
浏览文件 @
055aed43
...
@@ -210,12 +210,17 @@ typedef enum {
...
@@ -210,12 +210,17 @@ typedef enum {
extern
const
char
*
tsdbFileSuffix
[];
extern
const
char
*
tsdbFileSuffix
[];
typedef
struct
{
typedef
struct
{
int64_t
size
;
// total size of the file
uint32_t
offset
;
int64_t
tombSize
;
// unused file size
uint32_t
len
;
int32_t
totalBlocks
;
uint64_t
size
;
// total size of the file
int32_t
totalSubBlocks
;
uint64_t
tombSize
;
// unused file size
uint32_t
totalBlocks
;
uint32_t
totalSubBlocks
;
}
SFileInfo
;
}
SFileInfo
;
void
*
tsdbEncodeSFileInfo
(
void
*
buf
,
const
SFileInfo
*
pInfo
);
void
*
tsdbDecodeSFileInfo
(
void
*
buf
,
SFileInfo
*
pInfo
);
typedef
struct
{
typedef
struct
{
int
fd
;
int
fd
;
char
fname
[
128
];
char
fname
[
128
];
...
@@ -242,8 +247,7 @@ typedef struct {
...
@@ -242,8 +247,7 @@ typedef struct {
STsdbFileH
*
tsdbInitFileH
(
char
*
dataDir
,
STsdbCfg
*
pCfg
);
STsdbFileH
*
tsdbInitFileH
(
char
*
dataDir
,
STsdbCfg
*
pCfg
);
void
tsdbCloseFileH
(
STsdbFileH
*
pFileH
);
void
tsdbCloseFileH
(
STsdbFileH
*
pFileH
);
int
tsdbCreateFile
(
char
*
dataDir
,
int
fileId
,
const
char
*
suffix
,
int
maxTables
,
SFile
*
pFile
,
int
writeHeader
,
int
tsdbCreateFile
(
char
*
dataDir
,
int
fileId
,
const
char
*
suffix
,
SFile
*
pFile
);
int
toClose
);
SFileGroup
*
tsdbCreateFGroup
(
STsdbFileH
*
pFileH
,
char
*
dataDir
,
int
fid
,
int
maxTables
);
SFileGroup
*
tsdbCreateFGroup
(
STsdbFileH
*
pFileH
,
char
*
dataDir
,
int
fid
,
int
maxTables
);
int
tsdbOpenFile
(
SFile
*
pFile
,
int
oflag
);
int
tsdbOpenFile
(
SFile
*
pFile
,
int
oflag
);
int
tsdbCloseFile
(
SFile
*
pFile
);
int
tsdbCloseFile
(
SFile
*
pFile
);
...
@@ -266,15 +270,18 @@ void tsdbSeekFileGroupIter(SFileGroupIter *pIter, int fid);
...
@@ -266,15 +270,18 @@ void tsdbSeekFileGroupIter(SFileGroupIter *pIter, int fid);
SFileGroup
*
tsdbGetFileGroupNext
(
SFileGroupIter
*
pIter
);
SFileGroup
*
tsdbGetFileGroupNext
(
SFileGroupIter
*
pIter
);
typedef
struct
{
typedef
struct
{
int32_t
len
;
u
int32_t
len
;
int32_t
offset
;
u
int32_t
offset
;
int32_t
padding
;
// For padding purpose
uint32_t
padding
;
// For padding purpose
int32_t
hasLast
:
1
;
uint32_t
hasLast
:
2
;
int32_t
numOfBlocks
:
31
;
uint32_t
numOfBlocks
:
30
;
int64_t
uid
;
int64_t
uid
;
TSKEY
maxKey
;
TSKEY
maxKey
;
}
SCompIdx
;
/* sizeof(SCompIdx) = 28 */
}
SCompIdx
;
/* sizeof(SCompIdx) = 28 */
void
*
tsdbEncodeSCompIdx
(
void
*
buf
,
SCompIdx
*
pIdx
);
void
*
tsdbDecodeSCompIdx
(
void
*
buf
,
SCompIdx
*
pIdx
);
/**
/**
* if numOfSubBlocks == 0, then the SCompBlock is a sub-block
* if numOfSubBlocks == 0, then the SCompBlock is a sub-block
* if numOfSubBlocks >= 1, then the SCompBlock is a super-block
* if numOfSubBlocks >= 1, then the SCompBlock is a super-block
...
...
src/tsdb/src/tsdbFile.c
浏览文件 @
055aed43
...
@@ -38,7 +38,6 @@ const char *tsdbFileSuffix[] = {
...
@@ -38,7 +38,6 @@ const char *tsdbFileSuffix[] = {
static
int
compFGroupKey
(
const
void
*
key
,
const
void
*
fgroup
);
static
int
compFGroupKey
(
const
void
*
key
,
const
void
*
fgroup
);
static
int
compFGroup
(
const
void
*
arg1
,
const
void
*
arg2
);
static
int
compFGroup
(
const
void
*
arg1
,
const
void
*
arg2
);
static
int
tsdbWriteFileHead
(
SFile
*
pFile
);
static
int
tsdbWriteFileHead
(
SFile
*
pFile
);
static
int
tsdbWriteHeadFileIdx
(
SFile
*
pFile
,
int
maxTables
);
static
int
tsdbOpenFGroup
(
STsdbFileH
*
pFileH
,
char
*
dataDir
,
int
fid
);
static
int
tsdbOpenFGroup
(
STsdbFileH
*
pFileH
,
char
*
dataDir
,
int
fid
);
STsdbFileH
*
tsdbInitFileH
(
char
*
dataDir
,
STsdbCfg
*
pCfg
)
{
STsdbFileH
*
tsdbInitFileH
(
char
*
dataDir
,
STsdbCfg
*
pCfg
)
{
...
@@ -121,8 +120,7 @@ SFileGroup *tsdbCreateFGroup(STsdbFileH *pFileH, char *dataDir, int fid, int max
...
@@ -121,8 +120,7 @@ SFileGroup *tsdbCreateFGroup(STsdbFileH *pFileH, char *dataDir, int fid, int max
if
(
pGroup
==
NULL
)
{
// if not exists, create one
if
(
pGroup
==
NULL
)
{
// if not exists, create one
pFGroup
->
fileId
=
fid
;
pFGroup
->
fileId
=
fid
;
for
(
int
type
=
TSDB_FILE_TYPE_HEAD
;
type
<
TSDB_FILE_TYPE_MAX
;
type
++
)
{
for
(
int
type
=
TSDB_FILE_TYPE_HEAD
;
type
<
TSDB_FILE_TYPE_MAX
;
type
++
)
{
if
(
tsdbCreateFile
(
dataDir
,
fid
,
tsdbFileSuffix
[
type
],
maxTables
,
&
(
pFGroup
->
files
[
type
]),
if
(
tsdbCreateFile
(
dataDir
,
fid
,
tsdbFileSuffix
[
type
],
&
(
pFGroup
->
files
[
type
]))
<
0
)
type
==
TSDB_FILE_TYPE_HEAD
?
1
:
0
,
1
)
<
0
)
goto
_err
;
goto
_err
;
}
}
...
@@ -298,29 +296,6 @@ static int tsdbWriteFileHead(SFile *pFile) {
...
@@ -298,29 +296,6 @@ static int tsdbWriteFileHead(SFile *pFile) {
return
0
;
return
0
;
}
}
static
int
tsdbWriteHeadFileIdx
(
SFile
*
pFile
,
int
maxTables
)
{
int
size
=
sizeof
(
SCompIdx
)
*
maxTables
+
sizeof
(
TSCKSUM
);
void
*
buf
=
calloc
(
1
,
size
);
if
(
buf
==
NULL
)
return
-
1
;
if
(
lseek
(
pFile
->
fd
,
TSDB_FILE_HEAD_SIZE
,
SEEK_SET
)
<
0
)
{
free
(
buf
);
return
-
1
;
}
taosCalcChecksumAppend
(
0
,
(
uint8_t
*
)
buf
,
size
);
if
(
write
(
pFile
->
fd
,
buf
,
size
)
<
0
)
{
free
(
buf
);
return
-
1
;
}
pFile
->
info
.
size
+=
size
;
free
(
buf
);
return
0
;
}
int
tsdbGetFileName
(
char
*
dataDir
,
int
fileId
,
const
char
*
suffix
,
char
*
fname
)
{
int
tsdbGetFileName
(
char
*
dataDir
,
int
fileId
,
const
char
*
suffix
,
char
*
fname
)
{
if
(
dataDir
==
NULL
||
fname
==
NULL
)
return
-
1
;
if
(
dataDir
==
NULL
||
fname
==
NULL
)
return
-
1
;
...
@@ -354,7 +329,7 @@ SFileGroup * tsdbOpenFilesForCommit(STsdbFileH *pFileH, int fid) {
...
@@ -354,7 +329,7 @@ SFileGroup * tsdbOpenFilesForCommit(STsdbFileH *pFileH, int fid) {
return
pGroup
;
return
pGroup
;
}
}
int
tsdbCreateFile
(
char
*
dataDir
,
int
fileId
,
const
char
*
suffix
,
int
maxTables
,
SFile
*
pFile
,
int
writeHeader
,
int
toClos
e
)
{
int
tsdbCreateFile
(
char
*
dataDir
,
int
fileId
,
const
char
*
suffix
,
SFile
*
pFil
e
)
{
memset
((
void
*
)
pFile
,
0
,
sizeof
(
SFile
));
memset
((
void
*
)
pFile
,
0
,
sizeof
(
SFile
));
pFile
->
fd
=
-
1
;
pFile
->
fd
=
-
1
;
...
@@ -370,19 +345,12 @@ int tsdbCreateFile(char *dataDir, int fileId, const char *suffix, int maxTables,
...
@@ -370,19 +345,12 @@ int tsdbCreateFile(char *dataDir, int fileId, const char *suffix, int maxTables,
return
-
1
;
return
-
1
;
}
}
if
(
writeHeader
)
{
if
(
tsdbWriteHeadFileIdx
(
pFile
,
maxTables
)
<
0
)
{
tsdbCloseFile
(
pFile
);
return
-
1
;
}
}
if
(
tsdbWriteFileHead
(
pFile
)
<
0
)
{
if
(
tsdbWriteFileHead
(
pFile
)
<
0
)
{
tsdbCloseFile
(
pFile
);
tsdbCloseFile
(
pFile
);
return
-
1
;
return
-
1
;
}
}
if
(
toClose
)
tsdbCloseFile
(
pFile
);
tsdbCloseFile
(
pFile
);
return
0
;
return
0
;
}
}
...
...
src/tsdb/src/tsdbMain.c
浏览文件 @
055aed43
...
@@ -1148,8 +1148,16 @@ static void tsdbAlterKeep(STsdbRepo *pRepo, int32_t keep) {
...
@@ -1148,8 +1148,16 @@ static void tsdbAlterKeep(STsdbRepo *pRepo, int32_t keep) {
}
}
static
void
tsdbAlterMaxTables
(
STsdbRepo
*
pRepo
,
int32_t
maxTables
)
{
static
void
tsdbAlterMaxTables
(
STsdbRepo
*
pRepo
,
int32_t
maxTables
)
{
// TODO
int
oldMaxTables
=
pRepo
->
config
.
maxTables
;
int
oldMaxTables
=
pRepo
->
config
.
maxTables
;
if
(
oldMaxTables
<
pRepo
->
config
.
maxTables
)
{
// TODO
}
STsdbMeta
*
pMeta
=
pRepo
->
tsdbMeta
;
pMeta
->
maxTables
=
maxTables
;
pMeta
->
tables
=
realloc
(
pMeta
->
tables
,
maxTables
*
sizeof
(
STable
*
));
tsdbTrace
(
"vgId:%d, tsdb maxTables is changed from %d to %d!"
,
pRepo
->
config
.
tsdbId
,
oldMaxTables
,
maxTables
);
tsdbTrace
(
"vgId:%d, tsdb maxTables is changed from %d to %d!"
,
pRepo
->
config
.
tsdbId
,
oldMaxTables
,
maxTables
);
}
}
...
...
src/tsdb/src/tsdbMeta.c
浏览文件 @
055aed43
...
@@ -154,7 +154,6 @@ STsdbMeta *tsdbInitMeta(char *rootDir, int32_t maxTables) {
...
@@ -154,7 +154,6 @@ STsdbMeta *tsdbInitMeta(char *rootDir, int32_t maxTables) {
STsdbMeta
*
pMeta
=
(
STsdbMeta
*
)
malloc
(
sizeof
(
STsdbMeta
));
STsdbMeta
*
pMeta
=
(
STsdbMeta
*
)
malloc
(
sizeof
(
STsdbMeta
));
if
(
pMeta
==
NULL
)
return
NULL
;
if
(
pMeta
==
NULL
)
return
NULL
;
pMeta
->
maxTables
=
maxTables
;
pMeta
->
nTables
=
0
;
pMeta
->
nTables
=
0
;
pMeta
->
superList
=
NULL
;
pMeta
->
superList
=
NULL
;
pMeta
->
tables
=
(
STable
**
)
calloc
(
maxTables
,
sizeof
(
STable
*
));
pMeta
->
tables
=
(
STable
**
)
calloc
(
maxTables
,
sizeof
(
STable
*
));
...
...
src/tsdb/src/tsdbRWHelper.c
浏览文件 @
055aed43
...
@@ -18,6 +18,7 @@
...
@@ -18,6 +18,7 @@
#include "tchecksum.h"
#include "tchecksum.h"
#include "tscompression.h"
#include "tscompression.h"
#include "talgo.h"
#include "talgo.h"
#include "tcoding.h"
// Local function definitions
// Local function definitions
// static int tsdbCheckHelperCfg(SHelperCfg *pCfg);
// static int tsdbCheckHelperCfg(SHelperCfg *pCfg);
...
@@ -211,13 +212,15 @@ int tsdbSetAndOpenHelperFile(SRWHelper *pHelper, SFileGroup *pGroup) {
...
@@ -211,13 +212,15 @@ int tsdbSetAndOpenHelperFile(SRWHelper *pHelper, SFileGroup *pGroup) {
// Create and open .h
// Create and open .h
if
(
tsdbOpenFile
(
&
(
pHelper
->
files
.
nHeadF
),
O_WRONLY
|
O_CREAT
)
<
0
)
return
-
1
;
if
(
tsdbOpenFile
(
&
(
pHelper
->
files
.
nHeadF
),
O_WRONLY
|
O_CREAT
)
<
0
)
return
-
1
;
size_t
tsize
=
TSDB_FILE_HEAD_SIZE
+
sizeof
(
SCompIdx
)
*
pHelper
->
config
.
maxTables
+
sizeof
(
TSCKSUM
);
// size_t tsize = TSDB_FILE_HEAD_SIZE + sizeof(SCompIdx) * pHelper->config.maxTables + sizeof(TSCKSUM);
if
(
tsendfile
(
pHelper
->
files
.
nHeadF
.
fd
,
pHelper
->
files
.
headF
.
fd
,
NULL
,
tsize
)
<
tsize
)
goto
_err
;
if
(
tsendfile
(
pHelper
->
files
.
nHeadF
.
fd
,
pHelper
->
files
.
headF
.
fd
,
NULL
,
TSDB_FILE_HEAD_SIZE
)
<
TSDB_FILE_HEAD_SIZE
)
goto
_err
;
// Create and open .l file if should
// Create and open .l file if should
if
(
tsdbShouldCreateNewLast
(
pHelper
))
{
if
(
tsdbShouldCreateNewLast
(
pHelper
))
{
if
(
tsdbOpenFile
(
&
(
pHelper
->
files
.
nLastF
),
O_WRONLY
|
O_CREAT
)
<
0
)
goto
_err
;
if
(
tsdbOpenFile
(
&
(
pHelper
->
files
.
nLastF
),
O_WRONLY
|
O_CREAT
)
<
0
)
goto
_err
;
if
(
tsendfile
(
pHelper
->
files
.
nLastF
.
fd
,
pHelper
->
files
.
lastF
.
fd
,
NULL
,
TSDB_FILE_HEAD_SIZE
)
<
TSDB_FILE_HEAD_SIZE
)
goto
_err
;
if
(
tsendfile
(
pHelper
->
files
.
nLastF
.
fd
,
pHelper
->
files
.
lastF
.
fd
,
NULL
,
TSDB_FILE_HEAD_SIZE
)
<
TSDB_FILE_HEAD_SIZE
)
goto
_err
;
}
}
}
else
{
}
else
{
if
(
tsdbOpenFile
(
&
(
pHelper
->
files
.
dataF
),
O_RDONLY
)
<
0
)
goto
_err
;
if
(
tsdbOpenFile
(
&
(
pHelper
->
files
.
dataF
),
O_RDONLY
)
<
0
)
goto
_err
;
...
@@ -426,13 +429,26 @@ int tsdbWriteCompInfo(SRWHelper *pHelper) {
...
@@ -426,13 +429,26 @@ int tsdbWriteCompInfo(SRWHelper *pHelper) {
int
tsdbWriteCompIdx
(
SRWHelper
*
pHelper
)
{
int
tsdbWriteCompIdx
(
SRWHelper
*
pHelper
)
{
ASSERT
(
TSDB_HELPER_TYPE
(
pHelper
)
==
TSDB_WRITE_HELPER
);
ASSERT
(
TSDB_HELPER_TYPE
(
pHelper
)
==
TSDB_WRITE_HELPER
);
if
(
lseek
(
pHelper
->
files
.
nHeadF
.
fd
,
TSDB_FILE_HEAD_SIZE
,
SEEK_SET
)
<
0
)
return
-
1
;
off_t
offset
=
lseek
(
pHelper
->
files
.
nHeadF
.
fd
,
0
,
SEEK_END
);
if
(
offset
<
0
)
return
-
1
;
SFile
*
pFile
=
&
(
pHelper
->
files
.
nHeadF
);
pFile
->
info
.
offset
=
offset
;
void
*
buf
=
pHelper
->
blockBuffer
;
for
(
uint32_t
i
=
0
;
i
<
pHelper
->
config
.
maxTables
;
i
++
)
{
SCompIdx
*
pCompIdx
=
pHelper
->
pCompIdx
+
i
;
if
(
pCompIdx
->
offset
>
0
)
{
buf
=
taosEncodeVariant32
(
buf
,
i
);
buf
=
tsdbEncodeSCompIdx
(
buf
,
pCompIdx
);
}
}
ASSERT
(
tsizeof
(
pHelper
->
pCompIdx
)
==
sizeof
(
SCompIdx
)
*
pHelper
->
config
.
maxTables
+
sizeof
(
TSCKSUM
)
);
int
tsize
=
(
char
*
)
buf
-
(
char
*
)
pHelper
->
blockBuffer
+
sizeof
(
TSCKSUM
);
taosCalcChecksumAppend
(
0
,
(
uint8_t
*
)
pHelper
->
pCompIdx
,
tsizeof
(
pHelper
->
pCompIdx
)
);
taosCalcChecksumAppend
(
0
,
(
uint8_t
*
)
pHelper
->
blockBuffer
,
tsize
);
if
(
twrite
(
pHelper
->
files
.
nHeadF
.
fd
,
(
void
*
)
pHelper
->
pCompIdx
,
tsizeof
(
pHelper
->
pCompIdx
))
<
tsizeof
(
pHelper
->
pCompIdx
))
if
(
twrite
(
pHelper
->
files
.
nHeadF
.
fd
,
(
void
*
)
pHelper
->
blockBuffer
,
tsize
)
<
tsize
)
return
-
1
;
return
-
1
;
pFile
->
info
.
len
=
tsize
;
return
0
;
return
0
;
}
}
...
@@ -441,14 +457,34 @@ int tsdbLoadCompIdx(SRWHelper *pHelper, void *target) {
...
@@ -441,14 +457,34 @@ int tsdbLoadCompIdx(SRWHelper *pHelper, void *target) {
if
(
!
helperHasState
(
pHelper
,
TSDB_HELPER_IDX_LOAD
))
{
if
(
!
helperHasState
(
pHelper
,
TSDB_HELPER_IDX_LOAD
))
{
// If not load from file, just load it in object
// If not load from file, just load it in object
int
fd
=
pHelper
->
files
.
headF
.
fd
;
SFile
*
pFile
=
&
(
pHelper
->
files
.
headF
);
int
fd
=
pFile
->
fd
;
memset
(
pHelper
->
pCompIdx
,
0
,
tsizeof
(
pHelper
->
pCompIdx
));
if
(
pFile
->
info
.
offset
>
0
)
{
ASSERT
(
pFile
->
info
.
offset
>
TSDB_FILE_HEAD_SIZE
);
if
(
lseek
(
fd
,
pFile
->
info
.
offset
,
SEEK_SET
)
<
0
)
return
-
1
;
if
(
tread
(
fd
,
(
void
*
)(
pHelper
->
blockBuffer
),
pFile
->
info
.
len
)
<
pFile
->
info
.
len
)
return
-
1
;
if
(
!
taosCheckChecksumWhole
((
uint8_t
*
)(
pHelper
->
blockBuffer
),
pFile
->
info
.
len
))
{
// TODO: File is broken, try to deal with it
return
-
1
;
}
if
(
lseek
(
fd
,
TSDB_FILE_HEAD_SIZE
,
SEEK_SET
)
<
0
)
return
-
1
;
// Decode it
if
(
tread
(
fd
,
(
void
*
)(
pHelper
->
pCompIdx
),
tsizeof
((
void
*
)
pHelper
->
pCompIdx
))
<
tsizeof
(
pHelper
->
pCompIdx
))
return
-
1
;
void
*
ptr
=
pHelper
->
blockBuffer
;
if
(
!
taosCheckChecksumWhole
((
uint8_t
*
)(
pHelper
->
pCompIdx
),
tsizeof
((
void
*
)
pHelper
->
pCompIdx
)))
{
while
((
char
*
)
ptr
-
(
char
*
)
pHelper
->
blockBuffer
>=
pFile
->
info
.
len
-
sizeof
(
TSCKSUM
))
{
// TODO: File is broken, try to deal with it
uint32_t
tid
=
0
;
return
-
1
;
if
((
ptr
=
taosDecodeVariant32
(
ptr
,
&
tid
))
==
NULL
)
return
-
1
;
ASSERT
(
tid
>
0
&&
tid
<
pHelper
->
config
.
maxTables
);
if
((
ptr
=
tsdbDecodeSCompIdx
(
ptr
,
pHelper
->
pCompIdx
+
tid
))
==
NULL
)
return
-
1
;
ASSERT
((
char
*
)
ptr
-
(
char
*
)
pHelper
->
blockBuffer
<=
pFile
->
info
.
len
-
sizeof
(
TSCKSUM
));
}
}
}
}
}
helperSetState
(
pHelper
,
TSDB_HELPER_IDX_LOAD
);
helperSetState
(
pHelper
,
TSDB_HELPER_IDX_LOAD
);
...
@@ -1168,4 +1204,76 @@ static int tsdbGetRowsInRange(SDataCols *pDataCols, TSKEY minKey, TSKEY maxKey)
...
@@ -1168,4 +1204,76 @@ static int tsdbGetRowsInRange(SDataCols *pDataCols, TSKEY minKey, TSKEY maxKey)
if
((
TSKEY
*
)
ptr2
-
(
TSKEY
*
)
ptr1
<
0
)
return
0
;
if
((
TSKEY
*
)
ptr2
-
(
TSKEY
*
)
ptr1
<
0
)
return
0
;
return
((
TSKEY
*
)
ptr2
-
(
TSKEY
*
)
ptr1
)
+
1
;
return
((
TSKEY
*
)
ptr2
-
(
TSKEY
*
)
ptr1
)
+
1
;
}
void
*
tsdbEncodeSCompIdx
(
void
*
buf
,
SCompIdx
*
pIdx
)
{
buf
=
taosEncodeVariant32
(
buf
,
pIdx
->
len
);
buf
=
taosEncodeVariant32
(
buf
,
pIdx
->
offset
);
buf
=
taosEncodeFixed8
(
buf
,
pIdx
->
hasLast
);
buf
=
taosEncodeVariant32
(
buf
,
pIdx
->
numOfBlocks
);
buf
=
taosEncodeFixed64
(
buf
,
pIdx
->
uid
);
buf
=
taosEncodeFixed64
(
buf
,
pIdx
->
maxKey
);
return
buf
;
}
void
*
tsdbDecodeSCompIdx
(
void
*
buf
,
SCompIdx
*
pIdx
)
{
uint8_t
hasLast
=
0
;
uint32_t
numOfBlocks
=
0
;
uint64_t
value
=
0
;
if
((
buf
=
taosDecodeVariant32
(
buf
,
&
(
pIdx
->
len
)))
==
NULL
)
return
NULL
;
if
((
buf
=
taosDecodeVariant32
(
buf
,
&
(
pIdx
->
offset
)))
==
NULL
)
return
NULL
;
if
((
buf
=
taosDecodeFixed8
(
buf
,
&
(
hasLast
)))
==
NULL
)
return
NULL
;
pIdx
->
hasLast
=
hasLast
;
if
((
buf
=
taosDecodeVariant32
(
buf
,
&
(
numOfBlocks
)))
==
NULL
)
return
NULL
;
pIdx
->
numOfBlocks
=
numOfBlocks
;
if
((
buf
=
taosDecodeFixed64
(
buf
,
&
value
))
==
NULL
)
return
NULL
;
pIdx
->
uid
=
(
int64_t
)
value
;
if
((
buf
=
taosDecodeFixed64
(
buf
,
&
value
))
==
NULL
)
return
NULL
;
pIdx
->
maxKey
=
(
TSKEY
)
value
;
return
buf
;
}
int
tsdbUpdateFileHeader
(
SFile
*
pFile
,
uint32_t
version
)
{
char
buf
[
TSDB_FILE_HEAD_SIZE
]
=
"
\0
"
;
void
*
pBuf
=
(
void
*
)
buf
;
pBuf
=
taosEncodeFixed32
(
pBuf
,
version
);
pBuf
=
tsdbEncodeSFileInfo
(
pBuf
,
&
(
pFile
->
info
));
int
tsize
=
(
char
*
)
pBuf
-
buf
+
sizeof
(
TSCKSUM
);
ASSERT
(
tsize
<=
TSDB_FILE_HEAD_SIZE
);
taosCalcChecksumAppend
(
0
,
(
uint8_t
*
)
buf
,
tsize
);
if
(
lseek
(
pFile
->
fd
,
0
,
SEEK_SET
)
<
0
)
return
-
1
;
if
(
twrite
(
pFile
->
fd
,
(
void
*
)
buf
,
TSDB_FILE_HEAD_SIZE
)
<
TSDB_FILE_HEAD_SIZE
)
return
-
1
;
return
0
;
}
void
*
tsdbEncodeSFileInfo
(
void
*
buf
,
const
SFileInfo
*
pInfo
)
{
buf
=
taosEncodeFixed32
(
buf
,
pInfo
->
offset
);
buf
=
taosEncodeFixed32
(
buf
,
pInfo
->
len
);
buf
=
taosEncodeFixed64
(
buf
,
pInfo
->
size
);
buf
=
taosEncodeFixed64
(
buf
,
pInfo
->
tombSize
);
buf
=
taosEncodeFixed32
(
buf
,
pInfo
->
totalBlocks
);
buf
=
taosEncodeFixed32
(
buf
,
pInfo
->
totalSubBlocks
);
return
buf
;
}
void
*
tsdbDecodeSFileInfo
(
void
*
buf
,
SFileInfo
*
pInfo
)
{
buf
=
taosDecodeFixed32
(
buf
,
&
(
pInfo
->
offset
));
buf
=
taosDecodeFixed32
(
buf
,
&
(
pInfo
->
len
));
buf
=
taosDecodeFixed64
(
buf
,
&
(
pInfo
->
size
));
buf
=
taosDecodeFixed64
(
buf
,
&
(
pInfo
->
tombSize
));
buf
=
taosDecodeFixed32
(
buf
,
&
(
pInfo
->
totalBlocks
));
buf
=
taosDecodeFixed32
(
buf
,
&
(
pInfo
->
totalSubBlocks
));
return
buf
;
}
}
\ No newline at end of file
src/util/inc/tcoding.h
浏览文件 @
055aed43
...
@@ -29,6 +29,11 @@ extern "C" {
...
@@ -29,6 +29,11 @@ extern "C" {
static
const
int32_t
TNUMBER
=
1
;
static
const
int32_t
TNUMBER
=
1
;
#define IS_LITTLE_ENDIAN() (*(uint8_t *)(&TNUMBER) != 0)
#define IS_LITTLE_ENDIAN() (*(uint8_t *)(&TNUMBER) != 0)
static
FORCE_INLINE
void
*
taosEncodeFixed8
(
void
*
buf
,
uint8_t
value
)
{
((
uint8_t
*
)
buf
)[
0
]
=
value
;
return
POINTER_SHIFT
(
buf
,
sizeof
(
value
));
}
static
FORCE_INLINE
void
*
taosEncodeFixed16
(
void
*
buf
,
uint16_t
value
)
{
static
FORCE_INLINE
void
*
taosEncodeFixed16
(
void
*
buf
,
uint16_t
value
)
{
if
(
IS_LITTLE_ENDIAN
())
{
if
(
IS_LITTLE_ENDIAN
())
{
memcpy
(
buf
,
&
value
,
sizeof
(
value
));
memcpy
(
buf
,
&
value
,
sizeof
(
value
));
...
@@ -70,6 +75,11 @@ static FORCE_INLINE void *taosEncodeFixed64(void *buf, uint64_t value) {
...
@@ -70,6 +75,11 @@ static FORCE_INLINE void *taosEncodeFixed64(void *buf, uint64_t value) {
return
POINTER_SHIFT
(
buf
,
sizeof
(
value
));
return
POINTER_SHIFT
(
buf
,
sizeof
(
value
));
}
}
static
FORCE_INLINE
void
*
taosDecodeFixed8
(
void
*
buf
,
uint8_t
*
value
)
{
*
value
=
((
uint8_t
*
)
buf
)[
0
];
return
POINTER_SHIFT
(
buf
,
sizeof
(
*
value
));
}
static
FORCE_INLINE
void
*
taosDecodeFixed16
(
void
*
buf
,
uint16_t
*
value
)
{
static
FORCE_INLINE
void
*
taosDecodeFixed16
(
void
*
buf
,
uint16_t
*
value
)
{
if
(
IS_LITTLE_ENDIAN
())
{
if
(
IS_LITTLE_ENDIAN
())
{
memcpy
(
value
,
buf
,
sizeof
(
*
value
));
memcpy
(
value
,
buf
,
sizeof
(
*
value
));
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录