| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810 |
- /** BEGIN COPYRIGHT BLOCK
- * This Program is free software; you can redistribute it and/or modify it under
- * the terms of the GNU General Public License as published by the Free Software
- * Foundation; version 2 of the License.
- *
- * This Program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place, Suite 330, Boston, MA 02111-1307 USA.
- *
- * In addition, as a special exception, Red Hat, Inc. gives You the additional
- * right to link the code of this Program with code not covered under the GNU
- * General Public License ("Non-GPL Code") and to distribute linked combinations
- * including the two, subject to the limitations in this paragraph. Non-GPL Code
- * permitted under this exception must only link to the code of this Program
- * through those well defined interfaces identified in the file named EXCEPTION
- * found in the source code files (the "Approved Interfaces"). The files of
- * Non-GPL Code may instantiate templates or use macros or inline functions from
- * the Approved Interfaces without causing the resulting work to be covered by
- * the GNU General Public License. Only Red Hat, Inc. may make changes or
- * additions to the list of Approved Interfaces. You must obey the GNU General
- * Public License in all respects for all of the Program code and other code used
- * in conjunction with the Program except the Non-GPL Code covered by this
- * exception. If you modify this file, you may extend this exception to your
- * version of the file, but you are not obligated to do so. If you do not wish to
- * provide this exception without modification, you must delete this exception
- * statement from your version and license this file solely under the GPL without
- * exception.
- *
- *
- * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
- * Copyright (C) 2005 Red Hat, Inc.
- * All rights reserved.
- * END COPYRIGHT BLOCK **/
- #ifdef HAVE_CONFIG_H
- # include <config.h>
- #endif
-
- /* delete.c - ldbm backend delete routine */
- #include "back-ldbm.h"
- int
- ldbm_back_delete( Slapi_PBlock *pb )
- {
- backend *be;
- ldbm_instance *inst;
- struct ldbminfo *li = NULL;
- struct backentry *e = NULL;
- struct backentry *tombstone = NULL;
- char *dn = NULL;
- back_txn txn;
- back_txnid parent_txn;
- int retval = -1;
- char *msg;
- char *errbuf = NULL;
- int retry_count = 0;
- int disk_full = 0;
- int parent_found = 0;
- modify_context parent_modify_c = {0};
- int rc;
- int ldap_result_code= LDAP_SUCCESS;
- char *ldap_result_message= NULL;
- Slapi_DN sdn;
- char *e_uniqueid = NULL;
- Slapi_DN *nscpEntrySDN = NULL;
- int dblock_acquired= 0;
- Slapi_Operation *operation;
- CSN *opcsn = NULL;
- int is_fixup_operation = 0;
- int is_ruv = 0; /* True if the current entry is RUV */
- int is_replicated_operation= 0;
- int is_tombstone_entry = 0; /* True if the current entry is alreday a tombstone */
- int delete_tombstone_entry = 0; /* We must remove the given tombstone entry from the DB */
- int create_tombstone_entry = 0; /* We perform a "regular" LDAP delete but since we use */
- /* replication, we must create a new tombstone entry */
- int tombstone_in_cache = 0;
- entry_address *addr;
- int addordel_flags = 0; /* passed to index_addordel */
- char *entryusn_str = NULL;
- char *prev_entryusn_str = NULL;
- Slapi_Entry *orig_entry = NULL;
- slapi_pblock_get( pb, SLAPI_BACKEND, &be);
- slapi_pblock_get( pb, SLAPI_PLUGIN_PRIVATE, &li );
- slapi_pblock_get( pb, SLAPI_DELETE_TARGET, &dn );
- slapi_pblock_get( pb, SLAPI_TARGET_ADDRESS, &addr);
- slapi_pblock_get( pb, SLAPI_PARENT_TXN, (void**)&parent_txn );
- slapi_pblock_get( pb, SLAPI_OPERATION, &operation );
- slapi_pblock_get( pb, SLAPI_IS_REPLICATED_OPERATION, &is_replicated_operation );
-
- if (pb->pb_conn)
- {
- slapi_log_error (SLAPI_LOG_TRACE, "ldbm_back_delete", "enter conn=%" NSPRIu64 " op=%d\n", pb->pb_conn->c_connid, operation->o_opid);
- }
- is_fixup_operation = operation_is_flag_set(operation, OP_FLAG_REPL_FIXUP);
- is_ruv = operation_is_flag_set(operation, OP_FLAG_REPL_RUV);
- delete_tombstone_entry = operation_is_flag_set(operation, OP_FLAG_TOMBSTONE_ENTRY);
-
- inst = (ldbm_instance *) be->be_instance_info;
- slapi_sdn_init_dn_byref(&sdn,dn);
- dblayer_txn_init(li,&txn);
- /* The dblock serializes writes to the database,
- * which reduces deadlocking in the db code,
- * which means that we run faster.
- *
- * But, this lock is re-enterant for the fixup
- * operations that the URP code in the Replication
- * plugin generates.
- */
- if(SERIALLOCK(li) && !operation_is_flag_set(operation,OP_FLAG_REPL_FIXUP))
- {
- dblayer_lock_backend(be);
- dblock_acquired= 1;
- }
- /*
- * We are about to pass the last abandon test, so from now on we are
- * committed to finish this operation. Set status to "will complete"
- * before we make our last abandon check to avoid race conditions in
- * the code that processes abandon operations.
- */
- if (operation) {
- operation->o_status = SLAPI_OP_STATUS_WILL_COMPLETE;
- }
- if ( slapi_op_abandoned( pb ) ) {
- goto error_return;
- }
- /* find and lock the entry we are about to modify */
- if ( (e = find_entry2modify( pb, be, addr, NULL )) == NULL )
- {
- ldap_result_code= -1;
- goto error_return; /* error result sent by find_entry2modify() */
- }
- if ( slapi_entry_has_children( e->ep_entry ) )
- {
- ldap_result_code= LDAP_NOT_ALLOWED_ON_NONLEAF;
- goto error_return;
- }
- /* set entry in case be-preop plugins need to work on it (e.g., USN) */
- slapi_pblock_get( pb, SLAPI_DELETE_BEPREOP_ENTRY, &orig_entry );
- slapi_pblock_set( pb, SLAPI_DELETE_BEPREOP_ENTRY, e->ep_entry );
- /* Don't call pre-op for Tombstone entries */
- if (!delete_tombstone_entry)
- {
- /*
- * Some present state information is passed through the PBlock to the
- * backend pre-op plugin. To ensure a consistent snapshot of this state
- * we wrap the reading of the entry with the dblock.
- */
- ldap_result_code= get_copy_of_entry(pb, addr, &txn,
- SLAPI_DELETE_EXISTING_ENTRY, !is_replicated_operation);
- slapi_pblock_set(pb, SLAPI_RESULT_CODE, &ldap_result_code);
- if(plugin_call_plugins(pb, SLAPI_PLUGIN_BE_PRE_DELETE_FN)==-1)
- {
- /*
- * Plugin indicated some kind of failure,
- * or that this Operation became a No-Op.
- */
- slapi_pblock_get(pb, SLAPI_RESULT_CODE, &ldap_result_code);
- goto error_return;
- }
- /* the flag could be set in a preop plugin (e.g., USN) */
- delete_tombstone_entry = operation_is_flag_set(operation,
- OP_FLAG_TOMBSTONE_ENTRY);
- }
- slapi_pblock_set( pb, SLAPI_DELETE_BEPREOP_ENTRY, orig_entry );
- /*
- * Sanity check to avoid to delete a non-tombstone or to tombstone again
- * a tombstone entry. This should not happen (see bug 561003).
- */
- is_tombstone_entry = slapi_entry_flag_is_set(e->ep_entry, SLAPI_ENTRY_FLAG_TOMBSTONE);
- if (delete_tombstone_entry) {
- PR_ASSERT(is_tombstone_entry);
- if (!is_tombstone_entry) {
- slapi_log_error(SLAPI_LOG_FATAL, "ldbm_back_delete",
- "Attempt to delete a non-tombstone entry %s\n", dn);
- delete_tombstone_entry = 0;
- }
- } else {
- PR_ASSERT(!is_tombstone_entry);
- if (is_tombstone_entry) {
- slapi_log_error(SLAPI_LOG_FATAL, "ldbm_back_delete",
- "Attempt to Tombstone again a tombstone entry %s\n", dn);
- delete_tombstone_entry = 1;
- }
- }
- /*
- * If a CSN is set, we need to tombstone the entry,
- * rather than deleting it outright.
- */
- opcsn = operation_get_csn (operation);
- if (!delete_tombstone_entry)
- {
- /* If both USN and replication is enabled, csn set by replication
- * should be honored. */
- if ((opcsn == NULL || ldbm_usn_enabled(be)) &&
- !is_fixup_operation && operation->o_csngen_handler)
- {
- csn_free(&opcsn); /* free opcsn set by USN plugin, if any */
- /*
- * Current op is a user request. Opcsn will be assigned
- * by entry_assign_operation_csn() if the dn is in an
- * updatable replica.
- */
- opcsn = entry_assign_operation_csn ( pb, e->ep_entry, NULL );
- }
- if (opcsn != NULL)
- {
- if (!is_fixup_operation)
- {
- entry_set_maxcsn (e->ep_entry, opcsn);
- }
- /*
- * We are dealing with replication and if we haven't been called to
- * remove a tombstone, then it's because we want to create a new one.
- */
- if ( slapi_operation_get_replica_attr (pb, operation, "nsds5ReplicaTombstonePurgeInterval", &create_tombstone_entry) == 0)
- {
- create_tombstone_entry = (create_tombstone_entry < 0) ? 0 : 1;
- }
- }
- }
- #if DEBUG
- slapi_log_error(SLAPI_LOG_REPL, "ldbm_back_delete",
- "entry: %s - flags: delete %d is_tombstone_entry %d create %d \n",
- dn, delete_tombstone_entry, is_tombstone_entry, create_tombstone_entry);
- #endif
- /* Save away a copy of the entry, before modifications */
- slapi_pblock_set( pb, SLAPI_ENTRY_PRE_OP, slapi_entry_dup( e->ep_entry ));
- /* JCMACL - Shouldn't the access check be before the has children check...
- * otherwise we're revealing the fact that an entry exists and has children */
- ldap_result_code = plugin_call_acl_plugin (pb, e->ep_entry, NULL, NULL, SLAPI_ACL_DELETE,
- ACLPLUGIN_ACCESS_DEFAULT, &errbuf );
- if ( ldap_result_code != LDAP_SUCCESS )
- {
- ldap_result_message= errbuf;
- goto error_return;
- }
- /*
- * Get the entry's parent. We do this here because index_read
- * seems to deadlock the database when dblayer_txn_begin is
- * called.
- */
- if (!delete_tombstone_entry)
- {
- Slapi_DN parentsdn;
- slapi_sdn_init(&parentsdn);
- slapi_sdn_get_backend_parent(&sdn,&parentsdn,pb->pb_backend);
- if ( !slapi_sdn_isempty(&parentsdn) )
- {
- struct backentry *parent = NULL;
- entry_address parent_addr;
- parent_addr.dn = (char*)slapi_sdn_get_dn (&parentsdn);
- parent_addr.uniqueid = NULL;
- parent = find_entry2modify_only(pb,be,&parent_addr,&txn);
- if (NULL != parent) {
- int isglue;
- size_t haschildren = 0;
- /* Unfortunately findentry doesn't tell us whether it just didn't find the entry, or if
- there was an error, so we have to assume that the parent wasn't found */
- parent_found = 1;
- /* Modify the parent in memory */
- modify_init(&parent_modify_c,parent);
- retval = parent_update_on_childchange(&parent_modify_c,2,&haschildren); /* 2==delete */\
- /* The modify context now contains info needed later */
- if (0 != retval) {
- ldap_result_code= LDAP_OPERATIONS_ERROR;
- goto error_return;
- }
-
- /*
- * Replication urp_post_delete will delete the parent entry
- * if it is a glue entry without any more children.
- * Those urp condition checkings are done here to
- * save unnecessary entry dup.
- */
- isglue = slapi_entry_attr_hasvalue (parent_modify_c.new_entry->ep_entry,
- SLAPI_ATTR_OBJECTCLASS, "glue");
- if ( opcsn && parent_modify_c.new_entry && !haschildren && isglue)
- {
- slapi_pblock_set ( pb, SLAPI_DELETE_GLUE_PARENT_ENTRY,
- slapi_entry_dup (parent_modify_c.new_entry->ep_entry) );
- }
- }
- }
- slapi_sdn_done(&parentsdn);
- }
-
- if(create_tombstone_entry)
- {
- /*
- * The entry is not removed from the disk when we tombstone an
- * entry. We change the DN, add objectclass=tombstone, and record
- * the UniqueID of the parent entry.
- */
- const char *childuniqueid= slapi_entry_get_uniqueid(e->ep_entry);
- const char *parentuniqueid= NULL;
- char *tombstone_dn = compute_entry_tombstone_dn(slapi_entry_get_dn(e->ep_entry),
- childuniqueid);
- Slapi_Value *tomb_value;
- nscpEntrySDN = slapi_entry_get_sdn(e->ep_entry);
- /* Copy the entry unique_id for URP conflict checking */
- e_uniqueid = slapi_ch_strdup(childuniqueid);
- if(parent_modify_c.old_entry!=NULL)
- {
- /* The suffix entry has no parent */
- parentuniqueid= slapi_entry_get_uniqueid(parent_modify_c.old_entry->ep_entry);
- }
- tombstone = backentry_dup( e );
- slapi_entry_set_dn(tombstone->ep_entry,tombstone_dn); /* Consumes DN */
- /* Set tombstone flag on ep_entry */
- slapi_entry_set_flag(tombstone->ep_entry, SLAPI_ENTRY_FLAG_TOMBSTONE);
-
- if(parentuniqueid!=NULL)
- {
- /* The suffix entry has no parent */
- slapi_entry_add_string(tombstone->ep_entry, SLAPI_ATTR_VALUE_PARENT_UNIQUEID, parentuniqueid);
- }
- if(nscpEntrySDN!=NULL)
- {
- slapi_entry_add_string(tombstone->ep_entry, SLAPI_ATTR_NSCP_ENTRYDN, slapi_sdn_get_ndn(nscpEntrySDN));
- }
- tomb_value = slapi_value_new_string(SLAPI_ATTR_VALUE_TOMBSTONE);
- value_update_csn(tomb_value, CSN_TYPE_VALUE_UPDATED,
- operation_get_csn(operation));
- slapi_entry_add_value(tombstone->ep_entry, SLAPI_ATTR_OBJECTCLASS, tomb_value);
- slapi_value_free(&tomb_value);
-
- /* retrieve previous entry usn value, if any */
- prev_entryusn_str = slapi_entry_attr_get_charptr(tombstone->ep_entry,
- SLAPI_ATTR_ENTRYUSN_PREV);
- if (prev_entryusn_str) {
- /* discard the previous value from the tombstone entry */
- retval = slapi_entry_delete_string(tombstone->ep_entry,
- SLAPI_ATTR_ENTRYUSN_PREV, prev_entryusn_str);
- if (0 != retval) {
- LDAPDebug( LDAP_DEBUG_TRACE,
- "delete (deleting %s) failed, err=%d\n",
- SLAPI_ATTR_ENTRYUSN, retval, 0) ;
- }
- }
- /* XXXggood above used to be: slapi_entry_add_string(tombstone->ep_entry, SLAPI_ATTR_OBJECTCLASS, SLAPI_ATTR_VALUE_TOMBSTONE); */
- /* JCMREPL - Add a description of what's going on? */
- }
- /*
- * So, we believe that no code up till here actually added anything
- * to the persistent store. From now on, we're transacted
- */
-
- for (retry_count = 0; retry_count < RETRY_TIMES; retry_count++) {
- if (retry_count > 0) {
- dblayer_txn_abort(li,&txn);
- /* We're re-trying */
- LDAPDebug( LDAP_DEBUG_TRACE, "Delete Retrying Transaction\n", 0, 0, 0 );
- #ifndef LDBM_NO_BACKOFF_DELAY
- {
- PRIntervalTime interval;
- interval = PR_MillisecondsToInterval(slapi_rand() % 100);
- DS_Sleep(interval);
- }
- #endif
- }
- retval = dblayer_txn_begin(li,parent_txn,&txn);
- if (0 != retval) {
- if (LDBM_OS_ERR_IS_DISKFULL(retval)) disk_full = 1;
- ldap_result_code= LDAP_OPERATIONS_ERROR;
- goto error_return;
- }
- if(create_tombstone_entry)
- {
- /*
- * The entry is not removed from the disk when we tombstone an
- * entry. We change the DN, add objectclass=tombstone, and record
- * the UniqueID of the parent entry.
- */
- retval = id2entry_add( be, tombstone, &txn );
- if (DB_LOCK_DEADLOCK == retval) {
- LDAPDebug( LDAP_DEBUG_ARGS, "delete 1 DB_LOCK_DEADLOCK\n", 0, 0, 0 );
- /* Abort and re-try */
- continue;
- }
- if (0 != retval) {
- LDAPDebug( LDAP_DEBUG_ANY, "id2entry_add failed, err=%d %s\n",
- retval, (msg = dblayer_strerror( retval )) ? msg : "", 0 );
- if (LDBM_OS_ERR_IS_DISKFULL(retval)) disk_full = 1;
- ldap_result_code= LDAP_OPERATIONS_ERROR;
- goto error_return;
- }
- tombstone_in_cache = 1;
- }
- else
- {
- /* delete the entry from disk */
- retval = id2entry_delete( be, e, &txn );
- if (DB_LOCK_DEADLOCK == retval)
- {
- LDAPDebug( LDAP_DEBUG_ARGS, "delete 2 DEADLOCK\n", 0, 0, 0 );
- /* Retry txn */
- continue;
- }
- if (retval != 0 ) {
- if (retval == DB_RUNRECOVERY ||
- LDBM_OS_ERR_IS_DISKFULL(retval)) {
- disk_full = 1;
- }
- ldap_result_code= LDAP_OPERATIONS_ERROR;
- goto error_return;
- }
- }
- /* delete from attribute indexes */
- addordel_flags = BE_INDEX_DEL|BE_INDEX_PRESENCE|BE_INDEX_EQUALITY;
- if (delete_tombstone_entry)
- {
- addordel_flags |= BE_INDEX_TOMBSTONE; /* tell index code we are deleting a tombstone */
- }
- retval = index_addordel_entry( be, e, addordel_flags, &txn );
- if (DB_LOCK_DEADLOCK == retval)
- {
- LDAPDebug( LDAP_DEBUG_ARGS, "delete 1 DEADLOCK\n", 0, 0, 0 );
- /* Retry txn */
- continue;
- }
- if (retval != 0) {
- LDAPDebug( LDAP_DEBUG_TRACE, "index_del_entry failed\n", 0, 0, 0 );
- ldap_result_code= LDAP_OPERATIONS_ERROR;
- goto error_return;
- }
- if(create_tombstone_entry)
- {
- /*
- * The tombstone entry is removed from all attribute indexes
- * above, but we want it to remain in the nsUniqueID and nscpEntryDN indexes
- * and for objectclass=tombstone.
- */
- retval = index_addordel_string(be, SLAPI_ATTR_OBJECTCLASS,
- SLAPI_ATTR_VALUE_TOMBSTONE,
- tombstone->ep_id,BE_INDEX_ADD, &txn);
- if (DB_LOCK_DEADLOCK == retval) {
- LDAPDebug( LDAP_DEBUG_ARGS,
- "delete (adding %s) DB_LOCK_DEADLOCK\n",
- SLAPI_ATTR_VALUE_TOMBSTONE, 0, 0 );
- /* Retry txn */
- continue;
- }
- if (0 != retval) {
- LDAPDebug( LDAP_DEBUG_TRACE,
- "delete (adding %s) failed, err=%d %s\n",
- SLAPI_ATTR_VALUE_TOMBSTONE, retval,
- (msg = dblayer_strerror( retval )) ? msg : "" );
- if (LDBM_OS_ERR_IS_DISKFULL(retval)) disk_full = 1;
- ldap_result_code= LDAP_OPERATIONS_ERROR;
- goto error_return;
- }
- retval = index_addordel_string(be, SLAPI_ATTR_UNIQUEID,
- slapi_entry_get_uniqueid(tombstone->ep_entry),
- tombstone->ep_id,BE_INDEX_ADD,&txn);
- if (DB_LOCK_DEADLOCK == retval) {
- LDAPDebug( LDAP_DEBUG_ARGS,
- "delete (adding %s) DB_LOCK_DEADLOCK\n",
- SLAPI_ATTR_UNIQUEID, 0, 0 );
- /* Retry txn */
- continue;
- }
- if (0 != retval) {
- LDAPDebug( LDAP_DEBUG_TRACE,
- "delete (adding %s) failed, err=%d %s\n",
- SLAPI_ATTR_UNIQUEID, retval,
- (msg = dblayer_strerror( retval )) ? msg : "" );
- if (LDBM_OS_ERR_IS_DISKFULL(retval)) disk_full = 1;
- ldap_result_code= LDAP_OPERATIONS_ERROR;
- goto error_return;
- }
- retval = index_addordel_string(be, SLAPI_ATTR_NSCP_ENTRYDN,
- slapi_sdn_get_ndn(nscpEntrySDN),
- tombstone->ep_id, BE_INDEX_ADD, &txn);
- if (DB_LOCK_DEADLOCK == retval) {
- LDAPDebug( LDAP_DEBUG_ARGS,
- "delete (adding %s) DB_LOCK_DEADLOCK\n",
- SLAPI_ATTR_NSCP_ENTRYDN, 0, 0 );
- /* Retry txn */
- continue;
- }
- if (0 != retval) {
- LDAPDebug( LDAP_DEBUG_TRACE,
- "delete (adding %s) failed, err=%d %s\n",
- SLAPI_ATTR_NSCP_ENTRYDN, retval,
- (msg = dblayer_strerror( retval )) ? msg : "" );
- if (LDBM_OS_ERR_IS_DISKFULL(retval)) disk_full = 1;
- ldap_result_code= LDAP_OPERATIONS_ERROR;
- goto error_return;
- }
- /* add a new usn to the entryusn index */
- entryusn_str = slapi_entry_attr_get_charptr(tombstone->ep_entry,
- SLAPI_ATTR_ENTRYUSN);
- if (entryusn_str) {
- retval = index_addordel_string(be, SLAPI_ATTR_ENTRYUSN,
- entryusn_str, tombstone->ep_id, BE_INDEX_ADD, &txn);
- slapi_ch_free_string(&entryusn_str);
- if (DB_LOCK_DEADLOCK == retval) {
- LDAPDebug( LDAP_DEBUG_ARGS,
- "delete (adding %s) DB_LOCK_DEADLOCK\n",
- SLAPI_ATTR_ENTRYUSN, 0, 0 );
- /* Retry txn */
- continue;
- }
- if (0 != retval) {
- LDAPDebug( LDAP_DEBUG_TRACE,
- "delete (adding %s) failed, err=%d %s\n",
- SLAPI_ATTR_ENTRYUSN, retval,
- (msg = dblayer_strerror( retval )) ? msg : "" );
- if (LDBM_OS_ERR_IS_DISKFULL(retval)) disk_full = 1;
- ldap_result_code= LDAP_OPERATIONS_ERROR;
- goto error_return;
- }
- }
- /* delete a previous value (if it exists) from the entryusn index */
- if (prev_entryusn_str) {
- retval = index_addordel_string(be, SLAPI_ATTR_ENTRYUSN,
- prev_entryusn_str, tombstone->ep_id,
- BE_INDEX_DEL|BE_INDEX_EQUALITY, &txn);
- slapi_ch_free_string(&prev_entryusn_str);
- if (DB_LOCK_DEADLOCK == retval) {
- LDAPDebug( LDAP_DEBUG_ARGS,
- "delete (deleting %s) DB_LOCK_DEADLOCK\n",
- SLAPI_ATTR_ENTRYUSN, 0, 0 );
- /* Retry txn */
- continue;
- }
- if (0 != retval) {
- LDAPDebug( LDAP_DEBUG_TRACE,
- "delete (deleting %s) failed, err=%d %s\n",
- SLAPI_ATTR_ENTRYUSN, retval,
- (msg = dblayer_strerror( retval )) ? msg : "" );
- if (LDBM_OS_ERR_IS_DISKFULL(retval)) disk_full = 1;
- ldap_result_code= LDAP_OPERATIONS_ERROR;
- goto error_return;
- }
- }
- } /* create_tombstone_entry */
- else if (delete_tombstone_entry)
- {
- /*
- * We need to remove the Tombstone entry from the remaining indexes:
- * objectclass=nsTombstone, nsUniqueID, nscpEntryDN
- */
- char *nscpedn = NULL;
- retval = index_addordel_string(be, SLAPI_ATTR_OBJECTCLASS,
- SLAPI_ATTR_VALUE_TOMBSTONE, e->ep_id,
- BE_INDEX_DEL, &txn);
- if (DB_LOCK_DEADLOCK == retval) {
- LDAPDebug( LDAP_DEBUG_ARGS,
- "delete (deleting %s) DB_LOCK_DEADLOCK\n",
- SLAPI_ATTR_VALUE_TOMBSTONE, 0, 0 );
- /* Retry txn */
- continue;
- }
- if (0 != retval) {
- LDAPDebug( LDAP_DEBUG_TRACE,
- "delete (deleting %s) failed, err=%d %s\n",
- SLAPI_ATTR_VALUE_TOMBSTONE, retval,
- (msg = dblayer_strerror( retval )) ? msg : "" );
- if (LDBM_OS_ERR_IS_DISKFULL(retval)) disk_full = 1;
- ldap_result_code= LDAP_OPERATIONS_ERROR;
- goto error_return;
- }
- retval = index_addordel_string(be, SLAPI_ATTR_UNIQUEID,
- slapi_entry_get_uniqueid(e->ep_entry),
- e->ep_id, BE_INDEX_DEL, &txn);
- if (DB_LOCK_DEADLOCK == retval) {
- LDAPDebug( LDAP_DEBUG_ARGS,
- "delete (deleting %s) DB_LOCK_DEADLOCK\n",
- SLAPI_ATTR_UNIQUEID, 0, 0 );
- /* Retry txn */
- continue;
- }
- if (0 != retval) {
- LDAPDebug( LDAP_DEBUG_TRACE,
- "delete (deleting %s) failed, err=%d %s\n",
- SLAPI_ATTR_UNIQUEID, retval,
- (msg = dblayer_strerror( retval )) ? msg : "" );
- if (LDBM_OS_ERR_IS_DISKFULL(retval)) disk_full = 1;
- ldap_result_code= LDAP_OPERATIONS_ERROR;
- goto error_return;
- }
- nscpedn = slapi_entry_attr_get_charptr(e->ep_entry,
- SLAPI_ATTR_NSCP_ENTRYDN);
- if (nscpedn) {
- retval = index_addordel_string(be, SLAPI_ATTR_NSCP_ENTRYDN,
- nscpedn, e->ep_id, BE_INDEX_DEL, &txn);
- slapi_ch_free((void **)&nscpedn);
- if (DB_LOCK_DEADLOCK == retval) {
- LDAPDebug( LDAP_DEBUG_ARGS,
- "delete (deleting %s) DB_LOCK_DEADLOCK\n",
- SLAPI_ATTR_NSCP_ENTRYDN, 0, 0 );
- /* Retry txn */
- continue;
- }
- if (0 != retval) {
- LDAPDebug( LDAP_DEBUG_TRACE,
- "delete (deleting %s) failed, err=%d %s\n",
- SLAPI_ATTR_NSCP_ENTRYDN, retval,
- (msg = dblayer_strerror( retval )) ? msg : "" );
- if (LDBM_OS_ERR_IS_DISKFULL(retval)) disk_full = 1;
- ldap_result_code= LDAP_OPERATIONS_ERROR;
- goto error_return;
- }
- }
- /* delete usn from the entryusn index */
- entryusn_str = slapi_entry_attr_get_charptr(e->ep_entry,
- SLAPI_ATTR_ENTRYUSN);
- if (entryusn_str) {
- retval = index_addordel_string(be, SLAPI_ATTR_ENTRYUSN,
- entryusn_str, e->ep_id,
- BE_INDEX_DEL|BE_INDEX_EQUALITY, &txn);
- slapi_ch_free_string(&entryusn_str);
- if (DB_LOCK_DEADLOCK == retval) {
- LDAPDebug( LDAP_DEBUG_ARGS,
- "delete (deleting %s) DB_LOCK_DEADLOCK\n",
- SLAPI_ATTR_ENTRYUSN, 0, 0 );
- /* Retry txn */
- continue;
- }
- if (0 != retval) {
- LDAPDebug( LDAP_DEBUG_TRACE,
- "delete (deleting %s) failed, err=%d %s\n",
- SLAPI_ATTR_ENTRYUSN, retval,
- (msg = dblayer_strerror( retval )) ? msg : "" );
- if (LDBM_OS_ERR_IS_DISKFULL(retval)) disk_full = 1;
- ldap_result_code= LDAP_OPERATIONS_ERROR;
- goto error_return;
- }
- }
- } /* delete_tombstone_entry */
-
- if (parent_found) {
- /* Push out the db modifications from the parent entry */
- retval = modify_update_all(be,pb,&parent_modify_c,&txn);
- if (DB_LOCK_DEADLOCK == retval)
- {
- LDAPDebug( LDAP_DEBUG_ARGS, "del 4 DEADLOCK\n", 0, 0, 0 );
- /* Retry txn */
- continue;
- }
- if (0 != retval) {
- LDAPDebug( LDAP_DEBUG_TRACE, "delete 3 BAD, err=%d %s\n",
- retval, (msg = dblayer_strerror( retval )) ? msg : "", 0 );
- if (LDBM_OS_ERR_IS_DISKFULL(retval)) disk_full = 1;
- ldap_result_code= LDAP_OPERATIONS_ERROR;
- goto error_return;
- }
- }
- /*
- * first check if searchentry needs to be removed
- * Remove the entry from the Virtual List View indexes.
- */
- if (!delete_tombstone_entry && !is_ruv &&
- !vlv_delete_search_entry(pb,e->ep_entry,inst)) {
- retval = vlv_update_all_indexes(&txn, be, pb, e, NULL);
- if (DB_LOCK_DEADLOCK == retval)
- {
- LDAPDebug( LDAP_DEBUG_ARGS, "delete DEADLOCK vlv_update_index\n", 0, 0, 0 );
- /* Retry txn */
- continue;
- }
- if (retval != 0 ) {
- if (LDBM_OS_ERR_IS_DISKFULL(retval)) disk_full = 1;
- ldap_result_code= LDAP_OPERATIONS_ERROR;
- goto error_return;
- }
- }
- if (retval == 0 ) {
- break;
- }
- }
- if (retry_count == RETRY_TIMES) {
- /* Failed */
- LDAPDebug( LDAP_DEBUG_ANY, "Retry count exceeded in delete\n", 0, 0, 0 );
- ldap_result_code= LDAP_OPERATIONS_ERROR;
- goto error_return;
- }
- retval = dblayer_txn_commit(li,&txn);
- if (0 != retval)
- {
- if (LDBM_OS_ERR_IS_DISKFULL(retval)) disk_full = 1;
- ldap_result_code= LDAP_OPERATIONS_ERROR;
- goto error_return;
- }
- /* delete from cache and clean up */
- cache_remove(&inst->inst_cache, e);
- cache_unlock_entry( &inst->inst_cache, e );
- cache_return( &inst->inst_cache, &e );
- if (parent_found)
- {
- /* Replace the old parent entry with the newly modified one */
- modify_switch_entries( &parent_modify_c,be);
- }
-
- rc= 0;
- goto common_return;
- error_return:
- if (e!=NULL) {
- cache_unlock_entry( &inst->inst_cache, e );
- cache_return( &inst->inst_cache, &e );
- }
- if (tombstone_in_cache)
- {
- cache_remove( &inst->inst_cache, tombstone );
- }
- else
- {
- backentry_free( &tombstone );
- }
- if (retval == DB_RUNRECOVERY) {
- dblayer_remember_disk_filled(li);
- ldbm_nasty("Delete",79,retval);
- disk_full = 1;
- }
- if (disk_full) {
- rc= return_on_disk_full(li);
- goto diskfull_return;
- }
- else
- rc= SLAPI_FAIL_GENERAL;
- /* It is specifically OK to make this call even when no transaction was in progress */
- dblayer_txn_abort(li,&txn); /* abort crashes in case disk full */
-
- common_return:
- if (tombstone_in_cache)
- {
- cache_return( &inst->inst_cache, &tombstone );
- }
-
- /*
- * The bepostop is called even if the operation fails,
- * but not if the operation is purging tombstones.
- */
- if (!delete_tombstone_entry) {
- plugin_call_plugins (pb, SLAPI_PLUGIN_BE_POST_DELETE_FN);
- }
- diskfull_return:
- if(ldap_result_code!=-1)
- {
- slapi_send_ldap_result( pb, ldap_result_code, NULL, ldap_result_message, 0, NULL );
- }
- modify_term(&parent_modify_c,be);
- if(dblock_acquired)
- {
- dblayer_unlock_backend(be);
- }
- if (rc == 0 && opcsn && !is_fixup_operation && !delete_tombstone_entry)
- {
- /* URP Naming Collision
- * When an entry is deleted by a replicated delete operation
- * we must check for entries that have had a naming collision
- * with this entry. Now that this name has been given up, one
- * of those entries can take over the name.
- */
- slapi_pblock_set(pb, SLAPI_URP_NAMING_COLLISION_DN, slapi_ch_strdup (dn));
- }
- done_with_pblock_entry(pb, SLAPI_DELETE_EXISTING_ENTRY);
- slapi_ch_free((void**)&errbuf);
- slapi_sdn_done(&sdn);
- slapi_ch_free_string(&e_uniqueid);
- if (pb->pb_conn)
- {
- slapi_log_error (SLAPI_LOG_TRACE, "ldbm_back_delete", "leave conn=%" NSPRIu64 " op=%d\n", pb->pb_conn->c_connid, operation->o_opid);
- }
- return rc;
- }
|