andykimpe / rpms / 389-ds-base

Forked from rpms/389-ds-base 5 months ago
Clone

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

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