Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
5b1492cb
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
5b1492cb
编写于
6月 25, 2023
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refact code
上级
c161943f
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
200 addition
and
177 deletion
+200
-177
source/dnode/vnode/src/tsdb/tsdbDataFileRW.c
source/dnode/vnode/src/tsdb/tsdbDataFileRW.c
+71
-101
source/dnode/vnode/src/tsdb/tsdbSttFileRW.c
source/dnode/vnode/src/tsdb/tsdbSttFileRW.c
+119
-73
source/dnode/vnode/src/tsdb/tsdbUpgrade.c
source/dnode/vnode/src/tsdb/tsdbUpgrade.c
+10
-3
未找到文件。
source/dnode/vnode/src/tsdb/tsdbDataFileRW.c
浏览文件 @
5b1492cb
...
...
@@ -25,6 +25,11 @@ typedef struct {
SFDataPtr
rsrvd
[
2
];
}
STombFooter
;
extern
int32_t
tsdbFileDoWriteTombBlock
(
STsdbFD
*
fd
,
STombBlock
*
tombBlock
,
int8_t
cmprAlg
,
int64_t
*
fileSize
,
TTombBlkArray
*
tombBlkArray
,
uint8_t
**
bufArr
);
extern
int32_t
tsdbFileDoWriteTombBlk
(
STsdbFD
*
fd
,
const
TTombBlkArray
*
tombBlkArray
,
SFDataPtr
*
ptr
,
int64_t
*
fileSize
);
// SDataFileReader =============================================
struct
SDataFileReader
{
SDataFileReaderConfig
config
[
1
];
...
...
@@ -644,81 +649,89 @@ _exit:
return
code
;
}
static
int32_t
tsdbDataFileWriteBrinBlock
(
SDataFileWriter
*
writer
)
{
if
(
BRIN_BLOCK_SIZE
(
writer
->
brinBlock
)
==
0
)
return
0
;
int32_t
tsdbFileWriteBrinBlock
(
STsdbFD
*
fd
,
SBrinBlock
*
brinBlock
,
int8_t
cmprAlg
,
int64_t
*
fileSize
,
TBrinBlkArray
*
brinBlkArray
,
uint8_t
**
bufArr
)
{
if
(
BRIN_BLOCK_SIZE
(
brinBlock
)
==
0
)
return
0
;
int32_t
code
=
0
;
int32_t
lino
=
0
;
int32_t
code
;
// get SBrinBlk
SBrinBlk
brinBlk
[
1
]
=
{
{
.
dp
[
0
]
=
{
.
offset
=
writer
->
files
[
TSDB_FTYPE_HEAD
].
s
ize
,
.
offset
=
*
fileS
ize
,
.
size
=
0
,
},
.
minTbid
=
{
.
suid
=
TARRAY2_FIRST
(
writer
->
brinBlock
->
suid
),
.
uid
=
TARRAY2_FIRST
(
writer
->
brinBlock
->
uid
),
.
suid
=
TARRAY2_FIRST
(
brinBlock
->
suid
),
.
uid
=
TARRAY2_FIRST
(
brinBlock
->
uid
),
},
.
maxTbid
=
{
.
suid
=
TARRAY2_LAST
(
writer
->
brinBlock
->
suid
),
.
uid
=
TARRAY2_LAST
(
writer
->
brinBlock
->
uid
),
.
suid
=
TARRAY2_LAST
(
brinBlock
->
suid
),
.
uid
=
TARRAY2_LAST
(
brinBlock
->
uid
),
},
.
minVer
=
TARRAY2_FIRST
(
writer
->
brinBlock
->
minVer
),
.
maxVer
=
TARRAY2_FIRST
(
writer
->
brinBlock
->
minVer
),
.
numRec
=
BRIN_BLOCK_SIZE
(
writer
->
brinBlock
),
.
cmprAlg
=
writer
->
config
->
cmprAlg
,
.
minVer
=
TARRAY2_FIRST
(
brinBlock
->
minVer
),
.
maxVer
=
TARRAY2_FIRST
(
brinBlock
->
minVer
),
.
numRec
=
BRIN_BLOCK_SIZE
(
brinBlock
),
.
cmprAlg
=
cmprAlg
,
},
};
for
(
int32_t
i
=
1
;
i
<
BRIN_BLOCK_SIZE
(
writer
->
brinBlock
);
i
++
)
{
if
(
brinBlk
->
minVer
>
TARRAY2_GET
(
writer
->
brinBlock
->
minVer
,
i
))
{
brinBlk
->
minVer
=
TARRAY2_GET
(
writer
->
brinBlock
->
minVer
,
i
);
for
(
int32_t
i
=
1
;
i
<
BRIN_BLOCK_SIZE
(
brinBlock
);
i
++
)
{
if
(
brinBlk
->
minVer
>
TARRAY2_GET
(
brinBlock
->
minVer
,
i
))
{
brinBlk
->
minVer
=
TARRAY2_GET
(
brinBlock
->
minVer
,
i
);
}
if
(
brinBlk
->
maxVer
<
TARRAY2_GET
(
writer
->
brinBlock
->
maxVer
,
i
))
{
brinBlk
->
maxVer
=
TARRAY2_GET
(
writer
->
brinBlock
->
maxVer
,
i
);
if
(
brinBlk
->
maxVer
<
TARRAY2_GET
(
brinBlock
->
maxVer
,
i
))
{
brinBlk
->
maxVer
=
TARRAY2_GET
(
brinBlock
->
maxVer
,
i
);
}
}
// write to file
for
(
int32_t
i
=
0
;
i
<
ARRAY_SIZE
(
writer
->
brinBlock
->
dataArr1
);
i
++
)
{
code
=
tsdbCmprData
((
uint8_t
*
)
TARRAY2_DATA
(
writer
->
brinBlock
->
dataArr1
+
i
),
TARRAY2_DATA_LEN
(
writer
->
brinBlock
->
dataArr1
+
i
),
TSDB_DATA_TYPE_BIGINT
,
brinBlk
->
cmprAlg
,
&
writer
->
config
->
bufArr
[
0
],
0
,
&
brinBlk
->
size
[
i
],
&
writer
->
config
->
bufArr
[
1
]);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
for
(
int32_t
i
=
0
;
i
<
ARRAY_SIZE
(
brinBlock
->
dataArr1
);
i
++
)
{
code
=
tsdbCmprData
((
uint8_t
*
)
TARRAY2_DATA
(
brinBlock
->
dataArr1
+
i
),
TARRAY2_DATA_LEN
(
brinBlock
->
dataArr1
+
i
),
TSDB_DATA_TYPE_BIGINT
,
brinBlk
->
cmprAlg
,
&
bufArr
[
0
],
0
,
&
brinBlk
->
size
[
i
],
&
bufArr
[
1
]);
if
(
code
)
return
code
;
code
=
tsdbWriteFile
(
writer
->
fd
[
TSDB_FTYPE_HEAD
],
writer
->
files
[
TSDB_FTYPE_HEAD
].
size
,
writer
->
config
->
bufArr
[
0
],
brinBlk
->
size
[
i
]);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
code
=
tsdbWriteFile
(
fd
,
*
fileSize
,
bufArr
[
0
],
brinBlk
->
size
[
i
]);
if
(
code
)
return
code
;
brinBlk
->
dp
->
size
+=
brinBlk
->
size
[
i
];
writer
->
files
[
TSDB_FTYPE_HEAD
].
s
ize
+=
brinBlk
->
size
[
i
];
*
fileS
ize
+=
brinBlk
->
size
[
i
];
}
for
(
int32_t
i
=
0
,
j
=
ARRAY_SIZE
(
writer
->
brinBlock
->
dataArr1
);
i
<
ARRAY_SIZE
(
writer
->
brinBlock
->
dataArr2
);
i
++
,
j
++
)
{
code
=
tsdbCmprData
((
uint8_t
*
)
TARRAY2_DATA
(
writer
->
brinBlock
->
dataArr2
+
i
),
TARRAY2_DATA_LEN
(
writer
->
brinBlock
->
dataArr2
+
i
),
TSDB_DATA_TYPE_INT
,
brinBlk
->
cmprAlg
,
&
writer
->
config
->
bufArr
[
0
],
0
,
&
brinBlk
->
size
[
j
],
&
writer
->
config
->
bufArr
[
1
]);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
for
(
int32_t
i
=
0
,
j
=
ARRAY_SIZE
(
brinBlock
->
dataArr1
);
i
<
ARRAY_SIZE
(
brinBlock
->
dataArr2
);
i
++
,
j
++
)
{
code
=
tsdbCmprData
((
uint8_t
*
)
TARRAY2_DATA
(
brinBlock
->
dataArr2
+
i
),
TARRAY2_DATA_LEN
(
brinBlock
->
dataArr2
+
i
),
TSDB_DATA_TYPE_INT
,
brinBlk
->
cmprAlg
,
&
bufArr
[
0
],
0
,
&
brinBlk
->
size
[
j
],
&
bufArr
[
1
]);
if
(
code
)
return
code
;
code
=
tsdbWriteFile
(
writer
->
fd
[
TSDB_FTYPE_HEAD
],
writer
->
files
[
TSDB_FTYPE_HEAD
].
size
,
writer
->
config
->
bufArr
[
0
],
brinBlk
->
size
[
j
]);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
code
=
tsdbWriteFile
(
fd
,
*
fileSize
,
bufArr
[
0
],
brinBlk
->
size
[
j
]);
if
(
code
)
return
code
;
brinBlk
->
dp
->
size
+=
brinBlk
->
size
[
j
];
writer
->
files
[
TSDB_FTYPE_HEAD
].
s
ize
+=
brinBlk
->
size
[
j
];
*
fileS
ize
+=
brinBlk
->
size
[
j
];
}
// append to brinBlkArray
code
=
TARRAY2_APPEND_PTR
(
writer
->
brinBlkArray
,
brinBlk
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
)
;
code
=
TARRAY2_APPEND_PTR
(
brinBlkArray
,
brinBlk
);
if
(
code
)
return
code
;
tBrinBlockClear
(
writer
->
brinBlock
);
tBrinBlockClear
(
brinBlock
);
return
0
;
}
static
int32_t
tsdbDataFileWriteBrinBlock
(
SDataFileWriter
*
writer
)
{
if
(
BRIN_BLOCK_SIZE
(
writer
->
brinBlock
)
==
0
)
return
0
;
int32_t
code
=
0
;
int32_t
lino
=
0
;
code
=
tsdbFileWriteBrinBlock
(
writer
->
fd
[
TSDB_FTYPE_HEAD
],
writer
->
brinBlock
,
writer
->
config
->
cmprAlg
,
&
writer
->
files
[
TSDB_FTYPE_HEAD
].
size
,
writer
->
brinBlkArray
,
writer
->
config
->
bufArr
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
_exit:
if
(
code
)
{
...
...
@@ -1154,53 +1167,10 @@ static int32_t tsdbDataFileDoWriteTombBlock(SDataFileWriter *writer) {
int32_t
code
=
0
;
int32_t
lino
=
0
;
STombBlk
tombBlk
[
1
]
=
{{
.
numRec
=
TOMB_BLOCK_SIZE
(
writer
->
tombBlock
),
.
minTbid
=
{
.
suid
=
TARRAY2_FIRST
(
writer
->
tombBlock
->
suid
),
.
uid
=
TARRAY2_FIRST
(
writer
->
tombBlock
->
uid
),
},
.
maxTbid
=
{
.
suid
=
TARRAY2_LAST
(
writer
->
tombBlock
->
suid
),
.
uid
=
TARRAY2_LAST
(
writer
->
tombBlock
->
uid
),
},
.
minVer
=
TARRAY2_FIRST
(
writer
->
tombBlock
->
version
),
.
maxVer
=
TARRAY2_FIRST
(
writer
->
tombBlock
->
version
),
.
dp
[
0
]
=
{
.
offset
=
writer
->
files
[
TSDB_FTYPE_TOMB
].
size
,
.
size
=
0
,
},
}};
for
(
int32_t
i
=
1
;
i
<
TOMB_BLOCK_SIZE
(
writer
->
tombBlock
);
i
++
)
{
tombBlk
->
minVer
=
TMIN
(
tombBlk
->
minVer
,
TARRAY2_GET
(
writer
->
tombBlock
->
version
,
i
));
tombBlk
->
maxVer
=
TMAX
(
tombBlk
->
maxVer
,
TARRAY2_GET
(
writer
->
tombBlock
->
version
,
i
));
}
for
(
int32_t
i
=
0
;
i
<
ARRAY_SIZE
(
writer
->
tombBlock
->
dataArr
);
i
++
)
{
int32_t
size
;
code
=
tsdbCmprData
((
uint8_t
*
)
TARRAY2_DATA
(
&
writer
->
tombBlock
->
dataArr
[
i
]),
TARRAY2_DATA_LEN
(
&
writer
->
tombBlock
->
dataArr
[
i
]),
TSDB_DATA_TYPE_BIGINT
,
TWO_STAGE_COMP
,
&
writer
->
config
->
bufArr
[
0
],
0
,
&
size
,
&
writer
->
config
->
bufArr
[
1
]);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
code
=
tsdbWriteFile
(
writer
->
fd
[
TSDB_FTYPE_TOMB
],
writer
->
files
[
TSDB_FTYPE_TOMB
].
size
,
writer
->
config
->
bufArr
[
0
],
size
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
tombBlk
->
size
[
i
]
=
size
;
tombBlk
->
dp
[
0
].
size
+=
size
;
writer
->
files
[
TSDB_FTYPE_TOMB
].
size
+=
size
;
}
code
=
TARRAY2_APPEND_PTR
(
writer
->
tombBlkArray
,
tombBlk
);
code
=
tsdbFileDoWriteTombBlock
(
writer
->
fd
[
TSDB_FTYPE_TOMB
],
writer
->
tombBlock
,
writer
->
config
->
cmprAlg
,
&
writer
->
files
[
TSDB_FTYPE_TOMB
].
size
,
writer
->
tombBlkArray
,
writer
->
config
->
bufArr
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
tTombBlockClear
(
writer
->
tombBlock
);
_exit:
if
(
code
)
{
TSDB_ERROR_LOG
(
TD_VID
(
writer
->
config
->
tsdb
->
pVnode
),
lino
,
code
);
...
...
@@ -1214,14 +1184,9 @@ static int32_t tsdbDataFileDoWriteTombBlk(SDataFileWriter *writer) {
int32_t
code
=
0
;
int32_t
lino
=
0
;
int32_t
ftype
=
TSDB_FTYPE_TOMB
;
writer
->
tombFooter
->
tombBlkPtr
->
offset
=
writer
->
files
[
ftype
].
size
;
writer
->
tombFooter
->
tombBlkPtr
->
size
=
TARRAY2_DATA_LEN
(
writer
->
tombBlkArray
);
code
=
tsdbWriteFile
(
writer
->
fd
[
ftype
],
writer
->
tombFooter
->
tombBlkPtr
->
offset
,
(
const
uint8_t
*
)
TARRAY2_DATA
(
writer
->
tombBlkArray
),
writer
->
tombFooter
->
tombBlkPtr
->
size
);
code
=
tsdbFileDoWriteTombBlk
(
writer
->
fd
[
TSDB_FTYPE_TOMB
],
writer
->
tombBlkArray
,
writer
->
tombFooter
->
tombBlkPtr
,
&
writer
->
files
[
TSDB_FTYPE_TOMB
].
size
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
writer
->
files
[
ftype
].
size
+=
writer
->
tombFooter
->
tombBlkPtr
->
size
;
_exit:
if
(
code
)
{
...
...
@@ -1306,20 +1271,25 @@ _exit:
return
code
;
}
static
int32_t
tsdbDataFileWriteBrinBlk
(
SDataFileWriter
*
writer
)
{
ASSERT
(
TARRAY2_SIZE
(
writer
->
brinBlkArray
)
>
0
);
int32_t
tsdbFileWriteBrinBlk
(
STsdbFD
*
fd
,
TBrinBlkArray
*
brinBlkArray
,
SFDataPtr
*
ptr
,
int64_t
*
fileSize
)
{
ASSERT
(
TARRAY2_SIZE
(
brinBlkArray
)
>
0
);
ptr
->
offset
=
*
fileSize
;
ptr
->
size
=
TARRAY2_DATA_LEN
(
brinBlkArray
);
int32_t
code
=
tsdbWriteFile
(
fd
,
ptr
->
offset
,
(
uint8_t
*
)
TARRAY2_DATA
(
brinBlkArray
),
ptr
->
size
);
if
(
code
)
return
code
;
*
fileSize
+=
ptr
->
size
;
return
0
;
}
static
int32_t
tsdbDataFileWriteBrinBlk
(
SDataFileWriter
*
writer
)
{
int32_t
code
=
0
;
int32_t
lino
=
0
;
int32_t
ftype
=
TSDB_FTYPE_HEAD
;
writer
->
headFooter
->
brinBlkPtr
->
offset
=
writer
->
files
[
ftype
].
size
;
writer
->
headFooter
->
brinBlkPtr
->
size
=
TARRAY2_DATA_LEN
(
writer
->
brinBlkArray
);
code
=
tsdbWriteFile
(
writer
->
fd
[
ftype
],
writer
->
headFooter
->
brinBlkPtr
->
offset
,
(
uint8_t
*
)
TARRAY2_DATA
(
writer
->
brinBlkArray
),
writer
->
headFooter
->
brinBlkPtr
->
size
);
code
=
tsdbFileWriteBrinBlk
(
writer
->
fd
[
TSDB_FTYPE_HEAD
],
writer
->
brinBlkArray
,
writer
->
headFooter
->
brinBlkPtr
,
&
writer
->
files
[
TSDB_FTYPE_HEAD
].
size
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
writer
->
files
[
ftype
].
size
+=
writer
->
headFooter
->
brinBlkPtr
->
size
;
_exit:
if
(
code
)
{
...
...
source/dnode/vnode/src/tsdb/tsdbSttFileRW.c
浏览文件 @
5b1492cb
...
...
@@ -402,50 +402,63 @@ struct SSttFileWriter {
uint8_t
*
bufArr
[
5
];
};
static
int32_t
tsdbSttFileDoWriteBlockData
(
SSttFileWriter
*
writer
)
{
if
(
writer
->
blockData
->
nRow
==
0
)
return
0
;
int32_t
tsdbFileDoWriteBlockData
(
STsdbFD
*
fd
,
SBlockData
*
blockData
,
int8_t
cmprAlg
,
int64_t
*
fileSize
,
TSttBlkArray
*
sttBlkArray
,
uint8_t
**
bufArr
)
{
if
(
blockData
->
nRow
==
0
)
return
0
;
int32_t
code
=
0
;
int32_t
lino
=
0
;
SSttBlk
sttBlk
[
1
]
=
{{
.
suid
=
writer
->
blockData
->
suid
,
.
minUid
=
writer
->
blockData
->
uid
?
writer
->
blockData
->
uid
:
writer
->
blockData
->
aUid
[
0
],
.
maxUid
=
writer
->
blockData
->
uid
?
writer
->
blockData
->
uid
:
writer
->
blockData
->
aUid
[
writer
->
blockData
->
nRow
-
1
],
.
minKey
=
writer
->
blockData
->
aTSKEY
[
0
],
.
maxKey
=
writer
->
blockData
->
aTSKEY
[
0
],
.
minVer
=
writer
->
blockData
->
aVersion
[
0
],
.
maxVer
=
writer
->
blockData
->
aVersion
[
0
],
.
nRow
=
writer
->
blockData
->
nRow
,
.
suid
=
blockData
->
suid
,
.
minUid
=
blockData
->
uid
?
blockData
->
uid
:
blockData
->
aUid
[
0
],
.
maxUid
=
blockData
->
uid
?
blockData
->
uid
:
blockData
->
aUid
[
blockData
->
nRow
-
1
],
.
minKey
=
blockData
->
aTSKEY
[
0
],
.
maxKey
=
blockData
->
aTSKEY
[
0
],
.
minVer
=
blockData
->
aVersion
[
0
],
.
maxVer
=
blockData
->
aVersion
[
0
],
.
nRow
=
blockData
->
nRow
,
}};
for
(
int32_t
iRow
=
1
;
iRow
<
writer
->
blockData
->
nRow
;
iRow
++
)
{
if
(
sttBlk
->
minKey
>
writer
->
blockData
->
aTSKEY
[
iRow
])
sttBlk
->
minKey
=
writer
->
blockData
->
aTSKEY
[
iRow
];
if
(
sttBlk
->
maxKey
<
writer
->
blockData
->
aTSKEY
[
iRow
])
sttBlk
->
maxKey
=
writer
->
blockData
->
aTSKEY
[
iRow
];
if
(
sttBlk
->
minVer
>
writer
->
blockData
->
aVersion
[
iRow
])
sttBlk
->
minVer
=
writer
->
blockData
->
aVersion
[
iRow
];
if
(
sttBlk
->
maxVer
<
writer
->
blockData
->
aVersion
[
iRow
])
sttBlk
->
maxVer
=
writer
->
blockData
->
aVersion
[
iRow
];
for
(
int32_t
iRow
=
1
;
iRow
<
blockData
->
nRow
;
iRow
++
)
{
if
(
sttBlk
->
minKey
>
blockData
->
aTSKEY
[
iRow
])
sttBlk
->
minKey
=
blockData
->
aTSKEY
[
iRow
];
if
(
sttBlk
->
maxKey
<
blockData
->
aTSKEY
[
iRow
])
sttBlk
->
maxKey
=
blockData
->
aTSKEY
[
iRow
];
if
(
sttBlk
->
minVer
>
blockData
->
aVersion
[
iRow
])
sttBlk
->
minVer
=
blockData
->
aVersion
[
iRow
];
if
(
sttBlk
->
maxVer
<
blockData
->
aVersion
[
iRow
])
sttBlk
->
maxVer
=
blockData
->
aVersion
[
iRow
];
}
int32_t
sizeArr
[
5
]
=
{
0
};
code
=
tCmprBlockData
(
writer
->
blockData
,
writer
->
config
->
cmprAlg
,
NULL
,
NULL
,
writer
->
config
->
bufArr
,
sizeArr
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
)
;
code
=
tCmprBlockData
(
blockData
,
cmprAlg
,
NULL
,
NULL
,
bufArr
,
sizeArr
);
if
(
code
)
return
code
;
sttBlk
->
bInfo
.
offset
=
writer
->
file
->
s
ize
;
sttBlk
->
bInfo
.
offset
=
*
fileS
ize
;
sttBlk
->
bInfo
.
szKey
=
sizeArr
[
2
]
+
sizeArr
[
3
];
sttBlk
->
bInfo
.
szBlock
=
sizeArr
[
0
]
+
sizeArr
[
1
]
+
sttBlk
->
bInfo
.
szKey
;
for
(
int32_t
i
=
3
;
i
>=
0
;
i
--
)
{
if
(
sizeArr
[
i
])
{
code
=
tsdbWriteFile
(
writer
->
fd
,
writer
->
file
->
size
,
writer
->
config
->
bufArr
[
i
],
sizeArr
[
i
]);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
)
;
writer
->
file
->
s
ize
+=
sizeArr
[
i
];
code
=
tsdbWriteFile
(
fd
,
*
fileSize
,
bufArr
[
i
],
sizeArr
[
i
]);
if
(
code
)
return
code
;
*
fileS
ize
+=
sizeArr
[
i
];
}
}
code
=
TARRAY2_APPEND_PTR
(
writer
->
sttBlkArray
,
sttBlk
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
code
=
TARRAY2_APPEND_PTR
(
sttBlkArray
,
sttBlk
);
if
(
code
)
return
code
;
tBlockDataClear
(
blockData
);
tBlockDataClear
(
writer
->
blockData
);
return
0
;
}
static
int32_t
tsdbSttFileDoWriteBlockData
(
SSttFileWriter
*
writer
)
{
if
(
writer
->
blockData
->
nRow
==
0
)
return
0
;
int32_t
code
=
0
;
int32_t
lino
=
0
;
code
=
tsdbFileDoWriteBlockData
(
writer
->
fd
,
writer
->
blockData
,
writer
->
config
->
cmprAlg
,
&
writer
->
file
->
size
,
writer
->
sttBlkArray
,
writer
->
config
->
bufArr
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
_exit:
if
(
code
)
{
...
...
@@ -516,60 +529,71 @@ _exit:
return
code
;
}
static
int32_t
tsdbSttFileDoWriteTombBlock
(
SSttFileWriter
*
writer
)
{
if
(
TOMB_BLOCK_SIZE
(
writer
->
tombBlock
)
==
0
)
return
0
;
int32_t
tsdbFileDoWriteTombBlock
(
STsdbFD
*
fd
,
STombBlock
*
tombBlock
,
int8_t
cmprAlg
,
int64_t
*
fileSize
,
TTombBlkArray
*
tombBlkArray
,
uint8_t
**
bufArr
)
{
int32_t
code
;
int32_t
code
=
0
;
int32_t
lino
=
0
;
if
(
TOMB_BLOCK_SIZE
(
tombBlock
)
==
0
)
return
0
;
STombBlk
tombBlk
[
1
]
=
{{
.
dp
[
0
]
=
{
.
offset
=
writer
->
file
->
s
ize
,
.
offset
=
*
fileS
ize
,
.
size
=
0
,
},
.
minTbid
=
{
.
suid
=
TARRAY2_FIRST
(
writer
->
tombBlock
->
suid
),
.
uid
=
TARRAY2_FIRST
(
writer
->
tombBlock
->
uid
),
.
suid
=
TARRAY2_FIRST
(
tombBlock
->
suid
),
.
uid
=
TARRAY2_FIRST
(
tombBlock
->
uid
),
},
.
maxTbid
=
{
.
suid
=
TARRAY2_LAST
(
writer
->
tombBlock
->
suid
),
.
uid
=
TARRAY2_LAST
(
writer
->
tombBlock
->
uid
),
.
suid
=
TARRAY2_LAST
(
tombBlock
->
suid
),
.
uid
=
TARRAY2_LAST
(
tombBlock
->
uid
),
},
.
minVer
=
TARRAY2_FIRST
(
writer
->
tombBlock
->
version
),
.
maxVer
=
TARRAY2_FIRST
(
writer
->
tombBlock
->
version
),
.
numRec
=
TOMB_BLOCK_SIZE
(
writer
->
tombBlock
),
.
cmprAlg
=
writer
->
config
->
cmprAlg
,
.
minVer
=
TARRAY2_FIRST
(
tombBlock
->
version
),
.
maxVer
=
TARRAY2_FIRST
(
tombBlock
->
version
),
.
numRec
=
TOMB_BLOCK_SIZE
(
tombBlock
),
.
cmprAlg
=
cmprAlg
,
}};
for
(
int32_t
i
=
1
;
i
<
TOMB_BLOCK_SIZE
(
writer
->
tombBlock
);
i
++
)
{
if
(
tombBlk
->
minVer
>
TARRAY2_GET
(
writer
->
tombBlock
->
version
,
i
))
{
tombBlk
->
minVer
=
TARRAY2_GET
(
writer
->
tombBlock
->
version
,
i
);
for
(
int32_t
i
=
1
;
i
<
TOMB_BLOCK_SIZE
(
tombBlock
);
i
++
)
{
if
(
tombBlk
->
minVer
>
TARRAY2_GET
(
tombBlock
->
version
,
i
))
{
tombBlk
->
minVer
=
TARRAY2_GET
(
tombBlock
->
version
,
i
);
}
if
(
tombBlk
->
maxVer
<
TARRAY2_GET
(
writer
->
tombBlock
->
version
,
i
))
{
tombBlk
->
maxVer
=
TARRAY2_GET
(
writer
->
tombBlock
->
version
,
i
);
if
(
tombBlk
->
maxVer
<
TARRAY2_GET
(
tombBlock
->
version
,
i
))
{
tombBlk
->
maxVer
=
TARRAY2_GET
(
tombBlock
->
version
,
i
);
}
}
for
(
int32_t
i
=
0
;
i
<
ARRAY_SIZE
(
writer
->
tombBlock
->
dataArr
);
i
++
)
{
code
=
tsdbCmprData
((
uint8_t
*
)
TARRAY2_DATA
(
&
writer
->
tombBlock
->
dataArr
[
i
]),
TARRAY2_DATA_LEN
(
&
writer
->
tombBlock
->
dataArr
[
i
]),
TSDB_DATA_TYPE_BIGINT
,
tombBlk
->
cmprAlg
,
&
writer
->
config
->
bufArr
[
0
],
0
,
&
tombBlk
->
size
[
i
],
&
writer
->
config
->
bufArr
[
1
]);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
for
(
int32_t
i
=
0
;
i
<
ARRAY_SIZE
(
tombBlock
->
dataArr
);
i
++
)
{
code
=
tsdbCmprData
((
uint8_t
*
)
TARRAY2_DATA
(
&
tombBlock
->
dataArr
[
i
]),
TARRAY2_DATA_LEN
(
&
tombBlock
->
dataArr
[
i
]),
TSDB_DATA_TYPE_BIGINT
,
tombBlk
->
cmprAlg
,
&
bufArr
[
0
],
0
,
&
tombBlk
->
size
[
i
],
&
bufArr
[
1
]);
if
(
code
)
return
code
;
code
=
tsdbWriteFile
(
writer
->
fd
,
writer
->
file
->
size
,
writer
->
config
->
bufArr
[
0
],
tombBlk
->
size
[
i
]);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
)
;
code
=
tsdbWriteFile
(
fd
,
*
fileSize
,
bufArr
[
0
],
tombBlk
->
size
[
i
]);
if
(
code
)
return
code
;
tombBlk
->
dp
->
size
+=
tombBlk
->
size
[
i
];
writer
->
file
->
s
ize
+=
tombBlk
->
size
[
i
];
*
fileS
ize
+=
tombBlk
->
size
[
i
];
}
code
=
TARRAY2_APPEND_PTR
(
writer
->
tombBlkArray
,
tombBlk
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
)
;
code
=
TARRAY2_APPEND_PTR
(
tombBlkArray
,
tombBlk
);
if
(
code
)
return
code
;
tTombBlockClear
(
writer
->
tombBlock
);
tTombBlockClear
(
tombBlock
);
return
0
;
}
static
int32_t
tsdbSttFileDoWriteTombBlock
(
SSttFileWriter
*
writer
)
{
if
(
TOMB_BLOCK_SIZE
(
writer
->
tombBlock
)
==
0
)
return
0
;
int32_t
code
=
0
;
int32_t
lino
=
0
;
code
=
tsdbFileDoWriteTombBlock
(
writer
->
fd
,
writer
->
tombBlock
,
writer
->
config
->
cmprAlg
,
&
writer
->
file
->
size
,
writer
->
tombBlkArray
,
writer
->
config
->
bufArr
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
_exit:
if
(
code
)
{
...
...
@@ -578,18 +602,27 @@ _exit:
return
code
;
}
int32_t
tsdbFileDoWriteSttBlk
(
STsdbFD
*
fd
,
const
TSttBlkArray
*
sttBlkArray
,
SFDataPtr
*
ptr
,
int64_t
*
fileSize
)
{
ptr
->
size
=
TARRAY2_DATA_LEN
(
sttBlkArray
);
if
(
ptr
->
size
>
0
)
{
ptr
->
offset
=
*
fileSize
;
int32_t
code
=
tsdbWriteFile
(
fd
,
*
fileSize
,
(
const
uint8_t
*
)
TARRAY2_DATA
(
sttBlkArray
),
ptr
->
size
);
if
(
code
)
{
return
code
;
}
*
fileSize
+=
ptr
->
size
;
}
return
0
;
}
static
int32_t
tsdbSttFileDoWriteSttBlk
(
SSttFileWriter
*
writer
)
{
int32_t
code
=
0
;
int32_t
lino
;
writer
->
footer
->
sttBlkPtr
->
size
=
TARRAY2_DATA_LEN
(
writer
->
sttBlkArray
);
if
(
writer
->
footer
->
sttBlkPtr
->
size
)
{
writer
->
footer
->
sttBlkPtr
->
offset
=
writer
->
file
->
size
;
code
=
tsdbWriteFile
(
writer
->
fd
,
writer
->
file
->
size
,
(
const
uint8_t
*
)
TARRAY2_DATA
(
writer
->
sttBlkArray
),
writer
->
footer
->
sttBlkPtr
->
size
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
writer
->
file
->
size
+=
writer
->
footer
->
sttBlkPtr
->
size
;
}
code
=
tsdbFileDoWriteSttBlk
(
writer
->
fd
,
writer
->
sttBlkArray
,
writer
->
footer
->
sttBlkPtr
,
&
writer
->
file
->
size
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
_exit:
if
(
code
)
{
...
...
@@ -618,18 +651,27 @@ _exit:
return
code
;
}
int32_t
tsdbFileDoWriteTombBlk
(
STsdbFD
*
fd
,
const
TTombBlkArray
*
tombBlkArray
,
SFDataPtr
*
ptr
,
int64_t
*
fileSize
)
{
ptr
->
size
=
TARRAY2_DATA_LEN
(
tombBlkArray
);
if
(
ptr
->
size
>
0
)
{
ptr
->
offset
=
*
fileSize
;
int32_t
code
=
tsdbWriteFile
(
fd
,
*
fileSize
,
(
const
uint8_t
*
)
TARRAY2_DATA
(
tombBlkArray
),
ptr
->
size
);
if
(
code
)
{
return
code
;
}
*
fileSize
+=
ptr
->
size
;
}
return
0
;
}
static
int32_t
tsdbSttFileDoWriteTombBlk
(
SSttFileWriter
*
writer
)
{
int32_t
code
=
0
;
int32_t
lino
=
0
;
writer
->
footer
->
tombBlkPtr
->
size
=
TARRAY2_DATA_LEN
(
writer
->
tombBlkArray
);
if
(
writer
->
footer
->
tombBlkPtr
->
size
)
{
writer
->
footer
->
tombBlkPtr
->
offset
=
writer
->
file
->
size
;
code
=
tsdbWriteFile
(
writer
->
fd
,
writer
->
file
->
size
,
(
const
uint8_t
*
)
TARRAY2_DATA
(
writer
->
tombBlkArray
),
writer
->
footer
->
tombBlkPtr
->
size
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
writer
->
file
->
size
+=
writer
->
footer
->
tombBlkPtr
->
size
;
}
code
=
tsdbFileDoWriteTombBlk
(
writer
->
fd
,
writer
->
tombBlkArray
,
writer
->
footer
->
tombBlkPtr
,
&
writer
->
file
->
size
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
_exit:
if
(
code
)
{
...
...
@@ -638,13 +680,17 @@ _exit:
return
code
;
}
static
int32_t
tsdbSttFileDoWriteFooter
(
SSttFileWriter
*
writer
)
{
int32_t
code
=
tsdbWriteFile
(
writer
->
fd
,
writer
->
file
->
size
,
(
const
uint8_t
*
)
writer
->
footer
,
sizeof
(
writer
->
footer
));
int32_t
tsdbSttFileDoWriteFooterImpl
(
STsdbFD
*
fd
,
const
SSttFooter
*
footer
,
int64_t
*
fileSize
)
{
int32_t
code
=
tsdbWriteFile
(
fd
,
*
fileSize
,
(
const
uint8_t
*
)
footer
,
sizeof
(
*
footer
));
if
(
code
)
return
code
;
writer
->
file
->
size
+=
sizeof
(
writer
->
footer
);
*
fileSize
+=
sizeof
(
*
footer
);
return
0
;
}
static
int32_t
tsdbSttFileDoWriteFooter
(
SSttFileWriter
*
writer
)
{
return
tsdbSttFileDoWriteFooterImpl
(
writer
->
fd
,
writer
->
footer
,
&
writer
->
file
->
size
);
}
static
int32_t
tsdbSttFWriterDoOpen
(
SSttFileWriter
*
writer
)
{
int32_t
code
=
0
;
int32_t
lino
=
0
;
...
...
source/dnode/vnode/src/tsdb/tsdbUpgrade.c
浏览文件 @
5b1492cb
...
...
@@ -202,11 +202,15 @@ static int32_t tsdbDumpTombDataToFSet(STsdb *tsdb, SDelFReader *reader, SArray *
}
if
(
fd
)
{
// write footer
// sync and close
code
=
tsdbFsyncFile
(
fd
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
tsdbCloseFile
(
&
fd
);
}
// clear
TARRAY2_DESTROY
(
tombBlkArray
,
NULL
);
tTombBlockDestroy
(
tombBlock
);
taosArrayDestroy
(
aDelData
);
...
...
@@ -260,10 +264,11 @@ static int32_t tsdbDoUpgradeFileSystem(STsdb *tsdb, int8_t rollback) {
TFileSetArray
fileSetArray
[
1
]
=
{
0
};
//
load old file system and convert
//
open old file system
code
=
tsdbFSOpen
(
tsdb
,
rollback
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
// upgrade each file set
for
(
int32_t
i
=
0
;
i
<
taosArrayGetSize
(
tsdb
->
fs
.
aDFileSet
);
i
++
)
{
SDFileSet
*
pDFileSet
=
taosArrayGet
(
tsdb
->
fs
.
aDFileSet
,
i
);
...
...
@@ -271,21 +276,23 @@ static int32_t tsdbDoUpgradeFileSystem(STsdb *tsdb, int8_t rollback) {
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
}
// upgrade tomb file
if
(
tsdb
->
fs
.
pDelFile
!=
NULL
)
{
code
=
tsdbUpgradeTombFile
(
tsdb
,
tsdb
->
fs
.
pDelFile
,
fileSetArray
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
}
// close file system
code
=
tsdbFSClose
(
tsdb
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
// save new file system
char
fname
[
TSDB_FILENAME_LEN
];
current_fname
(
tsdb
,
fname
,
TSDB_FCURRENT
);
code
=
save_fs
(
fileSetArray
,
fname
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
// clear
TARRAY2_DESTROY
(
fileSetArray
,
tsdbTFileSetClear
);
_exit:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录