Blame SOURCES/0022-Ticket-50741-cont-bdb_start-Detected-Disorderly-Shut.patch

8394b4
From 1d2dca488c7b646dcf5d482414dec2ee032edea6 Mon Sep 17 00:00:00 2001
8394b4
From: Ludwig Krispenz <lkrispen@redhat.com>
8394b4
Date: Fri, 6 Dec 2019 13:54:04 +0100
8394b4
Subject: [PATCH] Ticket 50741-cont bdb_start - Detected Disorderly Shutdown
8394b4
8394b4
Bug: Offline import does no longer write guardian file, next
8394b4
	normal start will raise a Disorderly Shutdown
8394b4
8394b4
Fix: The bug was introduced with the fix for #50659 when dblayer_close() was
8394b4
	removed from import_moain_offline becasue it was called twice in some
8394b4
	scenarios. But it did miss in ldif2db. Add it there.
8394b4
	Also correct function reference in error messages
8394b4
8394b4
Reviewed by: Thierry, thanks
8394b4
---
8394b4
 .../slapd/back-ldbm/db-bdb/bdb_import.c       | 60 +++++++++----------
8394b4
 .../slapd/back-ldbm/db-bdb/bdb_ldif2db.c      |  3 +
8394b4
 2 files changed, 33 insertions(+), 30 deletions(-)
8394b4
8394b4
diff --git a/ldap/servers/slapd/back-ldbm/db-bdb/bdb_import.c b/ldap/servers/slapd/back-ldbm/db-bdb/bdb_import.c
8394b4
index 60b6e13eb..15574e60f 100644
8394b4
--- a/ldap/servers/slapd/back-ldbm/db-bdb/bdb_import.c
8394b4
+++ b/ldap/servers/slapd/back-ldbm/db-bdb/bdb_import.c
8394b4
@@ -2274,7 +2274,7 @@ bdb_import_main(void *arg)
8394b4
                                producer, PR_PRIORITY_NORMAL, PR_GLOBAL_BOUND_THREAD,
8394b4
                                PR_UNJOINABLE_THREAD, SLAPD_DEFAULT_THREAD_STACKSIZE)) {
8394b4
                 PRErrorCode prerr = PR_GetError();
8394b4
-                slapi_log_err(SLAPI_LOG_ERR, "import_main_offline",
8394b4
+                slapi_log_err(SLAPI_LOG_ERR, "bdb_import_main",
8394b4
                               "Unable to spawn upgrade dn producer thread, " SLAPI_COMPONENT_NAME_NSPR " error %d (%s)\n",
8394b4
                               prerr, slapd_pr_strerror(prerr));
8394b4
                 goto error;
8394b4
@@ -2285,19 +2285,19 @@ bdb_import_main(void *arg)
8394b4
                                PR_UNJOINABLE_THREAD,
8394b4
                                SLAPD_DEFAULT_THREAD_STACKSIZE)) {
8394b4
                 PRErrorCode prerr = PR_GetError();
8394b4
-                slapi_log_err(SLAPI_LOG_ERR, "import_main_offline",
8394b4
+                slapi_log_err(SLAPI_LOG_ERR, "bdb_import_main",
8394b4
                               "Unable to spawn index producer thread, " SLAPI_COMPONENT_NAME_NSPR " error %d (%s)\n",
8394b4
                               prerr, slapd_pr_strerror(prerr));
8394b4
                 goto error;
8394b4
             }
8394b4
         } else {
8394b4
-            import_log_notice(job, SLAPI_LOG_INFO, "import_main_offline", "Beginning import job...");
8394b4
+            import_log_notice(job, SLAPI_LOG_INFO, "bdb_import_main", "Beginning import job...");
8394b4
             if (!CREATE_THREAD(PR_USER_THREAD, (VFP)import_producer, producer,
8394b4
                                PR_PRIORITY_NORMAL, PR_GLOBAL_BOUND_THREAD,
8394b4
                                PR_UNJOINABLE_THREAD,
8394b4
                                SLAPD_DEFAULT_THREAD_STACKSIZE)) {
8394b4
                 PRErrorCode prerr = PR_GetError();
8394b4
-                slapi_log_err(SLAPI_LOG_ERR, "import_main_offline",
8394b4
+                slapi_log_err(SLAPI_LOG_ERR, "bdb_import_main",
8394b4
                               "Unable to spawn import producer thread, " SLAPI_COMPONENT_NAME_NSPR " error %d (%s)\n",
8394b4
                               prerr, slapd_pr_strerror(prerr));
8394b4
                 goto error;
8394b4
@@ -2305,9 +2305,9 @@ bdb_import_main(void *arg)
8394b4
         }
8394b4
 
8394b4
         if (0 == job->job_index_buffer_suggestion)
8394b4
-            import_log_notice(job, SLAPI_LOG_INFO, "import_main_offline", "Index buffering is disabled.");
8394b4
+            import_log_notice(job, SLAPI_LOG_INFO, "bdb_import_main", "Index buffering is disabled.");
8394b4
         else
8394b4
-            import_log_notice(job, SLAPI_LOG_INFO, "import_main_offline",
8394b4
+            import_log_notice(job, SLAPI_LOG_INFO, "bdb_import_main",
8394b4
                               "Index buffering enabled with bucket size %lu",
8394b4
                               (long unsigned int)job->job_index_buffer_suggestion);
8394b4
 
8394b4
@@ -2343,13 +2343,13 @@ bdb_import_main(void *arg)
8394b4
         if (ret == ERR_IMPORT_ABORTED) {
8394b4
             /* at least one of the threads has aborted -- shut down ALL
8394b4
              * of the threads */
8394b4
-            import_log_notice(job, SLAPI_LOG_ERR, "import_main_offline",
8394b4
+            import_log_notice(job, SLAPI_LOG_ERR, "bdb_import_main",
8394b4
                               "Aborting all %s threads...", opstr);
8394b4
             /* this abort sets the  abort flag on the threads and will block for
8394b4
              * the exit of all threads
8394b4
              */
8394b4
             import_set_abort_flag_all(job, 1);
8394b4
-            import_log_notice(job, SLAPI_LOG_ERR, "import_main_offline",
8394b4
+            import_log_notice(job, SLAPI_LOG_ERR, "bdb_import_main",
8394b4
                               "%s threads aborted.", opstr);
8394b4
             aborted = 1;
8394b4
             goto error;
8394b4
@@ -2359,7 +2359,7 @@ bdb_import_main(void *arg)
8394b4
             goto error;
8394b4
         } else if (0 != ret) {
8394b4
             /* Some horrible fate has befallen the import */
8394b4
-            import_log_notice(job, SLAPI_LOG_ERR, "import_main_offline",
8394b4
+            import_log_notice(job, SLAPI_LOG_ERR, "bdb_import_main",
8394b4
                               "Fatal pass error %d", ret);
8394b4
             goto error;
8394b4
         }
8394b4
@@ -2405,7 +2405,7 @@ bdb_import_main(void *arg)
8394b4
                 job->first_ID = job->ready_ID + 1;
8394b4
                 import_free_thread_data(job);
8394b4
                 job->worker_list = producer;
8394b4
-                import_log_notice(job, SLAPI_LOG_INFO, "import_main_offline",
8394b4
+                import_log_notice(job, SLAPI_LOG_INFO, "bdb_import_main",
8394b4
                                   "Beginning pass number %d", job->total_pass + 1);
8394b4
             } else {
8394b4
                 /* Bizarro-slapd */
8394b4
@@ -2416,7 +2416,7 @@ bdb_import_main(void *arg)
8394b4
 
8394b4
     /* kill the producer now; we're done */
8394b4
     if (producer) {
8394b4
-        import_log_notice(job, SLAPI_LOG_INFO, "import_main_offline", "Cleaning up producer thread...");
8394b4
+        import_log_notice(job, SLAPI_LOG_INFO, "bdb_import_main", "Cleaning up producer thread...");
8394b4
         producer->command = STOP;
8394b4
         /* wait for the lead thread to stop */
8394b4
         while (producer->state != FINISHED) {
8394b4
@@ -2424,18 +2424,18 @@ bdb_import_main(void *arg)
8394b4
         }
8394b4
     }
8394b4
 
8394b4
-    import_log_notice(job, SLAPI_LOG_INFO, "import_main_offline", "Indexing complete.  Post-processing...");
8394b4
+    import_log_notice(job, SLAPI_LOG_INFO, "bdb_import_main", "Indexing complete.  Post-processing...");
8394b4
     /* Now do the numsubordinates attribute */
8394b4
     /* [610066] reindexed db cannot be used in the following backup/restore */
8394b4
-    import_log_notice(job, SLAPI_LOG_INFO, "import_main_offline",
8394b4
+    import_log_notice(job, SLAPI_LOG_INFO, "bdb_import_main",
8394b4
                       "Generating numsubordinates (this may take several minutes to complete)...");
8394b4
     if ((!(job->flags & FLAG_REINDEXING) || (job->flags & FLAG_DN2RDN)) &&
8394b4
         (ret = bdb_update_subordinatecounts(be, job, NULL)) != 0) {
8394b4
-        import_log_notice(job, SLAPI_LOG_ERR, "import_main_offline",
8394b4
+        import_log_notice(job, SLAPI_LOG_ERR, "bdb_import_main",
8394b4
                           "Failed to update numsubordinates attributes");
8394b4
         goto error;
8394b4
     }
8394b4
-    import_log_notice(job, SLAPI_LOG_INFO, "import_main_offline",
8394b4
+    import_log_notice(job, SLAPI_LOG_INFO, "bdb_import_main",
8394b4
                       "Generating numSubordinates complete.");
8394b4
 
8394b4
     if (!entryrdn_get_noancestorid()) {
8394b4
@@ -2446,12 +2446,12 @@ bdb_import_main(void *arg)
8394b4
         ainfo_get(be, "ancestorid", &ai);
8394b4
         dblayer_erase_index_file(be, ai, PR_TRUE, 0);
8394b4
         if ((ret = bdb_ancestorid_create_index(be, job)) != 0) {
8394b4
-            import_log_notice(job, SLAPI_LOG_ERR, "import_main_offline", "Failed to create ancestorid index");
8394b4
+            import_log_notice(job, SLAPI_LOG_ERR, "bdb_import_main", "Failed to create ancestorid index");
8394b4
             goto error;
8394b4
         }
8394b4
     }
8394b4
 
8394b4
-    import_log_notice(job, SLAPI_LOG_INFO, "import_main_offline", "Flushing caches...");
8394b4
+    import_log_notice(job, SLAPI_LOG_INFO, "bdb_import_main", "Flushing caches...");
8394b4
 
8394b4
 /* New way to exit the routine: check the return code.
8394b4
      * If it's non-zero, delete the database files.
8394b4
@@ -2462,7 +2462,7 @@ bdb_import_main(void *arg)
8394b4
 error:
8394b4
     /* If we fail, the database is now in a mess, so we delete it
8394b4
        except dry run mode */
8394b4
-    import_log_notice(job, SLAPI_LOG_INFO, "import_main_offline", "Closing files...");
8394b4
+    import_log_notice(job, SLAPI_LOG_INFO, "bdb_import_main", "Closing files...");
8394b4
     cache_clear(&job->inst->inst_cache, CACHE_TYPE_ENTRY);
8394b4
     if (entryrdn_get_switch()) {
8394b4
         cache_clear(&job->inst->inst_dncache, CACHE_TYPE_DN);
8394b4
@@ -2476,14 +2476,14 @@ error:
8394b4
         /* initialize the entry cache */
8394b4
         if (!cache_init(&(inst->inst_cache), DEFAULT_CACHE_SIZE,
8394b4
                         DEFAULT_CACHE_ENTRIES, CACHE_TYPE_ENTRY)) {
8394b4
-            slapi_log_err(SLAPI_LOG_ERR, "import_main_offline",
8394b4
+            slapi_log_err(SLAPI_LOG_ERR, "bdb_import_main",
8394b4
                           "cache_init failed.  Server should be restarted.\n");
8394b4
         }
8394b4
 
8394b4
         /* initialize the dn cache */
8394b4
         if (!cache_init(&(inst->inst_dncache), DEFAULT_DNCACHE_SIZE,
8394b4
                         DEFAULT_DNCACHE_MAXCOUNT, CACHE_TYPE_DN)) {
8394b4
-            slapi_log_err(SLAPI_LOG_ERR, "import_main_offline",
8394b4
+            slapi_log_err(SLAPI_LOG_ERR, "bdb_import_main",
8394b4
                           "dn cache_init failed.  Server should be restarted.\n");
8394b4
         }
8394b4
     }
8394b4
@@ -2496,7 +2496,7 @@ error:
8394b4
         }
8394b4
     } else {
8394b4
         if (0 != (ret = dblayer_instance_close(job->inst->inst_be))) {
8394b4
-            import_log_notice(job, SLAPI_LOG_WARNING, "import_main_offline", "Failed to close database");
8394b4
+            import_log_notice(job, SLAPI_LOG_WARNING, "bdb_import_main", "Failed to close database");
8394b4
         }
8394b4
     }
8394b4
     end = slapi_current_utc_time();
8394b4
@@ -2508,7 +2508,7 @@ error:
8394b4
 
8394b4
         if (job->not_here_skipped) {
8394b4
             if (job->skipped) {
8394b4
-                import_log_notice(job, SLAPI_LOG_INFO, "import_main_offline",
8394b4
+                import_log_notice(job, SLAPI_LOG_INFO, "bdb_import_main",
8394b4
                                   "%s complete.  Processed %lu entries "
8394b4
                                   "(%d bad entries were skipped, "
8394b4
                                   "%d entries were skipped because they don't "
8394b4
@@ -2518,7 +2518,7 @@ error:
8394b4
                                   job->skipped, job->not_here_skipped,
8394b4
                                   seconds_to_import, entries_per_second);
8394b4
             } else {
8394b4
-                import_log_notice(job, SLAPI_LOG_INFO, "import_main_offline",
8394b4
+                import_log_notice(job, SLAPI_LOG_INFO, "bdb_import_main",
8394b4
                                   "%s complete.  Processed %lu entries "
8394b4
                                   "(%d entries were skipped because they don't "
8394b4
                                   "belong to this database) "
8394b4
@@ -2529,7 +2529,7 @@ error:
8394b4
             }
8394b4
         } else {
8394b4
             if (job->skipped) {
8394b4
-                import_log_notice(job, SLAPI_LOG_INFO, "import_main_offline",
8394b4
+                import_log_notice(job, SLAPI_LOG_INFO, "bdb_import_main",
8394b4
                                   "%s complete.  Processed %lu entries "
8394b4
                                   "(%d were skipped) in %d seconds. "
8394b4
                                   "(%.2f entries/sec)",
8394b4
@@ -2537,7 +2537,7 @@ error:
8394b4
                                   job->skipped, seconds_to_import,
8394b4
                                   entries_per_second);
8394b4
             } else {
8394b4
-                import_log_notice(job, SLAPI_LOG_INFO, "import_main_offline",
8394b4
+                import_log_notice(job, SLAPI_LOG_INFO, "bdb_import_main",
8394b4
                                   "%s complete.  Processed %lu entries "
8394b4
                                   "in %d seconds. (%.2f entries/sec)",
8394b4
                                   opstr, (long unsigned int)entries_processed,
8394b4
@@ -2548,7 +2548,7 @@ error:
8394b4
 
8394b4
     if (job->flags & (FLAG_DRYRUN | FLAG_UPGRADEDNFORMAT_V1)) {
8394b4
         if (0 == ret) {
8394b4
-            import_log_notice(job, SLAPI_LOG_INFO, "import_main_offline", "%s complete.  %s is up-to-date.",
8394b4
+            import_log_notice(job, SLAPI_LOG_INFO, "bdb_import_main", "%s complete.  %s is up-to-date.",
8394b4
                               opstr, job->inst->inst_name);
8394b4
             ret = 0;
8394b4
             if (job->task) {
8394b4
@@ -2556,7 +2556,7 @@ error:
8394b4
             }
8394b4
             import_all_done(job, ret);
8394b4
         } else if (NEED_DN_NORM_BT == ret) {
8394b4
-            import_log_notice(job, SLAPI_LOG_NOTICE, "import_main_offline",
8394b4
+            import_log_notice(job, SLAPI_LOG_NOTICE, "bdb_import_main",
8394b4
                               "%s complete. %s needs upgradednformat all.",
8394b4
                               opstr, job->inst->inst_name);
8394b4
             if (job->task) {
8394b4
@@ -2565,7 +2565,7 @@ error:
8394b4
             import_all_done(job, ret);
8394b4
             ret = 1;
8394b4
         } else if (NEED_DN_NORM == ret) {
8394b4
-            import_log_notice(job, SLAPI_LOG_NOTICE, "import_main_offline",
8394b4
+            import_log_notice(job, SLAPI_LOG_NOTICE, "bdb_import_main",
8394b4
                               "%s complete. %s needs upgradednformat.",
8394b4
                               opstr, job->inst->inst_name);
8394b4
             if (job->task) {
8394b4
@@ -2574,7 +2574,7 @@ error:
8394b4
             import_all_done(job, ret);
8394b4
             ret = 2;
8394b4
         } else if (NEED_DN_NORM_SP == ret) {
8394b4
-            import_log_notice(job, SLAPI_LOG_NOTICE, "import_main_offline",
8394b4
+            import_log_notice(job, SLAPI_LOG_NOTICE, "bdb_import_main",
8394b4
                               "%s complete. %s needs upgradednformat spaces.",
8394b4
                               opstr, job->inst->inst_name);
8394b4
             if (job->task) {
8394b4
@@ -2589,7 +2589,7 @@ error:
8394b4
             }
8394b4
         }
8394b4
     } else if (0 != ret) {
8394b4
-        import_log_notice(job, SLAPI_LOG_ERR, "import_main_offline", "%s failed.", opstr);
8394b4
+        import_log_notice(job, SLAPI_LOG_ERR, "bdb_import_main", "%s failed.", opstr);
8394b4
         if (job->task != NULL) {
8394b4
             slapi_task_finish(job->task, ret);
8394b4
         }
8394b4
diff --git a/ldap/servers/slapd/back-ldbm/db-bdb/bdb_ldif2db.c b/ldap/servers/slapd/back-ldbm/db-bdb/bdb_ldif2db.c
8394b4
index bb411a539..542147c3d 100644
8394b4
--- a/ldap/servers/slapd/back-ldbm/db-bdb/bdb_ldif2db.c
8394b4
+++ b/ldap/servers/slapd/back-ldbm/db-bdb/bdb_ldif2db.c
8394b4
@@ -383,6 +383,9 @@ bdb_ldif2db(Slapi_PBlock *pb)
8394b4
     /* always use "new" import code now */
8394b4
     slapi_pblock_set(pb, SLAPI_BACKEND, inst->inst_be);
8394b4
     ret = bdb_back_ldif2db(pb);
8394b4
+    if (task_flags & SLAPI_TASK_RUNNING_FROM_COMMANDLINE) {
8394b4
+        dblayer_close(li, DBLAYER_IMPORT_MODE);
8394b4
+    }
8394b4
     if (ret == 0) {
8394b4
         if (task_flags & SLAPI_TASK_RUNNING_FROM_COMMANDLINE) {
8394b4
             dblayer_import_file_update(inst);
8394b4
-- 
8394b4
2.21.1
8394b4