PBServer.ElectRecoveryMaster is pretty much done (but not debugged) except for replaying put operations; it does already decide when to replay though