Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2dot5
ClickHouse
提交
514a4d4f
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,发现更多精彩内容 >>
提交
514a4d4f
编写于
10月 27, 2017
作者:
A
Alexey Zatelepin
提交者:
alexey-milovidov
10月 27, 2017
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
use stale local replica if all remote replicas are unavailable [#CLICKHOUSE-3377]
上级
fbef2a98
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
43 addition
and
11 deletion
+43
-11
dbms/src/Interpreters/ClusterProxy/SelectStreamFactory.cpp
dbms/src/Interpreters/ClusterProxy/SelectStreamFactory.cpp
+33
-10
dbms/tests/integration/test_delayed_replica_failover/test.py
dbms/tests/integration/test_delayed_replica_failover/test.py
+10
-1
未找到文件。
dbms/src/Interpreters/ClusterProxy/SelectStreamFactory.cpp
浏览文件 @
514a4d4f
...
...
@@ -5,17 +5,23 @@
#include <DataStreams/LazyBlockInputStream.h>
#include <Storages/StorageReplicatedMergeTree.h>
#include <Common/Exception.h>
#include <Common/ProfileEvents.h>
#include <common/logger_useful.h>
namespace
ProfileEvents
{
extern
const
Event
DistributedConnectionMissingTable
;
extern
const
Event
DistributedConnectionStaleReplica
;
}
namespace
DB
{
namespace
ErrorCodes
{
extern
const
int
ALL_REPLICAS_ARE_STALE
;
extern
const
int
ALL_REPLICAS_ARE_STALE
;
}
namespace
ClusterProxy
...
...
@@ -72,6 +78,7 @@ void SelectStreamFactory::createForShard(
StoragePtr
main_table_storage
=
context
.
tryGetTable
(
main_table
.
database
,
main_table
.
table
);
if
(
!
main_table_storage
)
/// Table is absent on a local server.
{
ProfileEvents
::
increment
(
ProfileEvents
::
DistributedConnectionMissingTable
);
if
(
shard_info
.
pool
)
{
LOG_WARNING
(
...
...
@@ -117,6 +124,10 @@ void SelectStreamFactory::createForShard(
}
/// If we reached this point, local replica is stale.
ProfileEvents
::
increment
(
ProfileEvents
::
DistributedConnectionStaleReplica
);
LOG_WARNING
(
&
Logger
::
get
(
"ClusterProxy::SelectStreamFactory"
),
"Local replica of shard "
<<
shard_info
.
shard_num
<<
" is stale (delay: "
<<
local_delay
<<
"s.)"
);
if
(
!
settings
.
fallback_to_stale_replicas_for_distributed_queries
)
{
...
...
@@ -128,8 +139,8 @@ void SelectStreamFactory::createForShard(
}
else
throw
Exception
(
"Local replica for
shard "
+
toString
(
shard_info
.
shard_num
)
+
" is stale (delay: "
+
toString
(
local_delay
)
+
"), but no other replica configured.
"
,
"Local replica of
shard "
+
toString
(
shard_info
.
shard_num
)
+
" is stale (delay: "
+
toString
(
local_delay
)
+
"s.), but no other replica configured
"
,
ErrorCodes
::
ALL_REPLICAS_ARE_STALE
);
}
...
...
@@ -144,13 +155,25 @@ void SelectStreamFactory::createForShard(
/// Do it lazily to avoid connecting in the main thread.
auto
lazily_create_stream
=
[
pool
=
shard_info
.
pool
,
query
,
query_ast
,
context
,
throttler
,
pool
=
shard_info
.
pool
,
shard_num
=
shard_info
.
shard_num
,
query
,
query_ast
,
context
,
throttler
,
main_table
=
main_table
,
external_tables
=
external_tables
,
stage
=
processed_stage
,
local_delay
]()
->
BlockInputStreamPtr
{
std
::
vector
<
ConnectionPoolWithFailover
::
TryResult
>
try_results
=
pool
->
getManyChecked
(
&
context
.
getSettingsRef
(),
PoolMode
::
GET_MANY
,
main_table
);
std
::
vector
<
ConnectionPoolWithFailover
::
TryResult
>
try_results
;
try
{
try_results
=
pool
->
getManyChecked
(
&
context
.
getSettingsRef
(),
PoolMode
::
GET_MANY
,
main_table
);
}
catch
(
const
Exception
&
ex
)
{
if
(
ex
.
code
()
==
ErrorCodes
::
ALL_CONNECTION_TRIES_FAILED
)
LOG_WARNING
(
&
Logger
::
get
(
"ClusterProxy::SelectStreamFactory"
),
"Connections to remote replicas of local shard "
<<
shard_num
<<
" failed, will use stale local replica"
);
else
throw
;
}
double
max_remote_delay
=
0.0
;
for
(
const
auto
&
try_result
:
try_results
)
...
...
@@ -159,7 +182,7 @@ void SelectStreamFactory::createForShard(
max_remote_delay
=
std
::
max
(
try_result
.
staleness
,
max_remote_delay
);
}
if
(
local_delay
<
max_remote_delay
)
if
(
try_results
.
empty
()
||
local_delay
<
max_remote_delay
)
return
createLocalStream
(
query_ast
,
context
,
stage
);
else
{
...
...
dbms/tests/integration/test_delayed_replica_failover/test.py
浏览文件 @
514a4d4f
...
...
@@ -58,7 +58,7 @@ def test(started_cluster):
assert
node_2_1
.
query
(
"SELECT sum(x) FROM replicated"
).
strip
()
==
''
assert
node_2_2
.
query
(
"SELECT sum(x) FROM replicated"
).
strip
()
==
'2'
# With in_order balancing first replicas chosen.
# With in_order balancing first replicas
are
chosen.
assert
instance_with_dist_table
.
query
(
"SELECT count() FROM distributed SETTINGS load_balancing='in_order'"
).
strip
()
==
''
...
...
@@ -89,3 +89,12 @@ SELECT count() FROM distributed SETTINGS
max_replica_delay_for_distributed_queries=1,
fallback_to_stale_replicas_for_distributed_queries=0
'''
)
# Now partition off the remote replica of the local shard and test that failover still works.
pm
.
partition_instances
(
node_1_1
,
node_1_2
,
port
=
9000
)
assert
instance_with_dist_table
.
query
(
'''
SELECT sum(x) FROM distributed SETTINGS
load_balancing='in_order',
max_replica_delay_for_distributed_queries=1
'''
).
strip
()
==
'2'
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录