Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
a5725b50
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看板
提交
a5725b50
编写于
11月 16, 2022
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more code
上级
151d07e8
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
102 addition
and
163 deletion
+102
-163
include/common/tdataformat.h
include/common/tdataformat.h
+24
-50
source/common/src/tdataformat.c
source/common/src/tdataformat.c
+70
-105
source/dnode/vnode/src/inc/tsdb.h
source/dnode/vnode/src/inc/tsdb.h
+2
-2
source/dnode/vnode/src/tsdb/tsdbDiskData.c
source/dnode/vnode/src/tsdb/tsdbDiskData.c
+4
-4
source/dnode/vnode/src/tsdb/tsdbUtil.c
source/dnode/vnode/src/tsdb/tsdbUtil.c
+2
-2
未找到文件。
include/common/tdataformat.h
浏览文件 @
a5725b50
...
...
@@ -27,17 +27,17 @@
extern
"C"
{
#endif
typedef
struct
SBuffer
SBuffer
;
typedef
struct
SSchema
SSchema
;
typedef
struct
STColumn
STColumn
;
typedef
struct
STSchema
STSchema
;
typedef
struct
SValue
SValue
;
typedef
struct
SColVal
SColVal
;
typedef
struct
S
TSRow2
STSRow2
;
typedef
struct
S
TSRowBuilder
STSRowBuild
er
;
typedef
struct
STagVal
STagVal
;
typedef
struct
STag
STag
;
typedef
struct
SColData
SColData
;
typedef
struct
SBuffer
SBuffer
;
typedef
struct
SSchema
SSchema
;
typedef
struct
STColumn
STColumn
;
typedef
struct
STSchema
STSchema
;
typedef
struct
SValue
SValue
;
typedef
struct
SColVal
SColVal
;
typedef
struct
S
Row
SRow
;
typedef
struct
S
RowIter
SRowIt
er
;
typedef
struct
STagVal
STagVal
;
typedef
struct
STag
STag
;
typedef
struct
SColData
SColData
;
#define HAS_NONE ((uint8_t)0x1)
#define HAS_NULL ((uint8_t)0x2)
...
...
@@ -70,8 +70,7 @@ int32_t tBufferInit(SBuffer *pBuffer, int64_t size);
int32_t
tBufferPut
(
SBuffer
*
pBuffer
,
const
void
*
pData
,
int64_t
nData
);
// STSchema ================================
int32_t
tTSchemaCreate
(
int32_t
sver
,
SSchema
*
pSchema
,
int32_t
nCols
,
STSchema
**
ppTSchema
);
void
tTSchemaDestroy
(
STSchema
*
pTSchema
);
void
tTSchemaDestroy
(
STSchema
*
pTSchema
);
// SValue ================================
...
...
@@ -88,26 +87,12 @@ void tTSchemaDestroy(STSchema *pTSchema);
#define COL_VAL_IS_NULL(CV) ((CV)->flag == CV_FLAG_NULL)
#define COL_VAL_IS_VALUE(CV) ((CV)->flag == CV_FLAG_VALUE)
// STSRow2 ================================
#define TSROW_LEN(PROW, V) tGetI32v((uint8_t *)(PROW)->data, (V) ? &(V) : NULL)
#define TSROW_SVER(PROW, V) tGetI32v((PROW)->data + TSROW_LEN(PROW, NULL), (V) ? &(V) : NULL)
int32_t
tTSRowNew
(
STSRowBuilder
*
pBuilder
,
SArray
*
pArray
,
STSchema
*
pTSchema
,
STSRow2
**
ppRow
);
int32_t
tTSRowClone
(
const
STSRow2
*
pRow
,
STSRow2
**
ppRow
);
void
tTSRowFree
(
STSRow2
*
pRow
);
void
tTSRowGet
(
STSRow2
*
pRow
,
STSchema
*
pTSchema
,
int32_t
iCol
,
SColVal
*
pColVal
);
int32_t
tTSRowToArray
(
STSRow2
*
pRow
,
STSchema
*
pTSchema
,
SArray
**
ppArray
);
int32_t
tPutTSRow
(
uint8_t
*
p
,
STSRow2
*
pRow
);
int32_t
tGetTSRow
(
uint8_t
*
p
,
STSRow2
**
ppRow
);
// STSRowBuilder ================================
#define tsRowBuilderInit() ((STSRowBuilder){0})
#define tsRowBuilderClear(B) \
do { \
if ((B)->pBuf) { \
taosMemoryFree((B)->pBuf); \
} \
} while (0)
// SRow ================================
int32_t
tTSRowPut
(
SArray
*
aColVal
,
STSchema
*
pTSchema
,
SBuffer
*
pBuffer
);
void
tTSRowGet
(
SRow
*
pRow
,
STSchema
*
pTSchema
,
int32_t
iCol
,
SColVal
*
pColVal
);
int32_t
tTSRowToArray
(
SRow
*
pRow
,
STSchema
*
pTSchema
,
SArray
**
ppArray
);
// SRowIter ================================
// STag ================================
int32_t
tTagNew
(
SArray
*
pArray
,
int32_t
version
,
int8_t
isJson
,
STag
**
ppTag
);
...
...
@@ -151,23 +136,12 @@ struct STSchema {
STColumn
columns
[];
};
#define TSROW_HAS_NONE ((uint8_t)0x1)
#define TSROW_HAS_NULL ((uint8_t)0x2U)
#define TSROW_HAS_VAL ((uint8_t)0x4U)
#define TSROW_KV_SMALL ((uint8_t)0x10U)
#define TSROW_KV_MID ((uint8_t)0x20U)
#define TSROW_KV_BIG ((uint8_t)0x40U)
#pragma pack(push, 1)
struct
STSRow2
{
TSKEY
ts
;
uint8_t
flags
;
uint8_t
data
[];
};
#pragma pack(pop)
struct
STSRowBuilder
{
int32_t
szBuf
;
uint8_t
*
pBuf
;
struct
SRow
{
uint8_t
flag
;
uint8_t
rsv
;
uint16_t
sver
;
uint32_t
len
;
uint8_t
data
[];
};
struct
SValue
{
...
...
source/common/src/tdataformat.c
浏览文件 @
a5725b50
...
...
@@ -65,44 +65,42 @@ static FORCE_INLINE int32_t tPutValue(uint8_t *p, SValue *pValue, int8_t type) {
}
}
// STSRow2 ========================================================================
static
void
setBitMap
(
uint8_t
*
pb
,
uint8_t
v
,
int32_t
idx
,
uint8_t
flags
)
{
if
(
pb
)
{
switch
(
flags
&
0xf
)
{
case
TSROW_HAS_NULL
|
TSROW_HAS_NONE
:
case
TSROW_HAS_VAL
|
TSROW_HAS_NONE
:
if
(
v
)
{
SET_BIT1
(
pb
,
idx
,
(
uint8_t
)
1
);
}
else
{
SET_BIT1
(
pb
,
idx
,
(
uint8_t
)
0
);
}
break
;
case
TSROW_HAS_VAL
|
TSROW_HAS_NULL
:
v
=
v
-
1
;
SET_BIT1
(
pb
,
idx
,
v
);
break
;
case
TSROW_HAS_VAL
|
TSROW_HAS_NULL
|
TSROW_HAS_NONE
:
SET_BIT2
(
pb
,
idx
,
v
);
break
;
// SRow ========================================================================
int32_t
tTSRowPut
(
SArray
*
aColVal
,
STSchema
*
pTSchema
,
SBuffer
*
pBuffer
)
{
int32_t
code
=
0
;
default:
ASSERT
(
0
);
ASSERT
(
taosArrayGetSize
(
aColVal
)
==
0
);
uint8_t
flag
=
0
;
int32_t
iColVal
=
0
;
SColVal
*
pColVal
=
taosArrayGet
(
aColVal
,
iColVal
);
int32_t
iTColumn
=
0
;
STColumn
*
pTColumn
=
pTSchema
->
columns
+
iTColumn
;
while
(
pTColumn
)
{
if
(
pColVal
)
{
if
(
pColVal
->
cid
==
pTColumn
->
colId
)
{
if
(
COL_VAL_IS_VALUE
(
pColVal
))
{
// VALUE
flag
|=
HAS_VALUE
;
}
else
if
(
COL_VAL_IS_NONE
(
pColVal
))
{
// NONE
flag
|=
HAS_NONE
;
}
else
{
// NULL
flag
|=
HAS_NULL
;
}
pTColumn
=
(
++
iTColumn
<
pTSchema
->
numOfCols
)
?
pTSchema
->
columns
+
iTColumn
:
NULL
;
pColVal
=
(
++
iColVal
<
taosArrayGetSize
(
aColVal
))
?
taosArrayGet
(
aColVal
,
iColVal
)
:
NULL
;
}
else
if
(
pColVal
->
cid
<
pTColumn
->
colId
)
{
pColVal
=
(
++
iColVal
<
taosArrayGetSize
(
aColVal
))
?
taosArrayGet
(
aColVal
,
iColVal
)
:
NULL
;
}
else
{
// NONE
flag
|=
HAS_NONE
;
pTColumn
=
(
++
iTColumn
<
pTSchema
->
numOfCols
)
?
pTSchema
->
columns
+
iTColumn
:
NULL
;
}
}
else
{
// NONE
flag
|=
HAS_NONE
;
pTColumn
=
(
++
iTColumn
<
pTSchema
->
numOfCols
)
?
pTSchema
->
columns
+
iTColumn
:
NULL
;
}
}
}
#define SET_IDX(p, i, n, f) \
do { \
if ((f)&TSROW_KV_SMALL) { \
((uint8_t *)(p))[i] = (n); \
} else if ((f)&TSROW_KV_MID) { \
((uint16_t *)(p))[i] = (n); \
} else { \
((uint32_t *)(p))[i] = (n); \
} \
} while (0)
#if 0
int32_t tTSRowNew(STSRowBuilder *pBuilder, SArray *pArray, STSchema *pTSchema, STSRow2 **ppRow) {
int32_t code = 0;
#if 0
STColumn *pTColumn;
SColVal *pColVal;
...
...
@@ -238,7 +236,7 @@ int32_t tTSRowNew(STSRowBuilder *pBuilder, SArray *pArray, STSchema *pTSchema, S
*ppRow = &pBuilder->tsRow;
} else {
// create a new one
*ppRow = (S
TSRow2 *)taosMemoryMalloc(sizeof(STSRow2
));
*ppRow = (S
Row *)taosMemoryMalloc(sizeof(SRow
));
if (*ppRow == NULL) {
code = TSDB_CODE_OUT_OF_MEMORY;
goto _exit;
...
...
@@ -391,33 +389,54 @@ int32_t tTSRowNew(STSRowBuilder *pBuilder, SArray *pArray, STSchema *pTSchema, S
}
#endif
_exit:
return
code
;
}
int32_t tTSRowClone(const STSRow2 *pRow, STSRow2 **ppRow) {
int32_t code = 0;
int32_t rLen = 0;
#if 0
static void setBitMap(uint8_t *pb, uint8_t v, int32_t idx, uint8_t flags) {
if (pb) {
switch (flags & 0xf) {
case TSROW_HAS_NULL | TSROW_HAS_NONE:
case TSROW_HAS_VAL | TSROW_HAS_NONE:
if (v) {
SET_BIT1(pb, idx, (uint8_t)1);
} else {
SET_BIT1(pb, idx, (uint8_t)0);
}
break;
case TSROW_HAS_VAL | TSROW_HAS_NULL:
v = v - 1;
SET_BIT1(pb, idx, v);
break;
case TSROW_HAS_VAL | TSROW_HAS_NULL | TSROW_HAS_NONE:
SET_BIT2(pb, idx, v);
break;
TSROW_LEN(pRow, rLen);
(*ppRow) = (STSRow2 *)taosMemoryMalloc(rLen);
if (*ppRow == NULL) {
code = TSDB_CODE_OUT_OF_MEMORY;
goto _exit;
default:
ASSERT(0);
}
}
memcpy(*ppRow, pRow, rLen);
_exit:
return code;
}
#define SET_IDX(p, i, n, f) \
do { \
if ((f)&TSROW_KV_SMALL) { \
((uint8_t *)(p))[i] = (n); \
} else if ((f)&TSROW_KV_MID) { \
((uint16_t *)(p))[i] = (n); \
} else { \
((uint32_t *)(p))[i] = (n); \
} \
} while (0)
void tTSRowFree(S
TSRow2
*pRow) {
void tTSRowFree(S
Row
*pRow) {
if (pRow) {
taosMemoryFree(pRow);
}
}
void tTSRowGet(S
TSRow2
*pRow, STSchema *pTSchema, int32_t iCol, SColVal *pColVal) {
void tTSRowGet(S
Row
*pRow, STSchema *pTSchema, int32_t iCol, SColVal *pColVal) {
uint8_t isTuple = ((pRow->flags & 0xf0) == 0) ? 1 : 0;
STColumn *pTColumn = &pTSchema->columns[iCol];
uint8_t flags = pRow->flags & (uint8_t)0xf;
...
...
@@ -564,7 +583,7 @@ _return_value:
return;
}
int32_t tTSRowToArray(S
TSRow2
*pRow, STSchema *pTSchema, SArray **ppArray) {
int32_t tTSRowToArray(S
Row
*pRow, STSchema *pTSchema, SArray **ppArray) {
int32_t code = 0;
SColVal cv;
...
...
@@ -584,62 +603,8 @@ _exit:
return code;
}
#endif
int32_t
tPutTSRow
(
uint8_t
*
p
,
STSRow2
*
pRow
)
{
int32_t
n
=
0
;
TSROW_LEN
(
pRow
,
n
);
if
(
p
)
{
memcpy
(
p
,
pRow
,
n
);
}
return
n
;
}
int32_t
tGetTSRow
(
uint8_t
*
p
,
STSRow2
**
ppRow
)
{
int32_t
n
=
0
;
*
ppRow
=
(
STSRow2
*
)
p
;
TSROW_LEN
(
*
ppRow
,
n
);
return
n
;
}
// STSchema ========================================
int32_t
tTSchemaCreate
(
int32_t
sver
,
SSchema
*
pSchema
,
int32_t
ncols
,
STSchema
**
ppTSchema
)
{
*
ppTSchema
=
(
STSchema
*
)
taosMemoryMalloc
(
sizeof
(
STSchema
)
+
sizeof
(
STColumn
)
*
ncols
);
if
(
*
ppTSchema
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
}
(
*
ppTSchema
)
->
numOfCols
=
ncols
;
(
*
ppTSchema
)
->
version
=
sver
;
(
*
ppTSchema
)
->
flen
=
0
;
(
*
ppTSchema
)
->
vlen
=
0
;
(
*
ppTSchema
)
->
tlen
=
0
;
for
(
int32_t
iCol
=
0
;
iCol
<
ncols
;
iCol
++
)
{
SSchema
*
pColumn
=
&
pSchema
[
iCol
];
STColumn
*
pTColumn
=
&
((
*
ppTSchema
)
->
columns
[
iCol
]);
pTColumn
->
colId
=
pColumn
->
colId
;
pTColumn
->
type
=
pColumn
->
type
;
pTColumn
->
flags
=
pColumn
->
flags
;
pTColumn
->
bytes
=
pColumn
->
bytes
;
pTColumn
->
offset
=
(
*
ppTSchema
)
->
flen
;
// skip first column
if
(
iCol
)
{
(
*
ppTSchema
)
->
flen
+=
TYPE_BYTES
[
pColumn
->
type
];
if
(
IS_VAR_DATA_TYPE
(
pColumn
->
type
))
{
(
*
ppTSchema
)
->
vlen
+=
(
pColumn
->
bytes
+
5
);
}
}
}
return
0
;
}
void
tTSchemaDestroy
(
STSchema
*
pTSchema
)
{
if
(
pTSchema
)
taosMemoryFree
(
pTSchema
);
}
...
...
source/dnode/vnode/src/inc/tsdb.h
浏览文件 @
a5725b50
...
...
@@ -112,8 +112,8 @@ void tsdbRowGetColVal(TSDBROW *pRow, STSchema *pTSchema, int32_t iCol, SColVal *
// int32_t tPutTSDBRow(uint8_t *p, TSDBROW *pRow);
int32_t
tsdbRowCmprFn
(
const
void
*
p1
,
const
void
*
p2
);
// STSDBRowIter
void
tRowIterInit
(
STSDBRowIter
*
pIter
,
TSDBROW
*
pRow
,
STSchema
*
pTSchema
);
SColVal
*
tRowIterNext
(
STSDBRowIter
*
pIter
);
void
t
sdb
RowIterInit
(
STSDBRowIter
*
pIter
,
TSDBROW
*
pRow
,
STSchema
*
pTSchema
);
SColVal
*
t
sdb
RowIterNext
(
STSDBRowIter
*
pIter
);
// SRowMerger
int32_t
tRowMergerInit2
(
SRowMerger
*
pMerger
,
STSchema
*
pResTSchema
,
TSDBROW
*
pRow
,
STSchema
*
pTSchema
);
int32_t
tRowMergerAdd
(
SRowMerger
*
pMerger
,
TSDBROW
*
pRow
,
STSchema
*
pTSchema
);
...
...
source/dnode/vnode/src/tsdb/tsdbDiskData.c
浏览文件 @
a5725b50
...
...
@@ -596,20 +596,20 @@ int32_t tDiskDataAddRow(SDiskDataBuilder *pBuilder, TSDBROW *pRow, STSchema *pTS
if
(
pBuilder
->
bi
.
maxKey
<
kRow
.
ts
)
pBuilder
->
bi
.
maxKey
=
kRow
.
ts
;
STSDBRowIter
iter
=
{
0
};
tRowIterInit
(
&
iter
,
pRow
,
pTSchema
);
t
sdb
RowIterInit
(
&
iter
,
pRow
,
pTSchema
);
SColVal
*
pColVal
=
tRowIterNext
(
&
iter
);
SColVal
*
pColVal
=
t
sdb
RowIterNext
(
&
iter
);
for
(
int32_t
iBuilder
=
0
;
iBuilder
<
pBuilder
->
nBuilder
;
iBuilder
++
)
{
SDiskColBuilder
*
pDCBuilder
=
(
SDiskColBuilder
*
)
taosArrayGet
(
pBuilder
->
aBuilder
,
iBuilder
);
while
(
pColVal
&&
pColVal
->
cid
<
pDCBuilder
->
cid
)
{
pColVal
=
tRowIterNext
(
&
iter
);
pColVal
=
t
sdb
RowIterNext
(
&
iter
);
}
if
(
pColVal
&&
pColVal
->
cid
==
pDCBuilder
->
cid
)
{
code
=
tDiskColAddVal
(
pDCBuilder
,
pColVal
);
if
(
code
)
return
code
;
pColVal
=
tRowIterNext
(
&
iter
);
pColVal
=
t
sdb
RowIterNext
(
&
iter
);
}
else
{
code
=
tDiskColAddVal
(
pDCBuilder
,
&
COL_VAL_NONE
(
pDCBuilder
->
cid
,
pDCBuilder
->
type
));
if
(
code
)
return
code
;
...
...
source/dnode/vnode/src/tsdb/tsdbUtil.c
浏览文件 @
a5725b50
...
...
@@ -580,7 +580,7 @@ int32_t tsdbRowCmprFn(const void *p1, const void *p2) {
}
// STSDBRowIter ======================================================
void
tRowIterInit
(
STSDBRowIter
*
pIter
,
TSDBROW
*
pRow
,
STSchema
*
pTSchema
)
{
void
t
sdb
RowIterInit
(
STSDBRowIter
*
pIter
,
TSDBROW
*
pRow
,
STSchema
*
pTSchema
)
{
pIter
->
pRow
=
pRow
;
if
(
pRow
->
type
==
0
)
{
ASSERT
(
pTSchema
);
...
...
@@ -594,7 +594,7 @@ void tRowIterInit(STSDBRowIter *pIter, TSDBROW *pRow, STSchema *pTSchema) {
}
}
SColVal
*
tRowIterNext
(
STSDBRowIter
*
pIter
)
{
SColVal
*
t
sdb
RowIterNext
(
STSDBRowIter
*
pIter
)
{
if
(
pIter
->
pRow
->
type
==
0
)
{
if
(
pIter
->
i
<
pIter
->
pTSchema
->
numOfCols
)
{
tTSRowGetVal
(
pIter
->
pRow
->
pTSRow
,
pIter
->
pTSchema
,
pIter
->
i
,
&
pIter
->
colVal
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录