Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2dot5
ClickHouse
提交
db8d82f1
C
ClickHouse
项目概览
2dot5
/
ClickHouse
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
ClickHouse
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
db8d82f1
编写于
12月 09, 2015
作者:
A
Alexey Milovidov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
dbms: Buffer: better [#METR-19249].
上级
e4738347
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
16 addition
and
7 deletion
+16
-7
dbms/include/DB/Storages/StorageBuffer.h
dbms/include/DB/Storages/StorageBuffer.h
+2
-1
dbms/src/Storages/StorageBuffer.cpp
dbms/src/Storages/StorageBuffer.cpp
+13
-5
dbms/tests/queries/0_stateless/00289_buffer_test.sh
dbms/tests/queries/0_stateless/00289_buffer_test.sh
+1
-1
未找到文件。
dbms/include/DB/Storages/StorageBuffer.h
浏览文件 @
db8d82f1
...
...
@@ -128,7 +128,8 @@ private:
void
flushAllBuffers
(
bool
check_thresholds
=
true
);
/// Сбросить буфер. Если выставлено check_thresholds - сбрасывает только если превышены пороги.
void
flushBuffer
(
Buffer
&
buffer
,
bool
check_thresholds
);
bool
checkThresholds
(
Buffer
&
buffer
,
time_t
current_time
,
size_t
additional_rows
=
0
,
size_t
additional_bytes
=
0
);
bool
checkThresholds
(
const
Buffer
&
buffer
,
time_t
current_time
,
size_t
additional_rows
=
0
,
size_t
additional_bytes
=
0
)
const
;
bool
checkThresholdsImpl
(
size_t
rows
,
size_t
bytes
,
time_t
time_passed
)
const
;
/// Аргумент table передаётся, так как иногда вычисляется заранее. Он должен соответствовать destination-у.
void
writeBlockToDestination
(
const
Block
&
block
,
StoragePtr
table
);
...
...
dbms/src/Storages/StorageBuffer.cpp
浏览文件 @
db8d82f1
...
...
@@ -238,6 +238,8 @@ private:
void
insertIntoBuffer
(
const
Block
&
block
,
StorageBuffer
::
Buffer
&
buffer
,
std
::
unique_lock
<
std
::
mutex
>
&&
lock
)
{
time_t
current_time
=
time
(
0
);
/// Сортируем столбцы в блоке. Это нужно, чтобы было проще потом конкатенировать блоки.
Block
sorted_block
=
block
.
sortColumns
();
...
...
@@ -245,7 +247,7 @@ private:
{
buffer
.
data
=
sorted_block
.
cloneEmpty
();
}
else
if
(
storage
.
checkThresholds
(
buffer
,
time
(
0
)
,
sorted_block
.
rowsInFirstColumn
(),
sorted_block
.
bytes
()))
else
if
(
storage
.
checkThresholds
(
buffer
,
current_time
,
sorted_block
.
rowsInFirstColumn
(),
sorted_block
.
bytes
()))
{
/** Если после вставки в буфер, ограничения будут превышены, то будем сбрасывать буфер.
* Это также защищает от неограниченного потребления оперативки, так как в случае невозможности записать в таблицу,
...
...
@@ -258,7 +260,7 @@ private:
}
if
(
!
buffer
.
first_write_time
)
buffer
.
first_write_time
=
time
(
0
)
;
buffer
.
first_write_time
=
current_time
;
appendBlock
(
sorted_block
,
buffer
.
data
);
}
...
...
@@ -297,7 +299,7 @@ bool StorageBuffer::optimize(const Settings & settings)
}
bool
StorageBuffer
::
checkThresholds
(
Buffer
&
buffer
,
time_t
current_time
,
size_t
additional_rows
,
size_t
additional_bytes
)
bool
StorageBuffer
::
checkThresholds
(
const
Buffer
&
buffer
,
time_t
current_time
,
size_t
additional_rows
,
size_t
additional_bytes
)
const
{
time_t
time_passed
=
0
;
if
(
buffer
.
first_write_time
)
...
...
@@ -306,6 +308,12 @@ bool StorageBuffer::checkThresholds(Buffer & buffer, time_t current_time, size_t
size_t
rows
=
buffer
.
data
.
rowsInFirstColumn
()
+
additional_rows
;
size_t
bytes
=
buffer
.
data
.
bytes
()
+
additional_bytes
;
return
checkThresholdsImpl
(
rows
,
bytes
,
time_passed
);
}
bool
StorageBuffer
::
checkThresholdsImpl
(
size_t
rows
,
size_t
bytes
,
time_t
time_passed
)
const
{
return
(
time_passed
>
min_thresholds
.
time
&&
rows
>
min_thresholds
.
rows
&&
bytes
>
min_thresholds
.
bytes
)
||
(
time_passed
>
max_thresholds
.
time
||
rows
>
max_thresholds
.
rows
||
bytes
>
max_thresholds
.
bytes
);
...
...
@@ -322,7 +330,7 @@ void StorageBuffer::flushAllBuffers(const bool check_thresholds)
void
StorageBuffer
::
flushBuffer
(
Buffer
&
buffer
,
bool
check_thresholds
)
{
Block
block_to_write
=
buffer
.
data
.
cloneEmpty
();
time_t
current_time
=
check_thresholds
?
time
(
0
)
:
0
;
time_t
current_time
=
time
(
0
)
;
size_t
rows
=
0
;
size_t
bytes
=
0
;
...
...
@@ -344,7 +352,7 @@ void StorageBuffer::flushBuffer(Buffer & buffer, bool check_thresholds)
if
(
check_thresholds
)
{
if
(
!
checkThresholds
(
buffer
,
current_time
))
if
(
!
checkThresholds
Impl
(
rows
,
bytes
,
time_passed
))
return
;
}
else
...
...
dbms/tests/queries/0_stateless/00289_buffer_test.sh
浏览文件 @
db8d82f1
...
...
@@ -5,7 +5,7 @@ clickhouse-client -n --query="
DROP TABLE IF EXISTS test.buffer;
CREATE TABLE test.dst (x UInt64, d Date DEFAULT today()) ENGINE = MergeTree(d, x, 8192);
CREATE TABLE test.buffer (x UInt64, d Date DEFAULT today()) ENGINE = Buffer(test, dst, 16, 1, 10
0, 10000, 10, 1
000, 100000);
CREATE TABLE test.buffer (x UInt64, d Date DEFAULT today()) ENGINE = Buffer(test, dst, 16, 1, 10
, 100, 1000, 10
000, 100000);
"
;
seq
1 1000 |
sed
-r
-e
's/^(.+)$/INSERT INTO test.buffer (x) VALUES (\1);/'
| clickhouse-client
-n
&
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录