Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
9b600d6f
T
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1185
Star
22015
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
9b600d6f
编写于
9月 16, 2022
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
mroe code
上级
c5eed8a3
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
159 addition
and
20 deletion
+159
-20
source/dnode/vnode/src/tsdb/tsdbCompress.c
source/dnode/vnode/src/tsdb/tsdbCompress.c
+159
-20
未找到文件。
source/dnode/vnode/src/tsdb/tsdbCompress.c
浏览文件 @
9b600d6f
...
...
@@ -13,52 +13,191 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "lz4.h"
#include "tsdb.h"
// Integer =====================================================
typedef
struct
{
int8_t
rawCopy
;
int64_t
prevVal
;
int32_t
nVal
;
int32_t
nBuf
;
uint8_t
*
pBuf
;
}
SIntCompressor
;
int8_t
type
;
int8_t
cmprAlg
;
uint8_t
*
aBuf
[
2
];
int64_t
nBuf
[
2
];
union
{
// Timestamp ----
struct
{
/* data */
};
// Integer ----
struct
{
/* data */
};
// Binary ----
struct
{
/* data */
};
// Float ----
struct
{
/* data */
};
// Bool ----
struct
{
int32_t
bool_n
;
uint8_t
bool_b
;
};
};
}
SCompressor
;
// Timestamp =====================================================
static
int32_t
tCompTimestamp
(
SCompressor
*
pCmprsor
,
TSKEY
ts
)
{
int32_t
code
=
0
;
// TODO
return
code
;
}
// Integer =====================================================
#define I64_SAFE_ADD(a, b) (((a) >= 0 && (b) <= INT64_MAX - (b)) || ((a) < 0 && (b) >= INT64_MIN - (a)))
#define SIMPLE8B_MAX ((uint64_t)1152921504606846974LL)
static
int32_t
t
sdbCmprI64
(
SIntCompressor
*
pCompres
sor
,
int64_t
val
)
{
static
int32_t
t
CompI64
(
SCompressor
*
pCmpr
sor
,
int64_t
val
)
{
int32_t
code
=
0
;
#if 0
// raw copy
if
(
pC
ompres
sor
->
rawCopy
)
{
memcpy
(
pC
ompressor
->
pBuf
+
pCompres
sor
->
nBuf
,
&
val
,
sizeof
(
val
));
pC
ompres
sor
->
nBuf
+=
sizeof
(
val
);
pC
ompres
sor
->
nVal
++
;
if (pC
mpr
sor->rawCopy) {
memcpy(pC
mprsor->pBuf + pCmpr
sor->nBuf, &val, sizeof(val));
pC
mpr
sor->nBuf += sizeof(val);
pC
mpr
sor->nVal++;
goto _exit;
}
if
(
!
I64_SAFE_ADD
(
val
,
pC
ompres
sor
->
prevVal
))
{
pC
ompres
sor
->
rawCopy
=
1
;
if (!I64_SAFE_ADD(val, pC
mpr
sor->prevVal)) {
pC
mpr
sor->rawCopy = 1;
// TODO: decompress and copy
pC
ompres
sor
->
nVal
++
;
pC
mpr
sor->nVal++;
goto _exit;
}
int64_t
diff
=
val
-
pC
ompres
sor
->
prevVal
;
int64_t diff = val - pC
mpr
sor->prevVal;
uint8_t zigzag = ZIGZAGE(int64_t, diff);
if (zigzag >= SIMPLE8B_MAX) {
pC
ompres
sor
->
rawCopy
=
1
;
pC
mpr
sor->rawCopy = 1;
// TODO: decompress and copy
pC
ompres
sor
->
nVal
++
;
pC
mpr
sor->nVal++;
goto _exit;
}
_exit:
#endif
return
code
;
}
// Timestamp =====================================================
// Float =====================================================
static
int32_t
tCompFloat
()
{
int32_t
code
=
0
;
// TODO
return
code
;
}
// Binary =====================================================
static
int32_t
tCompBinary
(
SCompressor
*
pCmprsor
,
const
uint8_t
*
pData
,
int32_t
nData
)
{
int32_t
code
=
0
;
if
(
nData
)
{
memcpy
(
pCmprsor
->
aBuf
[
0
]
+
pCmprsor
->
nBuf
[
0
],
pData
,
nData
);
pCmprsor
->
nBuf
[
0
]
+=
nData
;
}
// Float =====================================================
\ No newline at end of file
return
code
;
}
// Bool =====================================================
static
uint8_t
BOOL_CMPR_TABLE
[]
=
{
0
b01
,
0
b0100
,
0
b010000
,
0
b01000000
};
static
int32_t
tCompBool
(
SCompressor
*
pCmprsor
,
bool
vBool
)
{
int32_t
code
=
0
;
if
(
vBool
)
{
pCmprsor
->
bool_b
|=
BOOL_CMPR_TABLE
[
pCmprsor
->
bool_n
%
4
];
}
pCmprsor
->
bool_n
++
;
if
(
pCmprsor
->
bool_n
%
4
==
0
)
{
pCmprsor
->
aBuf
[
0
][
pCmprsor
->
nBuf
[
0
]]
=
pCmprsor
->
bool_b
;
pCmprsor
->
nBuf
[
0
]
++
;
pCmprsor
->
bool_b
=
0
;
}
return
code
;
}
// SCompressor =====================================================
int32_t
tCompressorCreate
(
SCompressor
**
ppCmprsor
)
{
int32_t
code
=
0
;
*
ppCmprsor
=
(
SCompressor
*
)
taosMemoryCalloc
(
1
,
sizeof
(
SCompressor
));
if
((
*
ppCmprsor
)
==
NULL
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_exit
;
}
_exit:
return
code
;
}
int32_t
tCompressorDestroy
(
SCompressor
*
pCmprsor
)
{
int32_t
code
=
0
;
if
(
pCmprsor
)
{
for
(
int32_t
iBuf
=
0
;
iBuf
<
sizeof
(
pCmprsor
->
aBuf
)
/
sizeof
(
pCmprsor
->
aBuf
[
0
]);
iBuf
++
)
{
tFree
(
pCmprsor
->
aBuf
[
iBuf
]);
}
}
return
code
;
}
int32_t
tCompressorReset
(
SCompressor
*
pCmprsor
,
int8_t
type
,
int8_t
cmprAlg
)
{
int32_t
code
=
0
;
pCmprsor
->
type
=
type
;
pCmprsor
->
cmprAlg
=
cmprAlg
;
switch
(
type
)
{
case
TSDB_DATA_TYPE_BOOL
:
pCmprsor
->
bool_n
=
0
;
pCmprsor
->
bool_b
=
0
;
break
;
default:
break
;
}
return
code
;
}
int32_t
tCompGen
(
SCompressor
*
pCmprsor
,
const
uint8_t
**
ppData
,
int64_t
*
nData
)
{
int32_t
code
=
0
;
if
(
pCmprsor
->
cmprAlg
==
TWO_STAGE_COMP
||
IS_VAR_DATA_TYPE
(
pCmprsor
->
type
))
{
code
=
tRealloc
(
&
pCmprsor
->
aBuf
[
1
],
pCmprsor
->
nBuf
[
0
]
+
1
);
if
(
code
)
goto
_exit
;
int64_t
ret
=
LZ4_compress_default
(
pCmprsor
->
aBuf
[
0
],
pCmprsor
->
aBuf
[
1
]
+
1
,
pCmprsor
->
nBuf
[
0
],
pCmprsor
->
nBuf
[
0
]);
if
(
ret
)
{
pCmprsor
->
aBuf
[
1
][
0
]
=
0
;
pCmprsor
->
nBuf
[
1
]
=
ret
+
1
;
}
else
{
pCmprsor
->
aBuf
[
1
][
0
]
=
1
;
memcpy
(
pCmprsor
->
aBuf
[
1
]
+
1
,
pCmprsor
->
aBuf
[
0
],
pCmprsor
->
nBuf
[
0
]);
pCmprsor
->
nBuf
[
1
]
=
pCmprsor
->
nBuf
[
0
]
+
1
;
}
*
ppData
=
pCmprsor
->
aBuf
[
1
];
*
nData
=
pCmprsor
->
nBuf
[
1
];
}
else
{
*
ppData
=
pCmprsor
->
aBuf
[
0
];
*
nData
=
pCmprsor
->
nBuf
[
0
];
}
_exit:
return
code
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录