From patchwork Thu Sep 16 15:07:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dumitru Ceara X-Patchwork-Id: 1528903 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: 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=DrQdAMWR; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.136; helo=smtp3.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4H9L7K3TL4z9sR4 for ; Fri, 17 Sep 2021 01:08:13 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 6A7A5613F2; Thu, 16 Sep 2021 15:08:11 +0000 (UTC) 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 Yp3gpAuimQFP; Thu, 16 Sep 2021 15:08:10 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp3.osuosl.org (Postfix) with ESMTPS id 7F7666062E; Thu, 16 Sep 2021 15:08:09 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 539A3C000F; Thu, 16 Sep 2021 15:08:09 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by lists.linuxfoundation.org (Postfix) with ESMTP id 22F17C000D for ; Thu, 16 Sep 2021 15:08:08 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 0DF9D60638 for ; Thu, 16 Sep 2021 15:08:08 +0000 (UTC) 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 DVC1R6qm-Rm9 for ; Thu, 16 Sep 2021 15:08:06 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by smtp3.osuosl.org (Postfix) with ESMTPS id B7FA26062E for ; Thu, 16 Sep 2021 15:08:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631804885; 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=1VhCVaqnmeH4M99/fcr0DL7wA46YFIRJ3ekIXec27hA=; b=DrQdAMWRVOej4fv0W1yTWw40iu8Pwl3Z2Cg7LIZEdwfxRj3I7ULR46JUnLWkawzoFNMsWJ EvkZaPk9Mww8G+1dNmNhPeMXEMpopIxlj7sG8zVQSgKvuxcOINUbc3nggxHHfa2Iw9Z/HP 3ns94wDWJ/0AKw3Te7MMazY0JrbLmSM= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-179-wsxeFwyDOFi7eK6G-dOYLg-1; Thu, 16 Sep 2021 11:08:04 -0400 X-MC-Unique: wsxeFwyDOFi7eK6G-dOYLg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 25D3B91277; Thu, 16 Sep 2021 15:08:03 +0000 (UTC) Received: from dceara.remote.csb (unknown [10.39.193.243]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0398E61093; Thu, 16 Sep 2021 15:07:56 +0000 (UTC) From: Dumitru Ceara To: dev@openvswitch.org Date: Thu, 16 Sep 2021 17:07:48 +0200 Message-Id: <20210916150748.12692-1-dceara@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dceara@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Cc: i.maximets@ovn.org Subject: [ovs-dev] [PATCH] ovsdb-server: Log database transactions for user requested tables. 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" Add a new command, 'ovsdb-server/log-db-ops DB TABLE on|off', which allows the user to enable/disable transaction logging for specific databases and tables. By default, logging is disabled. Once enabled, logs are generated with level INFO and are also rate limited. If used with care, this command can be useful in analyzing production deployment performance issues, allowing the user to pin point bottlenecks without the need to enable wider debug logs, e.g., jsonrpc. Signed-off-by: Dumitru Ceara --- A sample use case is an ovn-kubernetes scaled deployment in which we're interesting in reducing time to bring up PODs (represented by OVN logical switch ports). In order to determine exactly where the bottleneck is when provisioning PODs (CMS/ovn-nbctl/client IDLs/ovsdb-server/ovn-controller/etc) we need timestamps of when operations happen at various places in the stack. Without this patch the only option for tracking when transactions happen in the Northbound database is to enable jsonrpc debug logs in ovsdb-server. This generates a rather large amount of data. Instead, now, users would be able to just enable logging for the Logical_Switch_Port table getting more relevant and precise information. --- NEWS | 4 ++++ ovsdb/ovsdb-server.c | 38 +++++++++++++++++++++++++++++++++ ovsdb/row.c | 17 +++++++++++++++ ovsdb/row.h | 1 + ovsdb/table.c | 7 ++++++ ovsdb/table.h | 3 +++ ovsdb/transaction.c | 51 ++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 121 insertions(+) diff --git a/NEWS b/NEWS index 1f2adf7180e0..392f8b340389 100644 --- a/NEWS +++ b/NEWS @@ -8,6 +8,10 @@ Post-v2.16.0 by default. 'other_config:dpdk-socket-limit' can be set equal to the 'other_config:dpdk-socket-mem' to preserve the legacy memory limiting behavior. + - OVSDB: + * New unixctl command 'ovsdb-server/log-db-ops DB TABLE on|off". + If turned on, ovsdb-server will log (at level INFO and rate limited) + all operations that are committed to table TABLE in the DB database. v2.16.0 - 16 Aug 2021 diff --git a/ovsdb/ovsdb-server.c b/ovsdb/ovsdb-server.c index 0b3d2bb71432..c48645f7e255 100644 --- a/ovsdb/ovsdb-server.c +++ b/ovsdb/ovsdb-server.c @@ -115,6 +115,7 @@ static unixctl_cb_func ovsdb_server_list_remotes; static unixctl_cb_func ovsdb_server_add_database; static unixctl_cb_func ovsdb_server_remove_database; static unixctl_cb_func ovsdb_server_list_databases; +static unixctl_cb_func ovsdb_server_log_db_ops; static void read_db(struct server_config *, struct db *); static struct ovsdb_error *open_db(struct server_config *, @@ -443,6 +444,8 @@ main(int argc, char *argv[]) ovsdb_server_remove_database, &server_config); unixctl_command_register("ovsdb-server/list-dbs", "", 0, 0, ovsdb_server_list_databases, &all_dbs); + unixctl_command_register("ovsdb-server/log-db-ops", "DB TABLE on|off", + 3, 3, ovsdb_server_log_db_ops, &all_dbs); unixctl_command_register("ovsdb-server/perf-counters-show", "", 0, 0, ovsdb_server_perf_counters_show, NULL); unixctl_command_register("ovsdb-server/perf-counters-clear", "", 0, 0, @@ -1769,6 +1772,41 @@ ovsdb_server_list_databases(struct unixctl_conn *conn, int argc OVS_UNUSED, ds_destroy(&s); } +static void +ovsdb_server_log_db_ops(struct unixctl_conn *conn, int argc OVS_UNUSED, + const char *argv[], void *all_dbs_) +{ + struct shash *all_dbs = all_dbs_; + const char *db_name = argv[1]; + const char *tbl_name = argv[2]; + const char *command = argv[3]; + bool log; + + if (!strcmp(command, "on")) { + log = true; + } else if (!strcmp(command, "off")) { + log = false; + } else { + unixctl_command_reply_error(conn, "invalid argument"); + return; + } + + struct db *db = shash_find_data(all_dbs, db_name); + if (!db) { + unixctl_command_reply_error(conn, "no such database"); + return; + } + + struct ovsdb_table *table = ovsdb_get_table(db->db, tbl_name); + if (!table) { + unixctl_command_reply_error(conn, "no such table"); + return; + } + + ovsdb_table_log_ops(table, log); + unixctl_command_reply(conn, NULL); +} + static void ovsdb_server_get_sync_status(struct unixctl_conn *conn, int argc OVS_UNUSED, const char *argv[] OVS_UNUSED, void *config_) diff --git a/ovsdb/row.c b/ovsdb/row.c index 65a0546211c8..5e31716506bc 100644 --- a/ovsdb/row.c +++ b/ovsdb/row.c @@ -278,6 +278,23 @@ ovsdb_row_to_json(const struct ovsdb_row *row, } return json; } + +void +ovsdb_row_to_string(const struct ovsdb_row *row, struct ds *out) +{ + struct shash_node *node; + + SHASH_FOR_EACH (node, &row->table->schema->columns) { + const struct ovsdb_column *column = node->data; + + ds_put_format(out, "%s:", column->name); + ovsdb_datum_to_string(&row->fields[column->index], &column->type, out); + ds_put_cstr(out, ","); + } + if (shash_count(&row->table->schema->columns)) { + ds_chomp(out, ','); + } +} void ovsdb_row_set_init(struct ovsdb_row_set *set) diff --git a/ovsdb/row.h b/ovsdb/row.h index 394ac8eb49b6..f22a08ecd197 100644 --- a/ovsdb/row.h +++ b/ovsdb/row.h @@ -95,6 +95,7 @@ struct ovsdb_error *ovsdb_row_from_json(struct ovsdb_row *, OVS_WARN_UNUSED_RESULT; struct json *ovsdb_row_to_json(const struct ovsdb_row *, const struct ovsdb_column_set *include); +void ovsdb_row_to_string(const struct ovsdb_row *, struct ds *); static inline const struct uuid * ovsdb_row_get_uuid(const struct ovsdb_row *row) diff --git a/ovsdb/table.c b/ovsdb/table.c index 455a3663fe89..b7b41d139914 100644 --- a/ovsdb/table.c +++ b/ovsdb/table.c @@ -301,10 +301,17 @@ ovsdb_table_create(struct ovsdb_table_schema *ts) hmap_init(&table->indexes[i]); } hmap_init(&table->rows); + table->log = false; return table; } +void +ovsdb_table_log_ops(struct ovsdb_table *table, bool enabled) +{ + table->log = enabled; +} + void ovsdb_table_destroy(struct ovsdb_table *table) { diff --git a/ovsdb/table.h b/ovsdb/table.h index ce69a5d130bf..be88b7a59279 100644 --- a/ovsdb/table.h +++ b/ovsdb/table.h @@ -63,10 +63,13 @@ struct ovsdb_table { * ovsdb_row"s. Each of the hmap_nodes in indexes[i] are at index 'i' at * the end of struct ovsdb_row, following the 'fields' member. */ struct hmap *indexes; + + bool log; /* True if logging is enabled for this table. */ }; struct ovsdb_table *ovsdb_table_create(struct ovsdb_table_schema *); void ovsdb_table_destroy(struct ovsdb_table *); +void ovsdb_table_log_ops(struct ovsdb_table *, bool); const struct ovsdb_row *ovsdb_table_get_row(const struct ovsdb_table *, const struct uuid *); diff --git a/ovsdb/transaction.c b/ovsdb/transaction.c index 8ffefcf7c9d0..dc07e9c00a4b 100644 --- a/ovsdb/transaction.c +++ b/ovsdb/transaction.c @@ -29,6 +29,7 @@ #include "openvswitch/vlog.h" #include "ovsdb-error.h" #include "ovsdb.h" +#include "ovs-thread.h" #include "row.h" #include "storage.h" #include "table.h" @@ -95,6 +96,7 @@ struct ovsdb_txn_row { static struct ovsdb_error * OVS_WARN_UNUSED_RESULT delete_garbage_row(struct ovsdb_txn *txn, struct ovsdb_txn_row *r); static void ovsdb_txn_row_prefree(struct ovsdb_txn_row *); +static void ovsdb_txn_row_log(const struct ovsdb_txn_row *); static struct ovsdb_error * OVS_WARN_UNUSED_RESULT for_each_txn_row(struct ovsdb_txn *txn, struct ovsdb_error *(*)(struct ovsdb_txn *, @@ -104,6 +106,11 @@ for_each_txn_row(struct ovsdb_txn *txn, * processed. */ static unsigned int serial; +/* Used by ovsdb_txn_row_log() to avoid reallocating dynamic strings + * every time a row operation is logged. + */ +DEFINE_STATIC_PER_THREAD_DATA(struct ds, row_log_str, DS_EMPTY_INITIALIZER); + struct ovsdb_txn * ovsdb_txn_create(struct ovsdb *db) { @@ -422,6 +429,49 @@ update_ref_counts(struct ovsdb_txn *txn) return for_each_txn_row(txn, check_ref_count); } +static void +ovsdb_txn_row_log(const struct ovsdb_txn_row *txn_row) +{ + static struct vlog_rate_limit rl_insert = VLOG_RATE_LIMIT_INIT(30, 60); + static struct vlog_rate_limit rl_update = VLOG_RATE_LIMIT_INIT(30, 60); + static struct vlog_rate_limit rl_delete = VLOG_RATE_LIMIT_INIT(30, 60); + + if (!txn_row->table->log) { + return; + } + + size_t n_columns = shash_count(&txn_row->table->schema->columns); + struct ovsdb_row *log_row; + const char *op = NULL; + + if (!txn_row->old && txn_row->new) { + if (!vlog_should_drop(&this_module, VLL_INFO, &rl_insert)) { + log_row = txn_row->new; + op = "inserted"; + } + } else if (txn_row->old && txn_row->new + && !bitmap_is_all_zeros(txn_row->changed, n_columns)) { + if (!vlog_should_drop(&this_module, VLL_INFO, &rl_update)) { + log_row = txn_row->new; + op = "updated"; + } + } else if (txn_row->old && !txn_row->new) { + if (!vlog_should_drop(&this_module, VLL_INFO, &rl_delete)) { + log_row = txn_row->old; + op = "deleted"; + } + } + + if (op) { + struct ds *ds = row_log_str_get(); + ds_clear(ds); + ds_put_format(ds, "table:%s,op:%s,", txn_row->table->schema->name, + op); + ovsdb_row_to_string(log_row, ds); + VLOG_INFO("%s", ds_cstr(ds)); + } +} + static struct ovsdb_error * ovsdb_txn_row_commit(struct ovsdb_txn *txn OVS_UNUSED, struct ovsdb_txn_row *txn_row) @@ -445,6 +495,7 @@ ovsdb_txn_row_commit(struct ovsdb_txn *txn OVS_UNUSED, } } + ovsdb_txn_row_log(txn_row); ovsdb_txn_row_prefree(txn_row); if (txn_row->new) { txn_row->new->n_refs = txn_row->n_refs;