Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
d630c7d0
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看板
提交
d630c7d0
编写于
1月 11, 2021
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more work
上级
8c5a3a95
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
61 addition
and
58 deletion
+61
-58
src/tsdb/inc/tsdbReadImpl.h
src/tsdb/inc/tsdbReadImpl.h
+1
-1
src/tsdb/src/tsdbCommit.c
src/tsdb/src/tsdbCommit.c
+60
-57
未找到文件。
src/tsdb/inc/tsdbReadImpl.h
浏览文件 @
d630c7d0
...
@@ -93,7 +93,7 @@ struct SReadH {
...
@@ -93,7 +93,7 @@ struct SReadH {
#define TSDB_READ_REPO(rh) ((rh)->pRepo)
#define TSDB_READ_REPO(rh) ((rh)->pRepo)
#define TSDB_READ_REPO_ID(rh) REPO_ID(TSDB_READ_REPO(rh))
#define TSDB_READ_REPO_ID(rh) REPO_ID(TSDB_READ_REPO(rh))
#define TSDB_READ_FSET(rh) (&((rh)->rSet))
#define TSDB_READ_FSET(rh) (&((rh)->rSet))
#define TSDB_READ_TABLE(
c
h) ((rh)->pTable)
#define TSDB_READ_TABLE(
r
h) ((rh)->pTable)
#define TSDB_READ_HEAD_FILE(rh) TSDB_DFILE_IN_SET(TSDB_READ_FSET(rh), TSDB_FILE_HEAD)
#define TSDB_READ_HEAD_FILE(rh) TSDB_DFILE_IN_SET(TSDB_READ_FSET(rh), TSDB_FILE_HEAD)
#define TSDB_READ_DATA_FILE(rh) TSDB_DFILE_IN_SET(TSDB_READ_FSET(rh), TSDB_FILE_DATA)
#define TSDB_READ_DATA_FILE(rh) TSDB_DFILE_IN_SET(TSDB_READ_FSET(rh), TSDB_FILE_DATA)
#define TSDB_READ_LAST_FILE(rh) TSDB_DFILE_IN_SET(TSDB_READ_FSET(rh), TSDB_FILE_LAST)
#define TSDB_READ_LAST_FILE(rh) TSDB_DFILE_IN_SET(TSDB_READ_FSET(rh), TSDB_FILE_LAST)
...
...
src/tsdb/src/tsdbCommit.c
浏览文件 @
d630c7d0
...
@@ -706,42 +706,48 @@ static int tsdbComparKeyBlock(const void *arg1, const void *arg2) {
...
@@ -706,42 +706,48 @@ static int tsdbComparKeyBlock(const void *arg1, const void *arg2) {
}
}
}
}
static
int
tsdbWriteBlock
(
SCommitH
*
pCommih
,
SDFile
*
pDFile
,
SDataCols
*
pDataCols
,
SBlock
*
pBlock
,
bool
isLast
,
static
int
tsdbWriteBlock
(
SCommitH
*
pCommi
t
h
,
SDFile
*
pDFile
,
SDataCols
*
pDataCols
,
SBlock
*
pBlock
,
bool
isLast
,
bool
isSuper
)
{
bool
isSuper
)
{
// TODO
STsdbRepo
*
pRepo
=
TSDB_COMMIT_REPO
(
pCommith
);
STsdbCfg
*
pCfg
=
&
(
pHelper
->
pRepo
->
config
);
STsdbCfg
*
pCfg
=
REPO_CFG
(
pRepo
);
SBlockData
*
p
CompData
=
(
SBlockData
*
)(
pHelper
->
pBuffer
)
;
SBlockData
*
p
BlockData
;
int64_t
offset
=
0
;
int64_t
offset
=
0
;
STable
*
pTable
=
TSDB_COMMIT_TABLE
(
pCommith
);
int
rowsToWrite
=
pDataCols
->
numOfRows
;
int
rowsToWrite
=
pDataCols
->
numOfRows
;
ASSERT
(
rowsToWrite
>
0
&&
rowsToWrite
<=
pCfg
->
maxRowsPerFileBlock
);
ASSERT
(
rowsToWrite
>
0
&&
rowsToWrite
<=
pCfg
->
maxRowsPerFileBlock
);
ASSERT
(
isLast
?
rowsToWrite
<
pCfg
->
minRowsPerFileBlock
:
true
);
ASSERT
(
(
!
isLast
)
||
rowsToWrite
<
pCfg
->
minRowsPerFileBlock
);
offset
=
lseek
(
pFile
->
fd
,
0
,
SEEK_END
);
// Seek file
offset
=
tsdbSeekDFile
(
pDFile
,
0
,
SEEK_END
);
if
(
offset
<
0
)
{
if
(
offset
<
0
)
{
tsdbError
(
"vgId:%d failed to write block to file %s since %s"
,
REPO_ID
(
pHelper
->
pRepo
),
TSDB_FILE_NAME
(
pFile
),
return
-
1
;
strerror
(
errno
));
}
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
goto
_err
;
// Make buffer space
if
(
tsdbMakeRoom
((
void
**
)(
&
TSDB_COMMIT_BUF
(
pCommith
)),
TSDB_BLOCK_STATIS_SIZE
(
pDataCols
->
numOfCols
))
<
0
)
{
return
-
1
;
}
}
pBlockData
=
(
SBlockData
*
)
TSDB_COMMIT_BUF
(
pCommith
);
// Get # of cols not all NULL(not including key column)
int
nColsNotAllNull
=
0
;
int
nColsNotAllNull
=
0
;
for
(
int
ncol
=
1
;
ncol
<
pDataCols
->
numOfCols
;
ncol
++
)
{
// ncol from 1, we skip the timestamp column
for
(
int
ncol
=
1
;
ncol
<
pDataCols
->
numOfCols
;
ncol
++
)
{
// ncol from 1, we skip the timestamp column
SDataCol
*
pDataCol
=
pDataCols
->
cols
+
ncol
;
SDataCol
*
pDataCol
=
pDataCols
->
cols
+
ncol
;
SBlockCol
*
p
CompCol
=
pComp
Data
->
cols
+
nColsNotAllNull
;
SBlockCol
*
p
BlockCol
=
pBlock
Data
->
cols
+
nColsNotAllNull
;
if
(
isNEleNull
(
pDataCol
,
rowsToWrite
))
{
// all data to commit are NULL, just ignore it
if
(
isNEleNull
(
pDataCol
,
rowsToWrite
))
{
// all data to commit are NULL, just ignore it
continue
;
continue
;
}
}
memset
(
p
CompCol
,
0
,
sizeof
(
*
pComp
Col
));
memset
(
p
BlockCol
,
0
,
sizeof
(
*
pBlock
Col
));
p
Comp
Col
->
colId
=
pDataCol
->
colId
;
p
Block
Col
->
colId
=
pDataCol
->
colId
;
p
Comp
Col
->
type
=
pDataCol
->
type
;
p
Block
Col
->
type
=
pDataCol
->
type
;
if
(
tDataTypeDesc
[
pDataCol
->
type
].
getStatisFunc
)
{
if
(
tDataTypeDesc
[
pDataCol
->
type
].
getStatisFunc
)
{
(
*
tDataTypeDesc
[
pDataCol
->
type
].
getStatisFunc
)(
(
*
tDataTypeDesc
[
pDataCol
->
type
].
getStatisFunc
)(
(
TSKEY
*
)(
pDataCols
->
cols
[
0
].
pData
),
pDataCol
->
pData
,
rowsToWrite
,
&
(
p
CompCol
->
min
),
&
(
pComp
Col
->
max
),
(
TSKEY
*
)(
pDataCols
->
cols
[
0
].
pData
),
pDataCol
->
pData
,
rowsToWrite
,
&
(
p
BlockCol
->
min
),
&
(
pBlock
Col
->
max
),
&
(
p
CompCol
->
sum
),
&
(
pCompCol
->
minIndex
),
&
(
pCompCol
->
maxIndex
),
&
(
pComp
Col
->
numOfNull
));
&
(
p
BlockCol
->
sum
),
&
(
pBlockCol
->
minIndex
),
&
(
pBlockCol
->
maxIndex
),
&
(
pBlock
Col
->
numOfNull
));
}
}
nColsNotAllNull
++
;
nColsNotAllNull
++
;
}
}
...
@@ -749,35 +755,41 @@ static int tsdbWriteBlock(SCommitH *pCommih, SDFile *pDFile, SDataCols *pDataCol
...
@@ -749,35 +755,41 @@ static int tsdbWriteBlock(SCommitH *pCommih, SDFile *pDFile, SDataCols *pDataCol
ASSERT
(
nColsNotAllNull
>=
0
&&
nColsNotAllNull
<=
pDataCols
->
numOfCols
);
ASSERT
(
nColsNotAllNull
>=
0
&&
nColsNotAllNull
<=
pDataCols
->
numOfCols
);
// Compress the data if neccessary
// Compress the data if neccessary
int
tcol
=
0
;
int
tcol
=
0
;
// counter of not all NULL and written columns
int32_t
toffset
=
0
;
int32_t
toffset
=
0
;
int32_t
tsize
=
TSDB_
GET_COMPCOL_LEN
(
nColsNotAllNull
);
int32_t
tsize
=
TSDB_
BLOCK_STATIS_SIZE
(
nColsNotAllNull
);
int32_t
lsize
=
tsize
;
int32_t
lsize
=
tsize
;
int32_t
keyLen
=
0
;
int32_t
keyLen
=
0
;
for
(
int
ncol
=
0
;
ncol
<
pDataCols
->
numOfCols
;
ncol
++
)
{
for
(
int
ncol
=
0
;
ncol
<
pDataCols
->
numOfCols
;
ncol
++
)
{
// All not NULL columns finish
if
(
ncol
!=
0
&&
tcol
>=
nColsNotAllNull
)
break
;
if
(
ncol
!=
0
&&
tcol
>=
nColsNotAllNull
)
break
;
SDataCol
*
pDataCol
=
pDataCols
->
cols
+
ncol
;
SDataCol
*
pDataCol
=
pDataCols
->
cols
+
ncol
;
SBlockCol
*
p
CompCol
=
pComp
Data
->
cols
+
tcol
;
SBlockCol
*
p
BlockCol
=
pBlock
Data
->
cols
+
tcol
;
if
(
ncol
!=
0
&&
(
pDataCol
->
colId
!=
pCompCol
->
colId
))
continue
;
if
(
ncol
!=
0
&&
(
pDataCol
->
colId
!=
pBlockCol
->
colId
))
continue
;
void
*
tptr
=
POINTER_SHIFT
(
pCompData
,
lsize
);
int32_t
flen
=
0
;
// final length
int32_t
flen
;
// final length
int32_t
tlen
=
dataColGetNEleLen
(
pDataCol
,
rowsToWrite
);
int32_t
tlen
=
dataColGetNEleLen
(
pDataCol
,
rowsToWrite
);
void
*
tptr
;
if
(
pCfg
->
compression
)
{
// Make room
if
(
pCfg
->
compression
==
TWO_STAGE_COMP
)
{
if
(
tsdbMakeRoom
((
void
**
)
TSDB_COMMIT_BUF
(
pCommith
),
lsize
+
tlen
+
COMP_OVERFLOW_BYTES
+
sizeof
(
TSCKSUM
))
<
0
)
{
pHelper
->
compBuffer
=
taosTRealloc
(
pHelper
->
compBuffer
,
tlen
+
COMP_OVERFLOW_BYTES
);
return
-
1
;
if
(
pHelper
->
compBuffer
==
NULL
)
{
}
terrno
=
TSDB_CODE_TDB_OUT_OF_MEMORY
;
pBlockData
=
(
SBlockData
*
)
TSDB_COMMIT_BUF
(
pCommith
);
goto
_err
;
tptr
=
POINTER_SHIFT
(
pBlockData
,
lsize
);
}
}
flen
=
(
*
(
tDataTypeDesc
[
pDataCol
->
type
].
compFunc
))(
if
(
pCfg
->
compression
==
TWO_STAGE_COMP
&&
(
char
*
)
pDataCol
->
pData
,
tlen
,
rowsToWrite
,
tptr
,
(
int32_t
)
taosTSizeof
(
pHelper
->
pBuffer
)
-
lsize
,
tsdbMakeRoom
((
void
**
)
TSDB_COMMIT_COMP_BUF
(
pCommith
),
tlen
+
COMP_OVERFLOW_BYTES
)
<
0
)
{
pCfg
->
compression
,
pHelper
->
compBuffer
,
(
int32_t
)
taosTSizeof
(
pHelper
->
compBuffer
));
return
-
1
;
}
// Compress or just copy
if
(
pCfg
->
compression
)
{
flen
=
(
*
(
tDataTypeDesc
[
pDataCol
->
type
].
compFunc
))((
char
*
)
pDataCol
->
pData
,
tlen
,
rowsToWrite
,
tptr
,
tlen
+
COMP_OVERFLOW_BYTES
,
pCfg
->
compression
,
TSDB_COMMIT_COMP_BUF
(
pCommith
),
tlen
+
COMP_OVERFLOW_BYTES
);
}
else
{
}
else
{
flen
=
tlen
;
flen
=
tlen
;
memcpy
(
tptr
,
pDataCol
->
pData
,
flen
);
memcpy
(
tptr
,
pDataCol
->
pData
,
flen
);
...
@@ -787,12 +799,11 @@ static int tsdbWriteBlock(SCommitH *pCommih, SDFile *pDFile, SDataCols *pDataCol
...
@@ -787,12 +799,11 @@ static int tsdbWriteBlock(SCommitH *pCommih, SDFile *pDFile, SDataCols *pDataCol
ASSERT
(
flen
>
0
);
ASSERT
(
flen
>
0
);
flen
+=
sizeof
(
TSCKSUM
);
flen
+=
sizeof
(
TSCKSUM
);
taosCalcChecksumAppend
(
0
,
(
uint8_t
*
)
tptr
,
flen
);
taosCalcChecksumAppend
(
0
,
(
uint8_t
*
)
tptr
,
flen
);
pFile
->
info
.
magic
=
tsdbUpdateDFileMagic
(
pDFile
,
POINTER_SHIFT
(
tptr
,
flen
-
sizeof
(
TSCKSUM
)));
taosCalcChecksum
(
pFile
->
info
.
magic
,
(
uint8_t
*
)
POINTER_SHIFT
(
tptr
,
flen
-
sizeof
(
TSCKSUM
)),
sizeof
(
TSCKSUM
));
if
(
ncol
!=
0
)
{
if
(
ncol
!=
0
)
{
p
Comp
Col
->
offset
=
toffset
;
p
Block
Col
->
offset
=
toffset
;
p
Comp
Col
->
len
=
flen
;
p
Block
Col
->
len
=
flen
;
tcol
++
;
tcol
++
;
}
else
{
}
else
{
keyLen
=
flen
;
keyLen
=
flen
;
...
@@ -802,20 +813,16 @@ static int tsdbWriteBlock(SCommitH *pCommih, SDFile *pDFile, SDataCols *pDataCol
...
@@ -802,20 +813,16 @@ static int tsdbWriteBlock(SCommitH *pCommih, SDFile *pDFile, SDataCols *pDataCol
lsize
+=
flen
;
lsize
+=
flen
;
}
}
p
Comp
Data
->
delimiter
=
TSDB_FILE_DELIMITER
;
p
Block
Data
->
delimiter
=
TSDB_FILE_DELIMITER
;
p
CompData
->
uid
=
pHelper
->
tableInfo
.
uid
;
p
BlockData
->
uid
=
TABLE_UID
(
pTable
)
;
p
Comp
Data
->
numOfCols
=
nColsNotAllNull
;
p
Block
Data
->
numOfCols
=
nColsNotAllNull
;
taosCalcChecksumAppend
(
0
,
(
uint8_t
*
)
pCompData
,
tsize
);
taosCalcChecksumAppend
(
0
,
(
uint8_t
*
)
pBlockData
,
tsize
);
pFile
->
info
.
magic
=
taosCalcChecksum
(
pFile
->
info
.
magic
,
(
uint8_t
*
)
POINTER_SHIFT
(
pCompData
,
tsize
-
sizeof
(
TSCKSUM
)),
tsdbUpdateDFileMagic
(
pDFile
,
POINTER_SHIFT
(
pBlockData
,
tsize
-
sizeof
(
TSCKSUM
)));
sizeof
(
TSCKSUM
));
// Write the whole block to file
// Write the whole block to file
if
(
taosWrite
(
pFile
->
fd
,
(
void
*
)
pCompData
,
lsize
)
<
lsize
)
{
if
(
tsdbWriteDFile
(
pDFile
,
(
void
*
)
pBlockData
,
lsize
<
lsize
))
{
tsdbError
(
"vgId:%d failed to write %d bytes to file %s since %s"
,
REPO_ID
(
helperRepo
(
pHelper
)),
lsize
,
return
-
1
;
TSDB_FILE_NAME
(
pFile
),
strerror
(
errno
));
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
goto
_err
;
}
}
// Update pBlock membership vairables
// Update pBlock membership vairables
...
@@ -828,20 +835,16 @@ static int tsdbWriteBlock(SCommitH *pCommih, SDFile *pDFile, SDataCols *pDataCol
...
@@ -828,20 +835,16 @@ static int tsdbWriteBlock(SCommitH *pCommih, SDFile *pDFile, SDataCols *pDataCol
pBlock
->
numOfSubBlocks
=
isSuper
?
1
:
0
;
pBlock
->
numOfSubBlocks
=
isSuper
?
1
:
0
;
pBlock
->
numOfCols
=
nColsNotAllNull
;
pBlock
->
numOfCols
=
nColsNotAllNull
;
pBlock
->
keyFirst
=
dataColsKeyFirst
(
pDataCols
);
pBlock
->
keyFirst
=
dataColsKeyFirst
(
pDataCols
);
pBlock
->
keyLast
=
dataColsKeyAt
(
pDataCols
,
rowsToWrite
-
1
);
pBlock
->
keyLast
=
dataColsKeyLast
(
pDataCols
);
pDFile
->
info
.
size
+=
pBlock
->
len
;
tsdbDebug
(
"vgId:%d tid:%d a block of data is written to file %s, offset %"
PRId64
tsdbDebug
(
"vgId:%d tid:%d a block of data is written to file %s, offset %"
PRId64
" numOfRows %d len %d numOfCols %"
PRId16
" keyFirst %"
PRId64
" keyLast %"
PRId64
,
" numOfRows %d len %d numOfCols %"
PRId16
" keyFirst %"
PRId64
" keyLast %"
PRId64
,
REPO_ID
(
helperRepo
(
pHelper
)),
pHelper
->
tableInfo
.
tid
,
TSDB_FILE_NAME
(
pFile
),
(
int64_t
)(
pBlock
->
offset
),
REPO_ID
(
pRepo
),
TABLE_TID
(
pTable
),
TSDB_FILE_FULL_NAME
(
pDFile
),
offset
,
rowsToWrite
,
pBlock
->
len
,
(
int
)(
pBlock
->
numOfRows
),
pBlock
->
len
,
pBlock
->
numOfCols
,
pBlock
->
keyFirst
,
pBlock
->
keyLast
);
pBlock
->
numOfCols
,
pBlock
->
keyFirst
,
pBlock
->
keyLast
);
pFile
->
info
.
size
+=
pBlock
->
len
;
// ASSERT(pFile->info.size == lseek(pFile->fd, 0, SEEK_CUR));
return
0
;
return
0
;
_err:
return
-
1
;
}
}
static
int
tsdbWriteBlockInfo
(
SCommitH
*
pCommih
)
{
static
int
tsdbWriteBlockInfo
(
SCommitH
*
pCommih
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录