Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2dot5
ClickHouse
提交
26021775
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,发现更多精彩内容 >>
提交
26021775
编写于
8月 24, 2018
作者:
A
Amos Bird
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Better locking for StorageBuffer
上级
9fa0c33b
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
13 addition
and
11 deletion
+13
-11
dbms/src/Storages/StorageBuffer.cpp
dbms/src/Storages/StorageBuffer.cpp
+12
-10
dbms/src/Storages/StorageBuffer.h
dbms/src/Storages/StorageBuffer.h
+1
-1
未找到文件。
dbms/src/Storages/StorageBuffer.cpp
浏览文件 @
26021775
...
...
@@ -277,7 +277,7 @@ public:
for
(
size_t
try_no
=
0
;
try_no
<
storage
.
num_shards
;
++
try_no
)
{
std
::
unique_lock
<
std
::
mutex
>
lock
(
storage
.
buffers
[
shard_num
].
mutex
,
std
::
try_to_lock
_t
()
);
std
::
unique_lock
<
std
::
mutex
>
lock
(
storage
.
buffers
[
shard_num
].
mutex
,
std
::
try_to_lock
);
if
(
lock
.
owns_lock
())
{
...
...
@@ -295,14 +295,16 @@ public:
/// If you still can not lock anything at once, then we'll wait on mutex.
if
(
!
least_busy_buffer
)
insertIntoBuffer
(
block
,
storage
.
buffers
[
start_shard_num
],
std
::
unique_lock
<
std
::
mutex
>
(
storage
.
buffers
[
start_shard_num
].
mutex
));
else
insertIntoBuffer
(
block
,
*
least_busy_buffer
,
std
::
move
(
least_busy_lock
));
{
least_busy_buffer
=
&
storage
.
buffers
[
start_shard_num
];
least_busy_lock
=
std
::
unique_lock
<
std
::
mutex
>
(
least_busy_buffer
->
mutex
);
}
insertIntoBuffer
(
block
,
*
least_busy_buffer
);
}
private:
StorageBuffer
&
storage
;
void
insertIntoBuffer
(
const
Block
&
block
,
StorageBuffer
::
Buffer
&
buffer
,
std
::
unique_lock
<
std
::
mutex
>
&&
lock
)
void
insertIntoBuffer
(
const
Block
&
block
,
StorageBuffer
::
Buffer
&
buffer
)
{
time_t
current_time
=
time
(
nullptr
);
...
...
@@ -320,9 +322,7 @@ private:
* an exception will be thrown, and new data will not be added to the buffer.
*/
lock
.
unlock
();
storage
.
flushBuffer
(
buffer
,
true
);
lock
.
lock
();
storage
.
flushBuffer
(
buffer
,
true
,
true
/* locked */
);
}
if
(
!
buffer
.
first_write_time
)
...
...
@@ -459,7 +459,7 @@ void StorageBuffer::flushAllBuffers(const bool check_thresholds)
}
void
StorageBuffer
::
flushBuffer
(
Buffer
&
buffer
,
bool
check_thresholds
)
void
StorageBuffer
::
flushBuffer
(
Buffer
&
buffer
,
bool
check_thresholds
,
bool
locked
)
{
Block
block_to_write
;
time_t
current_time
=
time
(
nullptr
);
...
...
@@ -468,7 +468,9 @@ void StorageBuffer::flushBuffer(Buffer & buffer, bool check_thresholds)
size_t
bytes
=
0
;
time_t
time_passed
=
0
;
std
::
lock_guard
<
std
::
mutex
>
lock
(
buffer
.
mutex
);
std
::
unique_lock
<
std
::
mutex
>
lock
(
buffer
.
mutex
,
std
::
defer_lock
);
if
(
!
locked
)
lock
.
lock
();
block_to_write
=
buffer
.
data
.
cloneEmpty
();
...
...
dbms/src/Storages/StorageBuffer.h
浏览文件 @
26021775
...
...
@@ -114,7 +114,7 @@ private:
void
flushAllBuffers
(
bool
check_thresholds
=
true
);
/// Reset the buffer. If check_thresholds is set - resets only if thresholds are exceeded.
void
flushBuffer
(
Buffer
&
buffer
,
bool
check_thresholds
);
void
flushBuffer
(
Buffer
&
buffer
,
bool
check_thresholds
,
bool
locked
=
false
);
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
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录