Implemented a fallback if the primary master server is down

as discussed in #2568 and #2574.