NAME

DBIO::Replicated::Pool - Manage a pool of replicant backends

VERSION

version 0.900004

DESCRIPTION

Holds the replicant backends of a DBIO::Replicated::Storage, in the order they were added, and decides which are active. Plain read/write accessors: maximum_lag (default 0), last_validated (epoch seconds, default 0), replicant_type (default DBIO::Replicated::Backend::Replicant), storage_class (default DBIO::Storage::DBI) and next_unknown_replicant_id (default 1).

METHODS

new

my $pool = DBIO::Replicated::Pool->new(
  master      => $master_backend,
  maximum_lag => 2,
);

master

Getter/setter for the master backend handed to new replicants.

replicants

Getter/setter for the hashref of replicants, keyed by name.

set_replicant

get_replicant

delete_replicant

$pool->set_replicant($name => $backend);
my $backend = $pool->get_replicant($name);
$pool->delete_replicant($name);

Store, fetch and remove one replicant by name, keeping the insertion order used by "all_replicants".

has_replicants

num_replicants

Both return the number of replicants.

all_replicants

All replicants, in the order they were added.

connected_replicants

The number of replicants that are currently connected.

active_replicants

The replicants currently flagged active, in order.

connect_replicants

my @new = $pool->connect_replicants($schema, @connect_infos);

Creates one replicant per connect info (via "connect_replicant") and adds it to the pool. The replicant is named after the part of its DSN following dbi:Driver:, without any password=, passwd= or pwd= part, so the name -- the value force_pool takes -- never carries a password. Replicants whose DSN is not known up front (a coderef or dbh_maker connect, or an AccessBroker) are named UNKNOWN_n. Returns the new replicants.

connect_replicant

my $replicant = $pool->connect_replicant($schema, $connect_info);

Builds one replicant: a new storage_class storage with this connect info (driver resolved right away), wrapped in a replicant_type backend tied to the master, with the master's trace object proxied onto it. Does not add it to the pool.

validate_replicants

Checks every replicant and sets its active flag: a replicant that cannot connect, or reports it is not replicating, is deactivated; one that is replicating is active if its lag_behind_master is at most maximum_lag. A replicant whose storage cannot answer is_replicating or lag_behind_master is left as it is. Updates last_validated.

AUTHOR

DBIO & DBIx::Class Authors

COPYRIGHT AND LICENSE

Copyright (C) 2026 DBIO Authors Portions Copyright (C) 2005-2025 DBIx::Class Authors Based on DBIx::Class, heavily modified.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.