Blame SOURCES/0036-Issue-4581-A-failed-re-indexing-leaves-the-database-.patch

ef1f48
From 4fb3023a55529c9d5332e3425ae8da590a8ebb69 Mon Sep 17 00:00:00 2001
ef1f48
From: tbordaz <tbordaz@redhat.com>
ef1f48
Date: Mon, 1 Feb 2021 09:28:25 +0100
ef1f48
Subject: [PATCH 3/4] Issue 4581 - A failed re-indexing leaves the database in
ef1f48
 broken state (#4582)
ef1f48
ef1f48
Bug description:
ef1f48
	During reindex the numsubordinates attribute is not updated in parent entries.
ef1f48
	The consequence is that the internal counter job->numsubordinates==0.
ef1f48
	Later when indexing the ancestorid, the server can show the progression of this
ef1f48
	indexing with a ratio using job->numsubordinates==0.
ef1f48
	Division with 0 -> SIGFPE
ef1f48
ef1f48
Fix description:
ef1f48
	if the numsubordinates is NULL, log a message without a division.
ef1f48
ef1f48
relates: https://github.com/389ds/389-ds-base/issues/4581
ef1f48
ef1f48
Reviewed by: Pierre Rogier, Mark Reynolds, Simon Pichugin, Teko Mihinto (thanks !!)
ef1f48
ef1f48
Platforms tested: F31
ef1f48
---
ef1f48
 .../slapd/back-ldbm/db-bdb/bdb_import.c       | 72 ++++++++++++++-----
ef1f48
 1 file changed, 54 insertions(+), 18 deletions(-)
ef1f48
ef1f48
diff --git a/ldap/servers/slapd/back-ldbm/db-bdb/bdb_import.c b/ldap/servers/slapd/back-ldbm/db-bdb/bdb_import.c
ef1f48
index 15574e60f..9713b52f6 100644
ef1f48
--- a/ldap/servers/slapd/back-ldbm/db-bdb/bdb_import.c
ef1f48
+++ b/ldap/servers/slapd/back-ldbm/db-bdb/bdb_import.c
ef1f48
@@ -468,18 +468,30 @@ bdb_get_nonleaf_ids(backend *be, DB_TXN *txn, IDList **idl, ImportJob *job)
ef1f48
         }
ef1f48
         key_count++;
ef1f48
         if (!(key_count % PROGRESS_INTERVAL)) {
ef1f48
-            import_log_notice(job, SLAPI_LOG_INFO, "bdb_get_nonleaf_ids",
ef1f48
-                              "Gathering ancestorid non-leaf IDs: processed %d%% (ID count %d)",
ef1f48
-                              (key_count * 100 / job->numsubordinates), key_count);
ef1f48
+            if (job->numsubordinates) {
ef1f48
+                import_log_notice(job, SLAPI_LOG_INFO, "bdb_get_nonleaf_ids",
ef1f48
+                                  "Gathering ancestorid non-leaf IDs: processed %d%% (ID count %d)",
ef1f48
+                                  (key_count * 100 / job->numsubordinates), key_count);
ef1f48
+            } else {
ef1f48
+                import_log_notice(job, SLAPI_LOG_INFO, "bdb_get_nonleaf_ids",
ef1f48
+                                  "Gathering ancestorid non-leaf IDs: processed %d ancestors...",
ef1f48
+                                  key_count);
ef1f48
+            }
ef1f48
             started_progress_logging = 1;
ef1f48
         }
ef1f48
     } while (ret == 0 && !(job->flags & FLAG_ABORT));
ef1f48
 
ef1f48
     if (started_progress_logging) {
ef1f48
         /* finish what we started logging */
ef1f48
-        import_log_notice(job, SLAPI_LOG_INFO, "bdb_get_nonleaf_ids",
ef1f48
-                          "Gathering ancestorid non-leaf IDs: processed %d%% (ID count %d)",
ef1f48
-                          (key_count * 100 / job->numsubordinates), key_count);
ef1f48
+        if (job->numsubordinates) {
ef1f48
+            import_log_notice(job, SLAPI_LOG_INFO, "bdb_get_nonleaf_ids",
ef1f48
+                              "Gathering ancestorid non-leaf IDs: processed %d%% (ID count %d)",
ef1f48
+                              (key_count * 100 / job->numsubordinates), key_count);
ef1f48
+        } else {
ef1f48
+            import_log_notice(job, SLAPI_LOG_INFO, "bdb_get_nonleaf_ids",
ef1f48
+                              "Gathering ancestorid non-leaf IDs: processed %d ancestors",
ef1f48
+                              key_count);
ef1f48
+        }
ef1f48
     }
ef1f48
     import_log_notice(job, SLAPI_LOG_INFO, "bdb_get_nonleaf_ids",
ef1f48
                       "Finished gathering ancestorid non-leaf IDs.");
ef1f48
@@ -660,9 +672,15 @@ bdb_ancestorid_default_create_index(backend *be, ImportJob *job)
ef1f48
 
ef1f48
         key_count++;
ef1f48
         if (!(key_count % PROGRESS_INTERVAL)) {
ef1f48
-            import_log_notice(job, SLAPI_LOG_INFO, "bdb_ancestorid_default_create_index",
ef1f48
-                              "Creating ancestorid index: processed %d%% (ID count %d)",
ef1f48
-                              (key_count * 100 / job->numsubordinates), key_count);
ef1f48
+            if (job->numsubordinates) {
ef1f48
+                import_log_notice(job, SLAPI_LOG_INFO, "bdb_ancestorid_default_create_index",
ef1f48
+                                  "Creating ancestorid index: processed %d%% (ID count %d)",
ef1f48
+                                  (key_count * 100 / job->numsubordinates), key_count);
ef1f48
+            } else {
ef1f48
+                import_log_notice(job, SLAPI_LOG_INFO, "bdb_ancestorid_default_create_index",
ef1f48
+                                  "Creating ancestorid index: processed %d ancestors...",
ef1f48
+                                  key_count);
ef1f48
+            }
ef1f48
             started_progress_logging = 1;
ef1f48
         }
ef1f48
 
ef1f48
@@ -743,9 +761,15 @@ out:
ef1f48
     if (ret == 0) {
ef1f48
         if (started_progress_logging) {
ef1f48
             /* finish what we started logging */
ef1f48
-            import_log_notice(job, SLAPI_LOG_INFO, "bdb_ancestorid_default_create_index",
ef1f48
-                              "Creating ancestorid index: processed %d%% (ID count %d)",
ef1f48
-                              (key_count * 100 / job->numsubordinates), key_count);
ef1f48
+            if (job->numsubordinates) {
ef1f48
+                import_log_notice(job, SLAPI_LOG_INFO, "bdb_ancestorid_default_create_index",
ef1f48
+                                  "Creating ancestorid index: processed %d%% (ID count %d)",
ef1f48
+                                  (key_count * 100 / job->numsubordinates), key_count);
ef1f48
+            } else {
ef1f48
+                import_log_notice(job, SLAPI_LOG_INFO, "bdb_ancestorid_default_create_index",
ef1f48
+                                  "Creating ancestorid index: processed %d ancestors",
ef1f48
+                                  key_count);
ef1f48
+            }
ef1f48
         }
ef1f48
         import_log_notice(job, SLAPI_LOG_INFO, "bdb_ancestorid_default_create_index",
ef1f48
                           "Created ancestorid index (old idl).");
ef1f48
@@ -869,9 +893,15 @@ bdb_ancestorid_new_idl_create_index(backend *be, ImportJob *job)
ef1f48
 
ef1f48
         key_count++;
ef1f48
         if (!(key_count % PROGRESS_INTERVAL)) {
ef1f48
-            import_log_notice(job, SLAPI_LOG_INFO, "bdb_ancestorid_new_idl_create_index",
ef1f48
-                              "Creating ancestorid index: progress %d%% (ID count %d)",
ef1f48
-                              (key_count * 100 / job->numsubordinates), key_count);
ef1f48
+            if (job->numsubordinates) {
ef1f48
+                import_log_notice(job, SLAPI_LOG_INFO, "bdb_ancestorid_new_idl_create_index",
ef1f48
+                                  "Creating ancestorid index: progress %d%% (ID count %d)",
ef1f48
+                                  (key_count * 100 / job->numsubordinates), key_count);
ef1f48
+            } else {
ef1f48
+                import_log_notice(job, SLAPI_LOG_INFO, "bdb_ancestorid_new_idl_create_index",
ef1f48
+                                  "Creating ancestorid index: progress %d ancestors...",
ef1f48
+                                  key_count);
ef1f48
+            }
ef1f48
             started_progress_logging = 1;
ef1f48
         }
ef1f48
 
ef1f48
@@ -932,9 +962,15 @@ out:
ef1f48
     if (ret == 0) {
ef1f48
         if (started_progress_logging) {
ef1f48
             /* finish what we started logging */
ef1f48
-            import_log_notice(job, SLAPI_LOG_INFO, "bdb_ancestorid_new_idl_create_index",
ef1f48
-                              "Creating ancestorid index: processed %d%% (ID count %d)",
ef1f48
-                              (key_count * 100 / job->numsubordinates), key_count);
ef1f48
+            if (job->numsubordinates) {
ef1f48
+                import_log_notice(job, SLAPI_LOG_INFO, "bdb_ancestorid_new_idl_create_index",
ef1f48
+                                  "Creating ancestorid index: processed %d%% (ID count %d)",
ef1f48
+                                  (key_count * 100 / job->numsubordinates), key_count);
ef1f48
+            } else {
ef1f48
+                import_log_notice(job, SLAPI_LOG_INFO, "bdb_ancestorid_new_idl_create_index",
ef1f48
+                                  "Creating ancestorid index: processed %d ancestors",
ef1f48
+                                  key_count);
ef1f48
+            }
ef1f48
         }
ef1f48
         import_log_notice(job, SLAPI_LOG_INFO, "bdb_ancestorid_new_idl_create_index",
ef1f48
                           "Created ancestorid index (new idl).");
ef1f48
-- 
ef1f48
2.26.2
ef1f48