From: Konstantin Belyavskiy <k.belyavskiy@tarantool.org> To: georgy@tarantool.org, kostja@tarantool.org Cc: tarantool-patches@freelists.org Subject: [tarantool-patches] [PATCH 1/3] replication: use applier_state to check quorum Date: Wed, 16 May 2018 14:32:25 +0300 [thread overview] Message-ID: <aa13ecf3f85949c5cc1c2e16d9e2a4df3271bb9e.1526469555.git.k.belyavskiy@tarantool.org> (raw) In-Reply-To: <cover.1526469555.git.k.belyavskiy@tarantool.org> In-Reply-To: <cover.1526469555.git.k.belyavskiy@tarantool.org> Small refactoring: remove 'enum replica_state' since reuse a subset from applier state machine 'enum replica_state' to check if we have achieved replication quorum and hence can leave read-only mode. --- src/box/replication.cc | 31 +++++++++++++++---------------- src/box/replication.h | 32 ++++++++++++-------------------- 2 files changed, 27 insertions(+), 36 deletions(-) diff --git a/src/box/replication.cc b/src/box/replication.cc index 185c05305..9aac1f077 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 */ @@ -138,7 +137,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; return replica; } @@ -219,9 +218,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(); @@ -234,7 +233,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; @@ -265,7 +264,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++; } @@ -276,7 +275,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)) { /* @@ -298,32 +297,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 @@ -424,7 +423,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); } @@ -458,7 +457,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 7b85c2fc4..e2bdd814f 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" @@ -214,24 +215,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. */ @@ -260,8 +243,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; }; enum { -- 2.14.3 (Apple Git-98)
next prev parent reply other threads:[~2018-05-16 11:32 UTC|newest] Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top 2018-05-16 11:32 [tarantool-patches] [PATCH 0/3] replication: improve logging Konstantin Belyavskiy 2018-05-16 11:32 ` Konstantin Belyavskiy [this message] 2018-05-16 11:32 ` [tarantool-patches] [PATCH 2/3] replication: do not delete relay on applier disconnect Konstantin Belyavskiy 2018-05-16 11:32 ` [tarantool-patches] [PATCH 3/3] replication: display downstream status at upstream Konstantin Belyavskiy
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=aa13ecf3f85949c5cc1c2e16d9e2a4df3271bb9e.1526469555.git.k.belyavskiy@tarantool.org \ --to=k.belyavskiy@tarantool.org \ --cc=georgy@tarantool.org \ --cc=kostja@tarantool.org \ --cc=tarantool-patches@freelists.org \ --subject='Re: [tarantool-patches] [PATCH 1/3] replication: use applier_state to check quorum' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox