ClickHouse/src/Storages/MergeTree/ParallelReplicasReadingCoordinator.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

47 lines
1.5 KiB
C++
Raw Normal View History

#pragma once
#include <memory>
#include <Storages/MergeTree/RequestResponse.h>
2022-11-14 05:09:03 +00:00
namespace DB
{
struct Progress;
using ProgressCallback = std::function<void(const Progress & progress)>;
2023-02-03 13:34:18 +00:00
/// The main class to spread mark ranges across replicas dynamically
class ParallelReplicasReadingCoordinator
{
public:
2023-02-03 13:34:18 +00:00
class ImplInterface;
explicit ParallelReplicasReadingCoordinator(size_t replicas_count_);
~ParallelReplicasReadingCoordinator();
2023-02-03 13:34:18 +00:00
void handleInitialAllRangesAnnouncement(InitialAllRangesAnnouncement);
ParallelReadResponse handleRequest(ParallelReadRequest request);
/// Called when some replica is unavailable and we skipped it.
/// This is needed to "finalize" reading state e.g. spread all the marks using
/// consistent hashing, because otherwise coordinator will continue working in
/// "pending" state waiting for the unavailable replica to send the announcement.
void markReplicaAsUnavailable(size_t replica_number);
/// needed to report total rows to read
void setProgressCallback(ProgressCallback callback);
private:
2023-02-03 13:34:18 +00:00
void initialize();
std::mutex mutex;
2023-02-03 13:34:18 +00:00
size_t replicas_count{0};
CoordinationMode mode{CoordinationMode::Default};
2023-02-03 13:34:18 +00:00
std::atomic<bool> initialized{false};
std::unique_ptr<ImplInterface> pimpl;
ProgressCallback progress_callback; // store the callback only to bypass it to coordinator implementation
};
using ParallelReplicasReadingCoordinatorPtr = std::shared_ptr<ParallelReplicasReadingCoordinator>;
}