mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-09-20 08:40:50 +00:00
Merge pull request #41569 from ClickHouse/fix_lost_table_shared_id
Fix lost table shared id
This commit is contained in:
commit
e91fae627c
@ -7440,12 +7440,21 @@ std::unique_ptr<MergeTreeSettings> StorageReplicatedMergeTree::getDefaultSetting
|
|||||||
|
|
||||||
String StorageReplicatedMergeTree::getTableSharedID() const
|
String StorageReplicatedMergeTree::getTableSharedID() const
|
||||||
{
|
{
|
||||||
|
/// Lock is not required in other places because createTableSharedID()
|
||||||
|
/// can be called only during table initialization
|
||||||
|
std::lock_guard lock(table_shared_id_mutex);
|
||||||
|
|
||||||
|
/// Can happen if table was partially initialized before drop by DatabaseCatalog
|
||||||
|
if (table_shared_id == UUIDHelpers::Nil)
|
||||||
|
createTableSharedID();
|
||||||
|
|
||||||
return toString(table_shared_id);
|
return toString(table_shared_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void StorageReplicatedMergeTree::createTableSharedID()
|
void StorageReplicatedMergeTree::createTableSharedID() const
|
||||||
{
|
{
|
||||||
|
LOG_DEBUG(log, "Creating shared ID for table {}", getStorageID().getNameForLogs());
|
||||||
if (table_shared_id != UUIDHelpers::Nil)
|
if (table_shared_id != UUIDHelpers::Nil)
|
||||||
throw Exception(ErrorCodes::LOGICAL_ERROR, "Table shared id already initialized");
|
throw Exception(ErrorCodes::LOGICAL_ERROR, "Table shared id already initialized");
|
||||||
|
|
||||||
@ -7454,6 +7463,7 @@ void StorageReplicatedMergeTree::createTableSharedID()
|
|||||||
String id;
|
String id;
|
||||||
if (!zookeeper->tryGet(zookeeper_table_id_path, id))
|
if (!zookeeper->tryGet(zookeeper_table_id_path, id))
|
||||||
{
|
{
|
||||||
|
LOG_DEBUG(log, "Shared ID for table {} doesn't exist in ZooKeeper on path {}", getStorageID().getNameForLogs(), zookeeper_table_id_path);
|
||||||
UUID table_id_candidate;
|
UUID table_id_candidate;
|
||||||
auto local_storage_id = getStorageID();
|
auto local_storage_id = getStorageID();
|
||||||
if (local_storage_id.uuid != UUIDHelpers::Nil)
|
if (local_storage_id.uuid != UUIDHelpers::Nil)
|
||||||
@ -7462,11 +7472,13 @@ void StorageReplicatedMergeTree::createTableSharedID()
|
|||||||
table_id_candidate = UUIDHelpers::generateV4();
|
table_id_candidate = UUIDHelpers::generateV4();
|
||||||
|
|
||||||
id = toString(table_id_candidate);
|
id = toString(table_id_candidate);
|
||||||
|
LOG_DEBUG(log, "Got candidate ID {}, will try to create it in ZooKeeper on path {}", id, zookeeper_table_id_path);
|
||||||
|
|
||||||
auto code = zookeeper->tryCreate(zookeeper_table_id_path, id, zkutil::CreateMode::Persistent);
|
auto code = zookeeper->tryCreate(zookeeper_table_id_path, id, zkutil::CreateMode::Persistent);
|
||||||
if (code == Coordination::Error::ZNODEEXISTS)
|
if (code == Coordination::Error::ZNODEEXISTS)
|
||||||
{ /// Other replica create node early
|
{ /// Other replica create node early
|
||||||
id = zookeeper->get(zookeeper_table_id_path);
|
id = zookeeper->get(zookeeper_table_id_path);
|
||||||
|
LOG_DEBUG(log, "Shared ID on path {} concurrently created, will set ID {}", zookeeper_table_id_path, id);
|
||||||
}
|
}
|
||||||
else if (code != Coordination::Error::ZOK)
|
else if (code != Coordination::Error::ZOK)
|
||||||
{
|
{
|
||||||
@ -7474,6 +7486,7 @@ void StorageReplicatedMergeTree::createTableSharedID()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LOG_DEBUG(log, "Initializing table shared ID with {}", id);
|
||||||
table_shared_id = parseFromString<UUID>(id);
|
table_shared_id = parseFromString<UUID>(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -475,7 +475,8 @@ private:
|
|||||||
ThrottlerPtr replicated_sends_throttler;
|
ThrottlerPtr replicated_sends_throttler;
|
||||||
|
|
||||||
/// Global ID, synced via ZooKeeper between replicas
|
/// Global ID, synced via ZooKeeper between replicas
|
||||||
UUID table_shared_id;
|
mutable std::mutex table_shared_id_mutex;
|
||||||
|
mutable UUID table_shared_id;
|
||||||
|
|
||||||
std::mutex last_broken_disks_mutex;
|
std::mutex last_broken_disks_mutex;
|
||||||
std::set<String> last_broken_disks;
|
std::set<String> last_broken_disks;
|
||||||
@ -840,7 +841,7 @@ private:
|
|||||||
void createAndStoreFreezeMetadata(DiskPtr disk, DataPartPtr part, String backup_part_path) const override;
|
void createAndStoreFreezeMetadata(DiskPtr disk, DataPartPtr part, String backup_part_path) const override;
|
||||||
|
|
||||||
// Create table id if needed
|
// Create table id if needed
|
||||||
void createTableSharedID();
|
void createTableSharedID() const;
|
||||||
|
|
||||||
|
|
||||||
bool checkZeroCopyLockExists(const String & part_name, const DiskPtr & disk);
|
bool checkZeroCopyLockExists(const String & part_name, const DiskPtr & disk);
|
||||||
|
Loading…
Reference in New Issue
Block a user