Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
51de627d
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看板
提交
51de627d
编写于
7月 27, 2021
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TD-5574]<hotfix>: fix change KV row value coredump
上级
b993a059
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
31 addition
and
53 deletion
+31
-53
src/common/inc/tdataformat.h
src/common/inc/tdataformat.h
+1
-0
src/common/src/tdataformat.c
src/common/src/tdataformat.c
+30
-53
未找到文件。
src/common/inc/tdataformat.h
浏览文件 @
51de627d
...
@@ -351,6 +351,7 @@ typedef struct {
...
@@ -351,6 +351,7 @@ typedef struct {
#define kvRowColIdxAt(r, i) (kvRowColIdx(r) + (i))
#define kvRowColIdxAt(r, i) (kvRowColIdx(r) + (i))
#define kvRowFree(r) tfree(r)
#define kvRowFree(r) tfree(r)
#define kvRowEnd(r) POINTER_SHIFT(r, kvRowLen(r))
#define kvRowEnd(r) POINTER_SHIFT(r, kvRowLen(r))
#define kvRowValLen(r) (kvRowLen(r) - TD_KV_ROW_HEAD_SIZE - sizeof(SColIdx) * kvRowNCols(r))
SKVRow
tdKVRowDup
(
SKVRow
row
);
SKVRow
tdKVRowDup
(
SKVRow
row
);
int
tdSetKVRowDataOfCol
(
SKVRow
*
orow
,
int16_t
colId
,
int8_t
type
,
void
*
value
);
int
tdSetKVRowDataOfCol
(
SKVRow
*
orow
,
int16_t
colId
,
int8_t
type
,
void
*
value
);
...
...
src/common/src/tdataformat.c
浏览文件 @
51de627d
...
@@ -553,42 +553,28 @@ int tdSetKVRowDataOfCol(SKVRow *orow, int16_t colId, int8_t type, void *value) {
...
@@ -553,42 +553,28 @@ int tdSetKVRowDataOfCol(SKVRow *orow, int16_t colId, int8_t type, void *value) {
SKVRow
nrow
=
NULL
;
SKVRow
nrow
=
NULL
;
void
*
ptr
=
taosbsearch
(
&
colId
,
kvRowColIdx
(
row
),
kvRowNCols
(
row
),
sizeof
(
SColIdx
),
comparTagId
,
TD_GE
);
void
*
ptr
=
taosbsearch
(
&
colId
,
kvRowColIdx
(
row
),
kvRowNCols
(
row
),
sizeof
(
SColIdx
),
comparTagId
,
TD_GE
);
if
(
ptr
==
NULL
||
((
SColIdx
*
)
ptr
)
->
colId
>
colId
)
{
// need to add a column value to the row
if
(
ptr
==
NULL
||
((
SColIdx
*
)
ptr
)
->
colId
>
colId
)
{
// need to add a column value to the row
int
diff
=
IS_VAR_DATA_TYPE
(
type
)
?
varDataTLen
(
value
)
:
TYPE_BYTES
[
type
];
int
diff
=
IS_VAR_DATA_TYPE
(
type
)
?
varDataTLen
(
value
)
:
TYPE_BYTES
[
type
];
nrow
=
malloc
(
kvRowLen
(
row
)
+
sizeof
(
SColIdx
)
+
diff
);
int
nRowLen
=
kvRowLen
(
row
)
+
sizeof
(
SColIdx
)
+
diff
;
int
oRowCols
=
kvRowNCols
(
row
);
ASSERT
(
diff
>
0
);
nrow
=
malloc
(
nRowLen
);
if
(
nrow
==
NULL
)
return
-
1
;
if
(
nrow
==
NULL
)
return
-
1
;
kvRowSetLen
(
nrow
,
kvRowLen
(
row
)
+
(
int16_t
)
sizeof
(
SColIdx
)
+
diff
);
kvRowSetLen
(
nrow
,
nRowLen
);
kvRowSetNCols
(
nrow
,
kvRowNCols
(
row
)
+
1
);
kvRowSetNCols
(
nrow
,
oRowCols
+
1
);
if
(
ptr
==
NULL
)
{
memcpy
(
kvRowColIdx
(
nrow
),
kvRowColIdx
(
row
),
sizeof
(
SColIdx
)
*
oRowCols
);
memcpy
(
kvRowColIdx
(
nrow
),
kvRowColIdx
(
row
),
sizeof
(
SColIdx
)
*
kvRowNCols
(
row
));
memcpy
(
kvRowValues
(
nrow
),
kvRowValues
(
row
),
kvRowValLen
(
row
));
memcpy
(
kvRowValues
(
nrow
),
kvRowValues
(
row
),
POINTER_DISTANCE
(
kvRowEnd
(
row
),
kvRowValues
(
row
)));
int
colIdx
=
kvRowNCols
(
nrow
)
-
1
;
kvRowColIdxAt
(
nrow
,
colIdx
)
->
colId
=
colId
;
kvRowColIdxAt
(
nrow
,
colIdx
)
->
offset
=
(
int16_t
)(
POINTER_DISTANCE
(
kvRowEnd
(
row
),
kvRowValues
(
row
)));
memcpy
(
kvRowColVal
(
nrow
,
kvRowColIdxAt
(
nrow
,
colIdx
)),
value
,
diff
);
}
else
{
int16_t
tlen
=
(
int16_t
)(
POINTER_DISTANCE
(
ptr
,
kvRowColIdx
(
row
)));
if
(
tlen
>
0
)
{
memcpy
(
kvRowColIdx
(
nrow
),
kvRowColIdx
(
row
),
tlen
);
memcpy
(
kvRowValues
(
nrow
),
kvRowValues
(
row
),
((
SColIdx
*
)
ptr
)
->
offset
);
}
int
colIdx
=
tlen
/
sizeof
(
SColIdx
);
pColIdx
=
kvRowColIdxAt
(
nrow
,
oRowCols
);
kvRowColIdxAt
(
nrow
,
colIdx
)
->
colId
=
colId
;
pColIdx
->
colId
=
colId
;
kvRowColIdxAt
(
nrow
,
colIdx
)
->
offset
=
((
SColIdx
*
)
ptr
)
->
offset
;
pColIdx
->
offset
=
kvRowValLen
(
row
);
memcpy
(
kvRowColVal
(
nrow
,
kvRowColIdxAt
(
nrow
,
colIdx
)),
value
,
diff
);
for
(
int
i
=
colIdx
;
i
<
kvRowNCols
(
row
);
i
++
)
{
memcpy
(
kvRowColVal
(
nrow
,
pColIdx
),
value
,
diff
);
// copy new value
kvRowColIdxAt
(
nrow
,
i
+
1
)
->
colId
=
kvRowColIdxAt
(
row
,
i
)
->
colId
;
kvRowColIdxAt
(
nrow
,
i
+
1
)
->
offset
=
kvRowColIdxAt
(
row
,
i
)
->
offset
+
diff
;
}
memcpy
(
kvRowColVal
(
nrow
,
kvRowColIdxAt
(
nrow
,
colIdx
+
1
)),
kvRowColVal
(
row
,
kvRowColIdxAt
(
row
,
colIdx
)),
POINTER_DISTANCE
(
kvRowEnd
(
row
),
kvRowColVal
(
row
,
kvRowColIdxAt
(
row
,
colIdx
)))
);
tdSortKVRowByColIdx
(
nrow
);
}
*
orow
=
nrow
;
*
orow
=
nrow
;
free
(
row
);
free
(
row
);
...
@@ -599,9 +585,8 @@ int tdSetKVRowDataOfCol(SKVRow *orow, int16_t colId, int8_t type, void *value) {
...
@@ -599,9 +585,8 @@ int tdSetKVRowDataOfCol(SKVRow *orow, int16_t colId, int8_t type, void *value) {
if
(
varDataTLen
(
value
)
==
varDataTLen
(
pOldVal
))
{
// just update the column value in place
if
(
varDataTLen
(
value
)
==
varDataTLen
(
pOldVal
))
{
// just update the column value in place
memcpy
(
pOldVal
,
value
,
varDataTLen
(
value
));
memcpy
(
pOldVal
,
value
,
varDataTLen
(
value
));
}
else
{
// need to reallocate the memory
}
else
{
// need to reallocate the memory
int16_t
diff
=
varDataTLen
(
value
)
-
varDataTLen
(
pOldVal
);
int16_t
nlen
=
kvRowLen
(
row
)
+
(
varDataTLen
(
value
)
-
varDataTLen
(
pOldVal
));
int16_t
nlen
=
kvRowLen
(
row
)
+
diff
;
ASSERT
(
nlen
>
0
);
ASSERT
(
nlen
>
0
);
nrow
=
malloc
(
nlen
);
nrow
=
malloc
(
nlen
);
if
(
nrow
==
NULL
)
return
-
1
;
if
(
nrow
==
NULL
)
return
-
1
;
...
@@ -609,30 +594,22 @@ int tdSetKVRowDataOfCol(SKVRow *orow, int16_t colId, int8_t type, void *value) {
...
@@ -609,30 +594,22 @@ int tdSetKVRowDataOfCol(SKVRow *orow, int16_t colId, int8_t type, void *value) {
kvRowSetLen
(
nrow
,
nlen
);
kvRowSetLen
(
nrow
,
nlen
);
kvRowSetNCols
(
nrow
,
kvRowNCols
(
row
));
kvRowSetNCols
(
nrow
,
kvRowNCols
(
row
));
// Copy part ahead
int
zsize
=
sizeof
(
SColIdx
)
*
kvRowNCols
(
row
)
+
((
SColIdx
*
)
ptr
)
->
offset
;
nlen
=
(
int16_t
)(
POINTER_DISTANCE
(
ptr
,
kvRowColIdx
(
row
)));
memcpy
(
kvRowColIdx
(
nrow
),
kvRowColIdx
(
row
),
zsize
);
ASSERT
(
nlen
%
sizeof
(
SColIdx
)
==
0
);
memcpy
(
kvRowColVal
(
nrow
,
((
SColIdx
*
)
ptr
)),
value
,
varDataTLen
(
value
));
if
(
nlen
>
0
)
{
// Copy left value part
ASSERT
(((
SColIdx
*
)
ptr
)
->
offset
>
0
);
int
lsize
=
kvRowLen
(
row
)
-
TD_KV_ROW_HEAD_SIZE
-
zsize
-
varDataTLen
(
pOldVal
);
memcpy
(
kvRowColIdx
(
nrow
),
kvRowColIdx
(
row
),
nlen
);
if
(
lsize
>
0
)
{
memcpy
(
kvRowValues
(
nrow
),
kvRowValues
(
row
),
((
SColIdx
*
)
ptr
)
->
offset
);
memcpy
(
POINTER_SHIFT
(
nrow
,
TD_KV_ROW_HEAD_SIZE
+
zsize
+
varDataTLen
(
value
)),
POINTER_SHIFT
(
nrow
,
TD_KV_ROW_HEAD_SIZE
+
zsize
+
varDataTLen
(
pOldVal
)),
lsize
);
}
}
// Construct current column value
for
(
int
i
=
0
;
i
<
kvRowNCols
(
nrow
);
i
++
)
{
int
colIdx
=
nlen
/
sizeof
(
SColIdx
);
pColIdx
=
kvRowColIdxAt
(
nrow
,
i
);
pColIdx
=
kvRowColIdxAt
(
nrow
,
colIdx
);
pColIdx
->
colId
=
((
SColIdx
*
)
ptr
)
->
colId
;
if
(
pColIdx
->
offset
>
((
SColIdx
*
)
ptr
)
->
offset
)
{
pColIdx
->
offset
=
((
SColIdx
*
)
ptr
)
->
offset
;
pColIdx
->
offset
=
pColIdx
->
offset
-
varDataTLen
(
pOldVal
)
+
varDataTLen
(
value
);
memcpy
(
kvRowColVal
(
nrow
,
pColIdx
),
value
,
varDataTLen
(
value
));
// Construct columns after
if
(
kvRowNCols
(
nrow
)
-
colIdx
-
1
>
0
)
{
for
(
int
i
=
colIdx
+
1
;
i
<
kvRowNCols
(
nrow
);
i
++
)
{
kvRowColIdxAt
(
nrow
,
i
)
->
colId
=
kvRowColIdxAt
(
row
,
i
)
->
colId
;
kvRowColIdxAt
(
nrow
,
i
)
->
offset
=
kvRowColIdxAt
(
row
,
i
)
->
offset
+
diff
;
}
}
memcpy
(
kvRowColVal
(
nrow
,
kvRowColIdxAt
(
nrow
,
colIdx
+
1
)),
kvRowColVal
(
row
,
kvRowColIdxAt
(
row
,
colIdx
+
1
)),
POINTER_DISTANCE
(
kvRowEnd
(
row
),
kvRowColVal
(
row
,
kvRowColIdxAt
(
row
,
colIdx
+
1
))));
}
}
*
orow
=
nrow
;
*
orow
=
nrow
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录