From patchwork Thu Nov 1 16:29:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Pfaff X-Patchwork-Id: 991985 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=none (p=none dis=none) header.from=ovn.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 42m9dX2w6TzB4Xs for ; Fri, 2 Nov 2018 03:29:20 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 63A8CED9; Thu, 1 Nov 2018 16:29:17 +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 2AFDCB4B for ; Thu, 1 Nov 2018 16:29:16 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 5E9AA76A for ; Thu, 1 Nov 2018 16:29:15 +0000 (UTC) X-Originating-IP: 75.54.222.30 Received: from sigabrt.attlocal.net (75-54-222-30.lightspeed.rdcyca.sbcglobal.net [75.54.222.30]) (Authenticated sender: blp@ovn.org) by relay2-d.mail.gandi.net (Postfix) with ESMTPSA id 3F9EF40004; Thu, 1 Nov 2018 16:29:11 +0000 (UTC) From: Ben Pfaff To: dev@openvswitch.org Date: Thu, 1 Nov 2018 09:29:07 -0700 Message-Id: <20181101162907.19059-1-blp@ovn.org> X-Mailer: git-send-email 2.16.1 X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Cc: Ben Pfaff Subject: [ovs-dev] [PATCH] osvdb: Add some helpful comments. 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 Signed-off-by: Ben Pfaff Acked-by: Justin Pettit --- ovsdb/row.h | 2 +- ovsdb/transaction.c | 29 +++++++++++++++++++---------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/ovsdb/row.h b/ovsdb/row.h index 5f0b8a7baf29..2c441b5a4b3b 100644 --- a/ovsdb/row.h +++ b/ovsdb/row.h @@ -49,7 +49,7 @@ struct ovsdb_row { struct ovsdb_table *table; /* Table to which this belongs. */ struct ovsdb_txn_row *txn_row; /* Transaction that row is in, if any. */ - /* Weak references. */ + /* Weak references. Updated and checked only at transaction commit. */ struct ovs_list src_refs; /* Weak references from this row. */ struct ovs_list dst_refs; /* Weak references to this row. */ diff --git a/ovsdb/transaction.c b/ovsdb/transaction.c index 9801aca2b08f..5a43132e4ab8 100644 --- a/ovsdb/transaction.c +++ b/ovsdb/transaction.c @@ -763,31 +763,40 @@ static struct ovsdb_error * OVS_WARN_UNUSED_RESULT check_index_uniqueness(struct ovsdb_txn *txn OVS_UNUSED, struct ovsdb_txn_row *txn_row) { - struct ovsdb_txn_table *txn_table = txn_row->table->txn_table; - struct ovsdb_table *table = txn_row->table; + /* Skip rows that are being deleted since they can't violate uniqueness. */ struct ovsdb_row *row = txn_row->new; - size_t i; - if (!row) { return NULL; } - for (i = 0; i < table->schema->n_indexes; i++) { + struct ovsdb_txn_table *txn_table = txn_row->table->txn_table; + struct ovsdb_table *table = txn_row->table; + for (size_t i = 0; i < table->schema->n_indexes; i++) { const struct ovsdb_column_set *index = &table->schema->indexes[i]; - struct ovsdb_row *irow; - uint32_t hash; - - hash = ovsdb_row_hash_columns(row, index, 0); - irow = ovsdb_index_search(&txn_table->txn_indexes[i], row, i, hash); + uint32_t hash = ovsdb_row_hash_columns(row, index, 0); + + /* Check whether the row has a match in the temporary hash table that + * we're building. If we add two rows with the same index data, then + * there's a duplicate within the rows added or modified in this + * transaction.*/ + struct ovsdb_row *irow + = ovsdb_index_search(&txn_table->txn_indexes[i], row, i, hash); if (irow) { return duplicate_index_row(index, irow, row); } + /* Also check whether the row has a match in the table's real index + * (which won't be updated until transaction commit is certain). If + * there's a match, and it's for a row that wasn't pulled into the + * transaction, then it's a duplicate. (If it is for a row that is + * part of the transaction, then the first check has already handled + * it.) */ irow = ovsdb_index_search(&table->indexes[i], row, i, hash); if (irow && !irow->txn_row) { return duplicate_index_row(index, irow, row); } + /* Add row to temporary hash table. */ hmap_insert(&txn_table->txn_indexes[i], ovsdb_row_get_index_node(row, i), hash); }