]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-ndb/init.cpp
ITS#7761 bail out of search if config is pausing
[openldap] / servers / slapd / back-ndb / init.cpp
index 82dcfa00b8c6e1b06aa2b4a69f61b2a1ba4bba75..28d658e03ba0566692f4dae3ce1c290405143d68 100644 (file)
@@ -2,7 +2,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 2008 The OpenLDAP Foundation.
+ * Copyright 2008-2013 The OpenLDAP Foundation.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -61,6 +61,9 @@ static int ndb_oplens[] = {
        -1
 };
 
+static Uint32 ndb_lastrow[1];
+NdbInterpretedCode *ndb_lastrow_code;
+
 static int
 ndb_db_init( BackendDB *be, ConfigReply *cr )
 {
@@ -115,13 +118,25 @@ ndb_db_open( BackendDB *be, ConfigReply *cr )
        if ( ni->ni_nconns < 1 )
                ni->ni_nconns = 1;
 
-       ni->ni_cluster = (Ndb_cluster_connection **)ch_malloc( ni->ni_nconns * sizeof( Ndb_cluster_connection *));
+       ni->ni_cluster = (Ndb_cluster_connection **)ch_calloc( ni->ni_nconns, sizeof( Ndb_cluster_connection *));
        for ( i=0; i<ni->ni_nconns; i++ ) {
                ni->ni_cluster[i] = new Ndb_cluster_connection( ni->ni_connectstr );
-               rc = ni->ni_cluster[i]->connect( 4, 5, 1 );
+               rc = ni->ni_cluster[i]->connect( 20, 5, 1 );
+               if ( rc ) {
+                       snprintf( cr->msg, sizeof( cr->msg ),
+                               "ndb_db_open: ni_cluster[%d]->connect failed (%d)",
+                               i, rc );
+                       goto fail;
+               }
        }
        for ( i=0; i<ni->ni_nconns; i++ ) {
-               rc = ni->ni_cluster[i]->wait_until_ready( 30, 0 );
+               rc = ni->ni_cluster[i]->wait_until_ready( 30, 30 );
+               if ( rc ) {
+                       snprintf( cr->msg, sizeof( cr->msg ),
+                               "ndb_db_open: ni_cluster[%d]->wait failed (%d)",
+                               i, rc );
+                       goto fail;
+               }
        }
 
        mysql_init( &ni->ni_sql );
@@ -288,16 +303,20 @@ fail:
 static int
 ndb_db_close( BackendDB *be, ConfigReply *cr )
 {
-       int i, rc;
+       int i;
        struct ndb_info *ni = (struct ndb_info *) be->be_private;
 
        mysql_close( &ni->ni_sql );
-       for ( i=0; i<ni->ni_nconns; i++ ) {
-               delete ni->ni_cluster[i];
-               ni->ni_cluster[i] = NULL;
+       if ( ni->ni_cluster ) {
+               for ( i=0; i<ni->ni_nconns; i++ ) {
+                       if ( ni->ni_cluster[i] ) {
+                               delete ni->ni_cluster[i];
+                               ni->ni_cluster[i] = NULL;
+                       }
+               }
+               ch_free( ni->ni_cluster );
+               ni->ni_cluster = NULL;
        }
-       ch_free( ni->ni_cluster );
-       ni->ni_cluster = NULL;
 
 #ifdef DO_MONITORING
        /* monitor handling */
@@ -331,6 +350,21 @@ extern "C" int
 ndb_back_initialize(
        BackendInfo     *bi )
 {
+       static char *controls[] = {
+               LDAP_CONTROL_ASSERT,
+               LDAP_CONTROL_MANAGEDSAIT,
+               LDAP_CONTROL_NOOP,
+               LDAP_CONTROL_PAGEDRESULTS,
+               LDAP_CONTROL_PRE_READ,
+               LDAP_CONTROL_POST_READ,
+               LDAP_CONTROL_SUBENTRIES,
+               LDAP_CONTROL_X_PERMISSIVE_MODIFY,
+#ifdef LDAP_X_TXN
+               LDAP_CONTROL_X_TXN_SPEC,
+#endif
+               NULL
+       };
+
        int rc = 0;
 
        /* initialize the underlying database system */
@@ -339,6 +373,18 @@ ndb_back_initialize(
 
        ndb_init();
 
+       ndb_lastrow_code = new NdbInterpretedCode( NULL, ndb_lastrow, 1 );
+       ndb_lastrow_code->interpret_exit_last_row();
+       ndb_lastrow_code->finalise();
+
+       bi->bi_flags |=
+               SLAP_BFLAG_INCREMENT |
+               SLAP_BFLAG_SUBENTRIES |
+               SLAP_BFLAG_ALIASES |
+               SLAP_BFLAG_REFERRALS;
+
+       bi->bi_controls = controls;
+
        bi->bi_open = 0;
        bi->bi_close = 0;
        bi->bi_config = 0;
@@ -397,6 +443,8 @@ ndb_back_initialize(
 #if    SLAPD_NDB == SLAPD_MOD_DYNAMIC
 
 /* conditionally define the init_module() function */
+extern "C" { int init_module( int argc, char *argv[] ); }
+
 SLAP_BACKEND_INIT_MODULE( ndb )
 
 #endif /* SLAPD_NDB == SLAPD_MOD_DYNAMIC */