diff --git a/src/box/replication.cc b/src/box/replication.cc index b445d3e026ce496f787774f0c08a352ff72efd06..5f6a9b7d2078006c58b038a9c5a6edb9d10ce74b 100644 --- a/src/box/replication.cc +++ b/src/box/replication.cc @@ -38,7 +38,6 @@ #include "box.h" #include "gc.h" -#include "applier.h" #include "error.h" #include "vclock.h" /* VCLOCK_MAX */ @@ -140,7 +139,7 @@ replica_new(void) rlist_create(&replica->in_anon); trigger_create(&replica->on_applier_state, replica_on_applier_state_f, NULL, NULL); - replica->state = REPLICA_DISCONNECTED; + replica->applier_sync_state = APPLIER_DISCONNECTED; latch_create(&replica->order_latch); return replica; } @@ -224,9 +223,9 @@ replica_clear_applier(struct replica *replica) static void replica_on_applier_sync(struct replica *replica) { - assert(replica->state == REPLICA_CONNECTED); + assert(replica->applier_sync_state == APPLIER_CONNECTED); - replica->state = REPLICA_SYNCED; + replica->applier_sync_state = APPLIER_SYNC; replicaset.applier.synced++; replicaset_check_quorum(); @@ -239,7 +238,7 @@ replica_on_applier_connect(struct replica *replica) assert(tt_uuid_is_nil(&replica->uuid)); assert(!tt_uuid_is_nil(&applier->uuid)); - assert(replica->state == REPLICA_DISCONNECTED); + assert(replica->applier_sync_state == APPLIER_DISCONNECTED); replica->uuid = applier->uuid; @@ -270,7 +269,7 @@ replica_on_applier_connect(struct replica *replica) replica_hash_insert(&replicaset.hash, replica); } - replica->state = REPLICA_CONNECTED; + replica->applier_sync_state = APPLIER_CONNECTED; replicaset.applier.connected++; } @@ -281,7 +280,7 @@ replica_on_applier_reconnect(struct replica *replica) assert(!tt_uuid_is_nil(&replica->uuid)); assert(!tt_uuid_is_nil(&applier->uuid)); - assert(replica->state == REPLICA_DISCONNECTED); + assert(replica->applier_sync_state == APPLIER_DISCONNECTED); if (!tt_uuid_is_equal(&replica->uuid, &applier->uuid)) { /* @@ -303,32 +302,32 @@ replica_on_applier_reconnect(struct replica *replica) replica_set_applier(orig, applier); replica_clear_applier(replica); - replica->state = REPLICA_DISCONNECTED; + replica->applier_sync_state = APPLIER_DISCONNECTED; replica = orig; } - replica->state = REPLICA_CONNECTED; + replica->applier_sync_state = APPLIER_CONNECTED; replicaset.applier.connected++; } static void replica_on_applier_disconnect(struct replica *replica) { - switch (replica->state) { - case REPLICA_SYNCED: + switch (replica->applier_sync_state) { + case APPLIER_SYNC: assert(replicaset.applier.synced > 0); replicaset.applier.synced--; FALLTHROUGH; - case REPLICA_CONNECTED: + case APPLIER_CONNECTED: assert(replicaset.applier.connected > 0); replicaset.applier.connected--; break; - case REPLICA_DISCONNECTED: + case APPLIER_DISCONNECTED: break; default: unreachable(); } - replica->state = REPLICA_DISCONNECTED; + replica->applier_sync_state = APPLIER_DISCONNECTED; } static void @@ -429,7 +428,7 @@ replicaset_update(struct applier **appliers, int count) continue; applier = replica->applier; replica_clear_applier(replica); - replica->state = REPLICA_DISCONNECTED; + replica->applier_sync_state = APPLIER_DISCONNECTED; applier_stop(applier); applier_delete(applier); } @@ -463,7 +462,7 @@ replicaset_update(struct applier **appliers, int count) replica_hash_insert(&replicaset.hash, replica); } - replica->state = REPLICA_CONNECTED; + replica->applier_sync_state = APPLIER_CONNECTED; replicaset.applier.connected++; } rlist_swap(&replicaset.anon, &anon_replicas); diff --git a/src/box/replication.h b/src/box/replication.h index 115f52e49055ebb4542cbd053d4bc7664b5f9a5a..0a32067893ff4f07f69d68de6594ec313c557bc5 100644 --- a/src/box/replication.h +++ b/src/box/replication.h @@ -36,6 +36,7 @@ #define RB_COMPACT 1 #include <small/rb.h> /* replicaset_t */ #include <small/rlist.h> +#include "applier.h" #include <small/mempool.h> #include "fiber_cond.h" #include "vclock.h" @@ -218,24 +219,6 @@ struct replicaset { }; extern struct replicaset replicaset; -enum replica_state { - /** - * Applier has not connected to the master yet - * or has disconnected. - */ - REPLICA_DISCONNECTED, - /** - * Applier has connected to the master and - * received UUID. - */ - REPLICA_CONNECTED, - /** - * Applier has synchronized with the master - * (left "sync" and entered "follow" state). - */ - REPLICA_SYNCED, -}; - /** * Summary information about a replica in the replica set. */ @@ -264,8 +247,17 @@ struct replica { * Trigger invoked when the applier changes its state. */ struct trigger on_applier_state; - /** Replica sync state. */ - enum replica_state state; + /** + * During initial connect or reconnect we require applier + * to sync with the master before the replica can leave + * read-only mode. This enum reflects the state of the + * state machine for applier sync. Technically it is a + * subset of the applier state machine, but since it's + * much simpler and is used for a different purpose + * (achieving replication connect quorum), we keep it + * separate from applier. + */ + enum applier_state applier_sync_state; /* The latch is used to order replication requests. */ struct latch order_latch; };