+// A slave responds with C_MASTER when it gets a message which should have gone to a master.
+static int cluster_set_master(in_addr_t peer, in_addr_t master)
+{
+ if (config->cluster_iam_master) // Sanity...
+ return 0;
+
+ LOG(3, 0, 0, "Peer %s set the master to %s...\n", fmtaddr(peer, 0),
+ fmtaddr(master, 1));
+
+ config->cluster_master_address = master;
+ if (master)
+ {
+ // catchup with new master
+ peer_send_message(master, C_LASTSEEN, config->cluster_seq_number, NULL, 0);
+
+ // delay next election
+ config->cluster_last_hb = TIME;
+ }
+
+ // run election (or reset "probed" if master was set)
+ cluster_check_master();
+ return 0;
+}
+