Semisynchronous Replication

MariaDB starting with 10.3

Semisynchronous replication is no longer a plugin in MariaDB 10.3 and later. This removes some overhead and improves performance. See MDEV-13073 for more information.

MariaDB starting with 10.1.3

Semisynchronous replication was significantly enhanced in MariaDB 10.1.3. See MDEV-162 for more information.

MariaDB starting with 5.5

Semisynchronous replication was first released in MariaDB 5.5 as a plugin.

Regular MariaDB replication is asynchronous, but MariaDB also provides a semisynchronous replication option. In MariaDB 10.3 and later, semisynchronous replication is built into the server. In MariaDB 10.2 and before, semisynchronous replication required the user to install a plugin.

In semisynchronous replication, only after the events have been written to the relay log and flushed does the slave acknowledge receipt of a transaction's events. If the slave does not acknowledge the transaction before a certain amount of time has passed (configurable with the rpl_semi_sync_master_timeout system variable), a timeout occurs and the master switches to asynchronous replication. When at least one semisynchronous slave catches up, semisynchronous replication is resumed.

Installing the Plugin

MariaDB starting with 10.3.3

In MariaDB 10.3.3 and later, the Semisynchronous Replication feature is built into the server itself and is no longer provided by a plugin, so this step is not supported on those versions. In MariaDB 10.3.3 and later, you can skip right to Enabling Semisynchronous Replication.

The semisynchronous replication plugin is actually two different plugins--one for the master, and one for the slave. Shared libraries for both plugins are included with MariaDB. Although the plugins' shared libraries distributed with MariaDB by default, the plugin is not actually installed by MariaDB by default prior to MariaDB 10.3.3. There are two methods that can be used to install the plugin with MariaDB.

The first method can be used to install the plugin without restarting the server. You can install the plugin dynamically by executing INSTALL SONAME or INSTALL PLUGIN.

For example, if it's a master:

INSTALL SONAME 'semisync_master';

Or if it's a slave:

INSTALL SONAME 'semisync_slave';

The second method can be used to tell the server to load the plugin when it starts up. The plugin can be installed this way by providing the --plugin-load or the --plugin-load-add options. This can be specified as a command-line argument to mysqld or it can be specified in a relevant server option group in an option file.

For example, if it's a master:

[mariadb]
...
plugin_load_add = semisync_master

Or if it's a slave:

[mariadb]
...
plugin_load_add = semisync_slave

Uninstalling the Plugin

MariaDB starting with 10.3.3

In MariaDB 10.3.3 and later, the Semisynchronous Replication feature is built into the server itself and is no longer provided by a plugin, so this step is not supported on those versions.

You can uninstall the plugin dynamically by executing UNINSTALL SONAME or UNINSTALL PLUGIN.

For example, if it's a master:

UNINSTALL SONAME 'semisync_master';

Or if it's a slave:

UNINSTALL SONAME 'semisync_slave';

If you installed the plugin by providing the --plugin-load or the --plugin-load-add options in a relevant server option group in an option file, then those options should be removed to prevent the plugin from being loaded the next time the server is restarted.

Enabling Semisynchronous Replication

Semisynchronous replication can be enabled by setting the relevant system variables on the master and the slave. Setting rpl_semi_sync_master_enabled=ON can enable the plugin on the master, and setting rpl_semi_sync_slave_enabled=ON can enable the plugin on the slave.

If semisynchronous replication is enabled on a server when slave threads were already running, the slave I/O thread will need to be restarted to enable the slave to register as a semisynchronous slave when it connects to the master. For example:

STOP SLAVE IO_THREAD;
START SLAVE IO_THREAD;

If this is not done, and the slave thread is already running, then it will continue to use asynchronous replication.

Versions

VersionStatusIntroduced
1.0StableMariaDB 10.1.13
1.0GammaMariaDB 10.0.13
1.0UnknownMariaDB 10.0.11
1.0N/AMariaDB 5.5

System Variables

rpl_semi_sync_master_enabled

  • Description: Set to ON to enable semi-synchronous replication master. Disabled by default.
  • Commandline: --rpl-semi-sync-master-enabled[={0|1}]
  • Scope: Global
  • Dynamic: Yes
  • Data Type: boolean
  • Default Value: OFF

rpl_semi_sync_master_timeout

  • Description: The timeout value, in milliseconds, for semi-synchronous replication in the master. If this timeout is exceeded in waiting on a commit for acknowledgement from a slave, the master will revert to asynchronous replication, setting the Rpl_semi_sync_master_status status variable to OFF as it does so.
  • Commandline: --rpl-semi-sync-master-timeout[=#]
  • Scope: Global
  • Dynamic: Yes
  • Data Type: numeric
  • Default Value: 10000 (10 seconds)
  • Range: 0 to 18446744073709551615

rpl_semi_sync_master_trace_level

  • Description: The tracing level for semi-sync replication. Four levels are defined:
    • 1: General level, including for example time function failures.
    • 16: More detailed level, with more verbose information.
    • 32: Net wait level, including more information about network waits.
    • 64: Function level, including information about function entries and exits.
  • Commandline: --rpl-semi-sync-master-trace-level[=#]
  • Scope: Global
  • Dynamic: Yes
  • Data Type: numeric
  • Default Value: 32
  • Range: 0 to 18446744073709551615

rpl_semi_sync_master_wait_no_slave

  • Description: If set to ON, the default, the slave count (recorded by Rpl_semi_sync_master_clients) may drop to zero, and the master will still wait for the timeout period. If set to OFF, the master will revert to asynchronous replication as soon as the slave count drops to zero.
  • Commandline: --rpl-semi-sync-master-wait-no-slave[={0|1}]
  • Scope: Global
  • Dynamic: Yes
  • Data Type: boolean
  • Default Value: ON

rpl_semi_sync_master_wait_point

  • Description: Whether the transaction should wait for semi-sync acknowledgement after having synced the binlog (AFTER_SYNC), or after having committed in storage engine (AFTER_COMMIT, the default).
    • When this variable is set to AFTER_SYNC, all clients see the same data on the master at the same time; after acknowledgement by the slave and after being committed to the storage engine on the master. If the master crashes, because all transactions committed on the master have been replicated to the slave, so failover is lossless.
    • When this variable is set to AFTER_COMMIT, the return status is received by the transaction only after the server commits to the storage engine and receives slave acknowledgement. Other clients may see the committed transaction before the committing client, and if the master crashes, it is possible that clients will see data loss relative to what they saw on the master.
  • Commandline: --rpl-semi-sync-master-wait-point=value
  • Scope: Global
  • Dynamic: Yes
  • Data Type: enum
  • Default Value: AFTER_COMMIT
  • Valid Values: AFTER_SYNC, AFTER_COMMIT

rpl_semi_sync_slave_delay_master

  • Description: Only write master info file when ack is needed.
  • Commandline: --rpl-semi-sync-slave-delay-master[={0|1}]
  • Scope: Global
  • Dynamic: Yes
  • Data Type: boolean
  • Default Value: OFF
  • Introduced: MariaDB 10.3.3

rpl_semi_sync_slave_enabled

  • Description: Set to ON to enable semi-synchronous replication slave. Disabled by default.
  • Commandline: --rpl-semi-sync-slave-enabled[={0|1}]
  • Scope: Global
  • Dynamic: Yes
  • Data Type: boolean
  • Default Value: OFF

rpl_semi_sync_slave_kill_conn_timeout

  • Description: Timeout for the mysql connection used to kill the slave io_thread's connection on master. This timeout comes into play when stop slave is executed.
  • Commandline: --rpl-semi-sync-slave-kill-conn-timeout[={0|1}]
  • Scope: Global
  • Dynamic: Yes
  • Data Type: numeric
  • Default Value: 5
  • Range: 0 to 4294967295
  • Introduced: MariaDB 10.3.3

rpl_semi_sync_slave_trace_level

  • Description: The tracing level for semi-sync replication. The levels are the same as for rpl_semi_sync_master_trace_level.
  • Commandline: --rpl-semi-sync-slave-trace_level[=#]
  • Scope: Global
  • Dynamic: Yes
  • Data Type: numeric
  • Default Value: 32
  • Range: 0 to 18446744073709551615

Status Variables

For a list of status variables added when the plugin is installed, see Semisynchronous Replication Plugin Status Variables.

Comments

Comments loading...