Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
9f398eca
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
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看板
提交
9f398eca
编写于
6月 14, 2022
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more work
上级
72e52508
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
314 addition
and
299 deletion
+314
-299
source/dnode/vnode/src/inc/tsdb.h
source/dnode/vnode/src/inc/tsdb.h
+34
-55
source/dnode/vnode/src/tsdb/tsdbCommit.c
source/dnode/vnode/src/tsdb/tsdbCommit.c
+17
-20
source/dnode/vnode/src/tsdb/tsdbReaderWriter.c
source/dnode/vnode/src/tsdb/tsdbReaderWriter.c
+55
-38
source/dnode/vnode/src/tsdb/tsdbUtil.c
source/dnode/vnode/src/tsdb/tsdbUtil.c
+208
-186
未找到文件。
source/dnode/vnode/src/inc/tsdb.h
浏览文件 @
9f398eca
...
...
@@ -35,10 +35,9 @@ typedef struct TSDBROW TSDBROW;
typedef
struct
TSDBKEY
TSDBKEY
;
typedef
struct
TABLEID
TABLEID
;
typedef
struct
SDelOp
SDelOp
;
typedef
struct
SDelDataItem
SDelDataItem
;
typedef
struct
SDelData
SDelData
;
typedef
struct
SDelIdxItem
SDelIdxItem
;
typedef
struct
SDelIdx
SDelIdx
;
typedef
struct
SDelDataInfo
SDelDataInfo
;
typedef
struct
STbData
STbData
;
typedef
struct
SMemTable
SMemTable
;
typedef
struct
STbDataIter
STbDataIter
;
...
...
@@ -49,6 +48,15 @@ typedef struct SMapData SMapData;
typedef
struct
SColData
SColData
;
typedef
struct
SColDataBlock
SColDataBlock
;
typedef
struct
SBlockSMA
SBlockSMA
;
typedef
struct
SBlockIdxItem
SBlockIdxItem
;
typedef
struct
SBlockIdx
SBlockIdx
;
typedef
struct
SBlockInfo
SBlockInfo
;
typedef
struct
SBlock
SBlock
;
typedef
struct
SBlockCol
SBlockCol
;
typedef
struct
SBlockStatis
SBlockStatis
;
typedef
struct
SAggrBlkCol
SAggrBlkCol
;
typedef
struct
SBlockData
SBlockData
;
typedef
struct
SReadH
SReadH
;
// tsdbMemTable ==============================================================================================
...
...
@@ -110,8 +118,9 @@ typedef struct SDelFWriter SDelFWriter;
int32_t
tsdbDelFWriterOpen
(
SDelFWriter
**
ppWriter
,
SDelFile
*
pFile
,
STsdb
*
pTsdb
);
int32_t
tsdbDelFWriterClose
(
SDelFWriter
*
pWriter
,
int8_t
sync
);
int32_t
tsdbWriteDelData
(
SDelFWriter
*
pWriter
,
SDelData
*
pDelData
,
uint8_t
**
ppBuf
,
int64_t
*
rOffset
,
int64_t
*
rSize
);
int32_t
tsdbWriteDelIdx
(
SDelFWriter
*
pWriter
,
SDelIdx
*
pDelIdx
,
uint8_t
**
ppBuf
);
int32_t
tsdbWriteDelData
(
SDelFWriter
*
pWriter
,
SDelDataInfo
*
pInfo
,
SMapData
*
pDelDataMap
,
uint8_t
**
ppBuf
,
int64_t
*
rOffset
,
int64_t
*
rSize
);
int32_t
tsdbWriteDelIdx
(
SDelFWriter
*
pWriter
,
SMapData
*
pDelIdxMap
,
uint8_t
**
ppBuf
);
int32_t
tsdbUpdateDelFileHdr
(
SDelFWriter
*
pWriter
,
uint8_t
**
ppBuf
);
// SDelFReader
...
...
@@ -119,27 +128,8 @@ typedef struct SDelFReader SDelFReader;
int32_t
tsdbDelFReaderOpen
(
SDelFReader
**
ppReader
,
SDelFile
*
pFile
,
STsdb
*
pTsdb
,
uint8_t
**
ppBuf
);
int32_t
tsdbDelFReaderClose
(
SDelFReader
*
pReader
);
int32_t
tsdbReadDelData
(
SDelFReader
*
pReader
,
SDelIdxItem
*
pItem
,
SDelData
*
pDelData
,
uint8_t
**
ppBuf
);
int32_t
tsdbReadDelIdx
(
SDelFReader
*
pReader
,
SDelIdx
*
pDelIdx
,
uint8_t
**
ppBuf
);
// SCacheFWriter
typedef
struct
SCacheFWriter
SCacheFWriter
;
// SCacheFReader
typedef
struct
SCacheFReader
SCacheFReader
;
// tsdbCommit.c ==============================================================================================
// tsdbReadImpl.c ==============================================================================================
typedef
struct
SBlockIdxItem
SBlockIdxItem
;
typedef
struct
SBlockIdx
SBlockIdx
;
typedef
struct
SBlockInfo
SBlockInfo
;
typedef
struct
SBlock
SBlock
;
typedef
struct
SBlockCol
SBlockCol
;
typedef
struct
SBlockStatis
SBlockStatis
;
typedef
struct
SAggrBlkCol
SAggrBlkCol
;
typedef
struct
SBlockData
SBlockData
;
typedef
struct
SReadH
SReadH
;
int32_t
tsdbReadDelData
(
SDelFReader
*
pReader
,
SDelIdx
*
pDelIdx
,
SMapData
*
pDelDataMap
,
uint8_t
**
ppBuf
);
int32_t
tsdbReadDelIdx
(
SDelFReader
*
pReader
,
SMapData
*
pDelIdxMap
,
uint8_t
**
ppBuf
);
// tsdbUtil.c ==============================================================================================
int32_t
tsdbKeyFid
(
TSKEY
key
,
int32_t
minutes
,
int8_t
precision
);
...
...
@@ -171,20 +161,20 @@ int32_t tGetBlockIdx(uint8_t *p, SBlockIdx *pBlockIdx);
int32_t
tBlockCmprFn
(
const
void
*
p1
,
const
void
*
p2
);
// SDelIdx
int32_t
tDelIdxClear
(
SDelIdx
*
pDelIdx
);
int32_t
tDelIdxPutItem
(
SDelIdx
*
pDelIdx
,
SDelIdxItem
*
pItem
);
int32_t
tDelIdxGetItemByIdx
(
SDelIdx
*
pDelIdx
,
SDelIdxItem
*
pItem
,
int32_t
idx
);
int32_t
tDelIdxGetItem
(
SDelIdx
*
pDelIdx
,
SDelIdxItem
*
pItem
,
TABLEID
id
);
int32_t
tPutDelIdx
(
uint8_t
*
p
,
SDelIdx
*
pDelIdx
);
int32_t
tGetDelIdx
(
uint8_t
*
p
,
SDelIdx
*
pDelIdx
);
//
int32_t tDelIdxClear(SDelIdx *pDelIdx);
//
int32_t tDelIdxPutItem(SDelIdx *pDelIdx, SDelIdxItem *pItem);
//
int32_t tDelIdxGetItemByIdx(SDelIdx *pDelIdx, SDelIdxItem *pItem, int32_t idx);
//
int32_t tDelIdxGetItem(SDelIdx *pDelIdx, SDelIdxItem *pItem, TABLEID id);
int32_t
tPutDelIdx
(
uint8_t
*
p
,
void
*
ph
);
int32_t
tGetDelIdx
(
uint8_t
*
p
,
void
*
ph
);
// SDelData
int32_t
tDelDataClear
(
SDelData
*
pDelData
);
int32_t
tDelDataPutItem
(
SDelData
*
pDelData
,
SDelDataItem
*
pItem
);
int32_t
tDelDataGetItemByIdx
(
SDelData
*
pDelData
,
SDelDataItem
*
pItem
,
int32_t
idx
);
int32_t
tDelDataGetItem
(
SDelData
*
pDelData
,
SDelDataItem
*
pItem
,
int64_t
version
);
int32_t
tPutDelData
(
uint8_t
*
p
,
SDelData
*
pDelData
);
int32_t
tGetDelData
(
uint8_t
*
p
,
SDelData
*
pDelData
);
//
int32_t tDelDataClear(SDelData *pDelData);
//
int32_t tDelDataPutItem(SDelData *pDelData, SDelDataItem *pItem);
//
int32_t tDelDataGetItemByIdx(SDelData *pDelData, SDelDataItem *pItem, int32_t idx);
//
int32_t tDelDataGetItem(SDelData *pDelData, SDelDataItem *pItem, int64_t version);
int32_t
tPutDelData
(
uint8_t
*
p
,
void
*
ph
);
int32_t
tGetDelData
(
uint8_t
*
p
,
void
*
ph
);
int32_t
tPutDelFileHdr
(
uint8_t
*
p
,
SDelFile
*
pDelFile
);
int32_t
tGetDelFileHdr
(
uint8_t
*
p
,
SDelFile
*
pDelFile
);
...
...
@@ -243,6 +233,11 @@ typedef struct SMemSkipList {
SMemSkipListNode
*
pTail
;
}
SMemSkipList
;
struct
SDelDataInfo
{
tb_uid_t
suid
;
tb_uid_t
uid
;
};
struct
STbData
{
tb_uid_t
suid
;
tb_uid_t
uid
;
...
...
@@ -376,22 +371,13 @@ struct SDelOp {
SDelOp
*
pNext
;
};
struct
SDelData
Item
{
struct
SDelData
{
int64_t
version
;
TSKEY
sKey
;
TSKEY
eKey
;
};
struct
SDelData
{
uint32_t
delimiter
;
tb_uid_t
suid
;
tb_uid_t
uid
;
SOffset
offset
;
uint32_t
nData
;
uint8_t
*
pData
;
};
struct
SDelIdxItem
{
struct
SDelIdx
{
tb_uid_t
suid
;
tb_uid_t
uid
;
TSKEY
minKey
;
...
...
@@ -402,13 +388,6 @@ struct SDelIdxItem {
int64_t
size
;
};
struct
SDelIdx
{
uint32_t
delimiter
;
SOffset
offset
;
uint32_t
nData
;
uint8_t
*
pData
;
};
struct
SDelFile
{
TSKEY
minKey
;
TSKEY
maxKey
;
...
...
source/dnode/vnode/src/tsdb/tsdbCommit.c
浏览文件 @
9f398eca
...
...
@@ -28,14 +28,14 @@ typedef struct {
int32_t
minRow
;
int32_t
maxRow
;
// commit file data
TSKEY
nextKey
;
int32_t
commitFid
;
TSKEY
minKey
;
TSKEY
maxKey
;
SD
FileSet
Reader
*
pReader
;
SMapData
oBlockIdx
;
// SMapData<SBlockIdx>, read from reader
SD
FileSet
Writer
*
pWriter
;
SMapData
nBlockIdx
;
// SMapData<SBlockIdx>, build by committer
TSKEY
nextKey
;
int32_t
commitFid
;
TSKEY
minKey
;
TSKEY
maxKey
;
SD
ataF
Reader
*
pReader
;
SMapData
oBlockIdx
;
// SMapData<SBlockIdx>, read from reader
SD
ataF
Writer
*
pWriter
;
SMapData
nBlockIdx
;
// SMapData<SBlockIdx>, build by committer
// commit table data
STbDataIter
iter
;
STbDataIter
*
pIter
;
...
...
@@ -46,15 +46,11 @@ typedef struct {
SColDataBlock
nColDataBlock
;
/* commit del */
SDelFReader
*
pDelFReader
;
SMapData
oDelIdxMap
;
// SMapData<SDelIdx>, old
SMapData
oDelDataMap
;
// SMapData<SDelData>, old
SDelFWriter
*
pDelFWriter
;
SDelIdx
delIdxOld
;
SDelIdx
delIdxNew
;
STbData
*
pTbData
;
SDelIdxItem
*
pDelIdxItem
;
SDelData
delDataOld
;
SDelData
delDataNew
;
SDelIdxItem
delIdxItem
;
/* commit cache */
SMapData
nDelIdxMap
;
// SMapData<SDelIdx>, new
SMapData
nDelDataMap
;
// SMapData<SDelData>, new
}
SCommitter
;
static
int32_t
tsdbStartCommit
(
STsdb
*
pTsdb
,
SCommitter
*
pCommitter
);
...
...
@@ -79,7 +75,7 @@ _err:
int32_t
tsdbCommit
(
STsdb
*
pTsdb
)
{
if
(
!
pTsdb
)
return
0
;
int32_t
code
=
0
;
SCommitter
commith
;
SMemTable
*
pMemTable
=
pTsdb
->
mem
;
...
...
@@ -179,22 +175,23 @@ static int32_t tsdbCommitDelStart(SCommitter *pCommitter) {
SDelFile
*
pDelFileR
=
NULL
;
// TODO
SDelFile
*
pDelFileW
=
NULL
;
// TODO
tMapDataReset
(
&
pCommitter
->
oDelIdxMap
);
tMapDataReset
(
&
pCommitter
->
nDelIdxMap
);
// load old
pCommitter
->
delIdxOld
=
(
SDelIdx
){
0
};
if
(
pDelFileR
)
{
code
=
tsdbDelFReaderOpen
(
&
pCommitter
->
pDelFReader
,
pDelFileR
,
pTsdb
,
NULL
);
if
(
code
)
{
goto
_err
;
}
code
=
tsdbReadDelIdx
(
pCommitter
->
pDelFReader
,
&
pCommitter
->
delIdxOld
,
&
pCommitter
->
pBuf1
);
code
=
tsdbReadDelIdx
(
pCommitter
->
pDelFReader
,
&
pCommitter
->
oDelIdxMap
,
&
pCommitter
->
pBuf1
);
if
(
code
)
{
goto
_err
;
}
}
// prepare new
pCommitter
->
delIdxNew
=
(
SDelIdx
){
0
};
code
=
tsdbDelFWriterOpen
(
&
pCommitter
->
pDelFWriter
,
pDelFileW
,
pTsdb
);
if
(
code
)
{
goto
_err
;
...
...
source/dnode/vnode/src/tsdb/tsdbReaderWriter.c
浏览文件 @
9f398eca
...
...
@@ -139,23 +139,29 @@ _err:
return
code
;
}
int32_t
tsdbWriteDelData
(
SDelFWriter
*
pWriter
,
SDelData
*
pDelData
,
uint8_t
**
ppBuf
,
int64_t
*
rOffset
,
int64_t
*
rSize
)
{
int32_t
tsdbWriteDelData
(
SDelFWriter
*
pWriter
,
SDelDataInfo
*
pInfo
,
SMapData
*
pDelDataMap
,
uint8_t
**
ppBuf
,
int64_t
*
rOffset
,
int64_t
*
rSize
)
{
int32_t
code
=
0
;
uint8_t
*
pBuf
=
NULL
;
int64_t
size
;
int64_t
n
;
int64_t
size
=
0
;
int64_t
n
=
0
;
// prepare
pDelData
->
delimiter
=
TSDB_FILE_DLMT
;
size
+=
tPutU32
(
NULL
,
TSDB_FILE_DLMT
);
size
+=
tPutI64
(
NULL
,
pInfo
->
suid
);
size
+=
tPutI64
(
NULL
,
pInfo
->
uid
);
size
=
size
+
tPutMapData
(
NULL
,
pDelDataMap
)
+
sizeof
(
TSCKSUM
);
// alloc
if
(
!
ppBuf
)
ppBuf
=
&
pBuf
;
size
=
tPutDelData
(
NULL
,
pDelData
)
+
sizeof
(
TSCKSUM
);
code
=
tsdbRealloc
(
ppBuf
,
size
);
if
(
code
)
goto
_err
;
// build
n
=
tPutDelData
(
*
ppBuf
,
pDelData
);
n
+=
tPutU32
(
*
ppBuf
+
n
,
TSDB_FILE_DLMT
);
n
+=
tPutI64
(
*
ppBuf
+
n
,
pInfo
->
suid
);
n
+=
tPutI64
(
*
ppBuf
+
n
,
pInfo
->
uid
);
n
+=
tPutMapData
(
*
ppBuf
+
n
,
pDelDataMap
);
taosCalcChecksumAppend
(
0
,
*
ppBuf
,
size
);
ASSERT
(
n
+
sizeof
(
TSCKSUM
)
==
size
);
...
...
@@ -184,23 +190,24 @@ _err:
return
code
;
}
int32_t
tsdbWriteDelIdx
(
SDelFWriter
*
pWriter
,
S
DelIdx
*
pDelIdx
,
uint8_t
**
ppBuf
)
{
int32_t
tsdbWriteDelIdx
(
SDelFWriter
*
pWriter
,
S
MapData
*
pDelIdxMap
,
uint8_t
**
ppBuf
)
{
int32_t
code
=
0
;
int64_t
size
;
int64_t
n
;
int64_t
size
=
0
;
int64_t
n
=
0
;
uint8_t
*
pBuf
=
NULL
;
// prepare
pDelIdx
->
delimiter
=
TSDB_FILE_DLMT
;
size
+=
tPutU32
(
NULL
,
TSDB_FILE_DLMT
);
size
=
size
+
tPutMapData
(
NULL
,
pDelIdxMap
)
+
sizeof
(
TSCKSUM
);
// alloc
if
(
!
ppBuf
)
ppBuf
=
&
pBuf
;
size
=
tPutDelIdx
(
NULL
,
pDelIdx
)
+
sizeof
(
TSCKSUM
);
code
=
tsdbRealloc
(
ppBuf
,
size
);
if
(
code
)
goto
_err
;
// build
n
=
tPutDelIdx
(
*
ppBuf
,
pDelIdx
);
n
+=
tPutU32
(
*
ppBuf
+
n
,
TSDB_FILE_DLMT
);
n
+=
tPutMapData
(
*
ppBuf
+
n
,
pDelIdxMap
);
taosCalcChecksumAppend
(
0
,
*
ppBuf
,
size
);
ASSERT
(
n
+
sizeof
(
TSCKSUM
)
==
size
);
...
...
@@ -261,7 +268,7 @@ int32_t tsdbUpdateDelFileHdr(SDelFWriter *pWriter, uint8_t **ppBuf) {
return
code
;
_err:
tsdbError
(
"vgId:%d
failed to update del file header
since %s"
,
TD_VID
(
pWriter
->
pTsdb
->
pVnode
),
tstrerror
(
code
));
tsdbError
(
"vgId:%d
update del file hdr failed
since %s"
,
TD_VID
(
pWriter
->
pTsdb
->
pVnode
),
tstrerror
(
code
));
tsdbFree
(
pBuf
);
return
code
;
}
...
...
@@ -320,6 +327,7 @@ _exit:
return
code
;
_err:
tsdbError
(
"vgId:%d del file reader open failed since %s"
,
TD_VID
(
pTsdb
->
pVnode
),
tstrerror
(
code
));
*
ppReader
=
NULL
;
return
code
;
}
...
...
@@ -339,39 +347,46 @@ _exit:
return
code
;
}
int32_t
tsdbReadDelData
(
SDelFReader
*
pReader
,
SDelIdxItem
*
pItem
,
SDelData
*
pDelData
,
uint8_t
**
ppBuf
)
{
int32_t
code
=
0
;
int64_t
n
;
int32_t
tsdbReadDelData
(
SDelFReader
*
pReader
,
SDelIdx
*
pDelIdx
,
SMapData
*
pDelDataMap
,
uint8_t
**
ppBuf
)
{
int32_t
code
=
0
;
int64_t
n
;
uint32_t
delimiter
;
SDelDataInfo
info
;
// seek
if
(
taosLSeekFile
(
pReader
->
pReadH
,
p
Item
->
offset
,
SEEK_SET
)
<
0
)
{
if
(
taosLSeekFile
(
pReader
->
pReadH
,
p
DelIdx
->
offset
,
SEEK_SET
)
<
0
)
{
code
=
TAOS_SYSTEM_ERROR
(
errno
);
goto
_err
;
}
// alloc
code
=
tsdbRealloc
(
ppBuf
,
pItem
->
size
);
if
(
!
ppBuf
)
ppBuf
=
&
pDelDataMap
->
pBuf
;
code
=
tsdbRealloc
(
ppBuf
,
pDelIdx
->
size
);
if
(
code
)
goto
_err
;
// read
n
=
taosReadFile
(
pReader
->
pReadH
,
*
ppBuf
,
p
Item
->
size
);
n
=
taosReadFile
(
pReader
->
pReadH
,
*
ppBuf
,
p
DelIdx
->
size
);
if
(
n
<
0
)
{
code
=
TAOS_SYSTEM_ERROR
(
errno
);
goto
_err
;
}
// check
if
(
!
taosCheckChecksumWhole
(
*
ppBuf
,
p
Item
->
size
))
{
if
(
!
taosCheckChecksumWhole
(
*
ppBuf
,
p
DelIdx
->
size
))
{
code
=
TSDB_CODE_FILE_CORRUPTED
;
goto
_err
;
}
// decode
n
=
tGetDelData
(
*
ppBuf
,
pDelData
);
ASSERT
(
n
+
sizeof
(
TSCKSUM
)
==
pItem
->
size
);
ASSERT
(
pDelData
->
delimiter
==
TSDB_FILE_DLMT
);
ASSERT
(
pDelData
->
suid
=
pItem
->
suid
);
ASSERT
(
pDelData
->
uid
=
pItem
->
uid
);
// // decode
n
=
0
;
n
+=
tGetU32
(
*
ppBuf
+
n
,
&
delimiter
);
ASSERT
(
delimiter
==
TSDB_FILE_DLMT
);
n
+=
tGetI64
(
*
ppBuf
+
n
,
&
info
.
suid
);
ASSERT
(
info
.
suid
==
pDelIdx
->
suid
);
n
+=
tGetI64
(
*
ppBuf
+
n
,
&
info
.
uid
);
ASSERT
(
info
.
uid
==
pDelIdx
->
uid
);
n
+=
tGetMapData
(
*
ppBuf
+
n
,
pDelDataMap
);
ASSERT
(
n
+
sizeof
(
TSCKSUM
)
==
pDelIdx
->
size
);
return
code
;
...
...
@@ -380,11 +395,12 @@ _err:
return
code
;
}
int32_t
tsdbReadDelIdx
(
SDelFReader
*
pReader
,
SDelIdx
*
pDelIdx
,
uint8_t
**
ppBuf
)
{
int32_t
code
=
0
;
int32_t
n
;
int64_t
offset
=
pReader
->
pFile
->
offset
;
int64_t
size
=
pReader
->
pFile
->
size
-
offset
;
int32_t
tsdbReadDelIdx
(
SDelFReader
*
pReader
,
SMapData
*
pDelIdxMap
,
uint8_t
**
ppBuf
)
{
int32_t
code
=
0
;
int32_t
n
;
int64_t
offset
=
pReader
->
pFile
->
offset
;
int64_t
size
=
pReader
->
pFile
->
size
-
offset
;
uint32_t
delimiter
;
ASSERT
(
ppBuf
&&
*
ppBuf
);
...
...
@@ -395,10 +411,9 @@ int32_t tsdbReadDelIdx(SDelFReader *pReader, SDelIdx *pDelIdx, uint8_t **ppBuf)
}
// alloc
if
(
!
ppBuf
)
ppBuf
=
&
pDelIdxMap
->
pBuf
;
code
=
tsdbRealloc
(
ppBuf
,
size
);
if
(
code
)
{
goto
_err
;
}
if
(
code
)
goto
_err
;
// read
if
(
taosReadFile
(
pReader
->
pReadH
,
*
ppBuf
,
size
)
<
size
)
{
...
...
@@ -413,13 +428,15 @@ int32_t tsdbReadDelIdx(SDelFReader *pReader, SDelIdx *pDelIdx, uint8_t **ppBuf)
}
// decode
n
=
tGetDelIdx
(
*
ppBuf
,
pDelIdx
);
ASSERT
(
n
==
size
-
sizeof
(
TSCKSUM
));
ASSERT
(
pDelIdx
->
delimiter
==
TSDB_FILE_DLMT
);
n
=
0
;
n
+=
tGetU32
(
*
ppBuf
+
n
,
&
delimiter
);
ASSERT
(
delimiter
==
TSDB_FILE_DLMT
);
n
+=
tGetMapData
(
*
ppBuf
+
n
,
pDelIdxMap
);
ASSERT
(
n
+
sizeof
(
TSCKSUM
)
==
size
);
return
code
;
_err:
tsdbError
(
"vgId:%d
failed to read del idx
since %s"
,
TD_VID
(
pReader
->
pTsdb
->
pVnode
),
tstrerror
(
code
));
tsdbError
(
"vgId:%d
read del idx failed
since %s"
,
TD_VID
(
pReader
->
pTsdb
->
pVnode
),
tstrerror
(
code
));
return
code
;
}
\ No newline at end of file
source/dnode/vnode/src/tsdb/tsdbUtil.c
浏览文件 @
9f398eca
...
...
@@ -207,18 +207,30 @@ int32_t tPutMapData(uint8_t *p, SMapData *pMapData) {
n
+=
tPutI32v
(
p
?
p
+
n
:
p
,
pMapData
->
nItem
);
if
(
maxOffset
<=
INT8_MAX
)
{
n
+=
tPutU8
(
p
?
p
+
n
:
p
,
TSDB_OFFSET_I8
);
for
(
int32_t
iItem
=
0
;
iItem
<
pMapData
->
nItem
;
iItem
++
)
{
n
+=
tPutI8
(
p
?
p
+
n
:
p
,
(
int8_t
)(((
int32_t
*
)
pMapData
->
pData
)[
iItem
]));
if
(
p
)
{
for
(
int32_t
iItem
=
0
;
iItem
<
pMapData
->
nItem
;
iItem
++
)
{
n
+=
tPutI8
(
p
+
n
,
(
int8_t
)(((
int32_t
*
)
pMapData
->
pData
)[
iItem
]));
}
}
else
{
n
=
n
+
sizeof
(
int8_t
)
*
pMapData
->
nItem
;
}
}
else
if
(
maxOffset
<=
INT16_MAX
)
{
n
+=
tPutU8
(
p
?
p
+
n
:
p
,
TSDB_OFFSET_I16
);
for
(
int32_t
iItem
=
0
;
iItem
<
pMapData
->
nItem
;
iItem
++
)
{
n
+=
tPutI8
(
p
?
p
+
n
:
p
,
(
int16_t
)(((
int32_t
*
)
pMapData
->
pData
)[
iItem
]));
if
(
p
)
{
for
(
int32_t
iItem
=
0
;
iItem
<
pMapData
->
nItem
;
iItem
++
)
{
n
+=
tPutI16
(
p
+
n
,
(
int16_t
)(((
int32_t
*
)
pMapData
->
pData
)[
iItem
]));
}
}
else
{
n
=
n
+
sizeof
(
int16_t
)
*
pMapData
->
nItem
;
}
}
else
{
n
+=
tPutU8
(
p
?
p
+
n
:
p
,
TSDB_OFFSET_I32
);
for
(
int32_t
iItem
=
0
;
iItem
<
pMapData
->
nItem
;
iItem
++
)
{
n
+=
tPutI8
(
p
?
p
+
n
:
p
,
(
int32_t
)(((
int32_t
*
)
pMapData
->
pData
)[
iItem
]));
if
(
p
)
{
for
(
int32_t
iItem
=
0
;
iItem
<
pMapData
->
nItem
;
iItem
++
)
{
n
+=
tPutI32
(
p
+
n
,
(
int32_t
)(((
int32_t
*
)
pMapData
->
pData
)[
iItem
]));
}
}
else
{
n
=
n
+
sizeof
(
int32_t
)
*
pMapData
->
nItem
;
}
}
n
+=
tPutBinary
(
p
?
p
+
n
:
p
,
pMapData
->
pData
,
pMapData
->
nData
);
...
...
@@ -344,36 +356,36 @@ static FORCE_INLINE int32_t tGetTSDBKEY(uint8_t *p, TSDBKEY *pKey) {
return
n
;
}
// SDelIdxItem ======================================================
static
FORCE_INLINE
int32_t
tPutDelIdxItem
(
uint8_t
*
p
,
SDelIdxItem
*
pDelIdxItem
)
{
int32_t
n
=
0
;
//
//
SDelIdxItem ======================================================
//
static FORCE_INLINE int32_t tPutDelIdxItem(uint8_t *p, SDelIdxItem *pDelIdxItem) {
//
int32_t n = 0;
n
+=
tPutI64
(
p
?
p
+
n
:
p
,
pDelIdxItem
->
suid
);
n
+=
tPutI64
(
p
?
p
+
n
:
p
,
pDelIdxItem
->
uid
);
n
+=
tPutI64
(
p
?
p
+
n
:
p
,
pDelIdxItem
->
minKey
);
n
+=
tPutI64
(
p
?
p
+
n
:
p
,
pDelIdxItem
->
maxKey
);
n
+=
tPutI64v
(
p
?
p
+
n
:
p
,
pDelIdxItem
->
minVersion
);
n
+=
tPutI64v
(
p
?
p
+
n
:
p
,
pDelIdxItem
->
maxVersion
);
n
+=
tPutI64v
(
p
?
p
+
n
:
p
,
pDelIdxItem
->
offset
);
n
+=
tPutI64v
(
p
?
p
+
n
:
p
,
pDelIdxItem
->
size
);
//
n += tPutI64(p ? p + n : p, pDelIdxItem->suid);
//
n += tPutI64(p ? p + n : p, pDelIdxItem->uid);
//
n += tPutI64(p ? p + n : p, pDelIdxItem->minKey);
//
n += tPutI64(p ? p + n : p, pDelIdxItem->maxKey);
//
n += tPutI64v(p ? p + n : p, pDelIdxItem->minVersion);
//
n += tPutI64v(p ? p + n : p, pDelIdxItem->maxVersion);
//
n += tPutI64v(p ? p + n : p, pDelIdxItem->offset);
//
n += tPutI64v(p ? p + n : p, pDelIdxItem->size);
return
n
;
}
//
return n;
//
}
static
FORCE_INLINE
int32_t
tGetDelIdxItem
(
uint8_t
*
p
,
SDelIdxItem
*
pDelIdxItem
)
{
int32_t
n
=
0
;
//
static FORCE_INLINE int32_t tGetDelIdxItem(uint8_t *p, SDelIdxItem *pDelIdxItem) {
//
int32_t n = 0;
n
+=
tGetI64
(
p
+
n
,
&
pDelIdxItem
->
suid
);
n
+=
tGetI64
(
p
+
n
,
&
pDelIdxItem
->
uid
);
n
+=
tGetI64
(
p
+
n
,
&
pDelIdxItem
->
minKey
);
n
+=
tGetI64
(
p
+
n
,
&
pDelIdxItem
->
maxKey
);
n
+=
tGetI64v
(
p
+
n
,
&
pDelIdxItem
->
minVersion
);
n
+=
tGetI64v
(
p
+
n
,
&
pDelIdxItem
->
maxVersion
);
n
+=
tGetI64v
(
p
+
n
,
&
pDelIdxItem
->
offset
);
n
+=
tGetI64v
(
p
+
n
,
&
pDelIdxItem
->
size
);
//
n += tGetI64(p + n, &pDelIdxItem->suid);
//
n += tGetI64(p + n, &pDelIdxItem->uid);
//
n += tGetI64(p + n, &pDelIdxItem->minKey);
//
n += tGetI64(p + n, &pDelIdxItem->maxKey);
//
n += tGetI64v(p + n, &pDelIdxItem->minVersion);
//
n += tGetI64v(p + n, &pDelIdxItem->maxVersion);
//
n += tGetI64v(p + n, &pDelIdxItem->offset);
//
n += tGetI64v(p + n, &pDelIdxItem->size);
return
n
;
}
//
return n;
//
}
// SBlockIdxItem ======================================================
static
FORCE_INLINE
int32_t
tPutBlockIdxItem
(
uint8_t
*
p
,
SBlockIdxItem
*
pItem
)
{
...
...
@@ -501,209 +513,219 @@ int32_t tBlockCmprFn(const void *p1, const void *p2) {
}
// SDelIdx ======================================================
int32_t
tDelIdxClear
(
SDelIdx
*
pDelIdx
)
{
int32_t
code
=
0
;
tdbFree
(
pDelIdx
->
offset
.
pOffset
);
tdbFree
(
pDelIdx
->
pData
);
return
code
;
}
//
int32_t tDelIdxClear(SDelIdx *pDelIdx) {
//
int32_t code = 0;
//
tdbFree(pDelIdx->offset.pOffset);
//
tdbFree(pDelIdx->pData);
//
return code;
//
}
int32_t
tDelIdxPutItem
(
SDelIdx
*
pDelIdx
,
SDelIdxItem
*
pItem
)
{
int32_t
code
=
0
;
uint32_t
offset
=
pDelIdx
->
nData
;
//
int32_t tDelIdxPutItem(SDelIdx *pDelIdx, SDelIdxItem *pItem) {
//
int32_t code = 0;
//
uint32_t offset = pDelIdx->nData;
// offset
code
=
tsdbAddOffset
(
&
pDelIdx
->
offset
,
offset
);
if
(
code
)
goto
_exit
;
//
// offset
//
code = tsdbAddOffset(&pDelIdx->offset, offset);
//
if (code) goto _exit;
// alloc
pDelIdx
->
nData
+=
tPutDelIdxItem
(
NULL
,
pItem
);
code
=
tsdbRealloc
(
&
pDelIdx
->
pData
,
pDelIdx
->
nData
);
if
(
code
)
goto
_exit
;
//
// alloc
//
pDelIdx->nData += tPutDelIdxItem(NULL, pItem);
//
code = tsdbRealloc(&pDelIdx->pData, pDelIdx->nData);
//
if (code) goto _exit;
// put
tPutDelIdxItem
(
pDelIdx
->
pData
+
offset
,
pItem
);
_exit:
return
code
;
}
int32_t
tDelIdxGetItemByIdx
(
SDelIdx
*
pDelIdx
,
SDelIdxItem
*
pItem
,
int32_t
idx
)
{
int32_t
code
=
0
;
int32_t
offset
;
// // put
// tPutDelIdxItem(pDelIdx->pData + offset, pItem);
offset
=
tsdbGetOffset
(
&
pDelIdx
->
offset
,
idx
);
if
(
offset
<
0
)
{
code
=
TSDB_CODE_NOT_FOUND
;
goto
_exit
;
}
// _exit:
// return code;
// }
tGetDelIdxItem
(
pDelIdx
->
pData
+
offset
,
pItem
);
// int32_t tDelIdxGetItemByIdx(SDelIdx *pDelIdx, SDelIdxItem *pItem, int32_t idx) {
// int32_t code = 0;
// int32_t offset;
_exit:
return
code
;
}
int32_t
tDelIdxGetItem
(
SDelIdx
*
pDelIdx
,
SDelIdxItem
*
pItem
,
TABLEID
id
)
{
int32_t
code
=
0
;
int32_t
lidx
=
0
;
int32_t
ridx
=
pDelIdx
->
offset
.
nOffset
-
1
;
int32_t
midx
;
int32_t
c
;
// offset = tsdbGetOffset(&pDelIdx->offset, idx);
// if (offset < 0) {
// code = TSDB_CODE_NOT_FOUND;
// goto _exit;
// }
while
(
lidx
<=
ridx
)
{
midx
=
(
lidx
+
ridx
)
/
2
;
// tGetDelIdxItem(pDelIdx->pData + offset, pItem);
code
=
tDelIdxGetItemByIdx
(
pDelIdx
,
pItem
,
midx
);
if
(
code
)
goto
_exit
;
// _exit:
// return code;
// }
c
=
tTABLEIDCmprFn
(
&
id
,
pItem
);
if
(
c
==
0
)
{
goto
_exit
;
}
else
if
(
c
<
0
)
{
ridx
=
midx
-
1
;
}
else
{
lidx
=
midx
+
1
;
}
}
// int32_t tDelIdxGetItem(SDelIdx *pDelIdx, SDelIdxItem *pItem, TABLEID id) {
// int32_t code = 0;
// int32_t lidx = 0;
// int32_t ridx = pDelIdx->offset.nOffset - 1;
// int32_t midx;
// int32_t c;
// while (lidx <= ridx) {
// midx = (lidx + ridx) / 2;
// code = tDelIdxGetItemByIdx(pDelIdx, pItem, midx);
// if (code) goto _exit;
// c = tTABLEIDCmprFn(&id, pItem);
// if (c == 0) {
// goto _exit;
// } else if (c < 0) {
// ridx = midx - 1;
// } else {
// lidx = midx + 1;
// }
// }
code
=
TSDB_CODE_NOT_FOUND
;
//
code = TSDB_CODE_NOT_FOUND;
_exit:
return
code
;
}
//
_exit:
//
return code;
//
}
int32_t
tPutDelIdx
(
uint8_t
*
p
,
SDelIdx
*
pDelIdx
)
{
int32_t
n
=
0
;
int32_t
tPutDelIdx
(
uint8_t
*
p
,
void
*
ph
)
{
SDelIdx
*
pDelIdx
=
(
SDelIdx
*
)
ph
;
int32_t
n
=
0
;
n
+=
tPutU32
(
p
?
p
+
n
:
p
,
pDelIdx
->
delimiter
);
n
+=
tPutOffset
(
p
?
p
+
n
:
p
,
&
pDelIdx
->
offset
);
n
+=
tPutBinary
(
p
?
p
+
n
:
p
,
pDelIdx
->
pData
,
pDelIdx
->
nData
);
n
+=
tPutI64
(
p
?
p
+
n
:
p
,
pDelIdx
->
suid
);
n
+=
tPutI64
(
p
?
p
+
n
:
p
,
pDelIdx
->
uid
);
n
+=
tPutI64
(
p
?
p
+
n
:
p
,
pDelIdx
->
minKey
);
n
+=
tPutI64
(
p
?
p
+
n
:
p
,
pDelIdx
->
maxKey
);
n
+=
tPutI64v
(
p
?
p
+
n
:
p
,
pDelIdx
->
minVersion
);
n
+=
tPutI64v
(
p
?
p
+
n
:
p
,
pDelIdx
->
maxVersion
);
n
+=
tPutI64v
(
p
?
p
+
n
:
p
,
pDelIdx
->
offset
);
n
+=
tPutI64v
(
p
?
p
+
n
:
p
,
pDelIdx
->
size
);
return
n
;
}
int32_t
tGetDelIdx
(
uint8_t
*
p
,
SDelIdx
*
pDelIdx
)
{
int32_t
n
=
0
;
int32_t
tGetDelIdx
(
uint8_t
*
p
,
void
*
ph
)
{
SDelIdx
*
pDelIdx
=
(
SDelIdx
*
)
ph
;
int32_t
n
=
0
;
n
+=
tGetU32
(
p
+
n
,
&
pDelIdx
->
delimiter
);
n
+=
tGetOffset
(
p
+
n
,
&
pDelIdx
->
offset
);
n
+=
tGetBinary
(
p
+
n
,
&
pDelIdx
->
pData
,
&
pDelIdx
->
nData
);
n
+=
tGetI64
(
p
+
n
,
&
pDelIdx
->
suid
);
n
+=
tGetI64
(
p
+
n
,
&
pDelIdx
->
uid
);
n
+=
tGetI64
(
p
+
n
,
&
pDelIdx
->
minKey
);
n
+=
tGetI64
(
p
+
n
,
&
pDelIdx
->
maxKey
);
n
+=
tGetI64v
(
p
+
n
,
&
pDelIdx
->
minVersion
);
n
+=
tGetI64v
(
p
+
n
,
&
pDelIdx
->
maxVersion
);
n
+=
tGetI64v
(
p
+
n
,
&
pDelIdx
->
offset
);
n
+=
tGetI64v
(
p
+
n
,
&
pDelIdx
->
size
);
return
n
;
}
// SDelDataItem ======================================================
static
FORCE_INLINE
int32_t
tPutDelDataItem
(
uint8_t
*
p
,
SDelDataItem
*
pItem
)
{
int32_t
n
=
0
;
//
//
SDelDataItem ======================================================
//
static FORCE_INLINE int32_t tPutDelDataItem(uint8_t *p, SDelDataItem *pItem) {
//
int32_t n = 0;
n
+=
tPutI64v
(
p
?
p
+
n
:
p
,
pItem
->
version
);
n
+=
tPutI64
(
p
?
p
+
n
:
p
,
pItem
->
sKey
);
n
+=
tPutI64
(
p
?
p
+
n
:
p
,
pItem
->
eKey
);
//
n += tPutI64v(p ? p + n : p, pItem->version);
//
n += tPutI64(p ? p + n : p, pItem->sKey);
//
n += tPutI64(p ? p + n : p, pItem->eKey);
return
n
;
}
//
return n;
//
}
static
FORCE_INLINE
int32_t
tGetDelDataItem
(
uint8_t
*
p
,
SDelDataItem
*
pItem
)
{
int32_t
n
=
0
;
//
static FORCE_INLINE int32_t tGetDelDataItem(uint8_t *p, SDelDataItem *pItem) {
//
int32_t n = 0;
n
+=
tGetI64v
(
p
+
n
,
&
pItem
->
version
);
n
+=
tGetI64
(
p
+
n
,
&
pItem
->
sKey
);
n
+=
tGetI64
(
p
+
n
,
&
pItem
->
eKey
);
//
n += tGetI64v(p + n, &pItem->version);
//
n += tGetI64(p + n, &pItem->sKey);
//
n += tGetI64(p + n, &pItem->eKey);
return
n
;
}
//
return n;
//
}
// SDelData ======================================================
int32_t
tDelDataClear
(
SDelData
*
pDelData
)
{
int32_t
code
=
0
;
tsdbFree
(
pDelData
->
offset
.
pOffset
);
tsdbFree
(
pDelData
->
pData
);
return
code
;
}
int32_t
tDelDataPutItem
(
SDelData
*
pDelData
,
SDelDataItem
*
pItem
)
{
int32_t
code
=
0
;
uint32_t
offset
=
pDelData
->
nData
;
// offset
code
=
tsdbAddOffset
(
&
pDelData
->
offset
,
offset
);
if
(
code
)
goto
_exit
;
// alloc
pDelData
->
nData
+=
tPutDelDataItem
(
NULL
,
pItem
);
code
=
tsdbRealloc
(
&
pDelData
->
pData
,
pDelData
->
nData
);
if
(
code
)
goto
_exit
;
// int32_t tDelDataClear(SDelData *pDelData) {
// int32_t code = 0;
// tsdbFree(pDelData->offset.pOffset);
// tsdbFree(pDelData->pData);
// return code;
// }
// put
tPutDelDataItem
(
pDelData
->
pData
+
offset
,
pItem
);
// int32_t tDelDataPutItem(SDelData *pDelData, SDelDataItem *pItem) {
// int32_t code = 0;
// uint32_t offset = pDelData->nData;
_exit:
return
code
;
}
// // offset
// code = tsdbAddOffset(&pDelData->offset, offset)
;
// if (code) goto _exit;
int32_t
tDelDataGetItemByIdx
(
SDelData
*
pDelData
,
SDelDataItem
*
pItem
,
int32_t
idx
)
{
int32_t
code
=
0
;
int32_t
offset
;
// // alloc
// pDelData->nData += tPutDelDataItem(NULL, pItem);
// code = tsdbRealloc(&pDelData->pData, pDelData->nData);
// if (code) goto _exit;
offset
=
tsdbGetOffset
(
&
pDelData
->
offset
,
idx
);
if
(
offset
<
0
)
{
code
=
TSDB_CODE_NOT_FOUND
;
goto
_exit
;
}
tGetDelDataItem
(
pDelData
->
pData
+
offset
,
pItem
);
// // put
// tPutDelDataItem(pDelData->pData + offset, pItem);
_exit:
return
code
;
}
//
_exit:
//
return code;
//
}
int32_t
tDelDataGetItem
(
SDelData
*
pDelData
,
SDelDataItem
*
pItem
,
int64_t
version
)
{
int32_t
code
=
0
;
int32_t
lidx
=
0
;
int32_t
ridx
=
pDelData
->
offset
.
nOffset
-
1
;
int32_t
midx
;
// int32_t tDelDataGetItemByIdx(SDelData *pDelData, SDelDataItem *pItem, int32_t idx) {
// int32_t code = 0;
// int32_t offset;
while
(
lidx
<=
ridx
)
{
midx
=
(
lidx
+
ridx
)
/
2
;
// offset = tsdbGetOffset(&pDelData->offset, idx);
// if (offset < 0) {
// code = TSDB_CODE_NOT_FOUND;
// goto _exit;
// }
// tGetDelDataItem(pDelData->pData + offset, pItem);
code
=
tDelDataGetItemByIdx
(
pDelData
,
pItem
,
midx
);
if
(
code
)
goto
_exit
;
// _exit:
// return code;
// }
if
(
version
==
pItem
->
version
)
{
goto
_exit
;
}
else
if
(
version
<
pItem
->
version
)
{
ridx
=
midx
-
1
;
}
else
{
ridx
=
midx
+
1
;
}
}
// int32_t tDelDataGetItem(SDelData *pDelData, SDelDataItem *pItem, int64_t version) {
// int32_t code = 0;
// int32_t lidx = 0;
// int32_t ridx = pDelData->offset.nOffset - 1;
// int32_t midx;
// while (lidx <= ridx) {
// midx = (lidx + ridx) / 2;
// code = tDelDataGetItemByIdx(pDelData, pItem, midx);
// if (code) goto _exit;
// if (version == pItem->version) {
// goto _exit;
// } else if (version < pItem->version) {
// ridx = midx - 1;
// } else {
// ridx = midx + 1;
// }
// }
code
=
TSDB_CODE_NOT_FOUND
;
//
code = TSDB_CODE_NOT_FOUND;
_exit:
return
code
;
}
//
_exit:
//
return code;
//
}
int32_t
tPutDelData
(
uint8_t
*
p
,
SDelData
*
pDelData
)
{
int32_t
n
=
0
;
int32_t
tPutDelData
(
uint8_t
*
p
,
void
*
ph
)
{
SDelData
*
pDelData
=
(
SDelData
*
)
ph
;
int32_t
n
=
0
;
n
+=
tPutU32
(
p
?
p
+
n
:
p
,
pDelData
->
delimiter
);
n
+=
tPutI64
(
p
?
p
+
n
:
p
,
pDelData
->
suid
);
n
+=
tPutI64
(
p
?
p
+
n
:
p
,
pDelData
->
uid
);
n
+=
tPutOffset
(
p
?
p
+
n
:
p
,
&
pDelData
->
offset
);
n
+=
tPutBinary
(
p
?
p
+
n
:
p
,
pDelData
->
pData
,
pDelData
->
nData
);
n
+=
tPutI64v
(
p
?
p
+
n
:
p
,
pDelData
->
version
);
n
+=
tPutI64
(
p
?
p
+
n
:
p
,
pDelData
->
sKey
);
n
+=
tPutI64
(
p
?
p
+
n
:
p
,
pDelData
->
eKey
);
return
n
;
}
int32_t
tGetDelData
(
uint8_t
*
p
,
SDelData
*
pDelData
)
{
int32_t
n
=
0
;
int32_t
tGetDelData
(
uint8_t
*
p
,
void
*
ph
)
{
SDelData
*
pDelData
=
(
SDelData
*
)
ph
;
int32_t
n
=
0
;
n
+=
tGetU32
(
p
+
n
,
&
pDelData
->
delimiter
);
n
+=
tGetI64
(
p
+
n
,
&
pDelData
->
suid
);
n
+=
tGetI64
(
p
+
n
,
&
pDelData
->
uid
);
n
+=
tGetOffset
(
p
+
n
,
&
pDelData
->
offset
);
n
+=
tGetBinary
(
p
+
n
,
&
pDelData
->
pData
,
&
pDelData
->
nData
);
n
+=
tGetI64v
(
p
+
n
,
&
pDelData
->
version
);
n
+=
tGetI64
(
p
+
n
,
&
pDelData
->
sKey
);
n
+=
tGetI64
(
p
+
n
,
&
pDelData
->
eKey
);
return
n
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录