Commit Scopes v5
Commit Scopes give applications granular control about durability and consistency of EDB Postgres Distributed.
A Commit Scope is a named rule that describes behavior of COMMIT replication. The actual behavior depends on whether a Commit Scope uses Group Commit, Commit At Most Once, Lag Control or combination of these.
Configuration
To use Group Commit, first define a commit scope. This determines the BDR nodes involved in the commit of a transaction. Once a scope is established, you can configure a transaction to use Group Commit as follows:
The commit scope must be set before the transaction has written any data.
For this example, you might previously have defined the commit scope as:
This assumes a node group named example_bdr_group
exists and
includes at least two BDR nodes as members, either directly or in
subgroups. Any transaction committed in the example_scope
requires one extra confirmation from a BDR node in the group.
Together with the origin node, this accounts for "ANY 2" nodes out of
the group, on which the transaction is guaranteed to be visible and
durable after the commit.
Origin groups
Rules for commit scopes can depend on the node the transaction is committed on, that is, the node that acts as the origin for the transaction. To make this transparent for the application, BDR allows a commit scope to define different rules depending on where the transaction originates from.
For example, consider a EDB Postgres Distributed cluster with nodes
spread across two data centers: a left and a right one.
Assume the top-level BDR node group
is called top_group
. You can use the following commands to set up
subgroups and create a commit scope requiring all nodes in the local
data center to confirm the transaction but only one node from the
remote one.
Now using the example_scope
on any node that's part of left_dc
will use the
first scope, while using same scope on node that's part of right_dc
will
use the second scope. This is effective way of creating inverted scope without
having to juggle scope names in application.
In addition to this, each group can also have default commit scope specified using
bdr.alter_node_group_option
admin interface.
So making the above scopes the default ones for all transactions originatin on nodes withing those groups would look like this.
Confirmation levels
BDR nodes can send confirmations for a transaction at different points in time. In increasing levels of protection, from the perspective of the confirming node, these are:
received
— A remote BDR node confirms the transaction immediately after receiving it, prior to starting the local application.replicated
— Confirm after applying changes of the transaction but before flushing them to disk.durable
— Confirm the transaction after all of its changes are flushed to disk.visible
(default) — Confirm the transaction after all of its changes are flushed to disk and it's visible to concurrent transactions.
In rules for commit scopes, you can append these confirmation levels
to the node group definition in parenthesis with ON
as follows:
ANY 2 (right_dc) ON replicated
ALL (left_dc) ON visible
(default and may as well be omitted)ALL (left_dc) ON received AND ANY 1 (right_dc) ON durable
Reference
Commit scope grammar
For reference, the grammar for commit scopes is composed as follows:
Parameters
node_group
- name of a node group( group_commit_parameter = value )
- options for Group Committransaction_tracking
(boolean) - specifies whether status of transaction should be trackedconflict_resolution
(enum) - how to handle conflicts, possible values are eitherasync
meaning conflicts should be resolved asynchronously after during replication using the conflict resolution policy oreager
meaning that conflicts are resolved eagerly during COMMIT by aborting one of the conflicting transactionscommit_decision
(enum) - how is COMMIT decision made, it can be eithergroup
meaning thecommit_scope_group
specification also affects the COMMIT decision, not just durability, it can also bepartner
which means partner node decides whether transaction can be committed (this is only allowed on 2 data node groups) or it can beraft
which means COMMIT decision is done using Raft consensus independently ofcommit_scope_group
consensus.
ABORT ON ( abort_on_parameter = value )
- allows automatic transaction abort on timeouttimeout
(interval) - timeout in milliseconds (accepts other units)
DEGRADE ON ( degrade_on_parameter = value )
- allows degrading to asynchronous operation on timeouttimeout
(interval) - timeout in milliseconds (accepts other units) after which operation becomes asynchronousrequire_write_lead
(boolean) - whether the node has to be a write lead to to be able to switch to asynchronous mode
( lag_control_parameter = value )
- options for Lag Controlmax_lag_size
(int) - maximum allowed lag based on WAL bytesmax_lag_time
(interval) - maximum allowed lag based on wall clock samplingmax_commit_delay
(interval) - maximum delay that can be injected to commit in order to try to keep within the lag limits
Note
CAMO
commit scope kind is mostly syntax sugar for
GROUP COMMIT (transaction_tracking = true, commit_decision = partner)
with
additional DEGRADE ON
clause. It's expected that GROUP COMMIT
will
eventually gain DEGRADE ON
clause as well, making CAMO
syntax deprecated.
Note
While the grammar for synchronous_standby_names
and Commit
Scopes can loo very similar, it is important to note that the former
does not account for the origin node, but the latter does.
Therefore, for example synchronous_standby_names = 'ANY 1 (..)'
is equivalent to a Commit Scope of ANY 2 (...)
. This choice
makes reasoning about majority easier and reflects that the origin
node also contributes to the durability and visibility of the
transaction.
Adding a commit scope rule
The function bdr.add_commit_scope
creates a rule for the given
commit scope name and origin node group. If the rule is the same for
all nodes in the EDB Postgres Distributed cluster, invoking this function once for the
top-level node group is enough to fully define the commit scope.
Alternatively, you can invoke it multiple times with the same
commit_scope_name
but different origin node groups and rules for
commit scopes that vary depending on the origin of the transaction.
Synopsis
Changing a commit scope rule
To change a specific rule for a single origin node group in a
commit scope, you can use the function bdr.alter_commit_scope
.
Synopsis
Removing a commit scope rule
You can use bdr.remove_commit_scope
to drop a single rule in
a commit scope. If you define multiple rules for the commit scope, you must invoke
this function once per rule to fully remove the entire
commit scope.
Synopsis
Note
Removing a commit scope that is still used as default by a node group is not allowed
- On this page
- Configuration
- Reference