From patchwork Fri Sep 16 08:40:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xavier Simonart X-Patchwork-Id: 1678568 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::136; helo=smtp3.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=UsUCarLg; dkim-atps=neutral Received: from smtp3.osuosl.org (smtp3.osuosl.org [IPv6:2605:bc80:3010::136]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MTSFG31Ryz1ynm for ; Fri, 16 Sep 2022 18:40:17 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 7961C61205; Fri, 16 Sep 2022 08:40:14 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 7961C61205 Authentication-Results: smtp3.osuosl.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=UsUCarLg X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id xysE_8Eqf22Q; Fri, 16 Sep 2022 08:40:13 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp3.osuosl.org (Postfix) with ESMTPS id 8853E611DA; Fri, 16 Sep 2022 08:40:12 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 8853E611DA Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 48D8CC0032; Fri, 16 Sep 2022 08:40:12 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp4.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by lists.linuxfoundation.org (Postfix) with ESMTP id 539FBC002D for ; Fri, 16 Sep 2022 08:40:11 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 2732941C9C for ; Fri, 16 Sep 2022 08:40:11 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org 2732941C9C Authentication-Results: smtp4.osuosl.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=UsUCarLg 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 PcjaR-26Y3og for ; Fri, 16 Sep 2022 08:40:09 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org 8027541C97 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by smtp4.osuosl.org (Postfix) with ESMTPS id 8027541C97 for ; Fri, 16 Sep 2022 08:40:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1663317607; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=6mqSmNTZFdNszOwDxdz+/B7tPQKizNvTmLj41Eu93Zg=; b=UsUCarLg8PVtjOGXJsd9nV/2142uCAdb//e/Z6FnCCSQd47usiZNdoXtmQJXPDmUb0PQ1f w6YbmW/CTsCZcqamrOrRyJYVKcCm9MZ+aSnQj4StZoTJT/QK8tVtjwPiKIIMfgTbPZc+O3 vPlDWtmwgv7T3FXfD/oFrookTuzZ8YQ= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-652-7gYQ6KQ1Mz-WxBqkW3qEPg-1; Fri, 16 Sep 2022 04:40:06 -0400 X-MC-Unique: 7gYQ6KQ1Mz-WxBqkW3qEPg-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7EE34811E87; Fri, 16 Sep 2022 08:40:06 +0000 (UTC) Received: from wsfd-netdev90.ntdv.lab.eng.bos.redhat.com (wsfd-netdev90.ntdv.lab.eng.bos.redhat.com [10.19.188.196]) by smtp.corp.redhat.com (Postfix) with ESMTP id 55B112087440; Fri, 16 Sep 2022 08:40:06 +0000 (UTC) From: Xavier Simonart To: xsimonar@redhat.com, dev@openvswitch.org Date: Fri, 16 Sep 2022 04:40:06 -0400 Message-Id: <20220916084006.884447-1-xsimonar@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Cc: dceara@redhat.com, i.maximets@ovn.org Subject: [ovs-dev] [PATCH] ovsdb-idl: Preserve references for rows deleted in same IDL as their insertion. 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" Considering two DB rows, 'a' from table A and 'b' from table B (with column 'ref_a' a reference to table A): a = {A._uuid=} b = {B._uuid=, B.ref_a=} Assuming both records are inserted in the IDL client's in-memory view of the database, if row 'b' is also deleted in the same transaction, it should generate the following tracked changes: - for table A: - inserted records: a = {A._uuid=} - for table B: - inserted records: b = {B._uuid=, B.ref_a=} - deleted records: b = {B._uuid=, B.ref_a=} Before this patch, inserted and deleted records in table B would (in some cases [0]) be b = {B._uuid=, B.ref_a=[]}. Having B.ref_a=[] would violate the integrity of the database from client perspective. test-ovsdb has also been updated to show that one row can be both inserted and deleted within one IDL. [0] In ovn-controller the fact that the reference is NULL caused a crash in the following case, when both commands were handled by ovn-controller within the same loop: $ ovn-nbctl ls-add sw0 -- lsp-add sw0 sw0-port1 -- lsp-set-addresses sw0-port1 "50:54:00:00:00:01 192.168.0.2" $ ovn-nbctl lsp-del sw0-port1 Reported-at: https://bugzilla.redhat.com/show_bug.cgi?id=2126450 Fixes: 91e1ff5dde39 ("ovsdb-idl: Don't reparse orphaned rows.") Signed-off-by: Xavier Simonart --- lib/ovsdb-idl.c | 4 +++ tests/ovsdb-idl.at | 89 ++++++++++++++++++++++++++++++++++++++++++++++ tests/test-ovsdb.c | 13 ++++--- 3 files changed, 101 insertions(+), 5 deletions(-) diff --git a/lib/ovsdb-idl.c b/lib/ovsdb-idl.c index 576979f9e..e33d2a5c5 100644 --- a/lib/ovsdb-idl.c +++ b/lib/ovsdb-idl.c @@ -2419,6 +2419,10 @@ ovsdb_idl_insert_row(struct ovsdb_idl_row *row, const struct shash *data) static void ovsdb_idl_delete_row(struct ovsdb_idl_row *row) { + /* If row has to be reparsed, reparse it before it's deleted */ + if (!ovs_list_is_empty(&row->reparse_node)) { + ovsdb_idl_row_parse(row); + } ovsdb_idl_remove_from_indexes(row); ovsdb_idl_row_clear_arcs(row, true); ovsdb_idl_row_destroy(row); diff --git a/tests/ovsdb-idl.at b/tests/ovsdb-idl.at index d1cfa59c5..8e75d00d7 100644 --- a/tests/ovsdb-idl.at +++ b/tests/ovsdb-idl.at @@ -2466,3 +2466,92 @@ unix:socket2 remote has col id in table simple7 OVSDB_SERVER_SHUTDOWN AT_CLEANUP + +dnl This test checks that inserting and deleting the source of a reference +dnl doesn't remove the reference in the (deleted) source tracked record. +OVSDB_CHECK_IDL_TRACK([track, insert and delete, refs to link1], + [], + [['["idltest", + {"op": "insert", + "table": "link2", + "uuid-name": "l2row0", + "row": {"i": 1, "l1": ["set", [["named-uuid", "l1row0"]]]} + }, + {"op": "insert", + "table": "link1", + "uuid-name": "l1row0", + "row": {"i": 1, "k": ["named-uuid", "l1row0"]} + }, + {"op": "insert", + "table": "link2", + "uuid-name": "l2row1", + "row": {"i": 2, "l1": ["set", [["named-uuid", "l1row0"]]]} + } + ]' \ + '+["idltest", + {"op": "delete", + "table": "link2", + "where": [["i", "==", 2]]} + ]' \ + '["idltest", + {"op": "delete", + "table": "link2", + "where": [["i", "==", 1]]} + ]' + ]], + [[000: empty +001: {"error":null,"result":[{"uuid":["uuid","<0>"]},{"uuid":["uuid","<1>"]},{"uuid":["uuid","<2>"]}]} +002: {"error":null,"result":[{"count":1}]} +003: table link1: inserted row: i=1 k=1 ka=[] l2= uuid=<1> +003: table link1: updated columns: i k +003: table link2: inserted row: i=1 l1=1 uuid=<0> +003: table link2: inserted/deleted row: i=2 l1=1 uuid=<2> +003: table link2: updated columns: i l1 +003: table link2: updated columns: i l1 +004: {"error":null,"result":[{"count":1}]} +005: table link1: i=1 k=1 ka=[] l2= uuid=<1> +006: done +]]) +OVSDB_CHECK_IDL_TRACK([track, insert and delete, refs to link2], + [], + [['["idltest", + {"op": "insert", + "table": "link1", + "uuid-name": "l1row0", + "row": {"i": 1, "k": ["named-uuid", "l1row0"], "l2": ["set", [["named-uuid", "l2row0"]]]} + }, + {"op": "insert", + "table": "link2", + "uuid-name": "l2row0", + "row": {"i": 1} + }, + {"op": "insert", + "table": "link1", + "uuid-name": "l1row1", + "row": {"i": 2, "k": ["named-uuid", "l1row0"], "l2": ["set", [["named-uuid", "l2row0"]]]} + } + ]' \ + '+["idltest", + {"op": "delete", + "table": "link1", + "where": [["i", "==", 2]]} + ]' \ + '["idltest", + {"op": "delete", + "table": "link1", + "where": [["i", "==", 1]]} + ]' + ]], + [[000: empty +001: {"error":null,"result":[{"uuid":["uuid","<0>"]},{"uuid":["uuid","<1>"]},{"uuid":["uuid","<2>"]}]} +002: {"error":null,"result":[{"count":1}]} +003: table link1: inserted row: i=1 k=1 ka=[] l2=1 uuid=<0> +003: table link1: inserted/deleted row: i=2 k=1 ka=[] l2=1 uuid=<2> +003: table link1: updated columns: i k l2 +003: table link1: updated columns: i k l2 +003: table link2: inserted row: i=1 l1= uuid=<1> +003: table link2: updated columns: i +004: {"error":null,"result":[{"count":1}]} +005: table link2: i=1 l1= uuid=<1> +006: done +]]) diff --git a/tests/test-ovsdb.c b/tests/test-ovsdb.c index 965b0f913..5f7110f41 100644 --- a/tests/test-ovsdb.c +++ b/tests/test-ovsdb.c @@ -1953,11 +1953,14 @@ format_idl_row(const struct ovsdb_idl_row *row, int step, const char *contents, const char *change_str = !ovsdb_idl_track_is_set(row->table) ? "" - : ovsdb_idl_row_get_seqno(row, OVSDB_IDL_CHANGE_INSERT) > 0 - ? "inserted row: " - : ovsdb_idl_row_get_seqno(row, OVSDB_IDL_CHANGE_DELETE) > 0 - ? "deleted row: " - : ""; + : ovsdb_idl_row_get_seqno(row, OVSDB_IDL_CHANGE_INSERT) > 0 && + ovsdb_idl_row_get_seqno(row, OVSDB_IDL_CHANGE_DELETE) > 0 + ? "inserted/deleted row: " + : ovsdb_idl_row_get_seqno(row, OVSDB_IDL_CHANGE_INSERT) > 0 + ? "inserted row: " + : ovsdb_idl_row_get_seqno(row, OVSDB_IDL_CHANGE_DELETE) > 0 + ? "deleted row: " + : ""; if (terse) { return xasprintf("%03d: table %s", step, row->table->class_->name);