Skip to content

Commit efee390

Browse files
committed
Fix mutations after turning on zero-copy
1 parent 3be2ae7 commit efee390

6 files changed

+82
-0
lines changed

src/Storages/MergeTree/DataPartsExchange.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,8 @@ void Service::processQuery(const HTMLForm & params, ReadBuffer & /*body*/, Write
208208
auto disk_type = part->getDataPartStorage().getDiskType();
209209
if (part->getDataPartStorage().supportZeroCopyReplication() && std::find(capabilities.begin(), capabilities.end(), disk_type) != capabilities.end())
210210
{
211+
data.lockSharedData(*part, false, {});
212+
211213
/// Send metadata if the receiver's capabilities covers the source disk type.
212214
response.addCookie({"remote_fs_metadata", disk_type});
213215
sendPartFromDisk(part, out, client_protocol_version, true, send_projections);

src/Storages/StorageReplicatedMergeTree.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10300,6 +10300,8 @@ void StorageReplicatedMergeTree::getZeroCopyLockNodeCreateOps(
1030010300
requests.emplace_back(zkutil::makeCreateRequest(zookeeper_node, "", mode));
1030110301
if (!path_to_set_hardlinked_files.empty() && !hardlinked_files.empty())
1030210302
{
10303+
/// Node may be missing in rare cases when zero-copy is turned on for an existing table.
10304+
zookeeper->checkExistsAndGetCreateAncestorsOps(path_to_set_hardlinked_files + "/", requests);
1030310305
std::string data = boost::algorithm::join(hardlinked_files, "\n");
1030410306
/// List of files used to detect hardlinks. path_to_set_hardlinked_files --
1030510307
/// is a path to source part zero copy node. During part removal hardlinked
@@ -10312,6 +10314,8 @@ void StorageReplicatedMergeTree::getZeroCopyLockNodeCreateOps(
1031210314
Coordination::Requests ops;
1031310315
if (!path_to_set_hardlinked_files.empty() && !hardlinked_files.empty())
1031410316
{
10317+
/// Node may be missing in rare cases when zero-copy is turned on for an existing table.
10318+
zookeeper->checkExistsAndGetCreateAncestorsOps(path_to_set_hardlinked_files + "/", requests);
1031510319
std::string data = boost::algorithm::join(hardlinked_files, "\n");
1031610320
/// List of files used to detect hardlinks. path_to_set_hardlinked_files --
1031710321
/// is a path to source part zero copy node. During part removal hardlinked
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env bash
2+
# Tags: no-parallel, no-fasttest
3+
4+
set -e
5+
6+
CUR_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
7+
# shellcheck source=../shell_config.sh
8+
. "$CUR_DIR"/../shell_config.sh
9+
10+
$CLICKHOUSE_CLIENT -q "DROP TABLE IF EXISTS test03391_zero_copy_mutations"
11+
$CLICKHOUSE_CLIENT -m -q "
12+
CREATE TABLE test03391_zero_copy_mutations
13+
(key UInt32, value UInt32)
14+
ENGINE=ReplicatedMergeTree('/clickhouse/tables/$CLICKHOUSE_TEST_ZOOKEEPER_PREFIX/test03391_zero_copy_mutations', 'r1')
15+
ORDER BY key
16+
SETTINGS storage_policy='s3_cache', allow_remote_fs_zero_copy_replication=0
17+
"
18+
19+
$CLICKHOUSE_CLIENT -q "INSERT INTO test03391_zero_copy_mutations VALUES (1,1)"
20+
$CLICKHOUSE_CLIENT -q "ALTER TABLE test03391_zero_copy_mutations MODIFY SETTING allow_remote_fs_zero_copy_replication=1"
21+
$CLICKHOUSE_CLIENT -q "ALTER TABLE test03391_zero_copy_mutations UPDATE value=value WHERE 0"
22+
23+
for i in {1..10}
24+
do
25+
if [ "$(${CLICKHOUSE_CLIENT} -q "SELECT count() FROM system.mutations WHERE table='test03391_zero_copy_mutations' AND is_done=1")" -eq 1 ]; then
26+
break
27+
fi
28+
sleep 1
29+
done
30+
31+
echo '1' | $CLICKHOUSE_CLIENT -q "SELECT count() FROM system.mutations WHERE table='test03391_zero_copy_mutations' AND is_done=1"
32+
33+
$CLICKHOUSE_CLIENT -q "DROP TABLE IF EXISTS test03391_zero_copy_mutations"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
15000000
2+
15000000
3+
15000000
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
-- Tags: no-parallel
2+
3+
DROP TABLE IF EXISTS test03392_zero_copy_replication_r1;
4+
DROP TABLE IF EXISTS test03392_zero_copy_replication_r2;
5+
DROP TABLE IF EXISTS test03392_zero_copy_replication_r3;
6+
7+
CREATE TABLE test03392_zero_copy_replication_r1 (x UInt64)
8+
ENGINE = ReplicatedMergeTree('/clickhouse/tables/test03392_zero_copy_replication','1')
9+
ORDER BY x
10+
SETTINGS storage_policy='s3_cache', allow_remote_fs_zero_copy_replication=0;
11+
12+
INSERT INTO test03392_zero_copy_replication_r1 SELECT number FROM numbers(5000000);
13+
INSERT INTO test03392_zero_copy_replication_r1 SELECT number+5000000 FROM numbers(5000000);
14+
INSERT INTO test03392_zero_copy_replication_r1 SELECT number+10000000 FROM numbers(5000000);
15+
16+
CREATE TABLE test03392_zero_copy_replication_r2 (x UInt64)
17+
ENGINE = ReplicatedMergeTree('/clickhouse/tables/test03392_zero_copy_replication','2')
18+
ORDER BY x
19+
SETTINGS storage_policy='s3_cache', allow_remote_fs_zero_copy_replication=0;
20+
21+
SYSTEM SYNC REPLICA test03392_zero_copy_replication_r2;
22+
23+
ALTER TABLE test03392_zero_copy_replication_r1 MODIFY SETTING allow_remote_fs_zero_copy_replication=1;
24+
ALTER TABLE test03392_zero_copy_replication_r2 MODIFY SETTING allow_remote_fs_zero_copy_replication=1;
25+
26+
CREATE TABLE test03392_zero_copy_replication_r3 (x UInt64)
27+
ENGINE = ReplicatedMergeTree('/clickhouse/tables/test03392_zero_copy_replication','3')
28+
ORDER BY x
29+
SETTINGS storage_policy='s3_cache', allow_remote_fs_zero_copy_replication=1;
30+
31+
SYSTEM SYNC REPLICA test03392_zero_copy_replication_r3;
32+
33+
SELECT count() FROM test03392_zero_copy_replication_r1;
34+
SELECT count() FROM test03392_zero_copy_replication_r2;
35+
SELECT count() FROM test03392_zero_copy_replication_r3;
36+
37+
DROP TABLE IF EXISTS test03392_zero_copy_replication_r1;
38+
DROP TABLE IF EXISTS test03392_zero_copy_replication_r2;
39+
DROP TABLE IF EXISTS test03392_zero_copy_replication_r3;

0 commit comments

Comments
 (0)