Blame SOURCES/0012-Issue-4778-RFE-Add-changelog-compaction-task-in-1.4..patch

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