From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id A3D40247D3 for ; Wed, 16 May 2018 07:32:31 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id uejv5aCs08FX for ; Wed, 16 May 2018 07:32:31 -0400 (EDT) Received: from smtp40.i.mail.ru (smtp40.i.mail.ru [94.100.177.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id C3EAC210B4 for ; Wed, 16 May 2018 07:32:30 -0400 (EDT) From: Konstantin Belyavskiy Subject: [tarantool-patches] [PATCH 1/3] replication: use applier_state to check quorum Date: Wed, 16 May 2018 14:32:25 +0300 Message-Id: In-Reply-To: References: In-Reply-To: References: Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-help: List-unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-subscribe: List-owner: List-post: List-archive: To: georgy@tarantool.org, kostja@tarantool.org Cc: tarantool-patches@freelists.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 /* replicaset_t */ #include +#include "applier.h" #include #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)