From patchwork Thu Jul 30 10:41:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Federico Paolinelli X-Patchwork-Id: 1338748 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.136; helo=silver.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com 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=VINhcTMe; dkim-atps=neutral Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BHRn20NNfz9s1x for ; Thu, 30 Jul 2020 20:42:12 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id C547920770; Thu, 30 Jul 2020 10:42:09 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Ht-C5judds1i; Thu, 30 Jul 2020 10:42:08 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by silver.osuosl.org (Postfix) with ESMTP id 326BF204A6; Thu, 30 Jul 2020 10:42:08 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 0890CC0050; Thu, 30 Jul 2020 10:42:08 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by lists.linuxfoundation.org (Postfix) with ESMTP id 43918C004D for ; Thu, 30 Jul 2020 10:42:06 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 28A2B204D9 for ; Thu, 30 Jul 2020 10:42:06 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 3djO6O7Av1f2 for ; Thu, 30 Jul 2020 10:42:04 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) by silver.osuosl.org (Postfix) with ESMTPS id 9CE52204A6 for ; Thu, 30 Jul 2020 10:42:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1596105723; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=NT0mOsogdXoHZNUAs6HajwpdJdpPD4lBpLXFHgO1W/Q=; b=VINhcTMevbMugBsKNUIuhfI8BwI1wFHobi7+rapvI33VwRXST34bgy8dUX/wNh56IMWZrC 1UvXq3Vx9+831D5XP0DH7PQcXapQ2fjBiOttdkiqlqFV4mX7AapXgwpGDPF/h1LA9l8WhM bIzufsi/mode6Fjz962wOCg+6rfEziw= Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-421-Fcn0QOv_NuWdpJ-dgt5v2A-1; Thu, 30 Jul 2020 06:41:59 -0400 X-MC-Unique: Fcn0QOv_NuWdpJ-dgt5v2A-1 Received: by mail-ed1-f71.google.com with SMTP id a9so9448040edn.7 for ; Thu, 30 Jul 2020 03:41:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=NT0mOsogdXoHZNUAs6HajwpdJdpPD4lBpLXFHgO1W/Q=; b=WDRtD5N/xZN7baAfTELhv4+y1McWkqqQRAp/AixsVKQeteRCCIFvR+u+ygINuXW9fq kuojcUB98PyIfK+6kv9GHiWluti5aaxapm0M5WaZ+XedeGtogTHb6aoqEF0q1ILQ7X+G HaU14aIlPCSxuPPnCkwJVW8gGJi8q9zqvaiLRoLsIIT83kUPcdzXa3sC209JLohiE5Iq 4zCivC+uRitgZQWczDEGAeDqkOuBh7ODKWoOJ3FhzuuEJ3HIcA6HfCntv79gvT5n8V38 hqEUSKfv3ppt0kFh7rLcfroF90/quwGz03XEpr24xw9WZV6yFLJAUHlGUrGlNWDYEbei C6BA== X-Gm-Message-State: AOAM5338QLptcO31ThlhH19OYvDkBxiSqSOeSPap7v/OtpeemrS6dTpW ktr3qRYWzYj0SZxu+P4qmZfaYE25Ts77TBXPjBLLUAlgBoVl0cEZeOYChm+yUURLIhrOSRtTG4Q DIODHgUUtQZniFTm5cs9DYjcFYSOb X-Received: by 2002:a17:906:1a0a:: with SMTP id i10mr2066184ejf.204.1596105718163; Thu, 30 Jul 2020 03:41:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzhHNU/dSLdNI5GcVmhp75+8yzYLNLuuwbM8lZiuDdkpm1Xi2Q7KIPz2uJ1zlobW/Awvi/UYwCbKLG6uloVaJo= X-Received: by 2002:a17:906:1a0a:: with SMTP id i10mr2066164ejf.204.1596105717869; Thu, 30 Jul 2020 03:41:57 -0700 (PDT) MIME-Version: 1.0 From: Federico Paolinelli Date: Thu, 30 Jul 2020 12:41:47 +0200 Message-ID: To: dev@openvswitch.org X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [ovs-dev] [PATCH v4] ovsdb-tool: Add a db consistency check to the ovsdb-tool check-cluster command 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" There are some occurrences where the database ends up in an inconsistent state. This happened in ovn-k8s and is described in [0]. Here we are adding a supported way to check that a given db is consistent, which is less error prone than checking the logs. Tested against both a valid db and a corrupted db attached to the above bug [1]. Also, tested with a fresh db that did not do a snapshot. [0]: https://bugzilla.redhat.com/show_bug.cgi?id=1837953#c23 [1]: https://bugzilla.redhat.com/attachment.cgi?id=1697595 Signed-off-by: Federico Paolinelli Suggested-by: Dumitru Ceara Acked-by: Dumitru Ceara --- ovsdb/ovsdb-tool.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/ovsdb/ovsdb-tool.c b/ovsdb/ovsdb-tool.c index 91662cab8..30d0472b2 100644 --- a/ovsdb/ovsdb-tool.c +++ b/ovsdb/ovsdb-tool.c @@ -1497,6 +1497,44 @@ do_check_cluster(struct ovs_cmdl_context *ctx) } } + /* Check for db consistency: + * The serverid must be in the servers list. + */ + + for (struct server *s = c.servers; s < &c.servers[c.n_servers]; s++) { + struct shash *servers_obj = json_object(s->snap->servers); + char *server_id = xasprintf(SID_FMT, SID_ARGS(&s->header.sid)); + bool found = false; + const struct shash_node *node; + + SHASH_FOR_EACH (node, servers_obj) { + if (!strncmp(server_id, node->name, SID_LEN)) { + found = true; + } + } + + if (!found) { + for (struct raft_entry *e = s->entries; + e < &s->entries[s->log_end - s->log_start]; e++) { + if (e->servers == NULL) { + continue; + } + struct shash *log_servers_obj = json_object(e->servers); + SHASH_FOR_EACH (node, log_servers_obj) { + if (!strncmp(server_id, node->name, SID_LEN)) { + found = true; + } + } + } + } + + if (!found) { + ovs_fatal(0, "%s: server %s not found in server list", + s->filename, server_id); + } + free(server_id); + } + /* Clean up. */ for (size_t i = 0; i < c.n_servers; i++) {