NAME
DBIO::Replicated::Storage - Replicated DBI storage coordinator
VERSION
version 0.900000
SYNOPSIS
my $schema = MyApp::Schema->connect($master_dsn, $user, $pass, {
storage_type => '+DBIO::Replicated::Storage',
balancer_type => 'DBIO::Replicated::Balancer::First',
});
$schema->storage->connect_replicants(
[ $replica_dsn_1, $user, $pass ],
[ $replica_dsn_2, $user, $pass ],
);
# Temporarily force reads to the master
$schema->storage->execute_reliably(sub {
my $artist = $schema->resultset('Artist')->find(1);
...
});
DESCRIPTION
DBIO::Replicated::Storage coordinates one master backend plus zero or more replicant backends.
The master backend handles write-oriented work such as inserts, updates, deletes, transactions, deploy operations, and connection-time setup. Read-oriented methods are delegated to the current read handler, which is a balancer by default.
Replicants are managed through DBIO::Replicated::Pool. The pool can use replication hooks such as is_replicating and lag_behind_master when the underlying driver storage provides them.
The replicated layer consumes a small set of connect-info options for itself: pool_type, pool_args, balancer_type, balancer_args, and backend_storage_class. All remaining connect attributes are passed through to the master backend.
METHODS
connect_info
Accepts the normal DBI connect-info arrayref used for the master connection.
Replicated-specific options can be supplied in connect-info hashrefs:
pool_type/pool_argsbalancer_type/balancer_argsbackend_storage_class
These options are consumed by the replicated layer. Remaining DBI attributes are passed through to the master backend and are also used as defaults when replicant connect info is merged later.
connect_replicants
$storage->connect_replicants(
[ $dsn_1, $user, $pass ],
[ $dsn_2, $user, $pass, { RaiseError => 1 } ],
);
Connects one or more replicant backends and adds them to the pool.
Any connect attributes captured from the master connection are merged into each replicant connect-info hashref unless explicitly overridden.
execute_reliably
$storage->execute_reliably(sub { ... });
Temporarily forces reads to use the master backend while the supplied coderef runs.
set_reliable_storage
Persistently switches the current read handler to the master backend.
set_balanced_storage
Restores the balancer as the current read handler after "set_reliable_storage".
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.