|
|
5873fa |
From 3b3faee01e645577ad77ff4f38429a9e0806231b Mon Sep 17 00:00:00 2001
|
|
|
5873fa |
From: Simon Pichugin <simon.pichugin@gmail.com>
|
|
|
5873fa |
Date: Tue, 16 Jun 2020 20:35:05 +0200
|
|
|
5873fa |
Subject: [PATCH] Issue 51157 - Reindex task may create abandoned index file
|
|
|
5873fa |
|
|
|
5873fa |
Bug Description: Recreating an index for the same attribute but changing
|
|
|
5873fa |
the case of for example 1 letter, results in abandoned indexfile.
|
|
|
5873fa |
|
|
|
5873fa |
Fix Decsription: Add a test case to a newly created 'indexes' test suite.
|
|
|
5873fa |
When we remove the index config from the backend, - remove the attribute
|
|
|
5873fa |
info from LDBM instance attributes.
|
|
|
5873fa |
|
|
|
5873fa |
https://pagure.io/389-ds-base/issue/51157
|
|
|
5873fa |
|
|
|
5873fa |
Reviewed by: firstyear, mreynolds (Thanks!)
|
|
|
5873fa |
---
|
|
|
5873fa |
dirsrvtests/tests/suites/indexes/__init__.py | 3 +
|
|
|
5873fa |
.../tests/suites/indexes/regression_test.py | 125 ++++++++++++++++++
|
|
|
5873fa |
ldap/servers/slapd/back-ldbm/ldbm_attr.c | 7 +
|
|
|
5873fa |
.../slapd/back-ldbm/ldbm_index_config.c | 3 +
|
|
|
5873fa |
.../servers/slapd/back-ldbm/proto-back-ldbm.h | 1 +
|
|
|
5873fa |
5 files changed, 139 insertions(+)
|
|
|
5873fa |
create mode 100644 dirsrvtests/tests/suites/indexes/__init__.py
|
|
|
5873fa |
create mode 100644 dirsrvtests/tests/suites/indexes/regression_test.py
|
|
|
5873fa |
|
|
|
5873fa |
diff --git a/dirsrvtests/tests/suites/indexes/__init__.py b/dirsrvtests/tests/suites/indexes/__init__.py
|
|
|
5873fa |
new file mode 100644
|
|
|
5873fa |
index 000000000..04441667e
|
|
|
5873fa |
--- /dev/null
|
|
|
5873fa |
+++ b/dirsrvtests/tests/suites/indexes/__init__.py
|
|
|
5873fa |
@@ -0,0 +1,3 @@
|
|
|
5873fa |
+"""
|
|
|
5873fa |
+ :Requirement: 389-ds-base: Indexes
|
|
|
5873fa |
+"""
|
|
|
5873fa |
diff --git a/dirsrvtests/tests/suites/indexes/regression_test.py b/dirsrvtests/tests/suites/indexes/regression_test.py
|
|
|
5873fa |
new file mode 100644
|
|
|
5873fa |
index 000000000..1a71f16e9
|
|
|
5873fa |
--- /dev/null
|
|
|
5873fa |
+++ b/dirsrvtests/tests/suites/indexes/regression_test.py
|
|
|
5873fa |
@@ -0,0 +1,125 @@
|
|
|
5873fa |
+# --- BEGIN COPYRIGHT BLOCK ---
|
|
|
5873fa |
+# Copyright (C) 2020 Red Hat, Inc.
|
|
|
5873fa |
+# All rights reserved.
|
|
|
5873fa |
+#
|
|
|
5873fa |
+# License: GPL (version 3 or any later version).
|
|
|
5873fa |
+# See LICENSE for details.
|
|
|
5873fa |
+# --- END COPYRIGHT BLOCK ---
|
|
|
5873fa |
+#
|
|
|
5873fa |
+import time
|
|
|
5873fa |
+import os
|
|
|
5873fa |
+import pytest
|
|
|
5873fa |
+import ldap
|
|
|
5873fa |
+from lib389._constants import DEFAULT_BENAME, DEFAULT_SUFFIX
|
|
|
5873fa |
+from lib389.index import Indexes
|
|
|
5873fa |
+from lib389.backend import Backends
|
|
|
5873fa |
+from lib389.idm.user import UserAccounts
|
|
|
5873fa |
+from lib389.topologies import topology_st as topo
|
|
|
5873fa |
+
|
|
|
5873fa |
+pytestmark = pytest.mark.tier1
|
|
|
5873fa |
+
|
|
|
5873fa |
+
|
|
|
5873fa |
+def test_reindex_task_creates_abandoned_index_file(topo):
|
|
|
5873fa |
+ """
|
|
|
5873fa |
+ Recreating an index for the same attribute but changing
|
|
|
5873fa |
+ the case of for example 1 letter, results in abandoned indexfile
|
|
|
5873fa |
+
|
|
|
5873fa |
+ :id: 07ae5274-481a-4fa8-8074-e0de50d89ac6
|
|
|
5873fa |
+ :setup: Standalone instance
|
|
|
5873fa |
+ :steps:
|
|
|
5873fa |
+ 1. Create a user object with additional attributes:
|
|
|
5873fa |
+ objectClass: mozillaabpersonalpha
|
|
|
5873fa |
+ mozillaCustom1: xyz
|
|
|
5873fa |
+ 2. Add an index entry mozillacustom1
|
|
|
5873fa |
+ 3. Reindex the backend
|
|
|
5873fa |
+ 4. Check the content of the index (after it has been flushed to disk) mozillacustom1.db
|
|
|
5873fa |
+ 5. Remove the index
|
|
|
5873fa |
+ 6. Notice the mozillacustom1.db is removed
|
|
|
5873fa |
+ 7. Recreate the index but now use the exact case as mentioned in the schema
|
|
|
5873fa |
+ 8. Reindex the backend
|
|
|
5873fa |
+ 9. Check the content of the index (after it has been flushed to disk) mozillaCustom1.db
|
|
|
5873fa |
+ 10. Check that an ldapsearch does not return a result (mozillacustom1=xyz)
|
|
|
5873fa |
+ 11. Check that an ldapsearch returns the results (mozillaCustom1=xyz)
|
|
|
5873fa |
+ 12. Restart the instance
|
|
|
5873fa |
+ 13. Notice that an ldapsearch does not return a result(mozillacustom1=xyz)
|
|
|
5873fa |
+ 15. Check that an ldapsearch does not return a result (mozillacustom1=xyz)
|
|
|
5873fa |
+ 16. Check that an ldapsearch returns the results (mozillaCustom1=xyz)
|
|
|
5873fa |
+ 17. Reindex the backend
|
|
|
5873fa |
+ 18. Notice the second indexfile for this attribute
|
|
|
5873fa |
+ 19. Check the content of the index (after it has been flushed to disk) no mozillacustom1.db
|
|
|
5873fa |
+ 20. Check the content of the index (after it has been flushed to disk) mozillaCustom1.db
|
|
|
5873fa |
+ :expectedresults:
|
|
|
5873fa |
+ 1. Should Success.
|
|
|
5873fa |
+ 2. Should Success.
|
|
|
5873fa |
+ 3. Should Success.
|
|
|
5873fa |
+ 4. Should Success.
|
|
|
5873fa |
+ 5. Should Success.
|
|
|
5873fa |
+ 6. Should Success.
|
|
|
5873fa |
+ 7. Should Success.
|
|
|
5873fa |
+ 8. Should Success.
|
|
|
5873fa |
+ 9. Should Success.
|
|
|
5873fa |
+ 10. Should Success.
|
|
|
5873fa |
+ 11. Should Success.
|
|
|
5873fa |
+ 12. Should Success.
|
|
|
5873fa |
+ 13. Should Success.
|
|
|
5873fa |
+ 14. Should Success.
|
|
|
5873fa |
+ 15. Should Success.
|
|
|
5873fa |
+ 16. Should Success.
|
|
|
5873fa |
+ 17. Should Success.
|
|
|
5873fa |
+ 18. Should Success.
|
|
|
5873fa |
+ 19. Should Success.
|
|
|
5873fa |
+ 20. Should Success.
|
|
|
5873fa |
+ """
|
|
|
5873fa |
+
|
|
|
5873fa |
+ inst = topo.standalone
|
|
|
5873fa |
+ attr_name = "mozillaCustom1"
|
|
|
5873fa |
+ attr_value = "xyz"
|
|
|
5873fa |
+
|
|
|
5873fa |
+ users = UserAccounts(inst, DEFAULT_SUFFIX)
|
|
|
5873fa |
+ user = users.create_test_user()
|
|
|
5873fa |
+ user.add("objectClass", "mozillaabpersonalpha")
|
|
|
5873fa |
+ user.add(attr_name, attr_value)
|
|
|
5873fa |
+
|
|
|
5873fa |
+ backends = Backends(inst)
|
|
|
5873fa |
+ backend = backends.get(DEFAULT_BENAME)
|
|
|
5873fa |
+ indexes = backend.get_indexes()
|
|
|
5873fa |
+ index = indexes.create(properties={
|
|
|
5873fa |
+ 'cn': attr_name.lower(),
|
|
|
5873fa |
+ 'nsSystemIndex': 'false',
|
|
|
5873fa |
+ 'nsIndexType': ['eq', 'pres']
|
|
|
5873fa |
+ })
|
|
|
5873fa |
+
|
|
|
5873fa |
+ backend.reindex()
|
|
|
5873fa |
+ time.sleep(3)
|
|
|
5873fa |
+ assert os.path.exists(f"{inst.ds_paths.db_home_dir}/{DEFAULT_BENAME}/{attr_name.lower()}.db")
|
|
|
5873fa |
+ index.delete()
|
|
|
5873fa |
+ assert not os.path.exists(f"{inst.ds_paths.db_home_dir}/{DEFAULT_BENAME}/{attr_name.lower()}.db")
|
|
|
5873fa |
+
|
|
|
5873fa |
+ index = indexes.create(properties={
|
|
|
5873fa |
+ 'cn': attr_name,
|
|
|
5873fa |
+ 'nsSystemIndex': 'false',
|
|
|
5873fa |
+ 'nsIndexType': ['eq', 'pres']
|
|
|
5873fa |
+ })
|
|
|
5873fa |
+
|
|
|
5873fa |
+ backend.reindex()
|
|
|
5873fa |
+ time.sleep(3)
|
|
|
5873fa |
+ assert not os.path.exists(f"{inst.ds_paths.db_home_dir}/{DEFAULT_BENAME}/{attr_name.lower()}.db")
|
|
|
5873fa |
+ assert os.path.exists(f"{inst.ds_paths.db_home_dir}/{DEFAULT_BENAME}/{attr_name}.db")
|
|
|
5873fa |
+
|
|
|
5873fa |
+ entries = inst.search_s(DEFAULT_SUFFIX, ldap.SCOPE_SUBTREE, f"{attr_name}={attr_value}")
|
|
|
5873fa |
+ assert len(entries) > 0
|
|
|
5873fa |
+ inst.restart()
|
|
|
5873fa |
+ entries = inst.search_s(DEFAULT_SUFFIX, ldap.SCOPE_SUBTREE, f"{attr_name}={attr_value}")
|
|
|
5873fa |
+ assert len(entries) > 0
|
|
|
5873fa |
+
|
|
|
5873fa |
+ backend.reindex()
|
|
|
5873fa |
+ time.sleep(3)
|
|
|
5873fa |
+ assert not os.path.exists(f"{inst.ds_paths.db_home_dir}/{DEFAULT_BENAME}/{attr_name.lower()}.db")
|
|
|
5873fa |
+ assert os.path.exists(f"{inst.ds_paths.db_home_dir}/{DEFAULT_BENAME}/{attr_name}.db")
|
|
|
5873fa |
+
|
|
|
5873fa |
+
|
|
|
5873fa |
+if __name__ == "__main__":
|
|
|
5873fa |
+ # Run isolated
|
|
|
5873fa |
+ # -s for DEBUG mode
|
|
|
5873fa |
+ CURRENT_FILE = os.path.realpath(__file__)
|
|
|
5873fa |
+ pytest.main("-s %s" % CURRENT_FILE)
|
|
|
5873fa |
diff --git a/ldap/servers/slapd/back-ldbm/ldbm_attr.c b/ldap/servers/slapd/back-ldbm/ldbm_attr.c
|
|
|
5873fa |
index f0d418572..688c4f137 100644
|
|
|
5873fa |
--- a/ldap/servers/slapd/back-ldbm/ldbm_attr.c
|
|
|
5873fa |
+++ b/ldap/servers/slapd/back-ldbm/ldbm_attr.c
|
|
|
5873fa |
@@ -98,6 +98,13 @@ ainfo_cmp(
|
|
|
5873fa |
return (strcasecmp(a->ai_type, b->ai_type));
|
|
|
5873fa |
}
|
|
|
5873fa |
|
|
|
5873fa |
+void
|
|
|
5873fa |
+attrinfo_delete_from_tree(backend *be, struct attrinfo *ai)
|
|
|
5873fa |
+{
|
|
|
5873fa |
+ ldbm_instance *inst = (ldbm_instance *)be->be_instance_info;
|
|
|
5873fa |
+ avl_delete(&inst->inst_attrs, ai, ainfo_cmp);
|
|
|
5873fa |
+}
|
|
|
5873fa |
+
|
|
|
5873fa |
/*
|
|
|
5873fa |
* Called when a duplicate "index" line is encountered.
|
|
|
5873fa |
*
|
|
|
5873fa |
diff --git a/ldap/servers/slapd/back-ldbm/ldbm_index_config.c b/ldap/servers/slapd/back-ldbm/ldbm_index_config.c
|
|
|
5873fa |
index 720f93036..9722d0ce7 100644
|
|
|
5873fa |
--- a/ldap/servers/slapd/back-ldbm/ldbm_index_config.c
|
|
|
5873fa |
+++ b/ldap/servers/slapd/back-ldbm/ldbm_index_config.c
|
|
|
5873fa |
@@ -201,7 +201,10 @@ ldbm_instance_index_config_delete_callback(Slapi_PBlock *pb,
|
|
|
5873fa |
*returncode = LDAP_UNWILLING_TO_PERFORM;
|
|
|
5873fa |
rc = SLAPI_DSE_CALLBACK_ERROR;
|
|
|
5873fa |
}
|
|
|
5873fa |
+ attrinfo_delete_from_tree(inst->inst_be, ainfo);
|
|
|
5873fa |
}
|
|
|
5873fa |
+ /* Free attrinfo structure */
|
|
|
5873fa |
+ attrinfo_delete(&ainfo);
|
|
|
5873fa |
bail:
|
|
|
5873fa |
return rc;
|
|
|
5873fa |
}
|
|
|
5873fa |
diff --git a/ldap/servers/slapd/back-ldbm/proto-back-ldbm.h b/ldap/servers/slapd/back-ldbm/proto-back-ldbm.h
|
|
|
5873fa |
index a07acee5e..4d2524fd9 100644
|
|
|
5873fa |
--- a/ldap/servers/slapd/back-ldbm/proto-back-ldbm.h
|
|
|
5873fa |
+++ b/ldap/servers/slapd/back-ldbm/proto-back-ldbm.h
|
|
|
5873fa |
@@ -21,6 +21,7 @@
|
|
|
5873fa |
*/
|
|
|
5873fa |
struct attrinfo *attrinfo_new(void);
|
|
|
5873fa |
void attrinfo_delete(struct attrinfo **pp);
|
|
|
5873fa |
+void attrinfo_delete_from_tree(backend *be, struct attrinfo *ai);
|
|
|
5873fa |
void ainfo_get(backend *be, char *type, struct attrinfo **at);
|
|
|
5873fa |
void attr_masks(backend *be, char *type, int *indexmask, int *syntaxmask);
|
|
|
5873fa |
void attr_masks_ex(backend *be, char *type, int *indexmask, int *syntaxmask, struct attrinfo **at);
|
|
|
5873fa |
--
|
|
|
5873fa |
2.26.2
|
|
|
5873fa |
|