Clio  develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
cluster::WriterDecider Class Reference

Decides which node in the cluster should be the writer based on cluster state. More...

#include <WriterDecider.hpp>

Public Member Functions

 WriterDecider (boost::asio::thread_pool &ctx, std::unique_ptr< etl::WriterStateInterface > writerState)
 Constructs a WriterDecider.
void onNewState (ClioNode::CUuid selfId, std::shared_ptr< Backend::ClusterData const > clusterData)
 Handles cluster state changes and decides whether this node should be the writer.

Detailed Description

Decides which node in the cluster should be the writer based on cluster state.

This class monitors cluster state changes and determines whether the current node should act as the writer to the database. The decision is made by:

  1. Sorting all nodes by UUID for deterministic ordering
  2. Selecting the first node that is allowed to write (not ReadOnly)
  3. Activating writing on this node if it's the current node, otherwise deactivating

This ensures only one node in the cluster actively writes to the database at a time.

Constructor & Destructor Documentation

◆ WriterDecider()

cluster::WriterDecider::WriterDecider ( boost::asio::thread_pool & ctx,
std::unique_ptr< etl::WriterStateInterface > writerState )

Constructs a WriterDecider.

Parameters
ctxThread pool for executing asynchronous operations
writerStateWriter state interface for controlling write operations

Member Function Documentation

◆ onNewState()

void cluster::WriterDecider::onNewState ( ClioNode::CUuid selfId,
std::shared_ptr< Backend::ClusterData const > clusterData )

Handles cluster state changes and decides whether this node should be the writer.

This method is called when cluster state changes. It asynchronously:

  • Sorts all nodes by UUID to establish a deterministic order
  • Identifies the first node allowed to write (not ReadOnly)
  • Activates writing if this node is selected, otherwise deactivates writing
  • Logs a warning if no nodes in the cluster are allowed to write
Parameters
selfIdThe UUID of the current node
clusterDataShared pointer to current cluster data; may be empty if communication failed

The documentation for this class was generated from the following files:
  • /__w/clio/clio/src/cluster/WriterDecider.hpp
  • /__w/clio/clio/src/cluster/WriterDecider.cpp