dse_replace_entry(struct dse *pdse, Slapi_Entry *e, int write_file, int use_lock)
{
    int rc = -1;
    if (NULL != e) {
        struct dse_node *n = dse_node_new(e);
        if (use_lock && pdse->dse_rwlock)
            slapi_rwlock_wrlock(pdse->dse_rwlock);
        rc = avl_insert(&(pdse->dse_tree), n, entry_dn_cmp, dupentry_replace);
        if (write_file)
            dse_write_file_nolock(pdse);
        /* If the entry was replaced i.e. not added as a new entry, we need to
           free the old data, which is set in dupentry_replace */
        if (DSE_ENTRY_WAS_REPLACED == rc) {
            dse_node_delete(&n);
            rc = 0; /* for return to caller */
        }
        if (use_lock && pdse->dse_rwlock)
            slapi_rwlock_unlock(pdse->dse_rwlock);
    }
    return rc;
}
dse_replace_entry(struct dse *pdse, Slapi_Entry *e, int write_file, int use_lock)
{
    int rc = -1;
    if (NULL != e) {
        struct dse_node *n = dse_node_new(e);
        if (use_lock && pdse->dse_rwlock)
            slapi_rwlock_wrlock(pdse->dse_rwlock);
        rc = avl_insert(&(pdse->dse_tree), n, entry_dn_cmp, dupentry_replace);
        if (write_file)
            dse_write_file_nolock(pdse);
         
        if (DSE_ENTRY_WAS_REPLACED == rc) {
            dse_node_delete(&n);
            rc = 0;  
        }
        if (use_lock && pdse->dse_rwlock)
            slapi_rwlock_unlock(pdse->dse_rwlock);
    }
    return rc;
}