From patchwork Tue Jan 29 20:01:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Han Zhou X-Patchwork-Id: 1032993 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="BH3jXOfC"; 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 43pyN42yhNz9sBQ for ; Wed, 30 Jan 2019 07:12:36 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 9D30E327D; Tue, 29 Jan 2019 20:09:38 +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 6682F2E4E for ; Tue, 29 Jan 2019 20:01:58 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-pf1-f195.google.com (mail-pf1-f195.google.com [209.85.210.195]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 5E24A85C for ; Tue, 29 Jan 2019 20:01:57 +0000 (UTC) Received: by mail-pf1-f195.google.com with SMTP id z9so10179098pfi.2 for ; Tue, 29 Jan 2019 12:01:57 -0800 (PST) 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=kBBG8mydFaETrW9erofiKy0Glcn/4FOfJZ9y3PWaHu0=; b=BH3jXOfCHXUZ0aD5Zjk9C2LZlWZma2XMLcQWuH8tK1A29xMx876y6VkCghICG4Cl/6 coaR1hWtB2FQjC8IbLPtzDu1svNuQ1gRi2g3KB4WyYymbQ50VXSWej4PNh6YHNKFaj2o 2/ZueXa/iFGsLZivDCATzvhm7uBM8AJ0YQv0mhFhdcpulLNKtCjvg2WfmrcjeHp/DqP5 cnaHOtAKfSsrs4nfOLff48C8uCs/ARznJvqHEFJMWFObpky2o0H6bLX4ahlafKNZ7dpc GSsmTan04WOu5tBKdF/rfl+zkSe9E7o2LO4rclqd0eSy/sqAo5muszsqfrUv2KA/Yzqp usVw== 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=kBBG8mydFaETrW9erofiKy0Glcn/4FOfJZ9y3PWaHu0=; b=OHCxcOLjDJ9bKvE/UjpmtUK27d4BkaYXhS3eOR/Ft9o00qehJ25j5eqSpIURPQVe0H NDQV/EVR75FV1iqygjxF/QStESXb4b00SiX/o4m/DKBZabD0Wy+XpAShhqjjetFIoPer wPQT8RZaUbgf/yfv7IV6b4K4UPQt40NAM1otwGwKqpMglFIGa+eE6G310+KP0H8kW1ME Yzyh4HRZwpPbjKjPKruGwm8sUVaQKqt+ehY8z3XFgO4bCjvjqxOTENsNfS48pnyS0aQw xAaSqGva1KRgcr24eRgIeyhmjQYJjxbFFzYNVeiSxqGidWJYkoyptXR5xAbXLlpgtB1Y DfFA== X-Gm-Message-State: AJcUukeI5BAsvN+loQIygsn1ll9KZTnLJE9bh0lumfIETscvYMWDXasY O5vpa6tTNv/MMQjRbe55XlH25QsW X-Google-Smtp-Source: ALg8bN5lbgU9yYXgZ1yTGvSo5+KX+w0B3O2TQtsiMWuWpreiWFMBED9atI7PCH/tXFk2/Elid0Wdzg== X-Received: by 2002:a63:ff16:: with SMTP id k22mr25145062pgi.244.1548792116745; Tue, 29 Jan 2019 12:01:56 -0800 (PST) Received: from localhost.localdomain.localdomain ([216.113.160.77]) by smtp.gmail.com with ESMTPSA id c23sm43097565pfi.83.2019.01.29.12.01.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Jan 2019 12:01:56 -0800 (PST) From: Han Zhou X-Google-Original-From: Han Zhou To: dev@openvswitch.org Date: Tue, 29 Jan 2019 12:01:49 -0800 Message-Id: <1548792109-111156-8-git-send-email-hzhou8@ebay.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1548792109-111156-1-git-send-email-hzhou8@ebay.com> References: <1548792109-111156-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] [RFC v2 7/7] ovsdb-idl.c: Fast resync from server when connection reset. 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 Use monitor_cond_since to request changes after last version of local data when connection to server is reset, without clearing the local data. It falls back to clearing and repopulate all the data when the requested id cannot be fulfilled by the server. Signed-off-by: Han Zhou --- lib/ovsdb-idl.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/lib/ovsdb-idl.c b/lib/ovsdb-idl.c index 7ef4ed0..8cfb201 100644 --- a/lib/ovsdb-idl.c +++ b/lib/ovsdb-idl.c @@ -216,6 +216,9 @@ struct ovsdb_idl_db { bool has_lock; /* Has db server told us we have the lock? */ bool is_lock_contended; /* Has db server told us we can't get lock? */ struct json *lock_request_id; /* JSON-RPC ID of in-flight lock request. */ + + /* Last db txn id, used for fast resync through monitor_cond_since */ + struct uuid last_id; }; static void ovsdb_idl_db_track_clear(struct ovsdb_idl_db *); @@ -2070,9 +2073,8 @@ ovsdb_idl_send_monitor_request(struct ovsdb_idl *idl, struct ovsdb_idl_db *db, break; case OVSDB_IDL_MM_MONITOR_COND_SINCE: method = "monitor_cond_since"; - struct uuid last_id = UUID_ZERO; struct json *json_last_id = json_string_create_nocopy( - xasprintf(UUID_FMT, UUID_ARGS(&last_id))); + xasprintf(UUID_FMT, UUID_ARGS(&db->last_id))); json_array_add(params, json_last_id); break; default: @@ -2100,6 +2102,7 @@ ovsdb_idl_db_parse_monitor_reply(struct ovsdb_idl_db *db, { db->change_seqno++; const struct json *table_updates = result; + bool clear_db = true; if (method == OVSDB_IDL_MM_MONITOR_COND_SINCE) { if (result->type != JSON_ARRAY || result->array.n != 3) { struct ovsdb_error *error = ovsdb_syntax_error(result, NULL, @@ -2110,12 +2113,24 @@ ovsdb_idl_db_parse_monitor_reply(struct ovsdb_idl_db *db, } bool found = json_boolean(result->array.elems[0]); + if (found) { + clear_db = false; + } + const char *last_id = json_string(result->array.elems[1]); + if (!uuid_from_string(&db->last_id, last_id)) { + struct ovsdb_error *error = ovsdb_syntax_error(result, NULL, + "Last-id %s is not in UUID format.", + last_id); + log_parse_update_error(error); + return; + } table_updates = result->array.elems[2]; - } - ovsdb_idl_db_clear(db); + if (clear_db) { + ovsdb_idl_db_clear(db); + } ovsdb_idl_db_parse_update(db, table_updates, method); } @@ -2158,6 +2173,14 @@ ovsdb_idl_db_parse_update_rpc(struct ovsdb_idl_db *db, struct json *table_updates = params->array.elems[1]; if (!strcmp(msg->method, "update3")) { table_updates = params->array.elems[2]; + const char *last_id = json_string(params->array.elems[1]); + if (!uuid_from_string(&db->last_id, last_id)) { + struct ovsdb_error *error = ovsdb_syntax_error(params, NULL, + "Last-id %s is not in UUID format.", + last_id); + log_parse_update_error(error); + return false; + } } ovsdb_idl_db_parse_update(db, table_updates, mm); return true;