]> git.sur5r.net Git - openldap/commitdiff
Some more txn infrastructure
authorKurt Zeilenga <kurt@openldap.org>
Tue, 7 Mar 2006 08:07:21 +0000 (08:07 +0000)
committerKurt Zeilenga <kurt@openldap.org>
Tue, 7 Mar 2006 08:07:21 +0000 (08:07 +0000)
servers/slapd/back-bdb/add.c
servers/slapd/back-bdb/delete.c
servers/slapd/back-bdb/init.c
servers/slapd/back-bdb/modify.c
servers/slapd/back-bdb/modrdn.c
servers/slapd/connection.c
servers/slapd/slap.h
servers/slapd/txn.c

index cd37908a20a8f29e479e798f8d1af21a60d3884a..3377541de7386c664ae945c1413c3a39db69e97b 100644 (file)
@@ -47,6 +47,36 @@ bdb_add(Operation *op, SlapReply *rs )
        Debug(LDAP_DEBUG_ARGS, "==> " LDAP_XSTRING(bdb_add) ": %s\n",
                op->oq_add.rs_e->e_name.bv_val, 0, 0);
 
+       if( op->o_txnSpec ) {
+               /* acquire connection lock */
+               ldap_pvt_thread_mutex_lock( &op->o_conn->c_mutex );
+               if( op->o_conn->c_txn == 0 ) {
+                       rs->sr_text = "invalid transaction identifier";
+                       rs->sr_err = LDAP_X_TXN_ID_INVALID;
+                       goto txnReturn;
+               }
+               if( op->o_conn->c_txn_backend == NULL ) {
+                       op->o_conn->c_txn_backend = op->o_bd;
+
+               } else if( op->o_conn->c_txn_backend != op->o_bd ) {
+                       rs->sr_text = "transaction cannot span multiple database contexts";
+                       rs->sr_err = LDAP_AFFECTS_MULTIPLE_DSAS;
+                       goto txnReturn;
+               }
+
+               /* insert operation into transaction */
+
+               rs->sr_text = "transaction specified";
+               rs->sr_err = LDAP_SUCCESS;
+
+txnReturn:
+               /* release connection lock */
+               ldap_pvt_thread_mutex_unlock( &op->o_conn->c_mutex );
+
+               send_ldap_result( op, rs );
+               return rs->sr_err;
+       }
+
        ctrls[num_ctrls] = 0;
 
        /* add opattrs to shadow as well, only missing attrs will actually
index 02038dc55cac55d06dfe073428a1d839fc2d4939..7ecf66e03af1865ae09432dfaad55106756ea0aa 100644 (file)
@@ -52,11 +52,41 @@ bdb_delete( Operation *op, SlapReply *rs )
        int     parent_is_glue = 0;
        int parent_is_leaf = 0;
 
-       ctrls[num_ctrls] = 0;
-
        Debug( LDAP_DEBUG_ARGS, "==> " LDAP_XSTRING(bdb_delete) ": %s\n",
                op->o_req_dn.bv_val, 0, 0 );
 
+       if( op->o_txnSpec ) {
+               /* acquire connection lock */
+               ldap_pvt_thread_mutex_lock( &op->o_conn->c_mutex );
+               if( op->o_conn->c_txn == 0 ) {
+                       rs->sr_text = "invalid transaction identifier";
+                       rs->sr_err = LDAP_X_TXN_ID_INVALID;
+                       goto txnReturn;
+               }
+               if( op->o_conn->c_txn_backend == NULL ) {
+                       op->o_conn->c_txn_backend = op->o_bd;
+
+               } else if( op->o_conn->c_txn_backend != op->o_bd ) {
+                       rs->sr_text = "transaction cannot span multiple database contexts";
+                       rs->sr_err = LDAP_AFFECTS_MULTIPLE_DSAS;
+                       goto txnReturn;
+               }
+
+               /* insert operation into transaction */
+
+               rs->sr_text = "transaction specified";
+               rs->sr_err = LDAP_SUCCESS;
+
+txnReturn:
+               /* release connection lock */
+               ldap_pvt_thread_mutex_unlock( &op->o_conn->c_mutex );
+
+               send_ldap_result( op, rs );
+               return rs->sr_err;
+       }
+
+       ctrls[num_ctrls] = 0;
+
        /* allocate CSN */
        if ( BER_BVISEMPTY( &op->o_csn )) {
                struct berval csn;
index da7b438f6efafe87eaef8fe986e608230232a147..b766f6b1c6f56e604b36115643de242cd98809b0 100644 (file)
@@ -305,10 +305,8 @@ bdb_db_open( BackendDB *be )
 #ifdef SLAP_ZONE_ALLOC
        if ( bdb->bi_cache.c_maxsize ) {
                bdb->bi_cache.c_zctx = slap_zn_mem_create(
-                                                               SLAP_ZONE_INITSIZE,
-                                                               SLAP_ZONE_MAXSIZE,
-                                                               SLAP_ZONE_DELTA,
-                                                               SLAP_ZONE_SIZE);
+                       SLAP_ZONE_INITSIZE, SLAP_ZONE_MAXSIZE,
+                       SLAP_ZONE_DELTA, SLAP_ZONE_SIZE);
        }
 #endif
 
@@ -555,6 +553,9 @@ bdb_back_initialize(
                LDAP_CONTROL_PAGEDRESULTS,
                LDAP_CONTROL_SUBENTRIES,
                LDAP_CONTROL_X_PERMISSIVE_MODIFY,
+#ifdef LDAP_X_TXN
+               LDAP_CONTROL_X_TXN_SPEC,
+#endif
                NULL
        };
 
index 21faa993e6e383f03ff32e3e49db0841eeea4937..60697881a8f57179850844e4adc585b3f844dcd7 100644 (file)
@@ -296,6 +296,36 @@ bdb_modify( Operation *op, SlapReply *rs )
        Debug( LDAP_DEBUG_ARGS, LDAP_XSTRING(bdb_modify) ": %s\n",
                op->o_req_dn.bv_val, 0, 0 );
 
+       if( op->o_txnSpec ) {
+               /* acquire connection lock */
+               ldap_pvt_thread_mutex_lock( &op->o_conn->c_mutex );
+               if( op->o_conn->c_txn == 0 ) {
+                       rs->sr_text = "invalid transaction identifier";
+                       rs->sr_err = LDAP_X_TXN_ID_INVALID;
+                       goto txnReturn;
+               }
+               if( op->o_conn->c_txn_backend == NULL ) {
+                       op->o_conn->c_txn_backend = op->o_bd;
+
+               } else if( op->o_conn->c_txn_backend != op->o_bd ) {
+                       rs->sr_text = "transaction cannot span multiple database contexts";
+                       rs->sr_err = LDAP_AFFECTS_MULTIPLE_DSAS;
+                       goto txnReturn;
+               }
+
+               /* insert operation into transaction */
+
+               rs->sr_text = "transaction specified";
+               rs->sr_err = LDAP_SUCCESS;
+
+txnReturn:
+               /* release connection lock */
+               ldap_pvt_thread_mutex_unlock( &op->o_conn->c_mutex );
+
+               send_ldap_result( op, rs );
+               return rs->sr_err;
+       }
+
        ctrls[num_ctrls] = NULL;
 
        slap_mods_opattrs( op, &op->orm_modlist, 1 );
index cc0ffcb476d72bc6d15b061989007c11cc8317e5..23b42a19e62f598baa8472fc60ebe734eb2a9584 100644 (file)
@@ -61,12 +61,42 @@ bdb_modrdn( Operation       *op, SlapReply *rs )
        int parent_is_glue = 0;
        int parent_is_leaf = 0;
 
-       ctrls[num_ctrls] = NULL;
-
        Debug( LDAP_DEBUG_TRACE, "==>" LDAP_XSTRING(bdb_modrdn) "(%s,%s,%s)\n",
                op->o_req_dn.bv_val,op->oq_modrdn.rs_newrdn.bv_val,
                op->oq_modrdn.rs_newSup ? op->oq_modrdn.rs_newSup->bv_val : "NULL" );
 
+       if( op->o_txnSpec ) {
+               /* acquire connection lock */
+               ldap_pvt_thread_mutex_lock( &op->o_conn->c_mutex );
+               if( op->o_conn->c_txn == 0 ) {
+                       rs->sr_text = "invalid transaction identifier";
+                       rs->sr_err = LDAP_X_TXN_ID_INVALID;
+                       goto txnReturn;
+               }
+               if( op->o_conn->c_txn_backend == NULL ) {
+                       op->o_conn->c_txn_backend = op->o_bd;
+
+               } else if( op->o_conn->c_txn_backend != op->o_bd ) {
+                       rs->sr_text = "transaction cannot span multiple database contexts";
+                       rs->sr_err = LDAP_AFFECTS_MULTIPLE_DSAS;
+                       goto txnReturn;
+               }
+
+               /* insert operation into transaction */
+
+               rs->sr_text = "transaction specified";
+               rs->sr_err = LDAP_SUCCESS;
+
+txnReturn:
+               /* release connection lock */
+               ldap_pvt_thread_mutex_unlock( &op->o_conn->c_mutex );
+
+               send_ldap_result( op, rs );
+               return rs->sr_err;
+       }
+
+       ctrls[num_ctrls] = NULL;
+
        slap_mods_opattrs( op, &op->orr_modlist, 1 );
 
        if( 0 ) {
index 16d9b429fb0fd617e2d31258944e8d986c8c11e9..252570efcf346df894ea59f935e4bcb2851357ba 100644 (file)
@@ -619,6 +619,12 @@ long connection_init(
                LDAP_STAILQ_INIT(&c->c_ops);
                LDAP_STAILQ_INIT(&c->c_pending_ops);
 
+#ifdef LDAP_X_TXN
+               c->c_txn = 0;
+               c->c_txn_backend = NULL;
+               LDAP_STAILQ_INIT(&c->c_txn_ops);
+#endif
+
                BER_BVZERO( &c->c_sasl_bind_mech );
                c->c_sasl_done = 0;
                c->c_sasl_authctx = NULL;
@@ -660,6 +666,11 @@ long connection_init(
        assert( BER_BVISNULL( &c->c_peer_name ) );
        assert( LDAP_STAILQ_EMPTY(&c->c_ops) );
        assert( LDAP_STAILQ_EMPTY(&c->c_pending_ops) );
+#ifdef LDAP_X_TXN
+       assert( c->c_txn == 0 );
+       assert( c->c_txn_backend == NULL );
+       assert( LDAP_STAILQ_EMPTY(&c->c_txn_ops) );
+#endif
        assert( BER_BVISNULL( &c->c_sasl_bind_mech ) );
        assert( c->c_sasl_done == 0 );
        assert( c->c_sasl_authctx == NULL );
index f0dd9296bff10d780fe5aa4a6b53e21d394e7d93..51d5ae3a9f3b74017aa1bd6e2816cde03fa63dad 100644 (file)
@@ -2635,7 +2635,9 @@ typedef struct slap_conn {
        struct slap_op  *c_sasl_bindop; /* set to current op if it's a bind */
 
 #ifdef LDAP_X_TXN
-       int             c_txn;  /* in transaction */
+       int c_txn;      /* true if transaction started */
+       Backend *c_txn_backend;
+       LDAP_STAILQ_HEAD(c_to, slap_op) c_txn_ops; /* list of operations in txn */
 #endif
 
        PagedResultsState c_pagedresults_state; /* paged result state */
index d1451c52d45d373903ea44a73ffa296513bfa881..f8fb65785d1f1017e594d0ca947de46177cf59a2 100644 (file)
@@ -62,6 +62,7 @@ int txn_start_extop(
                goto done;
        }
 
+       assert( op->o_conn->c_txn_backend == NULL );
        ++op->o_conn->c_txn;
 
        bv = (struct berval *) ch_malloc( sizeof (struct berval) );
@@ -180,6 +181,7 @@ int txn_end_extop(
        }
 
        op->o_conn->c_txn = 0;
+       op->o_conn->c_txn_backend = NULL;
 
 done:
        /* release connection lock */