MySQL Group Replication: Auto-increment configuration/handling

In 0.5.0 version of MySQL Group Replication plugin, we have introduced the Auto-increment configuration/handling feature through which auto increment variables (auto_increment_increment and auto_increment_offset) are auto configured by the plugin, so that different members of the group don’t generate duplicated auto increment values.

Auto increment variables – auto_increment_increment and auto_increment_offset

MySQL server already provides two auto increment variables: auto_increment_increment and auto_increment_offset, which can be used to generate different auto increment values on each member. MySQL circular (MySQL 5.0.2 onwards) replication already uses this approach, but the servers need to be configured manually.

auto_increment_increment: controls the interval between successive column values. The default value is 1.

auto_increment_offset: determines the starting point for the AUTO_INCREMENT column value. The default value is 1.

For example:


Auto increment in Group Replication (before 0.5.0 version)

Now consider a scenario where clients are concurrently inserting records in the table with a auto increment field on different members of the group.

where the Members column contains the group members in which data is inserted.

When using the default values for auto increment, there could be a situation when two members insert a new record at the same instant of time. In the example above value 4 was generated and inserted by member1 and member4 at the same instant of time, which would result in a deadlock error on one member and a successful commit on the other.

In versions earlier to 0.5.0, even though correctness was never compromised, when updating different members, there was always a potential for unnecessary rollbacks and degraded performance.


Auto increment in Group Replication (from 0.5.0 version)

In Group Replication 0.5.0 version, we have added changes which will automatically set auto_increment_increment and auto_increment_offset variables every time we start GR plugin, and reset every time we stop it. But what values should these variables take, when Group Replication starts? The value of the auto_increment_offset should somehow allow the generation of separated values for each group member. To accomplish this the simplest option is to set it to the server id on each member and so this value will  be different for every server.

At the same time the variable auto_increment_increment should have a value that when incremented to each offset generates a new individual id. The group size is the best option, but what is the group size? As it is undesirable to reconfigure the variables at each group change, the auto_increment_increment should then have by default a value that is suitable for most user scenarios.

For this reason we introduced a new system variable:


This variable will have a default value of ‘7’.
The default value for group_replication_auto_increment_increment  was chosen as 7, as a valid compromise taking into account the maximum usable values for each possible auto_increment_increment and what is a normal group expected size.

Table 1 above shows worst case scenario of maximum usable values for different auto_increment_increment values.

The variable auto_increment_increment is set, by default,  to the value of group_replication_auto_increment_increment , i.e., 7 and auto_increment_offset is set to server_id, every time GR plugin starts.

GR plugin also makes sure that:

  • GR plugin will only set auto_increment_increment and auto_increment_offset
    on GR plugin start if they are at their default values of 1. So making sure
    that it doesn’t override user set auto_increment values.
  • GR plugin will only reset auto_increment_increment and auto_increment_offset
    to default value of 1 on GR plugin stop, if they were modified earlier by GR
    plugin and not by the user.

Consider a three member group with following auto-increment configurations:
auto_increment_increment:    7 (size of group is 3)
auto_increment_offset:              server_id ( where M1 = 1, M2 = 2, M3 = 3)

And for inserts as sequenced in diagram below, you will see following values inserted in table:

where the Members column contains the group members in which data is inserted.

The arithmetic sequence with common difference of 7 for each member would be:
M1:  1,  8,  15,  22,  29,  36….
M2:  2,  9,  16,  23,  30,  37….
M3:  3,  10,  17,  24,  31,  38….

The next inserted value for auto_increment field will be picked from that member sequence and will be greater than last inserted value. So for example in Figure 2, after the insert of key 30, if the next insert is on M3, then inserted auto_increment value will be 31 (23+7), but if it is on M1 then the inserted value would be 36 (15+7+7+7). This approach will make sure that we don’t get duplicate auto_increment values, while inserting on any member of the group.

For example:


Override default auto_increment_increment value

If your group size is bigger or smaller than the default group_replication_auto_increment_increment  value of 7 and you want to override it, you can always do that by modify its  value before plugin start. This value cannot be changed when the plugin is running.

For example:



Before this feature, there was no provision available to automate the setting of different auto_increment_increment and auto_increment_offset values on each member of group replication. This feature improves the overall performance of group replication as there will be no rollbacks due to duplicate auto increment values. Also these settings can be conveniently overridden by modifying group_replication_auto_increment_increment  variable directly.

Go to labs releases and try latest MySQL Group Replication Plugin 0.5.0 version, and post your questions and feedback here.

3 thoughts on “MySQL Group Replication: Auto-increment configuration/handling

  1. Hi ,
    In my group replication lab ,my db1 server_id is 111 ,db2 server_id is 112 and db3 server_id is 113 .
    My inserts auto_increment values as below :

    Members | Inserted Values
    db1 | 1 14 28 29 30
    db2 | 5 12 33
    db3 | 6 13 20 27 34

    I don’t know why the db1 sequence not difference of 7 for each member?
    And why db2 start at 5 ,db3 start at 6 ?

    1. Hi Jerry,

      Thanks for testing it, we will look into it.
      If this is indeed an issue try, if you can, to use for now low values for server id.

Leave a Reply

Your email address will not be published. Required fields are marked *

Please enter. * Time limit is exhausted. Please reload CAPTCHA.