Blame SOURCES/0002-Ticket-51082-abort-when-a-empty-valueset-is-freed.patch

b55ad6
From 1426f086623404ab2eacb04de7e6414177c0993a Mon Sep 17 00:00:00 2001
b55ad6
From: Thierry Bordaz <tbordaz@redhat.com>
b55ad6
Date: Mon, 11 May 2020 17:11:49 +0200
b55ad6
Subject: [PATCH 02/12] Ticket 51082 - abort when a empty valueset is freed
b55ad6
b55ad6
Bug Description:
b55ad6
	A large valueset (more than 10 values) manages a sorted array of values.
b55ad6
        replication purges old values from a valueset (valueset_array_purge). If it purges all the values
b55ad6
        the valueset is freed (slapi_valueset_done).
b55ad6
        A problem is that the counter of values, in the valueset, is still reflecting the initial number
b55ad6
        of values (before the purge). When the valueset is freed (because empty) a safety checking
b55ad6
        detects incoherent values based on the wrong counter.
b55ad6
b55ad6
Fix Description:
b55ad6
	When all the values have been purge reset the counter before freeing the valueset
b55ad6
b55ad6
https://pagure.io/389-ds-base/issue/51082
b55ad6
b55ad6
Reviewed by: Mark Reynolds
b55ad6
b55ad6
Platforms tested: F30
b55ad6
b55ad6
Flag Day: no
b55ad6
b55ad6
Doc impact: no
b55ad6
---
b55ad6
 .../suites/replication/acceptance_test.py     | 57 +++++++++++++++++++
b55ad6
 ldap/servers/slapd/valueset.c                 |  4 ++
b55ad6
 2 files changed, 61 insertions(+)
b55ad6
b55ad6
diff --git a/dirsrvtests/tests/suites/replication/acceptance_test.py b/dirsrvtests/tests/suites/replication/acceptance_test.py
b55ad6
index c8e0a4c93..5009f4e7c 100644
b55ad6
--- a/dirsrvtests/tests/suites/replication/acceptance_test.py
b55ad6
+++ b/dirsrvtests/tests/suites/replication/acceptance_test.py
b55ad6
@@ -500,6 +500,63 @@ def test_warining_for_invalid_replica(topo_m4):
b55ad6
     assert topo_m4.ms["master1"].ds_error_log.match('.*nsds5ReplicaBackoffMax.*10.*invalid.*')
b55ad6
 
b55ad6
 
b55ad6
+@pytest.mark.ds51082
b55ad6
+def test_csnpurge_large_valueset(topo_m2):
b55ad6
+    """Test csn generator test
b55ad6
+
b55ad6
+    :id: 63e2bdb2-0a8f-4660-9465-7b80a9f72a74
b55ad6
+    :setup: MMR with 2 masters
b55ad6
+    :steps:
b55ad6
+        1. Create a test_user
b55ad6
+        2. add a large set of values (more than 10)
b55ad6
+        3. delete all the values (more than 10)
b55ad6
+        4. configure the replica to purge those values (purgedelay=5s)
b55ad6
+        5. Waiting for 6 second
b55ad6
+        6. do a series of update
b55ad6
+    :expectedresults:
b55ad6
+        1. Should succeeds
b55ad6
+        2. Should succeeds
b55ad6
+        3. Should succeeds
b55ad6
+        4. Should succeeds
b55ad6
+        5. Should succeeds
b55ad6
+        6. Should not crash
b55ad6
+    """
b55ad6
+    m1 = topo_m2.ms["master2"]
b55ad6
+
b55ad6
+    test_user = UserAccount(m1, TEST_ENTRY_DN)
b55ad6
+    if test_user.exists():
b55ad6
+        log.info('Deleting entry {}'.format(TEST_ENTRY_DN))
b55ad6
+        test_user.delete()
b55ad6
+    test_user.create(properties={
b55ad6
+        'uid': TEST_ENTRY_NAME,
b55ad6
+        'cn': TEST_ENTRY_NAME,
b55ad6
+        'sn': TEST_ENTRY_NAME,
b55ad6
+        'userPassword': TEST_ENTRY_NAME,
b55ad6
+        'uidNumber' : '1000',
b55ad6
+        'gidNumber' : '2000',
b55ad6
+        'homeDirectory' : '/home/mmrepl_test',
b55ad6
+    })
b55ad6
+
b55ad6
+    # create a large value set so that it is sorted
b55ad6
+    for i in range(1,20):
b55ad6
+        test_user.add('description', 'value {}'.format(str(i)))
b55ad6
+
b55ad6
+    # delete all values of the valueset
b55ad6
+    for i in range(1,20):
b55ad6
+        test_user.remove('description', 'value {}'.format(str(i)))
b55ad6
+
b55ad6
+    # set purging delay to 5 second and wait more that 5second
b55ad6
+    replicas = Replicas(m1)
b55ad6
+    replica = replicas.list()[0]
b55ad6
+    log.info('nsds5ReplicaPurgeDelay to 5')
b55ad6
+    replica.set('nsds5ReplicaPurgeDelay', '5')
b55ad6
+    time.sleep(6)
b55ad6
+
b55ad6
+    # add some new values to the valueset containing entries that should be purged
b55ad6
+    for i in range(21,25):
b55ad6
+        test_user.add('description', 'value {}'.format(str(i)))
b55ad6
+
b55ad6
+
b55ad6
 if __name__ == '__main__':
b55ad6
     # Run isolated
b55ad6
     # -s for DEBUG mode
b55ad6
diff --git a/ldap/servers/slapd/valueset.c b/ldap/servers/slapd/valueset.c
b55ad6
index 2af3ee18d..12027ecb8 100644
b55ad6
--- a/ldap/servers/slapd/valueset.c
b55ad6
+++ b/ldap/servers/slapd/valueset.c
b55ad6
@@ -801,6 +801,10 @@ valueset_array_purge(const Slapi_Attr *a, Slapi_ValueSet *vs, const CSN *csn)
b55ad6
             }
b55ad6
         }
b55ad6
     } else {
b55ad6
+        /* empty valueset - reset the vs->num so that further
b55ad6
+         * checking will not abort
b55ad6
+         */
b55ad6
+        vs->num = 0;
b55ad6
         slapi_valueset_done(vs);
b55ad6
     }
b55ad6
 
b55ad6
-- 
b55ad6
2.26.2
b55ad6