From patchwork Tue Jan 3 03:09:50 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guoshuai Li X-Patchwork-Id: 710366 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 3tszTd0M04z9t0q for ; Tue, 3 Jan 2017 14:10:27 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id BF1B78D4; Tue, 3 Jan 2017 03:10:23 +0000 (UTC) X-Original-To: ovs-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 1A909412 for ; Tue, 3 Jan 2017 03:10:22 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from smtp2203-239.mail.aliyun.com (smtp2203-239.mail.aliyun.com [121.197.203.239]) by smtp1.linuxfoundation.org (Postfix) with ESMTP id 651E7138 for ; Tue, 3 Jan 2017 03:10:18 +0000 (UTC) X-Alimail-AntiSpam: AC=CONTINUE; BC=0.084085|-1; FP=0|0|0|0|0|-1|-1|-1; HT=e02c03294; MF=ligs@dtdream.com; NM=1; PH=DS; RN=2; RT=2; SR=0; TI=SMTPD_---.7NsKKW8_1483413001; Received: from localhost.localdomain(mailfrom:ligs@dtdream.com ip:111.198.29.132) by smtp.aliyun-inc.com(10.147.40.7); Tue, 03 Jan 2017 11:10:02 +0800 From: Guoshuai Li To: ovs-dev@openvswitch.org Date: Tue, 3 Jan 2017 11:09:50 +0800 Message-Id: <20170103030950.8656-1-ligs@dtdream.com> X-Mailer: git-send-email 2.10.1.windows.1 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, UNPARSEABLE_RELAY 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] ovsdb: fix data loss when OVSDB replication from itself 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 Delete the local database after receiving the master data, this is safer for data. This patch is used by HA cluster that have no way to control the order of resources, such as kubernetes. Signed-off-by: Guoshuai Li --- ovsdb/replication.c | 73 +++++++++++++++++++++++++---------------------------- 1 file changed, 35 insertions(+), 38 deletions(-) diff --git a/ovsdb/replication.c b/ovsdb/replication.c index 1c77b18..109ae98 100644 --- a/ovsdb/replication.c +++ b/ovsdb/replication.c @@ -252,56 +252,53 @@ replication_run(void) } ovsdb_schema_destroy(schema); - /* After receiving schemas, reset the local databases that - * will be monitored and send out monitor requests for them. */ + /* After receiving schemas, send out monitor requests for DB. */ if (hmap_is_empty(&request_ids)) { - struct shash_node *node, *next; - - SHASH_FOR_EACH_SAFE (node, next, replication_dbs) { + struct shash_node *node; + SHASH_FOR_EACH (node, replication_dbs) { db = node->data; - struct ovsdb_error *error = reset_database(db); - if (error) { - const char *db_name = db->schema->name; - shash_find_and_delete(replication_dbs, db_name); - ovsdb_error_assert(error); - VLOG_WARN("Failed to reset database, " - "%s not replicated.", db_name); - } - } - - if (shash_is_empty(replication_dbs)) { - VLOG_WARN("Nothing to replicate."); - state = RPL_S_ERR; - } else { - SHASH_FOR_EACH (node, replication_dbs) { - db = node->data; - struct ovsdb *db = node->data; - struct jsonrpc_msg *request = - create_monitor_request(db); - - request_ids_add(request->id, db); - jsonrpc_session_send(session, request); - VLOG_DBG("Send monitor requests"); - state = RPL_S_MONITOR_REQUESTED; - } + struct ovsdb *db = node->data; + struct jsonrpc_msg *request = + create_monitor_request(db); + + request_ids_add(request->id, db); + jsonrpc_session_send(session, request); + VLOG_DBG("Send monitor requests"); + state = RPL_S_MONITOR_REQUESTED; } } break; } case RPL_S_MONITOR_REQUESTED: { - /* Reply to monitor requests. */ - struct ovsdb_error *error; - error = process_notification(msg->result, db); + /* After receiving monitor response, reset the local database + * that will be monitored and process message. */ + struct ovsdb_error *error = reset_database(db); if (error) { + const char *db_name = db->schema->name; + shash_find_and_delete(replication_dbs, db_name); ovsdb_error_assert(error); + VLOG_WARN("Failed to reset database, " + "%s not replicated.", db_name); + } + + if (shash_is_empty(replication_dbs)) { + VLOG_WARN("Nothing to replicate."); state = RPL_S_ERR; } else { - /* Transition to replicating state after receiving - * all replies of "monitor" requests. */ - if (hmap_is_empty(&request_ids)) { - VLOG_DBG("Listening to monitor updates"); - state = RPL_S_REPLICATING; + /* Reply to monitor requests. */ + struct ovsdb_error *error; + error = process_notification(msg->result, db); + if (error) { + ovsdb_error_assert(error); + state = RPL_S_ERR; + } else { + /* Transition to replicating state after receiving + * all replies of "monitor" requests. */ + if (hmap_is_empty(&request_ids)) { + VLOG_DBG("Listening to monitor updates"); + state = RPL_S_REPLICATING; + } } } break;