Blame SOURCES/0018-Ticket-50736-RetroCL-trimming-may-crash-at-shutdown-.patch

e52775
From 5497023c6857ae0fcf046e57744a91107d362c41 Mon Sep 17 00:00:00 2001
e52775
From: Thierry Bordaz <tbordaz@redhat.com>
e52775
Date: Mon, 25 Nov 2019 10:59:44 +0100
e52775
Subject: [PATCH] Ticket 50736 - RetroCL trimming may crash at shutdown if
e52775
 trimming configuration is invalid
e52775
e52775
Bug Description:
e52775
	If config of retroCL trimming contains invalid value for trim-interval
e52775
        and/or maxage, then the trimming initialization is skipped.
e52775
        In such case the trimming structures are not allocated and if they
e52775
        are freed at shutdown it triggers a crash
e52775
e52775
Fix Description:
e52775
        When trimming mechanism is stopped (at shutdown) check that
e52775
        it was successfully initialized before freeing the structs
e52775
e52775
https://pagure.io/389-ds-base/issue/50736
e52775
e52775
Reviewed by: Mark Reynolds
e52775
e52775
Platforms tested: F30
e52775
e52775
Flag Day: no
e52775
e52775
Doc impact: no
e52775
---
e52775
 .../suites/replication/changelog_test.py      | 185 ++++++++++++++++++
e52775
 ldap/servers/plugins/retrocl/retrocl_trim.c   |  17 +-
e52775
 2 files changed, 196 insertions(+), 6 deletions(-)
e52775
e52775
diff --git a/dirsrvtests/tests/suites/replication/changelog_test.py b/dirsrvtests/tests/suites/replication/changelog_test.py
e52775
index 0b6b886f3..0d3e85bb2 100755
e52775
--- a/dirsrvtests/tests/suites/replication/changelog_test.py
e52775
+++ b/dirsrvtests/tests/suites/replication/changelog_test.py
e52775
@@ -16,6 +16,12 @@ from lib389.replica import Replicas
e52775
 from lib389.idm.user import UserAccounts
e52775
 from lib389.topologies import topology_m2 as topo
e52775
 from lib389._constants import *
e52775
+from lib389.plugins import RetroChangelogPlugin
e52775
+from lib389.dseldif import DSEldif
e52775
+from lib389.tasks import *
e52775
+from lib389.utils import *
e52775
+
e52775
+pytestmark = pytest.mark.tier1
e52775
 
e52775
 TEST_ENTRY_NAME = 'replusr'
e52775
 NEW_RDN_NAME = 'cl5usr'
e52775
@@ -235,6 +241,185 @@ def test_verify_changelog_offline_backup(topo):
e52775
     _check_changelog_ldif(topo, changelog_ldif)
e52775
 
e52775
 
e52775
+@pytest.mark.ds47669
e52775
+def test_changelog_maxage(topo, changelog_init):
e52775
+    """Check nsslapd-changelog max age values
e52775
+
e52775
+    :id: d284ff27-03b2-412c-ac74-ac4f2d2fae3b
e52775
+    :setup: Replication with two master, change nsslapd-changelogdir to
e52775
+    '/var/lib/dirsrv/slapd-master1/changelog' and
e52775
+    set cn=Retro Changelog Plugin,cn=plugins,cn=config to 'on'
e52775
+    :steps:
e52775
+        1. Set nsslapd-changelogmaxage in cn=changelog5,cn=config to values - '12345','10s','30M','12h','2D','4w'
e52775
+        2. Set nsslapd-changelogmaxage in cn=changelog5,cn=config to values - '-123','xyz'
e52775
+
e52775
+    :expectedresults:
e52775
+        1. Operation should be successful
e52775
+        2. Operation should be unsuccessful
e52775
+     """
e52775
+    log.info('1. Test nsslapd-changelogmaxage in cn=changelog5,cn=config')
e52775
+
e52775
+    # bind as directory manager
e52775
+    topo.ms["master1"].log.info("Bind as %s" % DN_DM)
e52775
+    topo.ms["master1"].simple_bind_s(DN_DM, PASSWORD)
e52775
+
e52775
+    add_and_check(topo, CHANGELOG, MAXAGE, '12345', True)
e52775
+    add_and_check(topo, CHANGELOG, MAXAGE, '10s', True)
e52775
+    add_and_check(topo, CHANGELOG, MAXAGE, '30M', True)
e52775
+    add_and_check(topo, CHANGELOG, MAXAGE, '12h', True)
e52775
+    add_and_check(topo, CHANGELOG, MAXAGE, '2D', True)
e52775
+    add_and_check(topo, CHANGELOG, MAXAGE, '4w', True)
e52775
+    add_and_check(topo, CHANGELOG, MAXAGE, '-123', False)
e52775
+    add_and_check(topo, CHANGELOG, MAXAGE, 'xyz', False)
e52775
+
e52775
+
e52775
+@pytest.mark.ds47669
e52775
+def test_ticket47669_changelog_triminterval(topo, changelog_init):
e52775
+    """Check nsslapd-changelog triminterval values
e52775
+
e52775
+    :id: 8f850c37-7e7c-49dd-a4e0-9344638616d6
e52775
+    :setup: Replication with two master, change nsslapd-changelogdir to
e52775
+    '/var/lib/dirsrv/slapd-master1/changelog' and
e52775
+    set cn=Retro Changelog Plugin,cn=plugins,cn=config to 'on'
e52775
+    :steps:
e52775
+        1. Set nsslapd-changelogtrim-interval in cn=changelog5,cn=config to values -
e52775
+           '12345','10s','30M','12h','2D','4w'
e52775
+        2. Set nsslapd-changelogtrim-interval in cn=changelog5,cn=config to values - '-123','xyz'
e52775
+
e52775
+    :expectedresults:
e52775
+        1. Operation should be successful
e52775
+        2. Operation should be unsuccessful
e52775
+     """
e52775
+    log.info('2. Test nsslapd-changelogtrim-interval in cn=changelog5,cn=config')
e52775
+
e52775
+    # bind as directory manager
e52775
+    topo.ms["master1"].log.info("Bind as %s" % DN_DM)
e52775
+    topo.ms["master1"].simple_bind_s(DN_DM, PASSWORD)
e52775
+
e52775
+    add_and_check(topo, CHANGELOG, TRIMINTERVAL, '12345', True)
e52775
+    add_and_check(topo, CHANGELOG, TRIMINTERVAL, '10s', True)
e52775
+    add_and_check(topo, CHANGELOG, TRIMINTERVAL, '30M', True)
e52775
+    add_and_check(topo, CHANGELOG, TRIMINTERVAL, '12h', True)
e52775
+    add_and_check(topo, CHANGELOG, TRIMINTERVAL, '2D', True)
e52775
+    add_and_check(topo, CHANGELOG, TRIMINTERVAL, '4w', True)
e52775
+    add_and_check(topo, CHANGELOG, TRIMINTERVAL, '-123', False)
e52775
+    add_and_check(topo, CHANGELOG, TRIMINTERVAL, 'xyz', False)
e52775
+
e52775
+
e52775
+@pytest.mark.ds47669
e52775
+def test_changelog_compactdbinterval(topo, changelog_init):
e52775
+    """Check nsslapd-changelog compactdbinterval values
e52775
+
e52775
+    :id: 0f4b3118-9dfa-4c2a-945c-72847b42a48c
e52775
+    :setup: Replication with two master, change nsslapd-changelogdir to
e52775
+    '/var/lib/dirsrv/slapd-master1/changelog' and
e52775
+    set cn=Retro Changelog Plugin,cn=plugins,cn=config to 'on'
e52775
+    :steps:
e52775
+        1. Set nsslapd-changelogcompactdb-interval in cn=changelog5,cn=config to values -
e52775
+           '12345','10s','30M','12h','2D','4w'
e52775
+        2. Set nsslapd-changelogcompactdb-interval in cn=changelog5,cn=config to values -
e52775
+           '-123','xyz'
e52775
+
e52775
+    :expectedresults:
e52775
+        1. Operation should be successful
e52775
+        2. Operation should be unsuccessful
e52775
+     """
e52775
+    log.info('3. Test nsslapd-changelogcompactdb-interval in cn=changelog5,cn=config')
e52775
+
e52775
+    # bind as directory manager
e52775
+    topo.ms["master1"].log.info("Bind as %s" % DN_DM)
e52775
+    topo.ms["master1"].simple_bind_s(DN_DM, PASSWORD)
e52775
+
e52775
+    add_and_check(topo, CHANGELOG, COMPACTDBINTERVAL, '12345', True)
e52775
+    add_and_check(topo, CHANGELOG, COMPACTDBINTERVAL, '10s', True)
e52775
+    add_and_check(topo, CHANGELOG, COMPACTDBINTERVAL, '30M', True)
e52775
+    add_and_check(topo, CHANGELOG, COMPACTDBINTERVAL, '12h', True)
e52775
+    add_and_check(topo, CHANGELOG, COMPACTDBINTERVAL, '2D', True)
e52775
+    add_and_check(topo, CHANGELOG, COMPACTDBINTERVAL, '4w', True)
e52775
+    add_and_check(topo, CHANGELOG, COMPACTDBINTERVAL, '-123', False)
e52775
+    add_and_check(topo, CHANGELOG, COMPACTDBINTERVAL, 'xyz', False)
e52775
+
e52775
+
e52775
+@pytest.mark.ds47669
e52775
+def test_retrochangelog_maxage(topo, changelog_init):
e52775
+    """Check nsslapd-retrochangelog max age values
e52775
+
e52775
+    :id: 0cb84d81-3e86-4dbf-84a2-66aefd8281db
e52775
+    :setup: Replication with two master, change nsslapd-changelogdir to
e52775
+    '/var/lib/dirsrv/slapd-master1/changelog' and
e52775
+    set cn=Retro Changelog Plugin,cn=plugins,cn=config to 'on'
e52775
+    :steps:
e52775
+        1. Set nsslapd-changelogmaxage in cn=Retro Changelog Plugin,cn=plugins,cn=config to values -
e52775
+           '12345','10s','30M','12h','2D','4w'
e52775
+        2. Set nsslapd-changelogmaxage in cn=Retro Changelog Plugin,cn=plugins,cn=config to values -
e52775
+           '-123','xyz'
e52775
+
e52775
+    :expectedresults:
e52775
+        1. Operation should be successful
e52775
+        2. Operation should be unsuccessful
e52775
+     """
e52775
+    log.info('4. Test nsslapd-changelogmaxage in cn=Retro Changelog Plugin,cn=plugins,cn=config')
e52775
+
e52775
+    # bind as directory manager
e52775
+    topo.ms["master1"].log.info("Bind as %s" % DN_DM)
e52775
+    topo.ms["master1"].simple_bind_s(DN_DM, PASSWORD)
e52775
+
e52775
+    add_and_check(topo, RETROCHANGELOG, MAXAGE, '12345', True)
e52775
+    add_and_check(topo, RETROCHANGELOG, MAXAGE, '10s', True)
e52775
+    add_and_check(topo, RETROCHANGELOG, MAXAGE, '30M', True)
e52775
+    add_and_check(topo, RETROCHANGELOG, MAXAGE, '12h', True)
e52775
+    add_and_check(topo, RETROCHANGELOG, MAXAGE, '2D', True)
e52775
+    add_and_check(topo, RETROCHANGELOG, MAXAGE, '4w', True)
e52775
+    add_and_check(topo, RETROCHANGELOG, MAXAGE, '-123', False)
e52775
+    add_and_check(topo, RETROCHANGELOG, MAXAGE, 'xyz', False)
e52775
+
e52775
+    topo.ms["master1"].log.info("ticket47669 was successfully verified.")
e52775
+
e52775
+@pytest.mark.ds50736
e52775
+def test_retrochangelog_trimming_crash(topo, changelog_init):
e52775
+    """Check that when retroCL nsslapd-retrocthangelog contains invalid
e52775
+    value, then the instance does not crash at shutdown
e52775
+
e52775
+    :id: 5d9bd7ca-e9bf-4be9-8fc8-902aa5513052
e52775
+    :setup: Replication with two master, change nsslapd-changelogdir to
e52775
+    '/var/lib/dirsrv/slapd-master1/changelog' and
e52775
+    set cn=Retro Changelog Plugin,cn=plugins,cn=config to 'on'
e52775
+    :steps:
e52775
+        1. Set nsslapd-changelogmaxage in cn=Retro Changelog Plugin,cn=plugins,cn=config to value '-1'
e52775
+           This value is invalid. To disable retroCL trimming it should be set to 0
e52775
+        2. Do several restart
e52775
+        3. check there is no 'Detected Disorderly Shutdown' message (crash)
e52775
+        4. restore valid value for nsslapd-changelogmaxage '1w'
e52775
+
e52775
+    :expectedresults:
e52775
+        1. Operation should be successful
e52775
+        2. Operation should be successful
e52775
+        3. Operation should be successful
e52775
+        4. Operation should be successful
e52775
+     """
e52775
+    log.info('1. Test retroCL trimming crash in cn=Retro Changelog Plugin,cn=plugins,cn=config')
e52775
+
e52775
+    # set the nsslapd-changelogmaxage directly on dse.ldif
e52775
+    # because the set value is invalid
e52775
+    topo.ms["master1"].log.info("ticket50736 start verification")
e52775
+    topo.ms["master1"].stop()
e52775
+    retroPlugin = RetroChangelogPlugin(topo.ms["master1"])
e52775
+    dse_ldif = DSEldif(topo.ms["master1"])
e52775
+    dse_ldif.replace(retroPlugin.dn, 'nsslapd-changelogmaxage', '-1')
e52775
+    topo.ms["master1"].start()
e52775
+
e52775
+    # The crash should be systematic, but just in case do several restart
e52775
+    # with a delay to let all plugin init
e52775
+    for i in range(5):
e52775
+        time.sleep(1)
e52775
+        topo.ms["master1"].stop()
e52775
+        topo.ms["master1"].start()
e52775
+
e52775
+    assert not topo.ms["master1"].detectDisorderlyShutdown()
e52775
+
e52775
+    topo.ms["master1"].log.info("ticket 50736 was successfully verified.")
e52775
+
e52775
+
e52775
 if __name__ == '__main__':
e52775
     # Run isolated
e52775
     # -s for DEBUG mode
e52775
diff --git a/ldap/servers/plugins/retrocl/retrocl_trim.c b/ldap/servers/plugins/retrocl/retrocl_trim.c
e52775
index a46534984..0378eb7f6 100644
e52775
--- a/ldap/servers/plugins/retrocl/retrocl_trim.c
e52775
+++ b/ldap/servers/plugins/retrocl/retrocl_trim.c
e52775
@@ -481,11 +481,16 @@ retrocl_init_trimming(void)
e52775
 void
e52775
 retrocl_stop_trimming(void)
e52775
 {
e52775
-    retrocl_trimming = 0;
e52775
-    if (retrocl_trim_ctx) {
e52775
-        slapi_eq_cancel(retrocl_trim_ctx);
e52775
-        retrocl_trim_ctx = NULL;
e52775
+    if (retrocl_trimming) {
e52775
+        /* RetroCL trimming config was valid and trimming struct allocated
e52775
+         * Let's free them
e52775
+         */
e52775
+        retrocl_trimming = 0;
e52775
+        if (retrocl_trim_ctx) {
e52775
+            slapi_eq_cancel(retrocl_trim_ctx);
e52775
+            retrocl_trim_ctx = NULL;
e52775
+        }
e52775
+        PR_DestroyLock(ts.ts_s_trim_mutex);
e52775
+        ts.ts_s_trim_mutex = NULL;
e52775
     }
e52775
-    PR_DestroyLock(ts.ts_s_trim_mutex);
e52775
-    ts.ts_s_trim_mutex = NULL;
e52775
 }
e52775
-- 
e52775
2.24.1
e52775