From patchwork Mon Jan 10 02:42:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wentao Jia X-Patchwork-Id: 1577700 X-Patchwork-Delegate: i.maximets@samsung.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.137; helo=smtp4.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp4.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JXJ5J6bgRz9sPC for ; Mon, 10 Jan 2022 13:42:26 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 4722840287; Mon, 10 Jan 2022 02:42:24 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id jMkHhqEfn80f; Mon, 10 Jan 2022 02:42:23 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp4.osuosl.org (Postfix) with ESMTPS id 6A0514023C; Mon, 10 Jan 2022 02:42:22 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 3ED67C002F; Mon, 10 Jan 2022 02:42:22 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp2.osuosl.org (smtp2.osuosl.org [IPv6:2605:bc80:3010::133]) by lists.linuxfoundation.org (Postfix) with ESMTP id 57209C001E for ; Mon, 10 Jan 2022 02:42:21 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 2F92340439 for ; Mon, 10 Jan 2022 02:42:21 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id PLphEZTcu5I8 for ; Mon, 10 Jan 2022 02:42:20 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.8.0 Received: from mail-m24102.qiye.163.com (mail-m24102.qiye.163.com [220.194.24.102]) by smtp2.osuosl.org (Postfix) with ESMTPS id 8CA6340374 for ; Mon, 10 Jan 2022 02:42:19 +0000 (UTC) Received: from easystack.cn (localhost [127.0.0.1]) by mail-m24102.qiye.163.com (Hmail) with ESMTP id AB09728; Mon, 10 Jan 2022 10:42:16 +0800 (CST) Message-ID: To: ovs-dev@openvswitch.org X-Priority: 3 X-Mailer: HMail Webmail Server V2.0 Copyright (c) 2015-163.com X-Originating-IP: 103.10.86.235 MIME-Version: 1.0 Received: from wentao.jia@easystack.cn( [103.10.86.235) ] by ajax-webmail ( [127.0.0.1] ) ; Mon, 10 Jan 2022 10:42:16 +0800 (GMT+08:00) From: Wentao Jia Date: Mon, 10 Jan 2022 10:42:16 +0800 (GMT+08:00) X-HM-Spam-Status: e1kfGhgUHx5ZQUtXWQgPGg8OCBgUHx5ZQUlOS1dZCBgUCR5ZQVlLVUtZV1 kWDxoPAgseWUFZKDYvK1lXWShZQUlCN1dZLVlBSVdZDwkaFQgSH1lBWRkaThpWTB5NTh1JSxkeTB 8ZVRkRExYaEhckFA4PWVdZFhoPEhUdFFlBWVVLWQY+ X-HM-Sender-Digest: e1kMHhlZQQ8JDh5XWRIfHhUPWUFZRzo1STpPKjgLMjMrOB0uMAIvSi4U NgoJHlVKVUpNT0pMQ0lOSE1DT05VMxYaEhdVDB4VDxoUVRESGjseGggCCA8aGBBVGBVFWVdZEgtZ QVlKS0hVSktVQ01VSUhOWVdZCAFZQUpNSE9NNwY+ X-HM-Tid: 0a7e41d9b2d98c3bkuqt17e05c51135 X-Content-Filtered-By: Mailman/MimeDel 2.1.15 Cc: i.maximets@ovn.org Subject: [ovs-dev] =?utf-8?q?=5BPATCH=5D_relay=3Aprobe_interval_of_relay_ser?= =?utf-8?q?ver?= X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" probe interval of relay server can be configured from "sb_global/nb_global options:relay_probe_interval" minimum and default value is 5s Signed-off-by: Wentao Jia --- ovsdb/relay.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/ovsdb/relay.c b/ovsdb/relay.c index ef0e44d34..7e2314169 100644 --- a/ovsdb/relay.c +++ b/ovsdb/relay.c @@ -40,6 +40,10 @@ VLOG_DEFINE_THIS_MODULE(relay); static struct shash relay_dbs = SHASH_INITIALIZER(&relay_dbs); +/* Default probe interval for NB and SB DB connections. */ +#define MIN_PROBE_INTERVAL_MC 5000 +static int relay_probe_interval = MIN_PROBE_INTERVAL_MC; + struct relay_ctx { struct ovsdb *db; struct ovsdb_cs *cs; @@ -52,6 +56,73 @@ struct relay_ctx { long long int last_connected; }; +static int +ovsdb_relay_get_probe_interval(const struct ovsdb *db) +{ + int interval = MIN_PROBE_INTERVAL_MC; + + const struct ovsdb_table *table; + const struct ovsdb_column *column; + const struct ovsdb_row *row; + const char *table_name = NULL; + const char *column_name = "options"; + const char *probe_interval = "relay_probe_interval"; + + if (!strcmp(db->name, "OVN_Southbound")) { + table_name = "SB_Global"; + }else if (!strcmp(db->name, "OVN_Northbound")) { + table_name = "NB_Global"; + }else { + return interval; + } + + table = ovsdb_get_table(db, table_name); + if (!table) { + VLOG_INFO("%s has no table named %s", db->name, table_name); + return interval; + } + + column = ovsdb_table_schema_get_column(table->schema, column_name); + if (!column) { + VLOG_INFO("table %s has no column %s", table_name, column_name); + return interval; + } + + HMAP_FOR_EACH (row, hmap_node, &table->rows) { + const struct ovsdb_datum *datum; + size_t i; + + datum = &row->fields[column->index]; + for (i = 0; i < datum->n; i++) { + if (datum->keys[i].s->string[0] + && !strcmp(datum->keys[i].s->string, probe_interval)) { + if (str_to_int(datum->values[i].s->string, 10, &interval)) { + break; + } + } + } + } + + if (interval > 0 && interval < MIN_PROBE_INTERVAL_MC) { + interval = MIN_PROBE_INTERVAL_MC; + } + + return interval; +} + +static void +ovsdb_relay_set_probe_interval(const struct ovsdb *db, + const struct ovsdb_cs *cs) +{ + int interval = ovsdb_relay_get_probe_interval(db); + + if ((interval > 0) && !(relay_probe_interval == interval)) { + VLOG_INFO("set probe interval: %u", interval); + ovsdb_cs_set_probe_interval(cs, interval); + relay_probe_interval = interval; + } +} + #define RELAY_MAX_RECONNECTION_MS 30000 /* Reports if the database is connected to the relay source and functional, @@ -152,6 +223,7 @@ ovsdb_relay_add_db(struct ovsdb *db, const char *remote, shash_add(&relay_dbs, db->name, ctx); ovsdb_cs_set_leader_only(ctx->cs, false); ovsdb_cs_set_remote(ctx->cs, remote, true); + ovsdb_cs_set_probe_interval(ctx->cs, relay_probe_interval); VLOG_DBG("added database: %s, %s", db->name, remote); } @@ -368,6 +440,8 @@ ovsdb_relay_run(void) } ovsdb_cs_event_destroy(event); } + + ovsdb_relay_set_probe_interval(ctx->db, ctx->cs); } }