Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
3f5b1415
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看板
提交
3f5b1415
编写于
4月 16, 2020
作者:
H
hzcheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
TD-100
上级
a85c04c0
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
29 addition
and
77 deletion
+29
-77
src/util/src/tutil.c
src/util/src/tutil.c
+8
-2
src/vnode/tsdb/inc/tsdbMain.h
src/vnode/tsdb/inc/tsdbMain.h
+3
-3
src/vnode/tsdb/src/tsdbRWHelper.c
src/vnode/tsdb/src/tsdbRWHelper.c
+18
-72
未找到文件。
src/util/src/tutil.c
浏览文件 @
3f5b1415
...
...
@@ -710,11 +710,13 @@ void *tcalloc(size_t nmemb, size_t size) {
return
ret
;
}
size_t
tsizeof
(
void
*
ptr
)
{
return
*
(
size_t
*
)((
char
*
)
ptr
-
sizeof
(
size_t
))
;
}
size_t
tsizeof
(
void
*
ptr
)
{
return
(
ptr
)
?
(
*
(
size_t
*
)((
char
*
)
ptr
-
sizeof
(
size_t
)))
:
0
;
}
void
tmemset
(
void
*
ptr
,
int
c
)
{
memset
(
ptr
,
c
,
tsizeof
(
ptr
));
}
void
*
trealloc
(
void
*
ptr
,
size_t
size
)
{
if
(
ptr
==
NULL
)
return
tmalloc
(
size
);
if
(
size
<=
tsizeof
(
ptr
))
return
ptr
;
void
*
tptr
=
(
void
*
)((
char
*
)
ptr
-
sizeof
(
size_t
));
...
...
@@ -727,4 +729,8 @@ void * trealloc(void *ptr, size_t size) {
return
(
void
*
)((
char
*
)
tptr
+
sizeof
(
size_t
));
}
void
tzfree
(
void
*
ptr
)
{
free
((
void
*
)((
char
*
)
ptr
-
sizeof
(
size_t
)));
}
\ No newline at end of file
void
tzfree
(
void
*
ptr
)
{
if
(
ptr
)
{
free
((
void
*
)((
char
*
)
ptr
-
sizeof
(
size_t
)));
}
}
\ No newline at end of file
src/vnode/tsdb/inc/tsdbMain.h
浏览文件 @
3f5b1415
...
...
@@ -388,17 +388,17 @@ typedef struct {
// For file set usage
SHelperFile
files
;
SCompIdx
*
pCompIdx
;
size_t
compIdxSize
;
//
size_t compIdxSize;
// For table set usage
SHelperTable
tableInfo
;
SCompInfo
*
pCompInfo
;
size_t
compInfoSize
;
//
size_t compInfoSize;
bool
hasOldLastBlock
;
// For block set usage
SCompData
*
pCompData
;
size_t
compDataSize
;
//
size_t compDataSize;
SDataCols
*
pDataCols
[
2
];
}
SRWHelper
;
...
...
src/vnode/tsdb/src/tsdbRWHelper.c
浏览文件 @
3f5b1415
...
...
@@ -52,8 +52,9 @@ static void tsdbResetHelperFileImpl(SRWHelper *pHelper) {
}
static
int
tsdbInitHelperFile
(
SRWHelper
*
pHelper
)
{
pHelper
->
compIdxSize
=
sizeof
(
SCompIdx
)
*
pHelper
->
config
.
maxTables
+
sizeof
(
TSCKSUM
);
pHelper
->
pCompIdx
=
(
SCompIdx
*
)
malloc
(
pHelper
->
compIdxSize
);
// pHelper->compIdxSize = sizeof(SCompIdx) * pHelper->config.maxTables + sizeof(TSCKSUM);
size_t
tsize
=
sizeof
(
SCompIdx
)
*
pHelper
->
config
.
maxTables
+
sizeof
(
TSCKSUM
);
pHelper
->
pCompIdx
=
(
SCompIdx
*
)
tmalloc
(
tsize
);
if
(
pHelper
->
pCompIdx
==
NULL
)
return
-
1
;
tsdbResetHelperFileImpl
(
pHelper
);
...
...
@@ -62,7 +63,7 @@ static int tsdbInitHelperFile(SRWHelper *pHelper) {
static
void
tsdbDestroyHelperFile
(
SRWHelper
*
pHelper
)
{
tsdbCloseHelperFile
(
pHelper
,
false
);
tfree
(
pHelper
->
pCompIdx
);
t
z
free
(
pHelper
->
pCompIdx
);
}
// ---------- Operations on Helper Table part
...
...
@@ -75,7 +76,7 @@ static void tsdbInitHelperTable(SRWHelper *pHelper) {
tsdbResetHelperTableImpl
(
pHelper
);
}
static
void
tsdbDestroyHelperTable
(
SRWHelper
*
pHelper
)
{
return
;
}
static
void
tsdbDestroyHelperTable
(
SRWHelper
*
pHelper
)
{
tzfree
((
void
*
)
pHelper
->
pCompInfo
)
;
}
// ---------- Operations on Helper Block part
static
void
tsdbResetHelperBlockImpl
(
SRWHelper
*
pHelper
)
{
...
...
@@ -94,6 +95,7 @@ static int tsdbInitHelperBlock(SRWHelper *pHelper) {
}
static
void
tsdbDestroyHelperBlock
(
SRWHelper
*
pHelper
)
{
tzfree
(
pHelper
->
pCompData
);
tdFreeDataCols
(
pHelper
->
pDataCols
[
0
]);
tdFreeDataCols
(
pHelper
->
pDataCols
[
1
]);
}
...
...
@@ -377,7 +379,7 @@ int tsdbWriteCompInfo(SRWHelper *pHelper) {
int
tsdbWriteCompIdx
(
SRWHelper
*
pHelper
)
{
if
(
lseek
(
pHelper
->
files
.
nHeadF
.
fd
,
TSDB_FILE_HEAD_SIZE
,
SEEK_SET
)
<
0
)
return
-
1
;
if
(
twrite
(
pHelper
->
files
.
nHeadF
.
fd
,
(
void
*
)
pHelper
->
pCompIdx
,
pHelper
->
compIdxSize
)
<
pHelper
->
compIdxSize
)
if
(
twrite
(
pHelper
->
files
.
nHeadF
.
fd
,
(
void
*
)
pHelper
->
pCompIdx
,
tsizeof
(
pHelper
->
pCompIdx
))
<
tsizeof
(
pHelper
->
pCompIdx
)
)
return
-
1
;
return
0
;
}
...
...
@@ -390,13 +392,13 @@ int tsdbLoadCompIdx(SRWHelper *pHelper, void *target) {
int
fd
=
pHelper
->
files
.
headF
.
fd
;
if
(
lseek
(
fd
,
TSDB_FILE_HEAD_SIZE
,
SEEK_SET
)
<
0
)
return
-
1
;
if
(
tread
(
fd
,
(
void
*
)(
pHelper
->
pCompIdx
),
pHelper
->
compIdxSize
)
<
pHelper
->
compIdxSize
)
return
-
1
;
if
(
tread
(
fd
,
(
void
*
)(
pHelper
->
pCompIdx
),
tsizeof
(
pHelper
->
pCompIdx
))
<
tsizeof
(
pHelper
->
pCompIdx
)
)
return
-
1
;
// TODO: check the correctness of the part
}
helperSetState
(
pHelper
,
TSDB_HELPER_IDX_LOAD
);
// Copy the memory for outside usage
if
(
target
)
memcpy
(
target
,
pHelper
->
pCompIdx
,
pHelper
->
compIdxSize
);
if
(
target
)
memcpy
(
target
,
pHelper
->
pCompIdx
,
tsizeof
(
pHelper
->
pCompIdx
)
);
return
0
;
}
...
...
@@ -415,7 +417,8 @@ int tsdbLoadCompInfo(SRWHelper *pHelper, void *target) {
if
(
!
helperHasState
(
pHelper
,
TSDB_HELPER_INFO_LOAD
))
{
if
(
lseek
(
fd
,
pIdx
->
offset
,
SEEK_SET
)
<
0
)
return
-
1
;
adjustMem
(
pHelper
->
pCompInfo
,
pHelper
->
compInfoSize
,
pIdx
->
len
);
// adjustMem(pHelper->pCompInfo, pHelper->compInfoSize, pIdx->len);
pHelper
->
pCompInfo
=
trealloc
((
void
*
)
pHelper
->
pCompInfo
,
pIdx
->
len
);
if
(
tread
(
fd
,
(
void
*
)(
pHelper
->
pCompInfo
),
pIdx
->
len
)
<
pIdx
->
len
)
return
-
1
;
// TODO: check the checksum
...
...
@@ -433,9 +436,9 @@ int tsdbLoadCompData(SRWHelper *pHelper, SCompBlock *pCompBlock, void *target) {
if
(
lseek
(
fd
,
pCompBlock
->
offset
,
SEEK_SET
)
<
0
)
return
-
1
;
size_t
tsize
=
sizeof
(
SCompData
)
+
sizeof
(
SCompCol
)
*
pCompBlock
->
numOfCols
;
adjustMem
(
pHelper
->
pCompData
,
pHelper
->
compDataSize
,
tsize
);
size_t
tsize
=
sizeof
(
SCompData
)
+
sizeof
(
SCompCol
)
*
pCompBlock
->
numOfCols
+
sizeof
(
TSCKSUM
)
;
pHelper
->
pCompData
=
trealloc
((
void
*
)
pHelper
->
pCompData
,
tsize
);
if
(
pHelper
->
pCompData
==
NULL
)
return
-
1
;
if
(
tread
(
fd
,
(
void
*
)
pHelper
->
pCompData
,
tsize
)
<
tsize
)
return
-
1
;
ASSERT
(
pCompBlock
->
numOfCols
==
pHelper
->
pCompData
->
numOfCols
);
...
...
@@ -860,73 +863,16 @@ static int tsdbMergeDataWithBlock(SRWHelper *pHelper, int blkIdx, SDataCols *pDa
static
int
compTSKEY
(
const
void
*
key1
,
const
void
*
key2
)
{
return
((
TSKEY
*
)
key1
-
(
TSKEY
*
)
key2
);
}
// Get the number of rows the data can be merged into the block
// static int tsdbGetRowsCanBeMergedWithBlock(SRWHelper *pHelper, int blkIdx, SDataCols *pDataCols) {
// int rowsCanMerge = 0;
// TSKEY keyFirst = dataColsKeyFirst(pDataCols);
// SCompIdx * pIdx = pHelper->pCompIdx + pHelper->tableInfo.tid;
// SCompBlock *pCompBlock = pHelper->pCompInfo->blocks + blkIdx;
// ASSERT(blkIdx < pIdx->numOfSuperBlocks);
// TSKEY keyMax = (blkIdx < pIdx->numOfSuperBlocks + 1) ? (pCompBlock + 1)->keyFirst - 1 : pHelper->files.maxKey;
// if (keyFirst > pCompBlock->keyLast) {
// void *ptr = taosbsearch((void *)(&keyMax), pDataCols->cols[0].pData, pDataCols->numOfPoints, sizeof(TSKEY),
// compTSKEY, TD_LE);
// ASSERT(ptr != NULL);
// rowsCanMerge =
// MIN((TSKEY *)ptr - (TSKEY *)pDataCols->cols[0].pData, pHelper->config.minRowsPerFileBlock - pCompBlock->numOfPoints);
// } else {
// int32_t colId[1] = {0};
// if (tsdbLoadBlockDataCols(pHelper, NULL, blkIdx, colId, 1) < 0) goto _err;
// int iter1 = 0; // For pDataCols
// int iter2 = 0; // For loaded data cols
// while (1) {
// if (iter1 >= pDataCols->numOfPoints || iter2 >= pHelper->pDataCols[0]->numOfPoints) break;
// if (pCompBlock->numOfPoints + rowsCanMerge >= pHelper->config.maxRowsPerFileBlock) break;
// TSKEY key1 = dataColsKeyAt(pDataCols, iter1);
// TSKEY key2 = dataColsKeyAt(pHelper->pDataCols[0], iter2);
// if (key1 > keyMax) break;
// if (key1 < key2) {
// iter1++;
// } else if (key1 == key2) {
// iter1++;
// iter2++;
// } else {
// iter2++;
// rowsCanMerge++;
// }
// }
// }
// return rowsCanMerge;
// _err:
// return -1;
// }
static
int
tsdbAdjustInfoSizeIfNeeded
(
SRWHelper
*
pHelper
,
size_t
spaceNeeded
)
{
SCompIdx
*
pIdx
=
pHelper
->
pCompIdx
+
pHelper
->
tableInfo
.
tid
;
size_t
spaceLeft
=
pHelper
->
compInfoSize
-
pIdx
->
len
;
size_t
spaceLeft
=
tsizeof
((
void
*
)
pHelper
->
pCompInfo
)
-
pIdx
->
len
;
ASSERT
(
spaceLeft
>=
0
);
if
(
spaceLeft
<
spaceNeeded
)
{
size_t
tsize
=
pHelper
->
compInfoSize
+
sizeof
(
SCompBlock
)
*
16
;
if
(
pHelper
->
compInfoSize
==
0
)
tsize
+=
sizeof
(
SCompInfo
);
pHelper
->
pCompInfo
=
(
SCompInfo
*
)
realloc
((
void
*
)(
pHelper
->
pCompInfo
),
tsize
);
if
(
pHelper
->
pCompInfo
==
NULL
)
return
-
1
;
size_t
tsize
=
tsizeof
(
pHelper
->
pCompInfo
)
+
sizeof
(
SCompBlock
)
*
16
;
if
(
tsizeof
(
pHelper
->
pCompInfo
)
==
0
)
tsize
+=
sizeof
(
SCompInfo
);
pHelper
->
compInfoSize
=
tsize
;
pHelper
->
pCompInfo
=
(
SCompInfo
*
)
trealloc
(
pHelper
->
pCompInfo
,
tsize
)
;
}
return
0
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录