From patchwork Wed Apr 10 01:21:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Han Zhou X-Patchwork-Id: 1083053 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="fvYhoRor"; 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 44f5xm6Zngz9sTm for ; Wed, 10 Apr 2019 11:22:52 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 4382C1184; Wed, 10 Apr 2019 01:22:03 +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 9FDE11152 for ; Wed, 10 Apr 2019 01:21:41 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-pg1-f195.google.com (mail-pg1-f195.google.com [209.85.215.195]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 7867DF4 for ; Wed, 10 Apr 2019 01:21:40 +0000 (UTC) Received: by mail-pg1-f195.google.com with SMTP id k3so461632pga.6 for ; Tue, 09 Apr 2019 18:21:40 -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:in-reply-to:references; bh=1wjckwpfNRe/wM7NwIU9Dd3umjTxwU37gktxAlA5seA=; b=fvYhoRorrh/ge/cZ+siQBRGKRodVKm3ITDp7SlDg82Uff/37Zi3cJAlODCgt8Tdjdl yGDGDv9vWNvlbg4hKijGpYQZoLjVlxcwHsJ9pe/UU5got0xaXtyQHHGPTe/2fH0+toW1 ZZ01lhKxnLbE4s24Sp/h42uMTGBpjdaq8kcCvHwo/bKlg6PAk58tv+XjmMj5NU8kg29d PjcctCzeyzpa8L2u4WRt+EpHVupg08WmvgXnHr6+S8xrnPCnX2d97nCbtFNrQzClMWJx 8x0CrfKc3VGne0jOLL8/MeDBA1KvwCwQPksy6a26jveS918+Zbjo4CYLd+S55VSlpgNQ iBbg== 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:in-reply-to :references; bh=1wjckwpfNRe/wM7NwIU9Dd3umjTxwU37gktxAlA5seA=; b=tQ1yued3V9vGl9yRpmPDGAUQF/DEsIInImquOGmFIjUbsusOIJawi7+Jp9pmFCEbsV l7hi6LlcR1u4hPW4GQLSAFLYKsg/sEaSuya8qP8kjo/kySgg72x/DhYq6k2cL/B6/xLa GsgfR9Y+2GfegTxHGTW1CGik3n1GmAYTJxBoMJStHMu12jEUfg78nB3szZqrlEYFcXQS YyDHiXB8G6g0MLcEy2goO3JOmCH1/LP+/b9aykK4bhdekq1A39HzxQjHkqGWUCJYzJLB QM8/yUtNMqfSfjWRH9RY4Ul1m+fLi6T8OR7hcRsAxNTO/NoCUV/06fxB6zyIRnBNfx0f 2DOg== X-Gm-Message-State: APjAAAUXxNY2Y8TbZEEOUJ2eKJytwOnWidxZDXuI5tQsy3yu6259k9TJ K8ZRcrj7jx50jDkEndAG465FMYOo X-Google-Smtp-Source: APXvYqy/uaTKe86A/cCQCVU+aosINKy1r2HeVIX3ONRoSmY1fwwe2aUdLYd/3o1CiwDCNUy9qOnQdQ== X-Received: by 2002:a63:6941:: with SMTP id e62mr36313933pgc.99.1554859299795; Tue, 09 Apr 2019 18:21:39 -0700 (PDT) Received: from localhost.localdomain.localdomain ([216.113.160.71]) by smtp.gmail.com with ESMTPSA id u63sm17068802pgd.16.2019.04.09.18.21.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 09 Apr 2019 18:21:39 -0700 (PDT) From: Han Zhou X-Google-Original-From: Han Zhou To: dev@openvswitch.org Date: Tue, 9 Apr 2019 18:21:18 -0700 Message-Id: <1554859282-15144-3-git-send-email-hzhou8@ebay.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1554859282-15144-1-git-send-email-hzhou8@ebay.com> References: <1554859282-15144-1-git-send-email-hzhou8@ebay.com> 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 3/7] ovsdb-idl: Support optionally not shuffling multiple remotes. 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 This patch allows remotes not being shuffled if desired. By default it still shuffles as how it behaves today. Signed-off-by: Han Zhou --- lib/jsonrpc.c | 1 - lib/ovsdb-idl.c | 14 ++++++++++++++ lib/ovsdb-idl.h | 1 + 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/jsonrpc.c b/lib/jsonrpc.c index 4c2c1ba..3c60cd8 100644 --- a/lib/jsonrpc.c +++ b/lib/jsonrpc.c @@ -827,7 +827,6 @@ jsonrpc_session_open_multiple(const struct svec *remotes, bool retry) /* Set 'n' remotes from 'names', shuffling them into random order. */ ovs_assert(remotes->n > 0); svec_clone(&s->remotes, remotes); - svec_shuffle(&s->remotes); s->next_remote = 0; s->reconnect = reconnect_create(time_msec()); diff --git a/lib/ovsdb-idl.c b/lib/ovsdb-idl.c index 5ae86f7..370781b 100644 --- a/lib/ovsdb-idl.c +++ b/lib/ovsdb-idl.c @@ -260,6 +260,7 @@ struct ovsdb_idl { uint64_t min_index; bool leader_only; + bool shuffle_remotes; }; static void ovsdb_idl_transition_at(struct ovsdb_idl *, enum ovsdb_idl_state, @@ -485,6 +486,7 @@ ovsdb_idl_create_unconnected(const struct ovsdb_idl_class *class, idl->state_seqno = UINT_MAX; idl->request_id = NULL; idl->leader_only = true; + idl->shuffle_remotes = true; /* Monitor the Database table in the _Server database. * @@ -528,6 +530,9 @@ ovsdb_idl_set_remote(struct ovsdb_idl *idl, const char *remote, bool retry) if (remote) { struct svec remotes = SVEC_EMPTY_INITIALIZER; ovsdb_session_parse_remote(remote, &remotes, &idl->cid); + if (idl->shuffle_remotes) { + svec_shuffle(&remotes); + } idl->session = jsonrpc_session_open_multiple(&remotes, retry); svec_destroy(&remotes); @@ -538,6 +543,15 @@ ovsdb_idl_set_remote(struct ovsdb_idl *idl, const char *remote, bool retry) } } +/* Set whether the order of remotes should be shuffled, when there + * are more than one remotes. The setting doesn't take effect + * until the next time when ovsdb_idl_set_remote() is called. */ +void +ovsdb_idl_set_shuffle_remotes(struct ovsdb_idl *idl, bool shuffle) +{ + idl->shuffle_remotes = shuffle; +} + static void ovsdb_idl_db_destroy(struct ovsdb_idl_db *db) { diff --git a/lib/ovsdb-idl.h b/lib/ovsdb-idl.h index 8a168eb..0f5a6d0 100644 --- a/lib/ovsdb-idl.h +++ b/lib/ovsdb-idl.h @@ -63,6 +63,7 @@ struct ovsdb_idl *ovsdb_idl_create(const char *remote, struct ovsdb_idl *ovsdb_idl_create_unconnected( const struct ovsdb_idl_class *, bool monitor_everything_by_default); void ovsdb_idl_set_remote(struct ovsdb_idl *, const char *, bool); +void ovsdb_idl_set_shuffle_remotes(struct ovsdb_idl *, bool); void ovsdb_idl_destroy(struct ovsdb_idl *); void ovsdb_idl_set_leader_only(struct ovsdb_idl *, bool leader_only);