Comments - Getting Started with MariaDB Galera Cluster

9 years, 10 months ago Raghav Narayanan

Hi, I have a question around auto_increment values - is it always guaranteed to be in the ascending order? To give an example, say we have a 2 node cluster with the following settings

Node1: @@auto_increment_increment=2, @@auto_increment_offset=1 Node2: @@auto_increment_increment=2, @@auto_increment_offset=2

If 2 rows are inserted from Node1 into a table with an auto_increment primary key the IDs generated will be 1 and 3. If the next insert into the table is from Node2 the ID should be 4 as opposed to 2.

Thanks Raghav

 
9 years, 10 months ago Daniel Black

Hi, I have a question around auto_increment values - is it always guaranteed to be in the ascending order?

Yes.

say we have a 2 node cluster with the following settings

There is rarely a good reason not to have 3 nodes. With two you don't have a automated failure recovery

The autoincrement is sorted with the wsrep_auto_increment_control=1 (the default)

If 2 rows are inserted from Node1 into a table with an auto_increment primary key the IDs generated will be 1 and 3. If the next insert into the table is from Node2 the ID should be 4 as opposed to 2.

If the insert on Node 2 occurs before the from Node 1 applies you may get 2.

autoincrements can have gaps (due to transaction rollback). Use last_insert_id if you want the value of a last insert. Don't try to predict them.

 
9 years, 9 months ago Raghav Narayanan

Thanks Daniel, I used the two node example just to keep it simple.What happens if there are simultaneous inserts in more than one node for a particular table is that arbitrated somehow by the cluster and Ids generated accordingly?

Thanks

Raghav

 
Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.