You can use the alternating identifier strategy
Each server is numbered from 0 to n and adds its server number to the sequence that executes n. One of the implementations would be to have a table AUTO_INCREMENTfor generating identifiers, then use this identifier in such a function:
CREATE TABLE ID_CREATOR (ID INT AUTO_INCREMENT PRIMARY KEY);
Assuming there are 3 servers, and this server is server number 1, this function will give a unique value for each server:
CREATE FUNCTION generate_document_log_id() RETURNS INT
BEGIN
DECLARE NUMBER_OF_SERVERS INT DEFAULT 3; -- Or read from some table
DECLARE THIS_SERVER_ID INT DEFAULT 1; -- Or read from some table. Must be less than NUMBER_OF_SERVERS
INSERT INTO ID_CREATOR VALUES (); -- This creates the next id
RETURN LAST_INSERT_ID() * NUMBER_OF_SERVERS + THIS_SERVER_ID; -- Unique numbers that interleave each other
END
source
share