From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 84F496EC40; Thu, 8 Jul 2021 12:28:56 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 84F496EC40 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1625736536; bh=gOeKZZQe5Fe6nDNsbkxJfVhXX3FjTF+PBluOcNwlfzY=; h=Date:To:Cc:References:In-Reply-To:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=OlVii61skYjd/W88V5leClW7h04iiASyDoyJUpOJUJ0Q2CXUD9FtpFFqHFl0kO0ir VS42VFvq64mv/e13FxJaO1qeIWqcmig9Q42DT9PVmuZdemldCcUnpbUEOPzNKDakM9 TarCWlTWgUBqeD/04mBulI6HI+DkmdShx6DjOUEk= Received: from mail-lf1-f46.google.com (mail-lf1-f46.google.com [209.85.167.46]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 690676EC40 for ; Thu, 8 Jul 2021 12:28:55 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 690676EC40 Received: by mail-lf1-f46.google.com with SMTP id n14so13323279lfu.8 for ; Thu, 08 Jul 2021 02:28:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=zmfKI0LPk0T7kzDEZK/N8PfSiKtmax6CogEHAaRl18E=; b=t0u8LCTT+VpqyrlBlz/i7pLwy18y2KeeO42SNS/egs1QerpsAvFQvTO8isJvxlbMSd f05ePIlVHX+3H65Em8Ut+MzsKX6Mfc7kG3RHeVOPLbtTlrPdannMXnuDAeGBeO06dGmz ragC8JBbUZ+7QkBXphlRGq+qqdecSAVhWX9X4HJLl3s1ZwQYfYwLvlfLBpaIT3s/ZkHt PA9749mGkqiR4sxw0LPTW5YtOwdQ6EylP63xjpuR2Qqlh4AkSNdWQkvq5Pcmhi6pRELh gAgMl//AXJO932fA+/wSyORAmi422YA+xjFqQVUIq16imfVtPHQzrm7K9eRU334xWEEG 8nPQ== X-Gm-Message-State: AOAM532xCoffU0PppyBBM2tj1TQQq0sl4m+EqahM1sQFaBQP1M7i2Prd c7rcez+MeL5bqx3/VGB39I5U3lp8QMI= X-Google-Smtp-Source: ABdhPJxE5esQQFihI68VhiZbHZxId41xFFhZoOwV5AO5n9HO8ZVWY2tiAscdEAqlNw42dudFPnwOqQ== X-Received: by 2002:a19:7d05:: with SMTP id y5mr23076295lfc.159.1625736534259; Thu, 08 Jul 2021 02:28:54 -0700 (PDT) Received: from grain.localdomain ([5.18.199.94]) by smtp.gmail.com with ESMTPSA id a29sm139251lfk.293.2021.07.08.02.28.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Jul 2021 02:28:53 -0700 (PDT) Received: by grain.localdomain (Postfix, from userid 1000) id E454A5A001E; Thu, 8 Jul 2021 12:28:52 +0300 (MSK) Date: Thu, 8 Jul 2021 12:28:52 +0300 To: Vladislav Shpilevoy Cc: tml Message-ID: References: <20210625100707.87807-1-gorcunov@gmail.com> <9652278e-570e-40e5-b2d1-856fe58179fc@tarantool.org> <4b0f4d8f-4e0c-00d0-38ad-0b6abad3aafe@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/2.0.7 (2021-05-04) Subject: [Tarantool-patches] [PATCH v3] raft: change request state to uint64_t X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Cyrill Gorcunov via Tarantool-patches Reply-To: Cyrill Gorcunov Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" On Thu, Jul 08, 2021 at 01:05:00AM +0300, Cyrill Gorcunov wrote: > On Thu, Jul 08, 2021 at 12:59:33AM +0300, Cyrill Gorcunov wrote: > > > 2. You deleted the state decode. I assume not a single replication > > > test passes now, correct? > > > > Nope :) I write it back a bit later once verification is complete. > > I ran the test locally before sending the patch. > > Vlad, I think I know what happened: there was a typo which I fixed > and commited locally but didn't force pushed out. Just realized it. > I updated repo. But since we gonna switch to uintX instead of enum > I think it doesn't worth to resend the patch. I force pushed an update --- From: Cyrill Gorcunov Date: Fri, 25 Jun 2021 13:03:12 +0300 Subject: [PATCH v3] raft: change request state to uint64_t When new raft message comes in from the network we need to be sure that the payload is suitable for processing, in particular `raft_msg::state` must be valid because our code logic depends on it. For this sake make `raft_msg::state` being uint64_t which allows to an easier processing of the state field verification. Same time use panic() instead of unreacheable() macro because the test for valid state must be enabled all the time. Closes #6067 Signed-off-by: Cyrill Gorcunov --- src/box/xrow.h | 2 +- src/lib/raft/raft.c | 5 +++-- src/lib/raft/raft.h | 4 ++-- test/unit/raft.c | 10 +++++++++- test/unit/raft.result | 4 +++- 5 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/box/xrow.h b/src/box/xrow.h index 055fd31e1..9f61bfd47 100644 --- a/src/box/xrow.h +++ b/src/box/xrow.h @@ -288,7 +288,7 @@ xrow_decode_synchro(const struct xrow_header *row, struct synchro_request *req); struct raft_request { uint64_t term; uint32_t vote; - uint32_t state; + uint64_t state; const struct vclock *vclock; }; diff --git a/src/lib/raft/raft.c b/src/lib/raft/raft.c index eacdddb7e..ef11ef89f 100644 --- a/src/lib/raft/raft.c +++ b/src/lib/raft/raft.c @@ -44,7 +44,7 @@ * a valid data incomes. */ const char * -raft_state_str(uint32_t state) +raft_state_str(uint64_t state) { static const char *str[] = { [0] = "invalid (0)", @@ -406,7 +406,8 @@ raft_process_msg(struct raft *raft, const struct raft_msg *req, uint32_t source) raft_sm_become_leader(raft); break; default: - unreachable(); + panic("RAFT: unreacheable state hit"); + break; } } if (req->state != RAFT_STATE_LEADER) { diff --git a/src/lib/raft/raft.h b/src/lib/raft/raft.h index fae30b03d..223e0509f 100644 --- a/src/lib/raft/raft.h +++ b/src/lib/raft/raft.h @@ -92,7 +92,7 @@ enum raft_state { * Decode raft state into string representation. */ const char * -raft_state_str(uint32_t state); +raft_state_str(uint64_t state); /** * Basic Raft communication unit for talking to other nodes, and even to other @@ -110,7 +110,7 @@ struct raft_msg { * State of the instance. Can be 0 if the state does not matter for the * message. For instance, when the message is sent to disk. */ - enum raft_state state; + uint64_t state; /** * Vclock of the instance. Can be NULL, if the node is not a candidate. * Also is omitted when does not matter (when the message is for disk). diff --git a/test/unit/raft.c b/test/unit/raft.c index 6369c42d3..b9bc49b78 100644 --- a/test/unit/raft.c +++ b/test/unit/raft.c @@ -247,7 +247,7 @@ raft_test_recovery(void) static void raft_test_bad_msg(void) { - raft_start_test(9); + raft_start_test(11); struct raft_msg msg; struct raft_node node; struct vclock vclock; @@ -294,6 +294,14 @@ raft_test_bad_msg(void) is(raft_node_process_msg(&node, &msg, 2), -1, "bad state"); is(node.raft.term, 1, "term from the bad message wasn't used"); + msg = (struct raft_msg){ + .state = -1, + .term = 10, + .vote = 2, + }; + is(raft_node_process_msg(&node, &msg, 2), -1, "bad negative state"); + is(node.raft.term, 1, "term from the bad message wasn't used"); + raft_node_destroy(&node); raft_finish_test(); } diff --git a/test/unit/raft.result b/test/unit/raft.result index 598a7e760..f89cd1658 100644 --- a/test/unit/raft.result +++ b/test/unit/raft.result @@ -45,7 +45,7 @@ ok 1 - subtests ok 2 - subtests *** raft_test_recovery: done *** *** raft_test_bad_msg *** - 1..9 + 1..11 ok 1 - state can't be 0 ok 2 - term from the bad message wasn't used ok 3 - node can't be a candidate but vote for another node @@ -55,6 +55,8 @@ ok 2 - subtests ok 7 - term can't be 0 ok 8 - bad state ok 9 - term from the bad message wasn't used + ok 10 - bad negative state + ok 11 - term from the bad message wasn't used ok 3 - subtests *** raft_test_bad_msg: done *** *** raft_test_vote *** -- 2.31.1