Blame SOURCES/0012-Issue-51166-Log-an-error-when-a-search-is-fully-unin.patch

93ba16
From 1463ec463428e6a6ffd0de458823c6607c5e9831 Mon Sep 17 00:00:00 2001
93ba16
From: Mark Reynolds <mreynolds@redhat.com>
93ba16
Date: Thu, 18 Jun 2020 15:34:23 -0400
93ba16
Subject: [PATCH 1/5] Issue 51166 - Log an error when a search is fully
93ba16
 unindexed
93ba16
93ba16
Bug Description:  Some plugins can trigger very expensive internal searches
93ba16
                  that can exhaust the bdb db_locks.  It is very difficult
93ba16
                  to track these down.
93ba16
93ba16
Fix description:  Log a message to the errors log when any search (internal or not)
93ba16
                  is fully unindexed and provide the search details.  This will
93ba16
                  allow an admin to identify and fix indexing issues.
93ba16
93ba16
relates: https://pagure.io/389-ds-base/issue/51166
93ba16
93ba16
Reviewed by: firstyear & tbordaz(Thanks!!)
93ba16
---
93ba16
 ldap/servers/slapd/back-ldbm/ldbm_search.c | 42 ++++++++++++++++++++--
93ba16
 1 file changed, 40 insertions(+), 2 deletions(-)
93ba16
93ba16
diff --git a/ldap/servers/slapd/back-ldbm/ldbm_search.c b/ldap/servers/slapd/back-ldbm/ldbm_search.c
93ba16
index 2ad8f743a..212b6cb61 100644
93ba16
--- a/ldap/servers/slapd/back-ldbm/ldbm_search.c
93ba16
+++ b/ldap/servers/slapd/back-ldbm/ldbm_search.c
93ba16
@@ -825,13 +825,23 @@ ldbm_back_search(Slapi_PBlock *pb)
93ba16
         int pr_idx = -1;
93ba16
         Connection *pb_conn = NULL;
93ba16
         Operation *pb_op = NULL;
93ba16
+        struct slapdplugin *plugin = NULL;
93ba16
+        struct slapi_componentid *cid = NULL;
93ba16
+        char *filter_str;
93ba16
+        char *plugin_dn;
93ba16
+        char *base_dn;
93ba16
+        int32_t internal_op = operation_is_flag_set(operation, OP_FLAG_INTERNAL);
93ba16
+        uint64_t connid;
93ba16
+        int32_t op_id;
93ba16
+        int32_t op_internal_id;
93ba16
+        int32_t op_nested_count;
93ba16
 
93ba16
         /*
93ba16
          * Return error if nsslapd-require-index is set and
93ba16
          * this is not an internal operation.
93ba16
          * We hope the plugins know what they are doing!
93ba16
          */
93ba16
-        if (!operation_is_flag_set(operation, OP_FLAG_INTERNAL)) {
93ba16
+        if (!internal_op) {
93ba16
 
93ba16
             PR_Lock(inst->inst_config_mutex);
93ba16
             ri = inst->require_index;
93ba16
@@ -844,6 +854,35 @@ ldbm_back_search(Slapi_PBlock *pb)
93ba16
                 tmp_desc = "Search is not indexed";
93ba16
             }
93ba16
         }
93ba16
+        /*
93ba16
+         * When an search is fully unindexed we need to log the
93ba16
+         * details as these kinds of searches can cause issues with bdb db
93ba16
+         * locks being exhausted.  This will help expose what indexing is
93ba16
+         * missing.
93ba16
+         */
93ba16
+        slapi_pblock_get(pb, SLAPI_OPERATION, &pb_op);
93ba16
+        slapi_pblock_get(pb, SLAPI_SEARCH_STRFILTER, &filter_str);
93ba16
+        slapi_pblock_get(pb, SLAPI_TARGET_DN, &base_dn);
93ba16
+
93ba16
+        if (internal_op) {
93ba16
+            /* Get the plugin that triggered this internal search */
93ba16
+            slapi_pblock_get(pb, SLAPI_PLUGIN_IDENTITY, &cid;;
93ba16
+            if (cid) {
93ba16
+                plugin = (struct slapdplugin *)cid->sci_plugin;
93ba16
+            } else {
93ba16
+                slapi_pblock_get(pb, SLAPI_PLUGIN, &plugin);
93ba16
+            }
93ba16
+            plugin_dn = plugin_get_dn(plugin);
93ba16
+            get_internal_conn_op(&connid, &op_id, &op_internal_id, &op_nested_count);
93ba16
+            slapi_log_err(SLAPI_LOG_NOTICE, "ldbm_back_search",
93ba16
+                    "Internal unindexed search: source (%s) search base=\"%s\" scope=%d filter=\"%s\" conn=%" PRIu64 " op=%d (internal op=%d count=%d)\n",
93ba16
+                    plugin_dn, base_dn, scope, filter_str, connid, op_id, op_internal_id, op_nested_count);
93ba16
+            slapi_ch_free_string(&plugin_dn);
93ba16
+        } else {
93ba16
+            slapi_log_err(SLAPI_LOG_NOTICE, "ldbm_back_search",
93ba16
+                    "Unindexed search: search base=\"%s\" scope=%d filter=\"%s\" conn=%" PRIu64 " op=%d\n",
93ba16
+                    base_dn, scope, filter_str, pb_op->o_connid, pb_op->o_opid);
93ba16
+        }
93ba16
 
93ba16
         slapi_pblock_get(pb, SLAPI_OPERATION_NOTES, &opnote);
93ba16
         opnote |= SLAPI_OP_NOTE_FULL_UNINDEXED; /* the full filter leads to an unindexed search */
93ba16
@@ -851,7 +890,6 @@ ldbm_back_search(Slapi_PBlock *pb)
93ba16
         slapi_pblock_set(pb, SLAPI_OPERATION_NOTES, NULL);
93ba16
         slapi_pblock_set(pb, SLAPI_OPERATION_NOTES, &opnote);
93ba16
         slapi_pblock_get(pb, SLAPI_PAGED_RESULTS_INDEX, &pr_idx);
93ba16
-        slapi_pblock_get(pb, SLAPI_OPERATION, &pb_op);
93ba16
         slapi_pblock_get(pb, SLAPI_CONNECTION, &pb_conn);
93ba16
         pagedresults_set_unindexed(pb_conn, pb_op, pr_idx);
93ba16
     }
93ba16
-- 
93ba16
2.26.2
93ba16