Master instance

Luna-Video-Manager needs to a master instance for correct work several mechanics.

All running service instances choose the master instance for the correct execution of these processes (without race conditions and etc.). Only master instance can execute these processes.

Choice of master

Every service tries to get a database lock (update a field in the table single_process_lock). If an instance gets a lock it saves the state master and sends heartbeat message to database further. Other instances observe the heartbeat. If heartbeat is ended any service will try to be new master.