From patchwork Thu Aug 22 21:08:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Han Zhou X-Patchwork-Id: 1151821 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="SZ2n5HFt"; dkim-atps=neutral Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46Dxw5602sz9sMr for ; Fri, 23 Aug 2019 07:08:37 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id ABA7FE4E; Thu, 22 Aug 2019 21:08:32 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 9E753D95 for ; Thu, 22 Aug 2019 21:08:30 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-pl1-f194.google.com (mail-pl1-f194.google.com [209.85.214.194]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 5128689B for ; Thu, 22 Aug 2019 21:08:30 +0000 (UTC) Received: by mail-pl1-f194.google.com with SMTP id t14so4151541plr.11 for ; Thu, 22 Aug 2019 14:08:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=526qIpjBKtlt61TeAj9VVUten7p8wm7byhQx1kwS3cE=; b=SZ2n5HFt16zRUXDAy7nPmiETT/0aQgmxKe8153Hv8U3285H3SKhy7PPJJAJ01U3q20 OsNWQ0rDfN/F3LKb8n1YDIpRz76esG929Ho8UBbfyWEIlycKimG00QbvCledyXaqSLaE 9oD6d9D7UHddw32aVDYPiGsNkaJVbKvsoKsvqhOtiZH5+pRKibqa3JT0WUiotU+Rk3TN VJJbroKhJ0bP7YGWCwYTk34+IEzmHPWagu85CIwBXd9e2Zw8bE/sUCT6rDbcer0adDgt iSMPuyJMhkFsDDs1GBP0P0c0v63xe/jNpq5JXZTskN2/CBNQohEf3deLUYMMyvhmp8Vz ER9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=526qIpjBKtlt61TeAj9VVUten7p8wm7byhQx1kwS3cE=; b=s4dZ001Osabo0OuuzHLGgutV6wfSW4Fxt53juNmLJ6Y26qfHlClVo+aCtqHdQfB+f0 nCGG2yIaLyHOQaJ2ZkXirRUWUaYZQikd1E7o+9x4XfmM2C/RsY07YvSiN01DG2mMw+/V MFlLFrRdV2mCS/vJR2ICgxRAM8foauljo6J4SnwuhRxKm7HVW7AETa4iQLv4AX9lM0pB 0xVHWPdZs3XNi3giVE0xfQkAzyF60+J4eVKQzjoIGJi76HMdREI2kxEjvrgF7d9NNsWe 3Hj16eHOtpAAjkBFiAmY7fg9kP72G2+Y3u15XKZsxWgR02/nAES8IqP7IhtFa/o00Z5i OIRQ== X-Gm-Message-State: APjAAAX/oNzB9yKUulc+hwMeyqn9TN9KLS4xxWGC7h95Ye5aMNypGd2/ Y4lcugyLtPLdvCcDgMUSa3a2IzQXgZ4= X-Google-Smtp-Source: APXvYqzFWETIjUekSdoz9vqYdgzfy6P60p5ccirr2Zo38siC5Lw9X5IrIB9GzolrdHhas/sSnuZXDA== X-Received: by 2002:a17:902:26f:: with SMTP id 102mr869101plc.189.1566508109511; Thu, 22 Aug 2019 14:08:29 -0700 (PDT) Received: from localhost.localdomain.localdomain ([73.241.94.255]) by smtp.gmail.com with ESMTPSA id w2sm190808pgc.32.2019.08.22.14.08.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Aug 2019 14:08:29 -0700 (PDT) From: Han Zhou X-Google-Original-From: Han Zhou To: dev@openvswitch.org Date: Thu, 22 Aug 2019 14:08:21 -0700 Message-Id: <1566508103-22962-1-git-send-email-hzhou8@ebay.com> X-Mailer: git-send-email 2.1.0 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [PATCH 1/3] raft.c: Election timer initial reset with value from log. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org From: Han Zhou After election timer is changed through cluster/change-election-timer command, if a server restarts, it firstly initializes with the default value and use it to reset the timer. Although it reads the latest timer value later from the log, the first timeout may be much shorter than expected by other servers that use latest timeout, and it would start election before it receives the first heartbeat from the leader. This patch fixes it by changing the order of reading log and resetting timer so that the latest value is read from the log before the initial resetting of the timer. Fixes: commit 8e35461 ("ovsdb raft: Support leader election time change online.") Signed-off-by: Han Zhou --- ovsdb/raft.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ovsdb/raft.c b/ovsdb/raft.c index 796790e..9eabe2c 100644 --- a/ovsdb/raft.c +++ b/ovsdb/raft.c @@ -404,8 +404,6 @@ raft_alloc(void) hmap_init(&raft->commands); raft->election_timer = ELECTION_BASE_MSEC; - raft_reset_ping_timer(raft); - raft_reset_election_timer(raft); return raft; } @@ -970,6 +968,9 @@ raft_open(struct ovsdb_log *log, struct raft **raftp) raft->join_timeout = time_msec() + 1000; } + raft_reset_ping_timer(raft); + raft_reset_election_timer(raft); + *raftp = raft; hmap_insert(&all_rafts, &raft->hmap_node, hash_string(raft->name, 0)); return NULL;