Single (instance level) connection to a replica (messages from all databases get multiplexed through it) ReplicationClient split in two: ReplicationClient and ReplicationStorageClient New ReplicationClient, moved under replication, handles the raw connection, owned by MainRoleData ReplicationStorageClient handles the storage <-> replica state machine and holds to a stream Removed epoch and storage from *Clients rpc::Stream proactively aborts on error and sets itself to a defunct state Removed HandleRpcFailure, instead we simply log the error and let the FrequentCheck handle re-connection replica_state is now a synced variable ReplicaStorageClient state machine bugfixes Single FrequentCheck that goes through DBMS Moved ReplicationState under DbmsHandler Moved some replication startup logic under the DbmsHandler's constructor Removed InMemoryReplicationClient CreateReplicationClient has been removed from Storage Simplified GetRecoverySteps and made safer --------- Co-authored-by: Gareth Lloyd <gareth.lloyd@memgraph.io>
35 lines
1.5 KiB
C++
35 lines
1.5 KiB
C++
// Copyright 2023 Memgraph Ltd.
|
|
//
|
|
// Use of this software is governed by the Business Source License
|
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
|
// License, and you may not use this file except in compliance with the Business Source License.
|
|
//
|
|
// As of the Change Date specified in that file, in accordance with
|
|
// the Business Source License, use of this software will be governed
|
|
// by the Apache License, Version 2.0, included in the file
|
|
// licenses/APL.txt.
|
|
|
|
#include "dbms/replication_client.hpp"
|
|
|
|
namespace memgraph::dbms {
|
|
|
|
void StartReplicaClient(DbmsHandler &dbms_handler, replication::ReplicationClient &client) {
|
|
// No client error, start instance level client
|
|
auto const &endpoint = client.rpc_client_.Endpoint();
|
|
spdlog::trace("Replication client started at: {}:{}", endpoint.address, endpoint.port);
|
|
client.StartFrequentCheck([&dbms_handler](std::string_view name) {
|
|
// Working connection, check if any database has been left behind
|
|
dbms_handler.ForEach([name](dbms::Database *db) {
|
|
// Specific database <-> replica client
|
|
db->storage()->repl_storage_state_.WithClient(name, [&](storage::ReplicationStorageClient *client) {
|
|
if (client->State() == storage::replication::ReplicaState::MAYBE_BEHIND) {
|
|
// Database <-> replica might be behind, check and recover
|
|
client->TryCheckReplicaStateAsync(db->storage());
|
|
}
|
|
});
|
|
});
|
|
});
|
|
}
|
|
|
|
} // namespace memgraph::dbms
|