imatix/zguide — pull request #172 by jgallagher (2012-02-14 05:20:05+00:00)
Title: Bugfixes for bstar example.

The change to examples/C/bstar.c is just a plain bugfix (the example doesn't work without it).

The changes to examples/Python/bstar.py are to prevent a "dual masters" race condition. Prior to the changes, this sequence of events causes a dual masters exception:

1) start up both servers and the client as normal
2) kill the primary
3) wait for failover to succeed, then kill the client
4) start the client
5) immediately (< 2 seconds) start the primary server

Because the client (4) is still trying to talk to the primary, the primary will get the request and take that event as a trigger to become the active master. However, the backup is still acting as master from the failover! The next time the heartbeats are sent (< 1 second later), both servers throw a "dual masters" exception.

This patch adds a timeout when the primary first starts. It will not respond to clients until two heartbeats have passed. If the backup is on, it will send its current state (causing the primary to transition out of STATE_PRIMARY and into either STATE_ACTIVE or STATE_PASSIVE); if the backup is off, there's just a slight delay before the primary starts responding to clients.

If this seems like a good fix, the C bstar implementation exhibits the same dual masters error and should probably get analogous touchups.