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