|
|
dc8c34 |
From 73acb86b97a6f8a9850c6630fb8f21834916196b Mon Sep 17 00:00:00 2001
|
|
|
dc8c34 |
From: Noriko Hosoi <nhosoi@redhat.com>
|
|
|
dc8c34 |
Date: Fri, 28 Aug 2015 12:47:42 -0700
|
|
|
dc8c34 |
Subject: [PATCH 359/363] Ticket #48252 - db2index creates index entry from
|
|
|
dc8c34 |
deleted records
|
|
|
dc8c34 |
|
|
|
dc8c34 |
Bug Description: When an entry is deleted, its indexed attribute values
|
|
|
dc8c34 |
are also removed from each index file. But if the entry is turned to be
|
|
|
dc8c34 |
a tombstone entry, reindexing adds the removed attribute value back to
|
|
|
dc8c34 |
the index file.
|
|
|
dc8c34 |
|
|
|
dc8c34 |
Fix Description: In the reindexing function ldbm_back_ldbm2index, if the
|
|
|
dc8c34 |
entry is a tombstone entry, it skips reindexing operation unless the target
|
|
|
dc8c34 |
attribute is entryrdn or objectclass. If it is reindexing the objectclass,
|
|
|
dc8c34 |
it indexes just for the key "=nstombstone".
|
|
|
dc8c34 |
|
|
|
dc8c34 |
https://fedorahosted.org/389/ticket/48252
|
|
|
dc8c34 |
|
|
|
dc8c34 |
Reviewed by mreynolds@redhat.com and rmeggins@redhat.com (Thank you, Mark and Rich!!)
|
|
|
dc8c34 |
|
|
|
dc8c34 |
(cherry picked from commit ca4d38dff3bd820af2bf60c9bcc82fd64aac2556)
|
|
|
dc8c34 |
(cherry picked from commit 86b96278871d8b08f7c6a75379935c2183f6668f)
|
|
|
dc8c34 |
(cherry picked from commit ef0a2954cba650364ba4c48038d69731ebe19387)
|
|
|
dc8c34 |
|
|
|
dc8c34 |
Note: This patch contains the memory leak fixes.
|
|
|
dc8c34 |
(commit 4277f2ba4f1bb24efc771ea0fa02354654db255c)
|
|
|
dc8c34 |
(commit 8c9c2fcb14843089a7b5abd02ab1738249b64516)
|
|
|
dc8c34 |
(commit f10e2e633ad9c55bc2b42bceef3f9635d7ac5b7c)
|
|
|
dc8c34 |
|
|
|
dc8c34 |
(cherry picked from commit 6a1f2f0977ef04dc06b13c7efa3fd35e8f858eab)
|
|
|
dc8c34 |
---
|
|
|
dc8c34 |
ldap/servers/slapd/back-ldbm/ldif2ldbm.c | 73 +++++++++++++++++++++++---------
|
|
|
dc8c34 |
1 file changed, 54 insertions(+), 19 deletions(-)
|
|
|
dc8c34 |
|
|
|
dc8c34 |
diff --git a/ldap/servers/slapd/back-ldbm/ldif2ldbm.c b/ldap/servers/slapd/back-ldbm/ldif2ldbm.c
|
|
|
dc8c34 |
index 76eea2c..2d99a01 100644
|
|
|
dc8c34 |
--- a/ldap/servers/slapd/back-ldbm/ldif2ldbm.c
|
|
|
dc8c34 |
+++ b/ldap/servers/slapd/back-ldbm/ldif2ldbm.c
|
|
|
dc8c34 |
@@ -54,9 +54,12 @@
|
|
|
dc8c34 |
|
|
|
dc8c34 |
static char *sourcefile = "ldif2ldbm.c";
|
|
|
dc8c34 |
|
|
|
dc8c34 |
-#define DB2INDEX_ANCESTORID 0x1 /* index ancestorid */
|
|
|
dc8c34 |
-#define DB2INDEX_ENTRYRDN 0x2 /* index entryrdn */
|
|
|
dc8c34 |
-#define DB2LDIF_ENTRYRDN 0x4 /* export entryrdn */
|
|
|
dc8c34 |
+#define DB2INDEX_ANCESTORID 0x1 /* index ancestorid */
|
|
|
dc8c34 |
+#define DB2INDEX_ENTRYRDN 0x2 /* index entryrdn */
|
|
|
dc8c34 |
+#define DB2LDIF_ENTRYRDN 0x4 /* export entryrdn */
|
|
|
dc8c34 |
+#define DB2INDEX_OBJECTCLASS 0x10 /* for reindexing "objectclass: nstombstone" */
|
|
|
dc8c34 |
+
|
|
|
dc8c34 |
+#define LDIF2LDBM_EXTBITS(x) ((x) & 0xf)
|
|
|
dc8c34 |
|
|
|
dc8c34 |
typedef struct _export_args {
|
|
|
dc8c34 |
struct backentry *ep;
|
|
|
dc8c34 |
@@ -1679,6 +1682,8 @@ ldbm_back_ldbm2index(Slapi_PBlock *pb)
|
|
|
dc8c34 |
struct vlvIndex *vlvip = NULL;
|
|
|
dc8c34 |
back_txn txn;
|
|
|
dc8c34 |
ID suffixid = NOID; /* holds the id of the suffix entry */
|
|
|
dc8c34 |
+ Slapi_Value **nstombstone_vals = NULL;
|
|
|
dc8c34 |
+ int istombstone = 0;
|
|
|
dc8c34 |
|
|
|
dc8c34 |
LDAPDebug( LDAP_DEBUG_TRACE, "=> ldbm_back_ldbm2index\n", 0, 0, 0 );
|
|
|
dc8c34 |
if ( g_get_shutdown() || c_get_shutdown() ) {
|
|
|
dc8c34 |
@@ -1799,7 +1804,7 @@ ldbm_back_ldbm2index(Slapi_PBlock *pb)
|
|
|
dc8c34 |
if (strcasecmp(attrs[i]+1, LDBM_ANCESTORID_STR) == 0) {
|
|
|
dc8c34 |
if (task) {
|
|
|
dc8c34 |
slapi_task_log_notice(task, "%s: Indexing %s",
|
|
|
dc8c34 |
- inst->inst_name, LDBM_ENTRYRDN_STR);
|
|
|
dc8c34 |
+ inst->inst_name, LDBM_ANCESTORID_STR);
|
|
|
dc8c34 |
}
|
|
|
dc8c34 |
LDAPDebug2Args(LDAP_DEBUG_ANY, "%s: Indexing %s\n",
|
|
|
dc8c34 |
inst->inst_name, LDBM_ANCESTORID_STR);
|
|
|
dc8c34 |
@@ -1852,6 +1857,9 @@ ldbm_back_ldbm2index(Slapi_PBlock *pb)
|
|
|
dc8c34 |
inst->inst_name, attrs[i] + 1);
|
|
|
dc8c34 |
}
|
|
|
dc8c34 |
} else {
|
|
|
dc8c34 |
+ if (strcasecmp(attrs[i]+1, SLAPI_ATTR_OBJECTCLASS) == 0) {
|
|
|
dc8c34 |
+ index_ext |= DB2INDEX_OBJECTCLASS;
|
|
|
dc8c34 |
+ }
|
|
|
dc8c34 |
charray_add(&indexAttrs, attrs[i]+1);
|
|
|
dc8c34 |
ai->ai_indexmask |= INDEX_OFFLINE;
|
|
|
dc8c34 |
if (task) {
|
|
|
dc8c34 |
@@ -1897,7 +1905,7 @@ ldbm_back_ldbm2index(Slapi_PBlock *pb)
|
|
|
dc8c34 |
* idl composed from the ancestorid list, instead of traversing the
|
|
|
dc8c34 |
* entire database.
|
|
|
dc8c34 |
*/
|
|
|
dc8c34 |
- if (!indexAttrs && !index_ext && pvlv) {
|
|
|
dc8c34 |
+ if (!indexAttrs && !LDIF2LDBM_EXTBITS(index_ext) && pvlv) {
|
|
|
dc8c34 |
int err;
|
|
|
dc8c34 |
char **suffix_list = NULL;
|
|
|
dc8c34 |
|
|
|
dc8c34 |
@@ -2154,20 +2162,46 @@ ldbm_back_ldbm2index(Slapi_PBlock *pb)
|
|
|
dc8c34 |
}
|
|
|
dc8c34 |
|
|
|
dc8c34 |
/*
|
|
|
dc8c34 |
+ * If this entry is a tombstone, set nstombstone_vals for reindexing "objectclass: nstombstone"
|
|
|
dc8c34 |
+ */
|
|
|
dc8c34 |
+ if (ep->ep_entry->e_flags & SLAPI_ENTRY_FLAG_TOMBSTONE) {
|
|
|
dc8c34 |
+ istombstone = 1;
|
|
|
dc8c34 |
+ if (!nstombstone_vals) {
|
|
|
dc8c34 |
+ nstombstone_vals = (Slapi_Value **) slapi_ch_calloc(2, sizeof(Slapi_Value *));
|
|
|
dc8c34 |
+ *nstombstone_vals = slapi_value_new_string(SLAPI_ATTR_VALUE_TOMBSTONE);
|
|
|
dc8c34 |
+ }
|
|
|
dc8c34 |
+ } else {
|
|
|
dc8c34 |
+ istombstone = 0;
|
|
|
dc8c34 |
+ }
|
|
|
dc8c34 |
+ /*
|
|
|
dc8c34 |
* Update the attribute indexes
|
|
|
dc8c34 |
*/
|
|
|
dc8c34 |
- if (indexAttrs != NULL) {
|
|
|
dc8c34 |
+ if (indexAttrs) {
|
|
|
dc8c34 |
+ if (istombstone && !(index_ext & (DB2INDEX_ENTRYRDN|DB2INDEX_OBJECTCLASS))) {
|
|
|
dc8c34 |
+ /* if it is a tombstone entry, just entryrdn or "objectclass: nstombstone"
|
|
|
dc8c34 |
+ * need to be reindexed. the to-be-indexed list does not contain them. */
|
|
|
dc8c34 |
+ backentry_free( &ep );
|
|
|
dc8c34 |
+ continue;
|
|
|
dc8c34 |
+ }
|
|
|
dc8c34 |
for (i = slapi_entry_first_attr(ep->ep_entry, &attr); i == 0;
|
|
|
dc8c34 |
i = slapi_entry_next_attr(ep->ep_entry, attr, &attr)) {
|
|
|
dc8c34 |
Slapi_Value **svals;
|
|
|
dc8c34 |
|
|
|
dc8c34 |
slapi_attr_get_type( attr, &type );
|
|
|
dc8c34 |
for ( j = 0; indexAttrs[j] != NULL; j++ ) {
|
|
|
dc8c34 |
+ int is_tombstone_obj = 0;
|
|
|
dc8c34 |
if ( g_get_shutdown() || c_get_shutdown() ) {
|
|
|
dc8c34 |
goto err_out;
|
|
|
dc8c34 |
}
|
|
|
dc8c34 |
- if (slapi_attr_type_cmp(indexAttrs[j], type,
|
|
|
dc8c34 |
- SLAPI_TYPE_CMP_SUBTYPE) == 0 ) {
|
|
|
dc8c34 |
+ if (slapi_attr_type_cmp(indexAttrs[j], type, SLAPI_TYPE_CMP_SUBTYPE) == 0) {
|
|
|
dc8c34 |
+ if (istombstone) {
|
|
|
dc8c34 |
+ if (!slapi_attr_type_cmp(indexAttrs[j], SLAPI_ATTR_OBJECTCLASS, SLAPI_TYPE_CMP_SUBTYPE)) {
|
|
|
dc8c34 |
+ is_tombstone_obj = 1; /* is tombstone && is objectclass. need to index "nstombstone"*/
|
|
|
dc8c34 |
+ } else if (slapi_attr_type_cmp(indexAttrs[j], LDBM_ENTRYRDN_STR, SLAPI_TYPE_CMP_SUBTYPE)) {
|
|
|
dc8c34 |
+ /* Entry is a tombstone && this index is not an entryrdn. */
|
|
|
dc8c34 |
+ continue;
|
|
|
dc8c34 |
+ }
|
|
|
dc8c34 |
+ }
|
|
|
dc8c34 |
svals = attr_get_present_values(attr);
|
|
|
dc8c34 |
|
|
|
dc8c34 |
if (!run_from_cmdline) {
|
|
|
dc8c34 |
@@ -2191,10 +2225,12 @@ ldbm_back_ldbm2index(Slapi_PBlock *pb)
|
|
|
dc8c34 |
goto err_out;
|
|
|
dc8c34 |
}
|
|
|
dc8c34 |
}
|
|
|
dc8c34 |
- rc = index_addordel_values_sv(
|
|
|
dc8c34 |
- be, indexAttrs[j], svals,
|
|
|
dc8c34 |
- NULL, ep->ep_id, BE_INDEX_ADD, &txn);
|
|
|
dc8c34 |
- if (rc != 0) {
|
|
|
dc8c34 |
+ if (is_tombstone_obj) {
|
|
|
dc8c34 |
+ rc = index_addordel_values_sv(be, indexAttrs[j], nstombstone_vals, NULL, ep->ep_id, BE_INDEX_ADD, &txn);
|
|
|
dc8c34 |
+ } else {
|
|
|
dc8c34 |
+ rc = index_addordel_values_sv(be, indexAttrs[j], svals, NULL, ep->ep_id, BE_INDEX_ADD, &txn);
|
|
|
dc8c34 |
+ }
|
|
|
dc8c34 |
+ if (rc) {
|
|
|
dc8c34 |
LDAPDebug(LDAP_DEBUG_ANY,
|
|
|
dc8c34 |
"%s: ERROR: failed to update index '%s'\n",
|
|
|
dc8c34 |
inst->inst_name, indexAttrs[j], 0);
|
|
|
dc8c34 |
@@ -2240,18 +2276,16 @@ ldbm_back_ldbm2index(Slapi_PBlock *pb)
|
|
|
dc8c34 |
}
|
|
|
dc8c34 |
|
|
|
dc8c34 |
/*
|
|
|
dc8c34 |
- * Update the Virtual List View indexes
|
|
|
dc8c34 |
+ * If it is NOT a tombstone entry, update the Virtual List View indexes.
|
|
|
dc8c34 |
*/
|
|
|
dc8c34 |
- for ( vlvidx = 0; vlvidx < numvlv; vlvidx++ ) {
|
|
|
dc8c34 |
+ for (vlvidx = 0; !istombstone && (vlvidx < numvlv); vlvidx++) {
|
|
|
dc8c34 |
char *ai = "Unknown index";
|
|
|
dc8c34 |
|
|
|
dc8c34 |
if ( g_get_shutdown() || c_get_shutdown() ) {
|
|
|
dc8c34 |
goto err_out;
|
|
|
dc8c34 |
}
|
|
|
dc8c34 |
- if(indexAttrs){
|
|
|
dc8c34 |
- if(indexAttrs[vlvidx]){
|
|
|
dc8c34 |
- ai = indexAttrs[vlvidx];
|
|
|
dc8c34 |
- }
|
|
|
dc8c34 |
+ if (indexAttrs && indexAttrs[vlvidx]) {
|
|
|
dc8c34 |
+ ai = indexAttrs[vlvidx];
|
|
|
dc8c34 |
}
|
|
|
dc8c34 |
if (!run_from_cmdline) {
|
|
|
dc8c34 |
rc = dblayer_txn_begin(li, NULL, &txn);
|
|
|
dc8c34 |
@@ -2305,7 +2339,7 @@ ldbm_back_ldbm2index(Slapi_PBlock *pb)
|
|
|
dc8c34 |
/*
|
|
|
dc8c34 |
* Update the ancestorid and entryrdn index
|
|
|
dc8c34 |
*/
|
|
|
dc8c34 |
- if (!entryrdn_get_noancestorid() && index_ext & DB2INDEX_ANCESTORID) {
|
|
|
dc8c34 |
+ if (!entryrdn_get_noancestorid() && (index_ext & DB2INDEX_ANCESTORID)) {
|
|
|
dc8c34 |
rc = ldbm_ancestorid_index_entry(be, ep, BE_INDEX_ADD, NULL);
|
|
|
dc8c34 |
if (rc != 0) {
|
|
|
dc8c34 |
LDAPDebug(LDAP_DEBUG_ANY,
|
|
|
dc8c34 |
@@ -2469,6 +2503,7 @@ err_min:
|
|
|
dc8c34 |
}
|
|
|
dc8c34 |
}
|
|
|
dc8c34 |
|
|
|
dc8c34 |
+ valuearray_free(&nstombstone_vals);
|
|
|
dc8c34 |
if (indexAttrs) {
|
|
|
dc8c34 |
slapi_ch_free((void **)&indexAttrs);
|
|
|
dc8c34 |
}
|
|
|
dc8c34 |
--
|
|
|
dc8c34 |
2.4.3
|
|
|
dc8c34 |
|