Is is possible to have exclusive lock across all nodes?

26 views
Skip to first unread message

Aleksandr Savvopulo

unread,
Mar 20, 2017, 12:20:26 PM3/20/17
to codership
The task is: generate and use next id for the record during update. 
That means i have record that have someid field. 
I need to set next id value and update record. The main condition is to have id without gaps, even 
in case if multiple transactions running and trying to get next id (and some of them may fail).

In usual case with single db server instance I would use exclusive lock (select ... for update) to have last id, increment it and update rows. 
But how to achieve the same locking in distributed environment? 

How to lock the same row on multiple nodes? 
And is it possible to have an exclusive lock (select ... for update) for a row across all nodes at all? 

Thanks for your time!

Philip Stoev

unread,
Mar 20, 2017, 1:05:59 PM3/20/17
to Aleksandr Savvopulo, codership
Hello,

At this time Galera Cluster does not allow for an exclusive lock to be taken
on all nodes. SELECT FOR UPDATE takes effect only locally, and is not
replicated to the other nodes.

In your case, the easiest solution would be to only generate IDs on a single
node and make sure the other nodes do not manipulate the table that contains
the IDs.

Philip Stoev
--
You received this message because you are subscribed to the Google Groups
"codership" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to codership-tea...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages