Fix KeeperMap create after incomplete drop

This commit is contained in:
Antonio Andelic 2024-07-22 12:17:29 +02:00
parent 5547ce1a91
commit c36dde5103
4 changed files with 25 additions and 12 deletions

View File

@ -57,7 +57,8 @@ static struct InitFiu
PAUSEABLE_ONCE(finish_clean_quorum_failed_parts) \ PAUSEABLE_ONCE(finish_clean_quorum_failed_parts) \
PAUSEABLE(dummy_pausable_failpoint) \ PAUSEABLE(dummy_pausable_failpoint) \
ONCE(execute_query_calling_empty_set_result_func_on_exception) \ ONCE(execute_query_calling_empty_set_result_func_on_exception) \
ONCE(receive_timeout_on_table_status_response) ONCE(receive_timeout_on_table_status_response) \
ONCE(keepermap_fail_drop_data) \
namespace FailPoints namespace FailPoints

View File

@ -37,6 +37,7 @@
#include <Common/Base64.h> #include <Common/Base64.h>
#include <Common/Exception.h> #include <Common/Exception.h>
#include <Common/FailPoint.h>
#include <Common/ZooKeeper/IKeeper.h> #include <Common/ZooKeeper/IKeeper.h>
#include <Common/ZooKeeper/KeeperException.h> #include <Common/ZooKeeper/KeeperException.h>
#include <Common/ZooKeeper/Types.h> #include <Common/ZooKeeper/Types.h>
@ -64,6 +65,11 @@
namespace DB namespace DB
{ {
namespace FailPoints
{
extern const char keepermap_fail_drop_data[];
}
namespace ErrorCodes namespace ErrorCodes
{ {
extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH; extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH;
@ -411,18 +417,13 @@ StorageKeeperMap::StorageKeeperMap(
auto code = client->tryCreate(zk_table_path, "", zkutil::CreateMode::Persistent); auto code = client->tryCreate(zk_table_path, "", zkutil::CreateMode::Persistent);
// tables_path was removed with drop if (code == Coordination::Error::ZOK)
if (code == Coordination::Error::ZNONODE)
{
LOG_INFO(log, "Metadata nodes were removed by another server, will retry");
continue;
}
else if (code != Coordination::Error::ZOK)
{
throw zkutil::KeeperException(code, "Failed to create table on path {} because a table with same UUID already exists", zk_root_path);
}
return; return;
if (code != Coordination::Error::ZNONODE)
throw zkutil::KeeperException(code, "Failed to create table on path {} because a table with same UUID already exists", zk_root_path);
/// ZNONODE means we dropped zk_tables_path but didn't finish drop completely
} }
if (client->exists(zk_dropped_path)) if (client->exists(zk_dropped_path))
@ -561,6 +562,10 @@ void StorageKeeperMap::truncate(const ASTPtr &, const StorageMetadataPtr &, Cont
bool StorageKeeperMap::dropTable(zkutil::ZooKeeperPtr zookeeper, const zkutil::EphemeralNodeHolder::Ptr & metadata_drop_lock) bool StorageKeeperMap::dropTable(zkutil::ZooKeeperPtr zookeeper, const zkutil::EphemeralNodeHolder::Ptr & metadata_drop_lock)
{ {
fiu_do_on(FailPoints::keepermap_fail_drop_data,
{
throw zkutil::KeeperException(Coordination::Error::ZOPERATIONTIMEOUT, "Manually triggered operation timeout");
});
zookeeper->removeChildrenRecursive(zk_data_path); zookeeper->removeChildrenRecursive(zk_data_path);
bool completely_removed = false; bool completely_removed = false;

View File

@ -0,0 +1,7 @@
DROP TABLE IF EXISTS 03208_keepermap_test SYNC;
CREATE TABLE 03208_keepermap_test (key UInt64, value UInt64) Engine=KeeperMap('/' || currentDatabase() || '/test03208') PRIMARY KEY(key);
INSERT INTO 03208_keepermap_test VALUES (1, 11);
SYSTEM ENABLE FAILPOINT keepermap_fail_drop_data;
DROP TABLE 03208_keepermap_test;
CREATE TABLE 03208_keepermap_test_another (key UInt64, value UInt64) Engine=KeeperMap('/' || currentDatabase() || '/test03208') PRIMARY KEY(key);