| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361 |
- /** 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.
- * Copyright (C) 2009 Hewlett-Packard Development Company, L.P.
- * All rights reserved.
- * END COPYRIGHT BLOCK **/
- #ifdef HAVE_CONFIG_H
- # include <config.h>
- #endif
-
- /* delete.c - ldbm backend delete routine */
- #include "back-ldbm.h"
- #define DEL_SET_ERROR(rc, error, count) \
- { \
- (rc) = (error); \
- (count) = RETRY_TIMES; /* otherwise, the transaction may not be aborted */ \
- }
- int
- ldbm_back_delete( Slapi_PBlock *pb )
- {
- backend *be;
- ldbm_instance *inst = NULL;
- struct ldbminfo *li = NULL;
- struct backentry *e = NULL;
- struct backentry *tombstone = NULL;
- struct backentry *tmptombstone = NULL;
- struct backentry *original_tombstone = NULL;
- const 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;
- int ruv_c_init = 0;
- modify_context parent_modify_c = {0};
- modify_context ruv_c = {0};
- int rc = 0;
- int ldap_result_code= LDAP_SUCCESS;
- char *ldap_result_message = NULL;
- Slapi_DN *sdnp = NULL;
- char *e_uniqueid = NULL;
- Slapi_DN nscpEntrySDN;
- 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 remove_e_from_cache = 0;
- entry_address *addr;
- int addordel_flags = 0; /* passed to index_addordel */
- char *entryusn_str = NULL;
- Slapi_Entry *orig_entry = NULL;
- Slapi_DN parentsdn;
- int opreturn = 0;
- int free_delete_existing_entry = 0;
- ID ep_id = 0;
- ID tomb_ep_id = 0;
- slapi_pblock_get( pb, SLAPI_BACKEND, &be);
- slapi_pblock_get( pb, SLAPI_PLUGIN_PRIVATE, &li );
- slapi_pblock_get( pb, SLAPI_DELETE_TARGET_SDN, &sdnp );
- slapi_pblock_get( pb, SLAPI_TARGET_ADDRESS, &addr);
- slapi_pblock_get( pb, SLAPI_TXN, (void**)&parent_txn );
- slapi_pblock_get( pb, SLAPI_OPERATION, &operation );
- slapi_pblock_get( pb, SLAPI_IS_REPLICATED_OPERATION, &is_replicated_operation );
-
- slapi_sdn_init(&nscpEntrySDN);
- slapi_sdn_init(&parentsdn);
- /* dblayer_txn_init needs to be called before "goto error_return" */
- dblayer_txn_init(li,&txn);
- /* the calls to perform searches require the parent txn if any
- so set txn to the parent_txn until we begin the child transaction */
- if (parent_txn) {
- txn.back_txn_txn = parent_txn;
- } else {
- parent_txn = txn.back_txn_txn;
- slapi_pblock_set( pb, SLAPI_TXN, parent_txn );
- }
- 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);
- }
- if ((NULL == addr) || (NULL == sdnp))
- {
- /* retval is -1 */
- slapi_log_error(SLAPI_LOG_FATAL, "ldbm_back_delete",
- "Either of DELETE_TARGET_SDN or TARGET_ADDRESS is NULL.\n");
- goto error_return;
- }
- dn = slapi_sdn_get_dn(sdnp);
- ldap_result_code = slapi_dn_syntax_check(pb, dn, 1);
- if (ldap_result_code)
- {
- ldap_result_code = LDAP_INVALID_DN_SYNTAX;
- slapi_pblock_get(pb, SLAPI_PB_RESULT_TEXT, &ldap_result_message);
- /* retval is -1 */
- goto error_return;
- }
- 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;
- /* 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 ) ) {
- /* retval is -1 */
- goto error_return;
- }
- /* find and lock the entry we are about to modify */
- /*
- * A corner case:
- * If a conflict occurred in a MMR topology, a replicated delete
- * op from another master could target a conflict entry; while the
- * corresponding entry on this server could have been already
- * deleted. That is, the entry 'e' found with "addr" is a tomb-
- * stone. If it is the case, we need to back off.
- */
- if ( (e = find_entry2modify( pb, be, addr, &txn )) == NULL )
- {
- ldap_result_code= LDAP_NO_SUCH_OBJECT;
- /* retval is -1 */
- LDAPDebug0Args(LDAP_DEBUG_BACKLDBM, "ldbm_back_delete: Deleting entry is already deleted.\n");
- goto error_return; /* error result sent by find_entry2modify() */
- }
- ep_id = e->ep_id;
- retval = slapi_entry_has_children(e->ep_entry);
- if (retval) {
- ldap_result_code= LDAP_NOT_ALLOWED_ON_NONLEAF;
- slapi_log_error(SLAPI_LOG_FATAL, "ldbm_back_delete", "Deleting entry %s has %d children.\n",
- slapi_entry_get_dn(e->ep_entry), retval);
- retval = -1;
- goto error_return;
- }
- /* Don't call pre-op for Tombstone entries */
- if (!delete_tombstone_entry)
- {
- int rc = 0;
- /*
- * 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);
- free_delete_existing_entry = 1;
- if(ldap_result_code==LDAP_OPERATIONS_ERROR ||
- ldap_result_code==LDAP_INVALID_DN_SYNTAX)
- {
- /* restore original entry so the front-end delete code can free it */
- /* retval is -1 */
- goto error_return;
- }
- slapi_pblock_set(pb, SLAPI_RESULT_CODE, &ldap_result_code);
- rc = plugin_call_plugins(pb, SLAPI_PLUGIN_BE_PRE_DELETE_FN);
- if (rc == -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);
- if (!ldap_result_code) {
- if (LDAP_ALREADY_EXISTS == ldap_result_code) {
- /*
- * The target entry is already a tombstone.
- * We need to treat this as a success,
- * but we need to remove the entry e from the entry cache.
- */
- remove_e_from_cache = 1;
- ldap_result_code = LDAP_SUCCESS;
- }
- slapi_pblock_get(pb, SLAPI_RESULT_CODE, &ldap_result_code);
- }
- /* restore original entry so the front-end delete code can free it */
- slapi_pblock_get( pb, SLAPI_PLUGIN_OPRETURN, &opreturn );
- if (!opreturn) {
- slapi_pblock_set( pb, SLAPI_PLUGIN_OPRETURN, ldap_result_code ? &ldap_result_code : &rc );
- }
- /* retval is -1 */
- 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);
- }
- /*
- * 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) {
- 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 {
- 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 ((opcsn == NULL) && !is_fixup_operation && operation->o_csngen_handler)
- {
- /*
- * 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 (create_tombstone_entry && is_tombstone_entry) {
- slapi_log_error(SLAPI_LOG_FATAL, "ldbm_back_delete",
- "Attempt to convert a tombstone entry %s to tombstone\n", dn);
- retval = -1;
- ldap_result_code = LDAP_UNWILLING_TO_PERFORM;
- goto error_return;
- }
- #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;
- /* retval is -1 */
- 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.
- */
- slapi_sdn_get_backend_parent_ext(sdnp, &parentsdn, pb->pb_backend, is_tombstone_entry);
- if ( !slapi_sdn_isempty(&parentsdn) )
- {
- struct backentry *parent = NULL;
- char *pid_str = slapi_entry_attr_get_charptr(e->ep_entry, LDBM_PARENTID_STR);
- if (pid_str) {
- /* First, try to get the direct parent. */
- /*
- * Although a rare case, multiple parents from repl conflict could exist.
- * In such case, if a parent entry is found just by parentsdn
- * (find_entry2modify_only_ext), a wrong parent could be found,
- * and numsubordinate count could get confused.
- */
- ID pid;
- int cache_retry_count = 0;
- int cache_retry = 0;
- pid = (ID)strtol(pid_str, (char **)NULL, 10);
- slapi_ch_free_string(&pid_str);
- /*
- * Its possible that the parent entry retrieved from the cache in id2entry
- * could be removed before we lock it, because tombstone purging updated/replaced
- * the parent. If we fail to lock the entry, just try again.
- */
- while(1){
- parent = id2entry(be, pid ,&txn, &retval);
- if (parent && (cache_retry = cache_lock_entry(&inst->inst_cache, parent))) {
- /* Failed to obtain parent entry's entry lock */
- if(cache_retry == RETRY_CACHE_LOCK &&
- cache_retry_count < LDBM_CACHE_RETRY_COUNT)
- {
- /* try again */
- DS_Sleep(PR_MillisecondsToInterval(100));
- cache_retry_count++;
- continue;
- }
- retval = -1;
- CACHE_RETURN(&(inst->inst_cache), &parent);
- goto error_return;
- } else {
- /* entry locked, move on */
- break;
- }
- }
- }
- if (NULL == parent) {
- entry_address parent_addr;
- if (is_tombstone_entry) {
- parent_addr.uniqueid = slapi_entry_attr_get_charptr(e->ep_entry, SLAPI_ATTR_VALUE_PARENT_UNIQUEID);
- } else {
- parent_addr.uniqueid = NULL;
- }
- parent_addr.sdn = &parentsdn;
- parent = find_entry2modify_only_ext(pb, be, &parent_addr, TOMBSTONE_INCLUDED, &txn);
- }
- if (parent) {
- int isglue;
- size_t haschildren = 0;
- int op = PARENTUPDATE_DEL;
- /* 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);
- if (create_tombstone_entry) {
- op |= PARENTUPDATE_CREATE_TOMBSTONE;
- } else if (delete_tombstone_entry) {
- op |= PARENTUPDATE_DELETE_TOMBSTONE;
- }
- retval = parent_update_on_childchange(&parent_modify_c, op, &haschildren);
- /* The modify context now contains info needed later */
- if (0 != retval) {
- ldap_result_code= LDAP_OPERATIONS_ERROR;
- slapi_sdn_done(&parentsdn);
- 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) );
- }
- }
- }
-
- 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 *edn = slapi_entry_get_dn(e->ep_entry);
- char *tombstone_dn;
- Slapi_Value *tomb_value;
- if (slapi_entry_attr_hasvalue(e->ep_entry, SLAPI_ATTR_OBJECTCLASS, SLAPI_ATTR_VALUE_TOMBSTONE) &&
- slapi_is_special_rdn(edn, RDN_IS_TOMBSTONE)) {
- LDAPDebug1Arg(LDAP_DEBUG_ANY, "Turning a tombstone into a tombstone! \"%s\"\n", edn);
- ldap_result_code= LDAP_OPERATIONS_ERROR;
- retval = -1;
- goto error_return;
- }
- if (!childuniqueid) {
- slapi_log_error(SLAPI_LOG_FATAL, "ldbm_back_delete",
- "No nsUniqueId in the entry \"%s\"; e: 0x%p, cache_state: 0x%x, refcnt: %d\n",
- edn, e, e->ep_state, e->ep_refcnt);
- ldap_result_code = LDAP_OPERATIONS_ERROR;
- retval = -1;
- goto error_return;
- }
- if ((0 == PL_strncmp(edn + sizeof(SLAPI_ATTR_UNIQUEID), childuniqueid, strlen(childuniqueid))) &&
- (*(edn + SLAPI_ATTR_UNIQUEID_LENGTH + slapi_uniqueIDSize() + 1/*=*/) == ',')) {
- /* The DN already starts with "nsuniqueid=...," */
- tombstone_dn = slapi_ch_strdup(edn);
- } else {
- tombstone_dn = compute_entry_tombstone_dn(edn, childuniqueid);
- }
- slapi_sdn_set_ndn_byval(&nscpEntrySDN, slapi_sdn_get_ndn(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 );
- tomb_ep_id = tombstone->ep_id;
- slapi_entry_set_dn(tombstone->ep_entry,tombstone_dn); /* Consumes DN */
- if (entryrdn_get_switch()) /* subtree-rename: on */
- {
- Slapi_RDN *srdn = slapi_entry_get_srdn(tombstone->ep_entry);
- char *tombstone_rdn =
- compute_entry_tombstone_rdn(slapi_entry_get_rdn_const(e->ep_entry),
- childuniqueid);
- /* e_srdn has "uniaqueid=..., <ORIG RDN>" */
- slapi_rdn_replace_rdn(srdn, tombstone_rdn);
- slapi_ch_free_string(&tombstone_rdn);
- }
- /* 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);
- }
- 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);
- /* 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? */
- if ( (original_tombstone = backentry_dup( tombstone )) == NULL ) {
- ldap_result_code= LDAP_OPERATIONS_ERROR;
- retval = -1;
- goto error_return;
- }
- }
- /*
- * So, we believe that no code up till here actually added anything
- * to the persistent store. From now on, we're transacted
- */
-
- txn.back_txn_txn = NULL; /* ready to create the child transaction */
- for (retry_count = 0; retry_count < RETRY_TIMES; retry_count++) {
- if (txn.back_txn_txn && (txn.back_txn_txn != parent_txn)) {
- Slapi_Entry *ent = NULL;
- dblayer_txn_abort(li,&txn);
- slapi_pblock_set(pb, SLAPI_TXN, parent_txn);
- /* reset original entry */
- slapi_pblock_get( pb, SLAPI_DELETE_EXISTING_ENTRY, &ent );
- if (ent && free_delete_existing_entry) {
- slapi_entry_free(ent);
- slapi_pblock_set( pb, SLAPI_DELETE_EXISTING_ENTRY, NULL );
- }
- slapi_pblock_set( pb, SLAPI_DELETE_EXISTING_ENTRY, slapi_entry_dup( e->ep_entry ) );
- free_delete_existing_entry = 1; /* must free the dup */
- if (create_tombstone_entry) {
- slapi_sdn_set_ndn_byval(&nscpEntrySDN, slapi_sdn_get_ndn(slapi_entry_get_sdn(e->ep_entry)));
- }
- /* reset tombstone entry */
- if (original_tombstone) {
- /* must duplicate tombstone before returning it to cache,
- * which could free the entry. */
- if ( (tmptombstone = backentry_dup( original_tombstone )) == NULL ) {
- ldap_result_code= LDAP_OPERATIONS_ERROR;
- goto error_return;
- }
- if (cache_is_in_cache(&inst->inst_cache, tombstone)) {
- CACHE_REMOVE(&inst->inst_cache, tombstone);
- }
- CACHE_RETURN(&inst->inst_cache, &tombstone);
- tombstone = original_tombstone;
- original_tombstone = tmptombstone;
- tmptombstone = NULL;
- }
- if (ruv_c_init) {
- /* reset the ruv txn stuff */
- modify_term(&ruv_c, be);
- ruv_c_init = 0;
- }
- /* We're re-trying */
- LDAPDebug0Args(LDAP_DEBUG_BACKLDBM,
- "Delete Retrying Transaction\n");
- #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;
- }
- /* stash the transaction */
- slapi_pblock_set(pb, SLAPI_TXN, txn.back_txn_txn);
- /* call the transaction pre delete plugins just after creating
- * the transaction */
- /* these should not need to modify the entry to be deleted -
- if for some reason they ever do, do not use e->ep_entry since
- it could be in the cache and referenced by other search threads -
- instead, have them modify a copy of the entry */
- retval = plugin_call_plugins(pb, SLAPI_PLUGIN_BE_TXN_PRE_DELETE_FN);
- if (retval) {
- LDAPDebug1Arg( LDAP_DEBUG_TRACE,
- "SLAPI_PLUGIN_BE_TXN_PRE_DELETE_FN plugin "
- "returned error code %d\n", retval );
- if (!ldap_result_code) {
- slapi_pblock_get(pb, SLAPI_RESULT_CODE, &ldap_result_code);
- }
- if (!opreturn) {
- slapi_pblock_get( pb, SLAPI_PLUGIN_OPRETURN, &opreturn );
- }
- if (!opreturn) {
- slapi_pblock_set( pb, SLAPI_PLUGIN_OPRETURN,
- ldap_result_code ?
- &ldap_result_code : &retval );
- }
- goto error_return;
- }
- if(create_tombstone_entry)
- {
- slapi_pblock_get( pb, SLAPI_DELETE_BEPREOP_ENTRY, &orig_entry );
- /* this is ok because no other threads should be accessing
- the tombstone entry */
- slapi_pblock_set( pb, SLAPI_DELETE_BEPREOP_ENTRY,
- tombstone->ep_entry );
- rc = plugin_call_plugins(pb,
- SLAPI_PLUGIN_BE_TXN_PRE_DELETE_TOMBSTONE_FN);
- if (rc == -1) {
- /*
- * Plugin indicated some kind of failure,
- * or that this Operation became a No-Op.
- */
- if (!ldap_result_code) {
- slapi_pblock_get(pb, SLAPI_RESULT_CODE, &ldap_result_code);
- }
- /* restore original entry so the front-end delete code
- * can free it */
- slapi_pblock_get( pb, SLAPI_PLUGIN_OPRETURN, &opreturn );
- if (!opreturn) {
- slapi_pblock_set( pb, SLAPI_PLUGIN_OPRETURN,
- ldap_result_code ?
- &ldap_result_code : &rc );
- }
- /* retval is -1 */
- goto error_return;
- }
- slapi_pblock_set( pb, SLAPI_DELETE_BEPREOP_ENTRY, orig_entry );
- orig_entry = NULL;
- /*
- * 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.
- */
- /* Note: cache_add (tombstone) fails since the original entry having
- * the same ID is already in the cache. Thus, we have to add it
- * tentatively for now, then cache_add again when the original
- * entry is removed from the cache.
- */
- retval = cache_add_tentative(&inst->inst_cache, tombstone, NULL);
- if (0 > retval) {
- LDAPDebug2Args(LDAP_DEBUG_ANY,
- "tombstone entry %s failed to add to the cache: %d\n",
- slapi_entry_get_dn(tombstone->ep_entry), retval);
- if (LDBM_OS_ERR_IS_DISKFULL(retval)) disk_full = 1;
- DEL_SET_ERROR(ldap_result_code,
- LDAP_OPERATIONS_ERROR, retry_count);
- goto error_return;
- }
- retval = id2entry_add( be, tombstone, &txn );
- if (DB_LOCK_DEADLOCK == retval) {
- LDAPDebug( LDAP_DEBUG_BACKLDBM, "delete 1 DB_LOCK_DEADLOCK\n", 0, 0, 0 );
- /* Abort and re-try */
- continue;
- }
- if (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;
- DEL_SET_ERROR(ldap_result_code, LDAP_OPERATIONS_ERROR, retry_count);
- goto error_return;
- }
- }
- else
- {
- /* delete the entry from disk */
- retval = id2entry_delete( be, e, &txn );
- if (DB_LOCK_DEADLOCK == retval)
- {
- LDAPDebug( LDAP_DEBUG_BACKLDBM, "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;
- }
- DEL_SET_ERROR(ldap_result_code,
- LDAP_OPERATIONS_ERROR, retry_count);
- 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_BACKLDBM, "delete 1 DEADLOCK\n", 0, 0, 0 );
- /* Retry txn */
- continue;
- }
- if (retval) {
- LDAPDebug(LDAP_DEBUG_ANY, "index_del_entry(%s, 0x%x) failed (%d)\n",
- slapi_entry_get_dn(e->ep_entry), addordel_flags, retval);
- DEL_SET_ERROR(ldap_result_code, LDAP_OPERATIONS_ERROR, retry_count);
- 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_BACKLDBM,
- "delete (adding %s) DB_LOCK_DEADLOCK\n",
- SLAPI_ATTR_VALUE_TOMBSTONE, 0, 0 );
- /* Retry txn */
- continue;
- }
- if (0 != retval) {
- LDAPDebug( LDAP_DEBUG_ANY,
- "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;
- DEL_SET_ERROR(ldap_result_code,
- LDAP_OPERATIONS_ERROR, retry_count);
- 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_BACKLDBM,
- "delete (adding %s) DB_LOCK_DEADLOCK\n",
- SLAPI_ATTR_UNIQUEID, 0, 0 );
- /* Retry txn */
- continue;
- }
- if (0 != retval) {
- LDAPDebug( LDAP_DEBUG_ANY,
- "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;
- DEL_SET_ERROR(ldap_result_code,
- LDAP_OPERATIONS_ERROR, retry_count);
- 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_BACKLDBM,
- "delete (adding %s) DB_LOCK_DEADLOCK\n",
- SLAPI_ATTR_NSCP_ENTRYDN, 0, 0 );
- /* Retry txn */
- continue;
- }
- if (0 != retval) {
- LDAPDebug( LDAP_DEBUG_ANY,
- "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;
- DEL_SET_ERROR(ldap_result_code,
- LDAP_OPERATIONS_ERROR, retry_count);
- 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_BACKLDBM,
- "delete (adding %s) DB_LOCK_DEADLOCK\n",
- SLAPI_ATTR_ENTRYUSN, 0, 0 );
- /* Retry txn */
- continue;
- }
- if (0 != retval) {
- LDAPDebug( LDAP_DEBUG_ANY,
- "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;
- DEL_SET_ERROR(ldap_result_code,
- LDAP_OPERATIONS_ERROR, retry_count);
- goto error_return;
- }
- }
- if (entryrdn_get_switch()) /* subtree-rename: on */
- {
- Slapi_Attr *attr;
- Slapi_Value **svals;
- /* To maintain tombstonenumsubordinates,
- * parentid is needed for tombstone, as well. */
- slapi_entry_attr_find(tombstone->ep_entry, LDBM_PARENTID_STR,
- &attr);
- if (attr) {
- svals = attr_get_present_values(attr);
- retval = index_addordel_values_sv(be, LDBM_PARENTID_STR,
- svals, NULL, e->ep_id,
- BE_INDEX_ADD, &txn);
- if (DB_LOCK_DEADLOCK == retval) {
- LDAPDebug0Args( LDAP_DEBUG_BACKLDBM,
- "delete (updating " LDBM_PARENTID_STR ") DB_LOCK_DEADLOCK\n");
- /* Retry txn */
- continue;
- }
- if ( retval ) {
- LDAPDebug( LDAP_DEBUG_ANY,
- "delete (deleting %s) failed, err=%d %s\n",
- LDBM_PARENTID_STR, retval,
- (msg = dblayer_strerror( retval )) ? msg : "" );
- if (LDBM_OS_ERR_IS_DISKFULL(retval)) disk_full = 1;
- DEL_SET_ERROR(ldap_result_code,
- LDAP_OPERATIONS_ERROR, retry_count);
- goto error_return;
- }
- }
- #if 0 /* The entryrdn element is already deleted in the index_addordel_entry */
- retval = entryrdn_index_entry(be, e, BE_INDEX_DEL, &txn);
- if (DB_LOCK_DEADLOCK == retval) {
- LDAPDebug0Args( LDAP_DEBUG_BACKLDBM,
- "delete (deleting entryrdn) DB_LOCK_DEADLOCK\n");
- /* Retry txn */
- continue;
- }
- if (retval) {
- LDAPDebug2Args( LDAP_DEBUG_ANY,
- "delete (deleting entryrdn) failed, err=%d %s\n",
- retval,
- (msg = dblayer_strerror( retval )) ? msg : "" );
- if (LDBM_OS_ERR_IS_DISKFULL(retval)) disk_full = 1;
- DEL_SET_ERROR(ldap_result_code,
- LDAP_OPERATIONS_ERROR, retry_count);
- goto error_return;
- }
- #endif
- retval = entryrdn_index_entry(be, tombstone, BE_INDEX_ADD, &txn);
- if (DB_LOCK_DEADLOCK == retval) {
- LDAPDebug0Args( LDAP_DEBUG_BACKLDBM,
- "adding (adding tombstone entryrdn) DB_LOCK_DEADLOCK\n");
- /* Retry txn */
- continue;
- }
- if (retval) {
- LDAPDebug(LDAP_DEBUG_ANY,
- "adding (adding tombstone entryrdn %s) failed, err=%d %s\n",
- slapi_entry_get_dn(tombstone->ep_entry),
- retval, (msg = dblayer_strerror( retval )) ? msg : "" );
- if (LDBM_OS_ERR_IS_DISKFULL(retval)) disk_full = 1;
- if (LDBM_OS_ERR_IS_DISKFULL(retval)) disk_full = 1;
- DEL_SET_ERROR(ldap_result_code, LDAP_OPERATIONS_ERROR, retry_count);
- 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_BACKLDBM,
- "delete (deleting %s) DB_LOCK_DEADLOCK\n",
- SLAPI_ATTR_VALUE_TOMBSTONE, 0, 0 );
- /* Retry txn */
- continue;
- }
- if (0 != retval) {
- LDAPDebug( LDAP_DEBUG_ANY,
- "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;
- DEL_SET_ERROR(ldap_result_code,
- LDAP_OPERATIONS_ERROR, retry_count);
- 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_BACKLDBM,
- "delete (deleting %s) DB_LOCK_DEADLOCK\n",
- SLAPI_ATTR_UNIQUEID, 0, 0 );
- /* Retry txn */
- continue;
- }
- if (0 != retval) {
- LDAPDebug( LDAP_DEBUG_ANY,
- "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;
- DEL_SET_ERROR(ldap_result_code,
- LDAP_OPERATIONS_ERROR, retry_count);
- 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_BACKLDBM,
- "delete (deleting %s) DB_LOCK_DEADLOCK\n",
- SLAPI_ATTR_NSCP_ENTRYDN, 0, 0 );
- /* Retry txn */
- continue;
- }
- if (0 != retval) {
- LDAPDebug( LDAP_DEBUG_ANY,
- "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;
- DEL_SET_ERROR(ldap_result_code,
- LDAP_OPERATIONS_ERROR, retry_count);
- 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_BACKLDBM,
- "delete (deleting %s) DB_LOCK_DEADLOCK\n",
- SLAPI_ATTR_ENTRYUSN, 0, 0 );
- /* Retry txn */
- continue;
- }
- if (0 != retval) {
- LDAPDebug( LDAP_DEBUG_ANY,
- "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;
- DEL_SET_ERROR(ldap_result_code,
- LDAP_OPERATIONS_ERROR, retry_count);
- goto error_return;
- }
- }
- if (entryrdn_get_switch()) /* subtree-rename: on */
- {
- retval = entryrdn_index_entry(be, e, BE_INDEX_DEL, &txn);
- if (DB_LOCK_DEADLOCK == retval) {
- LDAPDebug0Args( LDAP_DEBUG_BACKLDBM,
- "delete (deleting entryrdn) DB_LOCK_DEADLOCK\n");
- /* Retry txn */
- continue;
- }
- if (0 != retval) {
- LDAPDebug2Args( LDAP_DEBUG_ANY,
- "delete (deleting entryrdn) failed, err=%d %s\n",
- retval,
- (msg = dblayer_strerror( retval )) ? msg : "" );
- if (LDBM_OS_ERR_IS_DISKFULL(retval)) disk_full = 1;
- DEL_SET_ERROR(ldap_result_code,
- LDAP_OPERATIONS_ERROR, retry_count);
- 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_BACKLDBM, "del 4 DEADLOCK\n", 0, 0, 0 );
- /* Retry txn */
- continue;
- }
- if (0 != retval) {
- LDAPDebug( LDAP_DEBUG_ANY, "delete 3 BAD, err=%d %s\n",
- retval, (msg = dblayer_strerror( retval )) ? msg : "", 0 );
- if (LDBM_OS_ERR_IS_DISKFULL(retval)) disk_full = 1;
- DEL_SET_ERROR(ldap_result_code,
- LDAP_OPERATIONS_ERROR, retry_count);
- 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_BACKLDBM, "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;
- DEL_SET_ERROR(ldap_result_code,
- LDAP_OPERATIONS_ERROR, retry_count);
- goto error_return;
- }
- }
- if (!is_ruv && !is_fixup_operation && !delete_tombstone_entry) {
- ruv_c_init = ldbm_txn_ruv_modify_context( pb, &ruv_c );
- if (-1 == ruv_c_init) {
- LDAPDebug( LDAP_DEBUG_ANY,
- "ldbm_back_delete: ldbm_txn_ruv_modify_context "
- "failed to construct RUV modify context\n",
- 0, 0, 0);
- ldap_result_code= LDAP_OPERATIONS_ERROR;
- retval = 0;
- goto error_return;
- }
- }
- if (ruv_c_init) {
- retval = modify_update_all( be, pb, &ruv_c, &txn );
- if (DB_LOCK_DEADLOCK == retval) {
- /* Abort and re-try */
- continue;
- }
- if (0 != retval) {
- LDAPDebug( LDAP_DEBUG_ANY,
- "modify_update_all 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;
- }
- }
- 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_BUSY;
- retval = -1;
- goto error_return;
- }
- if (create_tombstone_entry) {
- retval = cache_replace(&inst->inst_cache, e, tombstone);
- if (retval) {
- LDAPDebug(LDAP_DEBUG_CACHE, "ldbm_back_delete: cache_replace failed (%d): %s --> %s\n",
- retval, slapi_entry_get_dn(e->ep_entry), slapi_entry_get_dn(tombstone->ep_entry));
- retval= -1;
- goto error_return;
- }
- }
- /* call the transaction post delete plugins just before the commit */
- if (plugin_call_plugins(pb, SLAPI_PLUGIN_BE_TXN_POST_DELETE_FN)) {
- LDAPDebug0Args( LDAP_DEBUG_ANY, "SLAPI_PLUGIN_BE_TXN_POST_DELETE_FN plugin "
- "returned error code\n" );
- if (!ldap_result_code) {
- slapi_pblock_get(pb, SLAPI_RESULT_CODE, &ldap_result_code);
- }
- if (!ldap_result_code) {
- LDAPDebug0Args( LDAP_DEBUG_ANY, "SLAPI_PLUGIN_BE_TXN_POST_DELETE_FN plugin "
- "returned error code but did not set SLAPI_RESULT_CODE\n" );
- ldap_result_code = LDAP_OPERATIONS_ERROR;
- slapi_pblock_set(pb, SLAPI_RESULT_CODE, &ldap_result_code);
- }
- if (!opreturn) {
- slapi_pblock_get( pb, SLAPI_PLUGIN_OPRETURN, &opreturn );
- }
- if (!retval) {
- retval = -1;
- }
- if (!opreturn) {
- slapi_pblock_set( pb, SLAPI_PLUGIN_OPRETURN, &retval );
- }
- goto error_return;
- }
- retval = dblayer_txn_commit(li,&txn);
- /* after commit - txn is no longer valid - replace SLAPI_TXN with parent */
- slapi_pblock_set(pb, SLAPI_TXN, parent_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 */
- if (e) {
- if(!create_tombstone_entry){
- struct backentry *old_e = e;
- e = cache_find_id(&inst->inst_cache,e->ep_id);
- if(e != old_e){
- cache_unlock_entry(&inst->inst_cache, old_e);
- CACHE_RETURN(&inst->inst_cache, &old_e);
- } else {
- CACHE_RETURN(&inst->inst_cache, &e);
- }
- }
- /*
- * e could have been replaced by cache_find_id(), recheck if it's NULL
- * before trying to unlock it, etc.
- */
- if (e) {
- if (cache_is_in_cache(&inst->inst_cache, e)) {
- ep_id = e->ep_id; /* Otherwise, e might have been freed. */
- CACHE_REMOVE(&inst->inst_cache, e);
- }
- cache_unlock_entry(&inst->inst_cache, e);
- CACHE_RETURN(&inst->inst_cache, &e);
- /*
- * e is unlocked and no longer in cache.
- * It could be freed at any moment.
- */
- e = NULL;
- }
- if (entryrdn_get_switch() && ep_id) { /* subtree-rename: on */
- /* since the op was successful, delete the tombstone dn from the dn cache */
- struct backdn *bdn = dncache_find_id(&inst->inst_dncache, ep_id);
- if (bdn) { /* in the dncache, remove it. */
- CACHE_REMOVE(&inst->inst_dncache, bdn);
- CACHE_RETURN(&inst->inst_dncache, &bdn);
- }
- }
- }
- if (ruv_c_init) {
- if (modify_switch_entries(&ruv_c, be) != 0 ) {
- ldap_result_code= LDAP_OPERATIONS_ERROR;
- LDAPDebug( LDAP_DEBUG_ANY,
- "ldbm_back_delete: modify_switch_entries failed\n", 0, 0, 0);
- retval = -1;
- goto error_return;
- }
- }
- 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 (tombstone) {
- if (cache_is_in_cache(&inst->inst_cache, tombstone)) {
- tomb_ep_id = tombstone->ep_id;
- }
- if (entryrdn_get_switch() && tomb_ep_id) { /* subtree-rename: on */
- /* since the op was successful, add the addingentry's dn to the dn cache */
- struct backdn *bdn = dncache_find_id(&inst->inst_dncache, tomb_ep_id);
- if (bdn) { /* already in the dncache. Delete it. */
- CACHE_REMOVE(&inst->inst_dncache, bdn);
- CACHE_RETURN(&inst->inst_dncache, &bdn);
- }
- }
- if (cache_is_in_cache(&inst->inst_cache, tombstone)) {
- CACHE_REMOVE( &inst->inst_cache, tombstone );
- }
- CACHE_RETURN( &inst->inst_cache, &tombstone );
- tombstone = NULL;
- }
- 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 safer not to abort when the transaction is not started. */
- if (txn.back_txn_txn && (txn.back_txn_txn != parent_txn)) {
- /* make sure SLAPI_RESULT_CODE and SLAPI_PLUGIN_OPRETURN are set */
- int val = 0;
- slapi_pblock_get(pb, SLAPI_RESULT_CODE, &val);
- if (!val) {
- if (!ldap_result_code) {
- ldap_result_code = LDAP_OPERATIONS_ERROR;
- }
- slapi_pblock_set(pb, SLAPI_RESULT_CODE, &ldap_result_code);
- }
- slapi_pblock_get( pb, SLAPI_PLUGIN_OPRETURN, &val );
- if (!val) {
- opreturn = retval;
- slapi_pblock_set( pb, SLAPI_PLUGIN_OPRETURN, &retval );
- }
- /* call the transaction post delete plugins just before the commit */
- if (plugin_call_plugins(pb, SLAPI_PLUGIN_BE_TXN_POST_DELETE_FN)) {
- LDAPDebug1Arg( LDAP_DEBUG_ANY, "SLAPI_PLUGIN_BE_TXN_POST_DELETE_FN plugin "
- "returned error code %d\n", retval );
- if (!ldap_result_code) {
- slapi_pblock_get(pb, SLAPI_RESULT_CODE, &ldap_result_code);
- }
- if (!opreturn) {
- slapi_pblock_get( pb, SLAPI_PLUGIN_OPRETURN, &opreturn );
- }
- if (!opreturn) {
- slapi_pblock_set( pb, SLAPI_PLUGIN_OPRETURN, ldap_result_code ? &ldap_result_code : &retval );
- }
- slapi_pblock_get(pb, SLAPI_PB_RESULT_TEXT, &ldap_result_message);
- }
- dblayer_txn_abort(li,&txn); /* abort crashes in case disk full */
- /* txn is no longer valid - reset the txn pointer to the parent */
- slapi_pblock_set(pb, SLAPI_TXN, parent_txn);
- }
-
- common_return:
- if (orig_entry) {
- /* NOTE: #define SLAPI_DELETE_BEPREOP_ENTRY SLAPI_ENTRY_PRE_OP */
- /* so if orig_entry is NULL, we will wipe out SLAPI_ENTRY_PRE_OP
- for the post op plugins */
- slapi_pblock_set( pb, SLAPI_DELETE_BEPREOP_ENTRY, orig_entry );
- }
- if (inst && tombstone) {
- if ((0 == retval) && entryrdn_get_switch()) { /* subtree-rename: on */
- /* since the op was successful, add the addingentry's dn to the dn cache */
- struct backdn *bdn = dncache_find_id(&inst->inst_dncache, tombstone->ep_id);
- if (bdn) { /* already in the dncache */
- CACHE_RETURN(&inst->inst_dncache, &bdn);
- } else { /* not in the dncache yet */
- Slapi_DN *tombstonesdn = slapi_sdn_dup(slapi_entry_get_sdn(tombstone->ep_entry));
- if (tombstonesdn) {
- bdn = backdn_init(tombstonesdn, tombstone->ep_id, 0);
- if (bdn) {
- CACHE_ADD( &inst->inst_dncache, bdn, NULL );
- slapi_log_error(SLAPI_LOG_CACHE, "ldbm_back_delete",
- "set %s to dn cache\n", slapi_sdn_get_dn(tombstonesdn));
- CACHE_RETURN(&inst->inst_dncache, &bdn);
- }
- }
- }
- }
- CACHE_RETURN( &inst->inst_cache, &tombstone );
- tombstone = NULL;
- }
-
- /* result code could be used in the bepost plugin functions. */
- slapi_pblock_set(pb, SLAPI_RESULT_CODE, &ldap_result_code);
- /*
- * 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);
- }
- if (e) {
- if (cache_is_in_cache(&inst->inst_cache, e)) {
- if (remove_e_from_cache) {
- /* The entry is already transformed to a tombstone. */
- CACHE_REMOVE( &inst->inst_cache, e );
- }
- }
- cache_unlock_entry( &inst->inst_cache, e );
- CACHE_RETURN( &inst->inst_cache, &e );
- /*
- * e is unlocked and no longer in cache.
- * It could be freed at any moment.
- */
- e = NULL;
- }
- if (ruv_c_init) {
- modify_term(&ruv_c, be);
- }
- 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));
- }
- if (free_delete_existing_entry) {
- done_with_pblock_entry(pb, SLAPI_DELETE_EXISTING_ENTRY);
- } else { /* owned by someone else */
- slapi_pblock_set(pb, SLAPI_DELETE_EXISTING_ENTRY, NULL);
- }
- backentry_free(&original_tombstone);
- backentry_free(&tmptombstone);
- slapi_ch_free((void**)&errbuf);
- slapi_sdn_done(&nscpEntrySDN);
- slapi_ch_free_string(&e_uniqueid);
- slapi_sdn_done(&parentsdn);
- 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;
- }
|