From patchwork Thu Jan 24 23:11: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: 1030712 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="s4pBlSOI"; 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 43lyfB1q60z9s9h for ; Fri, 25 Jan 2019 10:14:26 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 4D7EFDBB; Thu, 24 Jan 2019 23:12:09 +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 799A2D9D for ; Thu, 24 Jan 2019 23:12:07 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id E2887852 for ; Thu, 24 Jan 2019 23:12:06 +0000 (UTC) Received: by mail-wr1-f43.google.com with SMTP id v13so8324380wrw.5 for ; Thu, 24 Jan 2019 15:12:06 -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=s4pBlSOIPaB1zDSBb5IH/JON6CfglU0bcCU0RFJ5Vgedq/eexY6mDFPL0ACIFAzvZe nwunTK7VFmKX2w03xRxOrU85teXHLE/s4LEwBUFJ4GD3zPxzyaSTMM6wYM6/I/3Jp6Cf DZ8uV9d/H1E9PVxwNvoKH6q/1Nhb/lqADGXVgsdsNDBoQ7oQXQKt0uV0+F2fMx/VaJf0 rNWOTy8CCG7l91igcKgVWRMeRH0CzOI1TWD4djtPflVUIbGL63Ot2CH0mEpbG8Flhmyj sbGd/DqdSvO5Q9TSS5h/YRz0j3iITT1c8IZ7wljacr6dTP3Omm6Vn6KdvxT8EL0L1U6m e4fg== 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=pvVo3jcKd/eiYIuRBUXBuuEcS5daEOeaSs7fb4rpPFmZ/RUKqxq3tcoDAm0I+xqbr+ qtv0UEnEREmt7UUMW6flokR6uJ4neLx58aYg0Qf5mbiZCHjOz+bIK+S0ZagNid71oAkO FK0RferSXii1zwZBSPTSHAOiM7mj1pG5CxhQ+7vTcWgvBxF9Bes1BF392uWnJNe0/PLn 778qoL2gBKwjaaKX4WLNFdZoKe3iA3i3vvbwNY9D6cSTzFxODr7IDKSP2h7sRlVtmihm sYSOLm9+Jpxq0kinzuy87+w4fruiU2niZ8R8bCwoOa+370klrWE6O+dxJlm/843ORMsY nn9Q== X-Gm-Message-State: AJcUukfj4thpEtsqn+30S7yuZIgUIzN9XnMb+aC30BECkLVh1GgF/hFs yLlmYP75ppJO3gQS6kQbegE9GkC7 X-Google-Smtp-Source: ALg8bN4HSpajj8hlRqKET6paxIuIDRiwZqVHc5JOVqQetHRaImsuIvDlfFH9/5qcMjSJgXW8DyfWqw== X-Received: by 2002:adf:f149:: with SMTP id y9mr9645206wro.284.1548371525315; Thu, 24 Jan 2019 15:12:05 -0800 (PST) Received: from localhost.localdomain.localdomain ([216.113.160.71]) by smtp.gmail.com with ESMTPSA id h62sm46719335wmf.11.2019.01.24.15.12.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 24 Jan 2019 15:12:04 -0800 (PST) From: Han Zhou X-Google-Original-From: Han Zhou To: dev@openvswitch.org Date: Thu, 24 Jan 2019 15:11:21 -0800 Message-Id: <1548371481-109219-8-git-send-email-hzhou8@ebay.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1548371481-109219-1-git-send-email-hzhou8@ebay.com> References: <1548371481-109219-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 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;