andykimpe / rpms / 389-ds-base

Forked from rpms/389-ds-base 5 months ago
Clone
6d0b66
From 580880a598a8f9972994684c49593a4cf8b8969b Mon Sep 17 00:00:00 2001
6d0b66
From: Mark Reynolds <mreynolds@redhat.com>
6d0b66
Date: Sat, 29 May 2021 13:19:53 -0400
6d0b66
Subject: [PATCH 12/12] Issue 4778 - RFE - Add changelog compaction task in
6d0b66
 1.4.3
6d0b66
6d0b66
Description:  In 1.4.3 the replication changelog is a separate database,
6d0b66
              so it needs a separate "nsds5task" compaction task (COMPACT_CL5)
6d0b66
6d0b66
relates: https://github.com/389ds/389-ds-base/issues/4778
6d0b66
6d0b66
ASAN tested and approved
6d0b66
6d0b66
Reviewed by: mreynolds
6d0b66
---
6d0b66
 ldap/servers/plugins/replication/cl5_api.c    | 21 +++++++++----------
6d0b66
 ldap/servers/plugins/replication/cl5_api.h    |  1 +
6d0b66
 .../replication/repl5_replica_config.c        |  9 +++++++-
6d0b66
 3 files changed, 19 insertions(+), 12 deletions(-)
6d0b66
6d0b66
diff --git a/ldap/servers/plugins/replication/cl5_api.c b/ldap/servers/plugins/replication/cl5_api.c
6d0b66
index 75a2f46f5..4c5077b48 100644
6d0b66
--- a/ldap/servers/plugins/replication/cl5_api.c
6d0b66
+++ b/ldap/servers/plugins/replication/cl5_api.c
6d0b66
@@ -266,7 +266,6 @@ static int _cl5TrimInit(void);
6d0b66
 static void _cl5TrimCleanup(void);
6d0b66
 static int _cl5TrimMain(void *param);
6d0b66
 static void _cl5DoTrimming(void);
6d0b66
-static void _cl5CompactDBs(void);
6d0b66
 static void _cl5PurgeRID(Object *file_obj, ReplicaId cleaned_rid);
6d0b66
 static int _cl5PurgeGetFirstEntry(Object *file_obj, CL5Entry *entry, void **iterator, DB_TXN *txnid, int rid, DBT *key);
6d0b66
 static int _cl5PurgeGetNextEntry(CL5Entry *entry, void *iterator, DBT *key);
6d0b66
@@ -3152,7 +3151,7 @@ _cl5TrimMain(void *param __attribute__((unused)))
6d0b66
             if (slapi_current_utc_time() > compactdb_time) {
6d0b66
 				/* time to trim */
6d0b66
 				timeCompactPrev = timeNow;
6d0b66
-				_cl5CompactDBs();
6d0b66
+				cl5CompactDBs();
6d0b66
 				compacting = PR_FALSE;
6d0b66
             }
6d0b66
         }
6d0b66
@@ -3250,8 +3249,8 @@ _cl5DoPurging(cleanruv_purge_data *purge_data)
6d0b66
 }
6d0b66
 
6d0b66
 /* clear free page files to reduce changelog */
6d0b66
-static void
6d0b66
-_cl5CompactDBs(void)
6d0b66
+void
6d0b66
+cl5CompactDBs(void)
6d0b66
 {
6d0b66
     int rc;
6d0b66
     Object *fileObj = NULL;
6d0b66
@@ -3264,14 +3263,14 @@ _cl5CompactDBs(void)
6d0b66
     rc = TXN_BEGIN(s_cl5Desc.dbEnv, NULL, &txnid, 0);
6d0b66
     if (rc) {
6d0b66
         slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name_cl,
6d0b66
-                      "_cl5CompactDBs - Failed to begin transaction; db error - %d %s\n",
6d0b66
+                      "cl5CompactDBs - Failed to begin transaction; db error - %d %s\n",
6d0b66
                       rc, db_strerror(rc));
6d0b66
         goto bail;
6d0b66
     }
6d0b66
 
6d0b66
 
6d0b66
     slapi_log_err(SLAPI_LOG_NOTICE, repl_plugin_name_cl,
6d0b66
-                  "_cl5CompactDBs - compacting replication changelogs...\n");
6d0b66
+                  "cl5CompactDBs - compacting replication changelogs...\n");
6d0b66
     for (fileObj = objset_first_obj(s_cl5Desc.dbFiles);
6d0b66
          fileObj;
6d0b66
          fileObj = objset_next_obj(s_cl5Desc.dbFiles, fileObj)) {
6d0b66
@@ -3284,17 +3283,17 @@ _cl5CompactDBs(void)
6d0b66
                          &c_data, DB_FREE_SPACE, NULL /*end*/);
6d0b66
         if (rc) {
6d0b66
             slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name_cl,
6d0b66
-                          "_cl5CompactDBs - Failed to compact %s; db error - %d %s\n",
6d0b66
+                          "cl5CompactDBs - Failed to compact %s; db error - %d %s\n",
6d0b66
                           dbFile->replName, rc, db_strerror(rc));
6d0b66
             goto bail;
6d0b66
         }
6d0b66
         slapi_log_err(SLAPI_LOG_REPL, repl_plugin_name_cl,
6d0b66
-                      "_cl5CompactDBs - %s - %d pages freed\n",
6d0b66
+                      "cl5CompactDBs - %s - %d pages freed\n",
6d0b66
                       dbFile->replName, c_data.compact_pages_free);
6d0b66
     }
6d0b66
 
6d0b66
     slapi_log_err(SLAPI_LOG_NOTICE, repl_plugin_name_cl,
6d0b66
-                  "_cl5CompactDBs - compacting replication changelogs finished.\n");
6d0b66
+                  "cl5CompactDBs - compacting replication changelogs finished.\n");
6d0b66
 bail:
6d0b66
     if (fileObj) {
6d0b66
         object_release(fileObj);
6d0b66
@@ -3303,14 +3302,14 @@ bail:
6d0b66
         rc = TXN_ABORT(txnid);
6d0b66
         if (rc) {
6d0b66
             slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name_cl,
6d0b66
-                          "_cl5CompactDBs - Failed to abort transaction; db error - %d %s\n",
6d0b66
+                          "cl5CompactDBs - Failed to abort transaction; db error - %d %s\n",
6d0b66
                           rc, db_strerror(rc));
6d0b66
         }
6d0b66
     } else {
6d0b66
         rc = TXN_COMMIT(txnid);
6d0b66
         if (rc) {
6d0b66
             slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name_cl,
6d0b66
-                          "_cl5CompactDBs - Failed to commit transaction; db error - %d %s\n",
6d0b66
+                          "cl5CompactDBs - Failed to commit transaction; db error - %d %s\n",
6d0b66
                           rc, db_strerror(rc));
6d0b66
         }
6d0b66
     }
6d0b66
diff --git a/ldap/servers/plugins/replication/cl5_api.h b/ldap/servers/plugins/replication/cl5_api.h
6d0b66
index 4b0949fb3..11db771f2 100644
6d0b66
--- a/ldap/servers/plugins/replication/cl5_api.h
6d0b66
+++ b/ldap/servers/plugins/replication/cl5_api.h
6d0b66
@@ -405,5 +405,6 @@ int cl5DeleteRUV(void);
6d0b66
 void cl5CleanRUV(ReplicaId rid);
6d0b66
 void cl5NotifyCleanup(int rid);
6d0b66
 void trigger_cl_purging(cleanruv_purge_data *purge_data);
6d0b66
+void cl5CompactDBs(void);
6d0b66
 
6d0b66
 #endif
6d0b66
diff --git a/ldap/servers/plugins/replication/repl5_replica_config.c b/ldap/servers/plugins/replication/repl5_replica_config.c
6d0b66
index a969ef82f..e708a1ccb 100644
6d0b66
--- a/ldap/servers/plugins/replication/repl5_replica_config.c
6d0b66
+++ b/ldap/servers/plugins/replication/repl5_replica_config.c
6d0b66
@@ -29,6 +29,8 @@
6d0b66
 #define CLEANRUVLEN 8
6d0b66
 #define CLEANALLRUV "CLEANALLRUV"
6d0b66
 #define CLEANALLRUVLEN 11
6d0b66
+#define COMPACT_CL5 "COMPACT_CL5"
6d0b66
+#define COMPACT_CL5_LEN 11
6d0b66
 #define REPLICA_RDN "cn=replica"
6d0b66
 
6d0b66
 #define CLEANALLRUV_MAX_WAIT 7200 /* 2 hours */
6d0b66
@@ -1050,7 +1052,6 @@ replica_config_change_flags(Replica *r, const char *new_flags, char *returntext
6d0b66
 static int
6d0b66
 replica_execute_task(Replica *r, const char *task_name, char *returntext, int apply_mods)
6d0b66
 {
6d0b66
-
6d0b66
     if (strcasecmp(task_name, CL2LDIF_TASK) == 0) {
6d0b66
         if (apply_mods) {
6d0b66
             return replica_execute_cl2ldif_task(r, returntext);
6d0b66
@@ -1084,6 +1085,12 @@ replica_execute_task(Replica *r, const char *task_name, char *returntext, int ap
6d0b66
             return replica_execute_cleanall_ruv_task(r, (ReplicaId)temprid, empty_task, "no", PR_TRUE, returntext);
6d0b66
         } else
6d0b66
             return LDAP_SUCCESS;
6d0b66
+    } else if (strncasecmp(task_name, COMPACT_CL5, COMPACT_CL5_LEN) == 0) {
6d0b66
+        /* compact the replication changelogs */
6d0b66
+        if (apply_mods) {
6d0b66
+            cl5CompactDBs();
6d0b66
+        }
6d0b66
+        return LDAP_SUCCESS;
6d0b66
     } else {
6d0b66
         PR_snprintf(returntext, SLAPI_DSE_RETURNTEXT_SIZE, "Unsupported replica task - %s", task_name);
6d0b66
         slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name,
6d0b66
-- 
6d0b66
2.26.3
6d0b66