Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
5401300
Code migration from #41734 to align diff and git blame.
devcrafter Oct 24, 2022
5336add
Disable fault injections by default
devcrafter Oct 24, 2022
8435cba
Merge remote-tracking branch 'origin/master' into igor/insert_zk_retr…
devcrafter Oct 26, 2022
649e8d3
Sync with retiring branch igor/insert_zk_retries
devcrafter Oct 26, 2022
f773436
Fix flaky test
devcrafter Oct 27, 2022
a601c16
Add clean up for faults injected before zk request
devcrafter Oct 27, 2022
3682913
Merge remote-tracking branch 'origin/master' into igor/insert_zk_retr…
devcrafter Oct 27, 2022
2b56bc4
Merge remote-tracking branch 'origin/master' into igor/insert_zk_retr…
devcrafter Oct 27, 2022
f31ce5d
Fix for messed up test output file
devcrafter Oct 28, 2022
c53b96a
Add more comments
devcrafter Oct 28, 2022
937dd44
Merge remote-tracking branch 'origin/master' into igor/insert_zk_retr…
devcrafter Oct 28, 2022
d09deaf
Fix style check
devcrafter Oct 28, 2022
2d5050e
Fix review comments
devcrafter Oct 31, 2022
9cc64a0
Merge remote-tracking branch 'origin/master' into igor/insert_zk_retr…
devcrafter Oct 31, 2022
e76c3c3
Better handling tables in read-only mode during insert
devcrafter Nov 1, 2022
3ed18ab
Mark a test as long
devcrafter Nov 2, 2022
9a315b7
Merge remote-tracking branch 'origin/master' into igor/insert_zk_retr…
devcrafter Nov 2, 2022
2347c93
Merge remote-tracking branch 'origin/master' into igor/insert_zk_retr…
devcrafter Nov 2, 2022
d5de687
Disable keeper retries during INSERT by default
devcrafter Nov 4, 2022
8590226
Merge remote-tracking branch 'origin/master' into igor/insert_zk_retr…
devcrafter Nov 4, 2022
dd598fd
Added missed insert_keeper_max_retries setting in test config
devcrafter Nov 5, 2022
e94b9cd
Fixes
devcrafter Nov 5, 2022
f44e4fe
Automatic style fix
Nov 5, 2022
503649a
Merge branch 'master' into igor/insert_zk_retries_retry
devcrafter Nov 6, 2022
544d98a
Fix for flaky test
devcrafter Nov 7, 2022
2c7a7fa
Disable fault injection and retries function tests settings
devcrafter Nov 7, 2022
6e4daa6
better tests
alesapin Nov 7, 2022
257e766
Trying to fix two flaky tests
alesapin Nov 7, 2022
345304a
Merge remote-tracking branch 'origin/master' into igor/insert_zk_retr…
devcrafter Nov 8, 2022
4c89fcc
fix flaky test
devcrafter Nov 8, 2022
761274d
Fix wrong logic
alesapin Nov 9, 2022
379113f
Merge remote-tracking branch 'origin/master' into igor/insert_zk_retr…
devcrafter Nov 9, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Common/ZooKeeper/TestKeeper.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ using TestKeeperRequestPtr = std::shared_ptr<TestKeeperRequest>;
class TestKeeper final : public IKeeper
{
public:
TestKeeper(const zkutil::ZooKeeperArgs & args_);
explicit TestKeeper(const zkutil::ZooKeeperArgs & args_);
~TestKeeper() override;

bool isExpired() const override { return expired; }
Expand Down
2 changes: 1 addition & 1 deletion src/Common/ZooKeeper/ZooKeeper.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class ZooKeeper
using Ptr = std::shared_ptr<ZooKeeper>;
using ErrorsList = std::initializer_list<Coordination::Error>;

ZooKeeper(const ZooKeeperArgs & args_, std::shared_ptr<DB::ZooKeeperLog> zk_log_ = nullptr);
explicit ZooKeeper(const ZooKeeperArgs & args_, std::shared_ptr<DB::ZooKeeperLog> zk_log_ = nullptr);

/** Config of the form:
<zookeeper>
Expand Down
5 changes: 5 additions & 0 deletions src/Core/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,11 @@ static constexpr UInt64 operator""_GiB(unsigned long long value)
M(Bool, multiple_joins_try_to_keep_original_names, false, "Do not add aliases to top level expression list on multiple joins rewrite", 0) \
M(Bool, optimize_distinct_in_order, true, "Enable DISTINCT optimization if some columns in DISTINCT form a prefix of sorting. For example, prefix of sorting key in merge tree or ORDER BY statement", 0) \
M(Bool, optimize_sorting_by_input_stream_properties, true, "Optimize sorting by sorting properties of input stream", 0) \
M(UInt64, insert_keeper_max_retries, 0, "Max retries for keeper operations during insert", 0) \
M(UInt64, insert_keeper_retry_initial_backoff_ms, 100, "Initial backoff timeout for keeper operations during insert", 0) \
M(UInt64, insert_keeper_retry_max_backoff_ms, 10000, "Max backoff timeout for keeper operations during insert", 0) \
M(Float, insert_keeper_fault_injection_probability, 0.0f, "Approximate probability of failure for a keeper request during insert. Valid value is in interval [0.0f, 1.0f]", 0) \
M(UInt64, insert_keeper_fault_injection_seed, 0, "0 - random seed, otherwise the setting value", 0) \
// End of COMMON_SETTINGS
// Please add settings related to formats into the FORMAT_FACTORY_SETTINGS and move obsolete settings to OBSOLETE_SETTINGS.

Expand Down
39 changes: 33 additions & 6 deletions src/Storages/MergeTree/EphemeralLockInZooKeeper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <Common/ZooKeeper/KeeperException.h>
#include <Common/logger_useful.h>
#include <base/types.h>
#include <Storages/MergeTree/ZooKeeperWithFaultInjection.h>


namespace DB
Expand All @@ -12,22 +13,22 @@ namespace ErrorCodes
extern const int LOGICAL_ERROR;
}

EphemeralLockInZooKeeper::EphemeralLockInZooKeeper(const String & path_prefix_, zkutil::ZooKeeper & zookeeper_, const String & path_)
: zookeeper(&zookeeper_), path_prefix(path_prefix_), path(path_)
EphemeralLockInZooKeeper::EphemeralLockInZooKeeper(const String & path_prefix_, const ZooKeeperWithFaultInjectionPtr & zookeeper_, const String & path_)
: zookeeper(zookeeper_), path_prefix(path_prefix_), path(path_)
{
if (path.size() <= path_prefix.size())
throw Exception("Logical error: name of the main node is shorter than prefix.", ErrorCodes::LOGICAL_ERROR);
}

std::optional<EphemeralLockInZooKeeper> createEphemeralLockInZooKeeper(
const String & path_prefix_, const String & temp_path, zkutil::ZooKeeper & zookeeper_, const String & deduplication_path)
const String & path_prefix_, const String & temp_path, const ZooKeeperWithFaultInjectionPtr & zookeeper_, const String & deduplication_path)
{
String path;

if (deduplication_path.empty())
{
String holder_path = temp_path + "/" + EphemeralLockInZooKeeper::LEGACY_LOCK_OTHER;
path = zookeeper_.create(path_prefix_, holder_path, zkutil::CreateMode::EphemeralSequential);
path = zookeeper_->create(path_prefix_, holder_path, zkutil::CreateMode::EphemeralSequential);
}
else
{
Expand All @@ -39,11 +40,15 @@ std::optional<EphemeralLockInZooKeeper> createEphemeralLockInZooKeeper(
ops.emplace_back(zkutil::makeRemoveRequest(deduplication_path, -1));
ops.emplace_back(zkutil::makeCreateRequest(path_prefix_, holder_path, zkutil::CreateMode::EphemeralSequential));
Coordination::Responses responses;
Coordination::Error e = zookeeper_.tryMulti(ops, responses);
Coordination::Error e = zookeeper_->tryMulti(ops, responses);
if (e != Coordination::Error::ZOK)
{
if (responses[0]->error == Coordination::Error::ZNODEEXISTS)
{
LOG_DEBUG(
&Poco::Logger::get("createEphemeralLockInZooKeeper"),
"Deduplication path already exists: deduplication_path={}",
deduplication_path);
return {};
}
else
Expand Down Expand Up @@ -82,9 +87,31 @@ EphemeralLockInZooKeeper::~EphemeralLockInZooKeeper()
{
unlock();
}
catch (const zkutil::KeeperException & e)
{
if (Coordination::isHardwareError(e.code))
LOG_DEBUG(
&Poco::Logger::get("EphemeralLockInZooKeeper"),
"ZooKeeper communication error during unlock: code={} message='{}'",
e.code,
e.message());
else if (e.code == Coordination::Error::ZNONODE)
/// To avoid additional round-trip for unlocking,
/// ephemeral node can be deleted explicitly as part of another multi op request to ZK
/// and marked as such via assumeUnlocked() if we got successful response.
/// But it's possible that the multi op request can be executed on server side, and client will not get response due to network issue.
/// In such case, assumeUnlocked() will not be called, so we'll get ZNONODE error here since the noded is already deleted
LOG_DEBUG(
&Poco::Logger::get("EphemeralLockInZooKeeper"),
"ZooKeeper node was already deleted: code={} message={}",
e.code,
e.message());
else
tryLogCurrentException("EphemeralLockInZooKeeper");
}
catch (...)
{
tryLogCurrentException("~EphemeralLockInZooKeeper");
tryLogCurrentException("EphemeralLockInZooKeeper");
}
}

Expand Down
15 changes: 9 additions & 6 deletions src/Storages/MergeTree/EphemeralLockInZooKeeper.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

namespace DB
{
class ZooKeeperWithFaultInjection;
using ZooKeeperWithFaultInjectionPtr = std::shared_ptr<ZooKeeperWithFaultInjection>;

namespace ErrorCodes
{
Expand All @@ -25,13 +27,14 @@ namespace ErrorCodes
class EphemeralLockInZooKeeper : public boost::noncopyable
{
friend std::optional<EphemeralLockInZooKeeper> createEphemeralLockInZooKeeper(
const String & path_prefix_, const String & temp_path, zkutil::ZooKeeper & zookeeper_, const String & deduplication_path);
const String & path_prefix_, const String & temp_path, const ZooKeeperWithFaultInjectionPtr & zookeeper_, const String & deduplication_path);

protected:
EphemeralLockInZooKeeper() = delete;
EphemeralLockInZooKeeper(const String & path_prefix_, zkutil::ZooKeeper & zookeeper_, const String & path_);
EphemeralLockInZooKeeper(const String & path_prefix_, const ZooKeeperWithFaultInjectionPtr & zookeeper_, const String & path_);

public:
EphemeralLockInZooKeeper() = delete;

/// Fake "secondary node" names for blocks with and without "deduplication_path"
static constexpr const char * LEGACY_LOCK_INSERT = "abandonable_lock-insert";
static constexpr const char * LEGACY_LOCK_OTHER = "abandonable_lock-other";
Expand All @@ -53,7 +56,7 @@ class EphemeralLockInZooKeeper : public boost::noncopyable

bool isLocked() const
{
return zookeeper;
return zookeeper.get();
}

String getPath() const
Expand Down Expand Up @@ -91,13 +94,13 @@ class EphemeralLockInZooKeeper : public boost::noncopyable
~EphemeralLockInZooKeeper();

private:
zkutil::ZooKeeper * zookeeper = nullptr;
ZooKeeperWithFaultInjectionPtr zookeeper;
String path_prefix;
String path;
};

std::optional<EphemeralLockInZooKeeper> createEphemeralLockInZooKeeper(
const String & path_prefix_, const String & temp_path, zkutil::ZooKeeper & zookeeper_, const String & deduplication_path);
const String & path_prefix_, const String & temp_path, const ZooKeeperWithFaultInjectionPtr & zookeeper_, const String & deduplication_path);


/// Acquires block number locks in all partitions.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ void ReplicatedMergeTreeMergeStrategyPicker::refreshState()
&& now - last_refresh_time < REFRESH_STATE_MINIMUM_INTERVAL_SECONDS)
return;

LOG_DEBUG(storage.log, "Updating strategy picker state");

auto zookeeper = storage.getZooKeeper();
auto all_replicas = zookeeper->getChildren(storage.zookeeper_path + "/replicas");

Expand Down Expand Up @@ -154,6 +156,8 @@ void ReplicatedMergeTreeMergeStrategyPicker::refreshState()
last_refresh_time = now;
current_replica_index = current_replica_index_tmp;
active_replicas = active_replicas_tmp;

LOG_DEBUG(storage.log, "Strategy picker state updated, current replica: {}, active replicas: [{}]", current_replica_index, fmt::join(active_replicas, ", "));
}


Expand Down
Loading