Blame SOURCES/0033-Issue-4910-db-reindex-corrupts-RUV-tombstone-nsuique.patch

33fd71
From 096c95690a27c942d47b20a85fa3d7fe15ffe624 Mon Sep 17 00:00:00 2001
33fd71
From: Mark Reynolds <mreynolds@redhat.com>
33fd71
Date: Wed, 8 Sep 2021 10:31:19 -0400
33fd71
Subject: [PATCH] Issue 4910 - db reindex corrupts RUV tombstone nsuiqueid
33fd71
 index
33fd71
33fd71
Bug Description:  During a reindex task we skip the RUV tombstone entry,
33fd71
                  which corrupts the nsuniqueid index.
33fd71
33fd71
Fix Description:  Make sure we still index nsuniqueid index for
33fd71
                  the RUV tombstone entry.
33fd71
33fd71
relates: https://github.com/389ds/389-ds-base/issues/4910
33fd71
33fd71
Reviewed by: firstyear & progier389 (Thanks!!)
33fd71
---
33fd71
 .../tests/suites/replication/ruvstore_test.py | 35 +++++++++++++++++++
33fd71
 .../slapd/back-ldbm/db-bdb/bdb_ldif2db.c      | 12 +++++--
33fd71
 2 files changed, 44 insertions(+), 3 deletions(-)
33fd71
33fd71
diff --git a/dirsrvtests/tests/suites/replication/ruvstore_test.py b/dirsrvtests/tests/suites/replication/ruvstore_test.py
33fd71
index c04fd079e..4e5326227 100644
33fd71
--- a/dirsrvtests/tests/suites/replication/ruvstore_test.py
33fd71
+++ b/dirsrvtests/tests/suites/replication/ruvstore_test.py
33fd71
@@ -12,6 +12,8 @@ import ldap
33fd71
 import pytest
33fd71
 from ldif import LDIFParser
33fd71
 from lib389.replica import Replicas
33fd71
+from lib389.backend import Backends
33fd71
+from lib389.idm.domain import Domain
33fd71
 from lib389.idm.user import UserAccounts
33fd71
 from lib389.topologies import topology_m2 as topo
33fd71
 from lib389._constants import *
33fd71
@@ -156,6 +158,39 @@ def test_memoryruv_sync_with_databaseruv(topo):
33fd71
     _compare_memoryruv_and_databaseruv(topo, 'delete')
33fd71
 
33fd71
 
33fd71
+def test_ruv_after_reindex(topo):
33fd71
+    """Test that the tombstone RUV entry is not corrupted after a reindex task
33fd71
+
33fd71
+    :id: 988c0fab-1905-4dc5-a45d-fbf195843a33
33fd71
+    :setup: 2 suppliers
33fd71
+    :steps:
33fd71
+        1. Reindex database
33fd71
+        2. Perform some updates
33fd71
+        3. Check error log does not have "_entryrdn_insert_key" errors
33fd71
+    :expectedresults:
33fd71
+        1. Success
33fd71
+        2. Success
33fd71
+        3. Success
33fd71
+    """
33fd71
+
33fd71
+    inst = topo.ms['supplier1']
33fd71
+    suffix = Domain(inst, "ou=people," + DEFAULT_SUFFIX)
33fd71
+    backends = Backends(inst)
33fd71
+    backend = backends.get(DEFAULT_BENAME)
33fd71
+
33fd71
+    # Reindex nsuniqueid
33fd71
+    backend.reindex(attrs=['nsuniqueid'], wait=True)
33fd71
+
33fd71
+    # Do some updates
33fd71
+    for idx in range(0, 5):
33fd71
+        suffix.replace('description', str(idx))
33fd71
+
33fd71
+    # Check error log for RUV entryrdn errors.  Stopping instance forces RUV
33fd71
+    # to be written and quickly exposes the error
33fd71
+    inst.stop()
33fd71
+    assert not inst.searchErrorsLog("entryrdn_insert_key")
33fd71
+
33fd71
+
33fd71
 if __name__ == '__main__':
33fd71
     # Run isolated
33fd71
     # -s for DEBUG mode
33fd71
diff --git a/ldap/servers/slapd/back-ldbm/db-bdb/bdb_ldif2db.c b/ldap/servers/slapd/back-ldbm/db-bdb/bdb_ldif2db.c
33fd71
index 506c285a3..6100dbf77 100644
33fd71
--- a/ldap/servers/slapd/back-ldbm/db-bdb/bdb_ldif2db.c
33fd71
+++ b/ldap/servers/slapd/back-ldbm/db-bdb/bdb_ldif2db.c
33fd71
@@ -25,6 +25,7 @@
33fd71
 #define DB2INDEX_ENTRYRDN 0x2     /* index entryrdn */
33fd71
 #define DB2LDIF_ENTRYRDN 0x4      /* export entryrdn */
33fd71
 #define DB2INDEX_OBJECTCLASS 0x10 /* for reindexing "objectclass: nstombstone" */
33fd71
+#define DB2INDEX_NSUNIQUEID 0x20  /* for reindexing RUV tombstone */
33fd71
 
33fd71
 #define LDIF2LDBM_EXTBITS(x) ((x)&0xf)
33fd71
 
33fd71
@@ -1543,6 +1544,9 @@ bdb_db2index(Slapi_PBlock *pb)
33fd71
                     if (strcasecmp(attrs[i] + 1, SLAPI_ATTR_OBJECTCLASS) == 0) {
33fd71
                         index_ext |= DB2INDEX_OBJECTCLASS;
33fd71
                     }
33fd71
+                    if (strcasecmp(attrs[i] + 1, SLAPI_ATTR_UNIQUEID) == 0) {
33fd71
+                        index_ext |= DB2INDEX_NSUNIQUEID;
33fd71
+                    }
33fd71
                     charray_add(&indexAttrs, attrs[i] + 1);
33fd71
                     ai->ai_indexmask |= INDEX_OFFLINE;
33fd71
                     slapi_task_log_notice(task, "%s: Indexing attribute: %s",
33fd71
@@ -1895,7 +1899,7 @@ bdb_db2index(Slapi_PBlock *pb)
33fd71
          * Update the attribute indexes
33fd71
          */
33fd71
         if (indexAttrs) {
33fd71
-            if (istombstone && !(index_ext & (DB2INDEX_ENTRYRDN | DB2INDEX_OBJECTCLASS))) {
33fd71
+            if (istombstone && !(index_ext & (DB2INDEX_ENTRYRDN | DB2INDEX_OBJECTCLASS | DB2INDEX_NSUNIQUEID))) {
33fd71
                 /* if it is a tombstone entry, just entryrdn or "objectclass: nstombstone"
33fd71
                  * need to be reindexed.  the to-be-indexed list does not contain them. */
33fd71
                 backentry_free(&ep);
33fd71
@@ -1915,8 +1919,10 @@ bdb_db2index(Slapi_PBlock *pb)
33fd71
                         if (istombstone) {
33fd71
                             if (!slapi_attr_type_cmp(indexAttrs[j], SLAPI_ATTR_OBJECTCLASS, SLAPI_TYPE_CMP_SUBTYPE)) {
33fd71
                                 is_tombstone_obj = 1; /* is tombstone && is objectclass. need to index "nstombstone"*/
33fd71
-                            } else if (slapi_attr_type_cmp(indexAttrs[j], LDBM_ENTRYRDN_STR, SLAPI_TYPE_CMP_SUBTYPE)) {
33fd71
-                                /* Entry is a tombstone && this index is not an entryrdn. */
33fd71
+                            } else if (slapi_attr_type_cmp(indexAttrs[j], LDBM_ENTRYRDN_STR, SLAPI_TYPE_CMP_SUBTYPE) &&
33fd71
+                                       slapi_attr_type_cmp(indexAttrs[j], SLAPI_ATTR_UNIQUEID, SLAPI_TYPE_CMP_SUBTYPE))
33fd71
+                            {
33fd71
+                                /* Entry is a tombstone && this index is not entryrdn or nsuniqueid */
33fd71
                                 continue;
33fd71
                             }
33fd71
                         }
33fd71
-- 
33fd71
2.31.1
33fd71