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

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