Merge pull request #53501 from azat/dist-flush_on_detach

Add ability to turn off flush of Distributed on DETACH/DROP/server shutdown
This commit is contained in:
Alexander Tokmakov 2023-08-17 16:56:04 +03:00 committed by GitHub
commit 72b52250ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 67 additions and 0 deletions

View File

@ -26,6 +26,7 @@ class ASTStorage;
M(UInt64, monitor_split_batch_on_failure, 0, "Default - distributed_directory_monitor_split_batch_on_failure", 0) \
M(Milliseconds, monitor_sleep_time_ms, 0, "Default - distributed_directory_monitor_sleep_time_ms", 0) \
M(Milliseconds, monitor_max_sleep_time_ms, 0, "Default - distributed_directory_monitor_max_sleep_time_ms", 0) \
M(Bool, flush_on_detach, true, "Flush data to remote nodes on DETACH/DROP/server shutdown", 0) \
DECLARE_SETTINGS_TRAITS(DistributedSettingsTraits, LIST_OF_DISTRIBUTED_SETTINGS)

View File

@ -1438,6 +1438,12 @@ ActionLock StorageDistributed::getActionLock(StorageActionBlockType type)
void StorageDistributed::flushAndPrepareForShutdown()
{
if (!getDistributedSettingsRef().flush_on_detach)
{
LOG_INFO(log, "Skip flushing data (due to flush_on_detach=0)");
return;
}
try
{
flushClusterNodesAllData(getContext());

View File

@ -0,0 +1,27 @@
-- { echoOn }
create table data (key Int) engine=Memory();
create table dist (key Int) engine=Distributed(default, currentDatabase(), data);
system stop distributed sends dist;
-- check that FLUSH DISTRIBUTED does flushing anyway
insert into dist values (1);
select * from data;
system flush distributed dist;
select * from data;
1
truncate table data;
-- check that flush_on_detach=1 by default
insert into dist values (1);
detach table dist;
select * from data;
1
attach table dist;
truncate table data;
-- check flush_on_detach=0
drop table dist;
create table dist (key Int) engine=Distributed(default, currentDatabase(), data) settings flush_on_detach=0;
system stop distributed sends dist;
insert into dist values (1);
detach table dist;
select * from data;
attach table dist;

View File

@ -0,0 +1,33 @@
set prefer_localhost_replica=0;
drop table if exists data;
drop table if exists dist;
-- { echoOn }
create table data (key Int) engine=Memory();
create table dist (key Int) engine=Distributed(default, currentDatabase(), data);
system stop distributed sends dist;
-- check that FLUSH DISTRIBUTED does flushing anyway
insert into dist values (1);
select * from data;
system flush distributed dist;
select * from data;
truncate table data;
-- check that flush_on_detach=1 by default
insert into dist values (1);
detach table dist;
select * from data;
attach table dist;
truncate table data;
-- check flush_on_detach=0
drop table dist;
create table dist (key Int) engine=Distributed(default, currentDatabase(), data) settings flush_on_detach=0;
system stop distributed sends dist;
insert into dist values (1);
detach table dist;
select * from data;
attach table dist;