From: Kurt Zeilenga Date: Sat, 2 Feb 2002 03:28:32 +0000 (+0000) Subject: Add cache txn_prepare code based upon submission (ITS#1575) by X-Git-Tag: OPENLDAP_REL_ENG_2_1_BP~103 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=1bf1621efec8f4c65f53179e4aecc45195106c6e;p=openldap Add cache txn_prepare code based upon submission (ITS#1575) by Jong Hyuk Choi . Needs a bit more work (GID should be globally unique). --- diff --git a/servers/slapd/back-bdb/add.c b/servers/slapd/back-bdb/add.c index 7da553e59f..f203434b9a 100644 --- a/servers/slapd/back-bdb/add.c +++ b/servers/slapd/back-bdb/add.c @@ -13,6 +13,8 @@ #include "back-bdb.h" #include "external.h" +static char bdb_gid[DB_XIDDATASIZE]; + int bdb_add( BackendDB *be, @@ -69,7 +71,7 @@ bdb_add( if( 0 ) { retry: /* transaction retry */ - rc = txn_abort( ltid ); + rc = TXN_ABORT( ltid ); ltid = NULL; op->o_private = NULL; if( rc != 0 ) { @@ -81,7 +83,7 @@ retry: /* transaction retry */ } /* begin transaction */ - rc = txn_begin( bdb->bi_dbenv, NULL, <id, + rc = TXN_BEGIN( bdb->bi_dbenv, NULL, <id, bdb->bi_db_opflags ); text = NULL; if( rc != 0 ) { @@ -351,40 +353,50 @@ retry: /* transaction retry */ } if( op->o_noop ) { - rc = txn_abort( ltid ); + if (( rc=TXN_ABORT( ltid )) != 0 ) { + text = "txn_abort (no-op) failed"; + } else { + rc = LDAP_SUCCESS; + } + } else { - rc = txn_commit( ltid, 0 ); + if (( rc=TXN_PREPARE( ltid, bdb_gid )) != 0 ) { + text = "txn_prepare failed"; + + } else { + if ( bdb_cache_add_entry_rw(&bdb->bi_cache, + e, CACHE_WRITE_LOCK) != 0 ) + { + if(( rc=TXN_ABORT( ltid )) != 0 ) { + text = "cache add & txn_abort failed"; + } else { + rc = LDAP_OTHER; + text = "cache add failed"; + } + } else { + if(( rc=TXN_COMMIT( ltid, 0 )) != 0 ) { + text = "txn_commit failed"; + } else { + rc = LDAP_SUCCESS; + } + } + } } + ltid = NULL; op->o_private = NULL; - if( rc != 0 ) { - Debug( LDAP_DEBUG_TRACE, - "bdb_add: txn_%s failed: %s (%d)\n", - op->o_noop ? "abort (no-op)" : "commit", - db_strerror(rc), rc ); - rc = LDAP_OTHER; - text = "commit failed"; - - } else { - /* add the entry to the entry cache */ - /* we should add to cache only upon free of txn-abort */ - if (!op->o_noop && - bdb_cache_add_entry_rw(&bdb->bi_cache, e, CACHE_WRITE_LOCK) != 0) - { - text = "cache add failed"; - goto return_results; - } - - Debug( LDAP_DEBUG_TRACE, - "bdb_add: added%s id=%08lx dn=\"%s\"\n", - op->o_noop ? " (no-op)" : "", - e->e_id, e->e_dn ); - rc = LDAP_SUCCESS; + if (rc == LDAP_SUCCESS) { + Debug(LDAP_DEBUG_TRACE, "bdb_add: added%s id=%08lx dn=\"%s\"\n", + op->o_noop ? " (no-op)" : "", e->e_id, e->e_dn ); text = NULL; + bdb_cache_entry_commit( e ); + } + else { + Debug( LDAP_DEBUG_TRACE, "bdb_add: %s : %s (%d)\n", + text, db_strerror(rc), rc ); + rc = LDAP_OTHER; } - - bdb_cache_entry_commit( e ); return_results: send_ldap_result( conn, op, rc, @@ -399,7 +411,7 @@ return_results: done: if( ltid != NULL ) { - txn_abort( ltid ); + TXN_ABORT( ltid ); op->o_private = NULL; } diff --git a/servers/slapd/back-bdb/back-bdb.h b/servers/slapd/back-bdb/back-bdb.h index e0d6cd7842..8a8417a327 100644 --- a/servers/slapd/back-bdb/back-bdb.h +++ b/servers/slapd/back-bdb/back-bdb.h @@ -149,15 +149,23 @@ struct bdb_op_info { }; #if DB_VERSION_MAJOR < 4 -#define TXN_CHECKPOINT(env, k, m, f) txn_checkpoint(env, k, m, f) -#define TXN_ID(txn) txn_id(txn) -#define LOCK_DETECT(env, f, t, a) lock_detect(env, f, t, a) -#define LOCK_GET(env, i, f, o, m, l) lock_get(env, i, f, o, m, l) +#define LOCK_DETECT(env,f,t,a) lock_detect(env, f, t, a) +#define LOCK_GET(env,i,f,o,m,l) lock_get(env, i, f, o, m, l) +#define TXN_CHECKPOINT(env,k,m,f) txn_checkpoint(env, k, m, f) +#define TXN_BEGIN(env,p,t,f) txn_begin((env), p, t, f) +#define TXN_PREPARE(txn,gid) txn_prepare((txn), (gid)) +#define TXN_COMMIT(txn,f) txn_commit((txn), (f)) +#define TXN_ABORT(txn) txn_abort((txn)) +#define TXN_ID(txn) txn_id(txn) #else -#define TXN_CHECKPOINT(env, k, m, f) (env)->txn_checkpoint(env, k, m, f) -#define TXN_ID(txn) (txn)->id(txn) -#define LOCK_DETECT(env, f, t, a) (env)->lock_detect(env, f, t, a) -#define LOCK_GET(env, i, f, o, m, l) (env)->lock_get(env, i, f, o, m, l) +#define LOCK_DETECT(env,f,t,a) (env)->lock_detect(env, f, t, a) +#define LOCK_GET(env,i,f,o,m,l) (env)->lock_get(env, i, f, o, m, l) +#define TXN_CHECKPOINT(env,k,m,f) (env)->txn_checkpoint(env, k, m, f) +#define TXN_BEGIN(env,p,t,f) (env)->txn_begin((env), p, t, f) +#define TXN_PREPARE(txn,g) (txn)->prepare((txn), (g)) +#define TXN_COMMIT(txn,f) (txn)->commit((txn), (f)) +#define TXN_ABORT(txn) (txn)->abort((txn)) +#define TXN_ID(txn) (txn)->id(txn) #endif LDAP_END_DECL diff --git a/servers/slapd/back-bdb/delete.c b/servers/slapd/back-bdb/delete.c index 24d4f2ecb4..a469fb1265 100644 --- a/servers/slapd/back-bdb/delete.c +++ b/servers/slapd/back-bdb/delete.c @@ -47,7 +47,7 @@ retry: /* transaction retry */ } Debug( LDAP_DEBUG_TRACE, "==> bdb_delete: retrying...\n", 0, 0, 0 ); - rc = txn_abort( ltid ); + rc = TXN_ABORT( ltid ); ltid = NULL; op->o_private = NULL; if( rc != 0 ) { @@ -59,7 +59,7 @@ retry: /* transaction retry */ } /* begin transaction */ - rc = txn_begin( bdb->bi_dbenv, NULL, <id, + rc = TXN_BEGIN( bdb->bi_dbenv, NULL, <id, bdb->bi_db_opflags ); text = NULL; if( rc != 0 ) { @@ -332,9 +332,9 @@ retry: /* transaction retry */ #endif if( op->o_noop ) { - rc = txn_abort( ltid ); + rc = TXN_ABORT( ltid ); } else { - rc = txn_commit( ltid, 0 ); + rc = TXN_COMMIT( ltid, 0 ); } ltid = NULL; op->o_private = NULL; @@ -372,7 +372,7 @@ done: } if( ltid != NULL ) { - txn_abort( ltid ); + TXN_ABORT( ltid ); op->o_private = NULL; } diff --git a/servers/slapd/back-bdb/modify.c b/servers/slapd/back-bdb/modify.c index d9dc92be05..bd82300d89 100644 --- a/servers/slapd/back-bdb/modify.c +++ b/servers/slapd/back-bdb/modify.c @@ -204,7 +204,7 @@ retry: /* transaction retry */ } Debug(LDAP_DEBUG_TRACE, "bdb_modify: retrying...\n", 0, 0, 0); - rc = txn_abort( ltid ); + rc = TXN_ABORT( ltid ); ltid = NULL; op->o_private = NULL; if( rc != 0 ) { @@ -216,7 +216,7 @@ retry: /* transaction retry */ } /* begin transaction */ - rc = txn_begin( bdb->bi_dbenv, NULL, <id, + rc = TXN_BEGIN( bdb->bi_dbenv, NULL, <id, bdb->bi_db_opflags ); text = NULL; if( rc != 0 ) { @@ -328,9 +328,9 @@ retry: /* transaction retry */ } if( op->o_noop ) { - rc = txn_abort( ltid ); + rc = TXN_ABORT( ltid ); } else { - rc = txn_commit( ltid, 0 ); + rc = TXN_COMMIT( ltid, 0 ); } ltid = NULL; op->o_private = NULL; @@ -364,7 +364,7 @@ return_results: done: if( ltid != NULL ) { - txn_abort( ltid ); + TXN_ABORT( ltid ); op->o_private = NULL; } diff --git a/servers/slapd/back-bdb/modrdn.c b/servers/slapd/back-bdb/modrdn.c index 29888ae7d0..914eae9927 100644 --- a/servers/slapd/back-bdb/modrdn.c +++ b/servers/slapd/back-bdb/modrdn.c @@ -13,19 +13,20 @@ #include "back-bdb.h" #include "external.h" +static char bdb_gid[DB_XIDDATASIZE]; + int bdb_modrdn( - Backend *be, - Connection *conn, - Operation *op, - struct berval *dn, - struct berval *ndn, - struct berval *newrdn, - struct berval *nnewrdn, - int deleteoldrdn, - struct berval *newSuperior, - struct berval *nnewSuperior -) + Backend *be, + Connection *conn, + Operation *op, + struct berval *dn, + struct berval *ndn, + struct berval *newrdn, + struct berval *nnewrdn, + int deleteoldrdn, + struct berval *newSuperior, + struct berval *nnewSuperior ) { struct bdb_info *bdb = (struct bdb_info *) be->be_private; AttributeDescription *children = slap_schema.si_ad_children; @@ -81,7 +82,7 @@ retry: /* transaction retry */ bdb_cache_return_entry_r(&bdb->bi_cache, np); } Debug( LDAP_DEBUG_TRACE, "==>bdb_modrdn: retrying...\n", 0, 0, 0 ); - rc = txn_abort( ltid ); + rc = TXN_ABORT( ltid ); ltid = NULL; op->o_private = NULL; if( rc != 0 ) { @@ -93,7 +94,7 @@ retry: /* transaction retry */ } /* begin transaction */ - rc = txn_begin( bdb->bi_dbenv, NULL, <id, + rc = TXN_BEGIN( bdb->bi_dbenv, NULL, <id, bdb->bi_db_opflags ); text = NULL; if( rc != 0 ) { @@ -581,7 +582,7 @@ retry: /* transaction retry */ e->e_nname = new_ndn; new_dn.bv_val = NULL; - new_ndn.bv_val = NULL; + new_ndn.bv_val = NULL; /* add new one */ rc = bdb_dn2id_add( be, ltid, np_ndn, e ); @@ -623,30 +624,48 @@ retry: /* transaction retry */ } if( op->o_noop ) { - rc = txn_abort( ltid ); + if(( rc=TXN_ABORT( ltid )) != 0 ) { + text = "txn_abort (no-op) failed"; + } else { + rc = LDAP_SUCCESS; + } + } else { - rc = txn_commit( ltid, 0 ); + if(( rc=TXN_PREPARE( ltid, bdb_gid )) != 0 ) { + text = "txn_prepare failed"; + } else { + if( bdb_cache_update_entry(&bdb->bi_cache, e) == -1 ) { + if(( rc=TXN_ABORT( ltid )) != 0 ) { + text ="cache update & txn_abort failed"; + } else { + rc = LDAP_OTHER; + text = "cache update failed"; + } + + } else { + if(( rc=TXN_COMMIT( ltid, 0 )) != 0 ) { + text = "txn_commit failed"; + } else { + rc = LDAP_SUCCESS; + } + } + } } + ltid = NULL; op->o_private = NULL; - - if( rc != 0 ) { - Debug( LDAP_DEBUG_TRACE, - "bdb_modrdn: txn_%s failed: %s (%d)\n", - op->o_noop ? "abort (no-op)" : "commit", - db_strerror(rc), rc ); - rc = LDAP_OTHER; - text = "commit failed"; - - } else { - (void) bdb_cache_update_entry(&bdb->bi_cache, e); - Debug( LDAP_DEBUG_TRACE, - "bdb_modrdn: added%s id=%08lx dn=\"%s\"\n", - op->o_noop ? " (no-op)" : "", - e->e_id, e->e_dn ); - rc = LDAP_SUCCESS; + + if( rc == LDAP_SUCCESS ) { + Debug(LDAP_DEBUG_TRACE, + "bdb_modrdn: rdn modified%s id=%08lx dn=\"%s\"\n", + op->o_noop ? " (no-op)" : "", e->e_id, e->e_dn ); text = NULL; bdb_cache_entry_commit( e ); + + } else { + Debug( LDAP_DEBUG_TRACE, "bdb_add: %s : %s (%d)\n", + text, db_strerror(rc), rc ); + rc = LDAP_OTHER; } return_results: @@ -691,7 +710,7 @@ done: } if( ltid != NULL ) { - txn_abort( ltid ); + TXN_ABORT( ltid ); op->o_private = NULL; } diff --git a/servers/slapd/back-bdb/passwd.c b/servers/slapd/back-bdb/passwd.c index 38cee4b7c6..bec8619789 100644 --- a/servers/slapd/back-bdb/passwd.c +++ b/servers/slapd/back-bdb/passwd.c @@ -91,7 +91,7 @@ retry: /* transaction retry */ bdb_cache_return_entry_w(&bdb->bi_cache, e); } Debug( LDAP_DEBUG_TRACE, "bdb_exop_passwd: retrying...\n", 0, 0, 0 ); - rc = txn_abort( ltid ); + rc = TXN_ABORT( ltid ); ltid = NULL; op->o_private = NULL; if( rc != 0 ) { @@ -103,7 +103,7 @@ retry: /* transaction retry */ } /* begin transaction */ - rc = txn_begin( bdb->bi_dbenv, NULL, <id, + rc = TXN_BEGIN( bdb->bi_dbenv, NULL, <id, bdb->bi_db_opflags ); *text = NULL; if( rc != 0 ) { @@ -208,9 +208,9 @@ retry: /* transaction retry */ if( rc == 0 ) { if( op->o_noop ) { - rc = txn_abort( ltid ); + rc = TXN_ABORT( ltid ); } else { - rc = txn_commit( ltid, 0 ); + rc = TXN_COMMIT( ltid, 0 ); } ltid = NULL; } @@ -231,7 +231,7 @@ done: } if( ltid != NULL ) { - txn_abort( ltid ); + TXN_ABORT( ltid ); op->o_private = NULL; } diff --git a/servers/slapd/back-bdb/tools.c b/servers/slapd/back-bdb/tools.c index 737a0c8180..bcec7c7c55 100644 --- a/servers/slapd/back-bdb/tools.c +++ b/servers/slapd/back-bdb/tools.c @@ -130,7 +130,7 @@ ID bdb_tool_entry_put( Debug( LDAP_DEBUG_TRACE, "=> bdb_tool_entry_put( %ld, \"%s\" )\n", (long) e->e_id, e->e_dn, 0 ); - rc = txn_begin( bdb->bi_dbenv, NULL, &tid, + rc = TXN_BEGIN( bdb->bi_dbenv, NULL, &tid, bdb->bi_db_opflags ); if( rc != 0 ) { snprintf( text->bv_val, text->bv_len, @@ -191,7 +191,7 @@ ID bdb_tool_entry_put( done: if( rc == 0 ) { - rc = txn_commit( tid, 0 ); + rc = TXN_COMMIT( tid, 0 ); if( rc != 0 ) { snprintf( text->bv_val, text->bv_len, "txn_commit failed: %s (%d)", @@ -203,7 +203,7 @@ done: } } else { - txn_abort( tid ); + TXN_ABORT( tid ); snprintf( text->bv_val, text->bv_len, "txn_aborted! %s (%d)", db_strerror(rc), rc ); @@ -238,7 +238,7 @@ int bdb_tool_entry_reindex( return -1; } - rc = txn_begin( bi->bi_dbenv, NULL, &tid, bi->bi_db_opflags ); + rc = TXN_BEGIN( bi->bi_dbenv, NULL, &tid, bi->bi_db_opflags ); if( rc != 0 ) { Debug( LDAP_DEBUG_ANY, "=> bdb_tool_entry_reindex: txn_begin failed: %s (%d)\n", @@ -274,7 +274,7 @@ int bdb_tool_entry_reindex( done: if( rc == 0 ) { - rc = txn_commit( tid, 0 ); + rc = TXN_COMMIT( tid, 0 ); if( rc != 0 ) { Debug( LDAP_DEBUG_ANY, "=> bdb_tool_entry_reindex: txn_commit failed: %s (%d)\n", @@ -283,7 +283,7 @@ done: } } else { - txn_abort( tid ); + TXN_ABORT( tid ); Debug( LDAP_DEBUG_ANY, "=> bdb_tool_entry_reindex: txn_aborted! %s (%d)\n", db_strerror(rc), rc, 0 );