3 * back-bdb Context CSN Management Routines
5 /* Copyright (c) 2003 by International Business Machines, Inc.
7 * International Business Machines, Inc. (hereinafter called IBM) grants
8 * permission under its copyrights to use, copy, modify, and distribute this
9 * Software with or without fee, provided that the above copyright notice and
10 * all paragraphs of this notice appear in all copies, and that the name of IBM
11 * not be used in connection with the marketing of any product incorporating
12 * the Software or modifications thereof, without specific, written prior
15 * THE SOFTWARE IS PROVIDED "AS IS", AND IBM DISCLAIMS ALL WARRANTIES,
16 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
17 * PARTICULAR PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL,
18 * DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER ARISING
19 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE, EVEN
20 * IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES.
27 #include <ac/string.h>
40 EntryInfo **suffix_ei,
46 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
47 struct berval ctxcsn_rdn = { 0, NULL };
48 struct berval ctxcsn_ndn = { 0, NULL };
49 EntryInfo *ctxcsn_ei = NULL;
51 struct berval *max_committed_csn = NULL;
61 ber_str2bv( "cn=ldapsync", strlen("cn=ldapsync"), 0, &ctxcsn_rdn );
62 build_new_dn( &ctxcsn_ndn, &op->o_bd->be_nsuffix[0], &ctxcsn_rdn );
64 rc = bdb_dn2entry( op, tid, &ctxcsn_ndn, &ctxcsn_ei,
65 0, locker, &ctxcsn_lock );
68 *ctxcsn_e = ctxcsn_ei->bei_e;
69 bdb_cache_entry_db_relock( bdb->bi_dbenv, locker, ctxcsn_ei, 1, 0, &ctxcsn_lock );
72 max_committed_csn = slap_get_commit_csn( op );
74 if ( max_committed_csn == NULL )
75 return BDB_CSN_COMMIT;
82 rs->sr_err = LDAP_OTHER;
83 rs->sr_text = "context csn not present";
86 attr_delete( &(*ctxcsn_e)->e_attrs, slap_schema.si_ad_contextCSN );
87 attr_merge_normalize_one( *ctxcsn_e, slap_schema.si_ad_contextCSN,
88 max_committed_csn, NULL );
89 ret = bdb_id2entry_update( op->o_bd, tid, *ctxcsn_e );
93 case DB_LOCK_DEADLOCK :
94 case DB_LOCK_NOTGRANTED :
98 rs->sr_text = "context csn update failed";
101 ret = bdb_index_entry_add( op, tid, *ctxcsn_e );
105 case DB_LOCK_DEADLOCK :
106 case DB_LOCK_NOTGRANTED :
109 rs->sr_err = LDAP_OTHER;
110 rs->sr_text = "context csn indexing failed";
111 return BDB_CSN_ABORT;
116 if ( op->o_tag == LDAP_REQ_ADD && !be_issuffix( op->o_bd, &op->oq_add.rs_e->e_nname )) {
117 rc = bdb_dn2entry( op, tid, &op->o_bd->be_nsuffix[0], suffix_ei,
118 0, locker, &suffix_lock );
119 } else if ( op->o_tag != LDAP_REQ_ADD && !be_issuffix( op->o_bd, &e->e_nname )) {
120 rc = bdb_dn2entry( op, tid, &op->o_bd->be_nsuffix[0], suffix_ei,
121 0, locker, &suffix_lock );
126 /* This serializes add. But this case is very rare : only once. */
127 rs->sr_err = bdb_next_id( op->o_bd, NULL, &ctxcsn_id );
128 if ( rs->sr_err != 0 ) {
130 LDAP_LOG ( OPERATION, ERR,
131 "bdb_add: next_id failed (%d)\n", rs->sr_err, 0, 0 );
133 Debug( LDAP_DEBUG_TRACE,
134 "bdb_add: next_id failed (%d)\n", rs->sr_err, 0, 0 );
136 rs->sr_err = LDAP_OTHER;
137 rs->sr_text = "internal error";
138 return BDB_CSN_ABORT;
141 *ctxcsn_e = slap_create_context_csn_entry( op->o_bd, max_committed_csn );
142 (*ctxcsn_e)->e_id = ctxcsn_id;
144 ret = bdb_dn2id_add( op, tid, *suffix_ei, *ctxcsn_e );
148 case DB_LOCK_DEADLOCK :
149 case DB_LOCK_NOTGRANTED :
152 rs->sr_err = LDAP_OTHER;
153 rs->sr_text = "context csn exists before contex prefix does";
154 return BDB_CSN_ABORT;
156 rs->sr_err = LDAP_OTHER;
157 rs->sr_text = "context csn store failed";
158 return BDB_CSN_ABORT;
160 ret = bdb_id2entry_add( op->o_bd, tid, *ctxcsn_e );
164 case DB_LOCK_DEADLOCK :
165 case DB_LOCK_NOTGRANTED :
168 rs->sr_err = LDAP_OTHER;
169 rs->sr_text = "context csn store failed";
170 return BDB_CSN_ABORT;
172 ret = bdb_index_entry_add( op, tid, *ctxcsn_e );
176 case DB_LOCK_DEADLOCK :
177 case DB_LOCK_NOTGRANTED :
180 rs->sr_err = LDAP_OTHER;
181 rs->sr_text = "context csn indexing failed";
182 return BDB_CSN_ABORT;
185 case DB_LOCK_DEADLOCK:
186 case DB_LOCK_NOTGRANTED:
190 rs->sr_text = "ldap server busy";
191 return BDB_CSN_ABORT;
193 rs->sr_err = LDAP_OTHER;
194 rs->sr_text = "internal error";
195 return BDB_CSN_ABORT;
198 return BDB_CSN_COMMIT;
201 slap_rewind_commit_csn( op );
202 return BDB_CSN_RETRY;