|
18 | 18 | #include <Common/getRandomASCIIString.h> |
19 | 19 | #include <Common/randomSeed.h> |
20 | 20 | #include <Common/DNSResolver.h> |
| 21 | +#include <Interpreters/DDLTask.h> |
21 | 22 | #include <shared_mutex> |
22 | 23 | #include <Core/ServerUUID.h> |
23 | 24 |
|
@@ -244,24 +245,30 @@ ObjectStorageQueueMetadata::tryAcquireBucket(const Bucket & bucket, const Proces |
244 | 245 |
|
245 | 246 | void ObjectStorageQueueMetadata::alterSettings(const SettingsChanges & changes, const ContextPtr & context) |
246 | 247 | { |
| 248 | + bool is_initial_query = context->getClientInfo().query_kind == ClientInfo::QueryKind::INITIAL_QUERY || |
| 249 | + (context->getZooKeeperMetadataTransaction() && context->getZooKeeperMetadataTransaction()->isInitialQuery()); |
| 250 | + |
247 | 251 | const fs::path alter_settings_lock_path = zookeeper_path / "alter_settings_lock"; |
248 | 252 | zkutil::EphemeralNodeHolder::Ptr alter_settings_lock; |
249 | 253 | auto zookeeper = getZooKeeper(); |
250 | 254 |
|
251 | | - /// We will retry taking alter_settings_lock for the duration of 5 seconds. |
252 | | - /// Do we need to add a setting for this? |
253 | | - const size_t num_tries = 100; |
254 | | - for (size_t i = 0; i < num_tries; ++i) |
| 255 | + if (is_initial_query) |
255 | 256 | { |
256 | | - alter_settings_lock = zkutil::EphemeralNodeHolder::tryCreate(alter_settings_lock_path, *zookeeper, toString(getCurrentTime())); |
| 257 | + /// We will retry taking alter_settings_lock for the duration of 5 seconds. |
| 258 | + /// Do we need to add a setting for this? |
| 259 | + const size_t num_tries = 100; |
| 260 | + for (size_t i = 0; i < num_tries; ++i) |
| 261 | + { |
| 262 | + alter_settings_lock = zkutil::EphemeralNodeHolder::tryCreate(alter_settings_lock_path, *zookeeper, toString(getCurrentTime())); |
257 | 263 |
|
258 | | - if (alter_settings_lock) |
259 | | - break; |
| 264 | + if (alter_settings_lock) |
| 265 | + break; |
260 | 266 |
|
261 | | - if (i == num_tries - 1) |
262 | | - throw Exception(ErrorCodes::LOGICAL_ERROR, "Failed to take alter setting lock"); |
| 267 | + if (i == num_tries - 1) |
| 268 | + throw Exception(ErrorCodes::LOGICAL_ERROR, "Failed to take alter setting lock"); |
263 | 269 |
|
264 | | - sleepForMilliseconds(50); |
| 270 | + sleepForMilliseconds(50); |
| 271 | + } |
265 | 272 | } |
266 | 273 |
|
267 | 274 | Coordination::Stat stat; |
@@ -373,7 +380,11 @@ void ObjectStorageQueueMetadata::alterSettings(const SettingsChanges & changes, |
373 | 380 | LOG_TRACE(log, "New metadata: {}", new_metadata_str); |
374 | 381 |
|
375 | 382 | const fs::path table_metadata_path = zookeeper_path / "metadata"; |
376 | | - zookeeper->set(table_metadata_path, new_metadata_str, stat.version); |
| 383 | + /// Here we intentionally do not add zk retries, |
| 384 | + /// because we modify metadata under ephemeral metadata lock, |
| 385 | + /// so we do not want to retry if it expires. |
| 386 | + if (is_initial_query) |
| 387 | + zookeeper->set(table_metadata_path, new_metadata_str, stat.version); |
377 | 388 |
|
378 | 389 | table_metadata.syncChangeableSettings(new_table_metadata); |
379 | 390 | } |
|
0 commit comments