Browse Source

Ticket 47326 - idl switch does not work

    Bug Description:  Setting nsslapd-idl-switch to "old" always gets converted
                      to "new", as the server tries to update the idl type.
                      This makes it impossible to test the "old" idl processes.

    Fix Description:  Added a new ldbm config setting to control if we do the upgrade
                      check or not: "nsslapd-idl-update".  The default is "on".  This
                      still allows the server to update the type by default, but if
                      you must use "old", then you must turn the "update" off.

                      Also did some minor code cleanup, and fixed some small memory leaks.

    https://fedorahosted.org/389/ticket/47326

    Reviewed by: Noriko(Thanks!)
Mark Reynolds 12 years ago
parent
commit
0c3ca8a49a

+ 8 - 7
ldap/servers/slapd/back-ldbm/back-ldbm.h

@@ -645,13 +645,14 @@ struct ldbminfo {
     int li_fat_lock;         /* 608146 -- make this configurable, first */
     int li_legacy_errcode;   /* 615428 -- in case legacy err code is expected */
     Slapi_Counter *li_global_usn_counter; /* global USN counter */
-    int             li_reslimit_allids_handle; /* allids aka idlistscan */
-    int             li_pagedlookthroughlimit;
-    int             li_pagedallidsthreshold;
-    int             li_reslimit_pagedlookthrough_handle;
-    int             li_reslimit_pagedallids_handle; /* allids aka idlistscan */
-    int             li_rangelookthroughlimit;
-    int             li_reslimit_rangelookthrough_handle;
+    int li_reslimit_allids_handle; /* allids aka idlistscan */
+    int li_pagedlookthroughlimit;
+    int li_pagedallidsthreshold;
+    int li_reslimit_pagedlookthrough_handle;
+    int li_reslimit_pagedallids_handle; /* allids aka idlistscan */
+    int li_rangelookthroughlimit;
+    int li_reslimit_rangelookthrough_handle;
+    int li_idl_update;
 };
 
 /* li_flags could store these bits defined in ../slapi-plugin.h

+ 17 - 5
ldap/servers/slapd/back-ldbm/dblayer.c

@@ -2091,6 +2091,7 @@ int dblayer_instance_start(backend *be, int mode)
                     LDAPDebug(LDAP_DEBUG_ANY, "Instance %s does not have the "
                               "expected version\n", inst->inst_name, 0, 0);
                     PR_ASSERT(0);
+                    slapi_ch_free_string(&dataversion);
                     return_value = -1;
                     goto errout;
                 }
@@ -2100,6 +2101,7 @@ int dblayer_instance_start(backend *be, int mode)
                         "%s is on, while the instance %s is in the DN format. "
                         "Please run dn2rdn to convert the database format.\n",
                         CONFIG_ENTRYRDN_SWITCH, inst->inst_name);
+                    slapi_ch_free_string(&dataversion);
                     return_value = -1;
                     goto errout;
                 }
@@ -2109,6 +2111,7 @@ int dblayer_instance_start(backend *be, int mode)
                         "%s is off, while the instance %s is in the RDN "
                         "format. Please change the value to on in dse.ldif.\n",
                         CONFIG_ENTRYRDN_SWITCH, inst->inst_name);
+                    slapi_ch_free_string(&dataversion);
                     return_value = -1;
                     goto errout;
                 }
@@ -2976,6 +2979,7 @@ dblayer_remove_env(struct ldbminfo *li)
 static int
 _dblayer_set_db_callbacks(dblayer_private *priv, DB *dbp, struct attrinfo *ai)
 {
+    int idl_use_new = 0;
     int rc = 0;
 
     /* With the new idl design, the large 8Kbyte pages we use are not
@@ -3005,16 +3009,24 @@ _dblayer_set_db_callbacks(dblayer_private *priv, DB *dbp, struct attrinfo *ai)
     if (rc)
         return rc;
 #endif
-
-    if (idl_get_idl_new() && !(ai->ai_indexmask & INDEX_VLV)) {
+    /*
+     * If using the "new" idl, set the flags and the compare function.
+     * If using the "old" idl, we still need to set the index DB flags
+     * for the attribute "entryRDN".
+     */
+    if ( ((idl_use_new = idl_get_idl_new()) ||
+          0 == strcasecmp(ai->ai_type, LDBM_ENTRYRDN_STR)) &&
+        !(ai->ai_indexmask & INDEX_VLV))
+    {
+        /* set the flags */
         rc = dbp->set_flags(dbp, DB_DUP | DB_DUPSORT);
         if (rc)
             return rc;
-
+        /* set the compare function */
         if (ai->ai_dup_cmp_fn) {
             /* If set, use the special dup compare callback */
             rc = dbp->set_dup_compare(dbp, ai->ai_dup_cmp_fn);
-        } else {
+        } else if(idl_use_new) {
             rc = dbp->set_dup_compare(dbp, idl_new_compare_dups);
         }
         if (rc)
@@ -6950,7 +6962,7 @@ int dblayer_restore(struct ldbminfo *li, char *src_dir, Slapi_Task *task, char *
         {
             adjust_idl_switch(ldbmversion, li);
             slapi_ch_free_string(&ldbmversion);
-            slapi_ch_free_string(&ldbmversion);
+            slapi_ch_free_string(&dataversion);
         }
     }
 

+ 2 - 2
ldap/servers/slapd/back-ldbm/id2entry.c

@@ -367,7 +367,7 @@ id2entry( backend *be, ID id, back_txn *txn, int *err  )
             ee = slapi_str2entry( data.dptr, SLAPI_STR2ENTRY_NO_ENTRYDN );
         } else {
             char *normdn = NULL;
-	    Slapi_RDN * srdn = NULL;
+            Slapi_RDN * srdn = NULL;
             struct backdn *bdn = dncache_find_id(&inst->inst_dncache, id);
             if (bdn) {
                 normdn = slapi_ch_strdup(slapi_sdn_get_dn(bdn->dn_sdn));
@@ -407,7 +407,7 @@ id2entry( backend *be, ID id, back_txn *txn, int *err  )
                                       SLAPI_STR2ENTRY_NO_ENTRYDN );
             slapi_ch_free_string(&rdn);
             slapi_ch_free_string(&normdn);
-	    slapi_rdn_free(&srdn);
+            slapi_rdn_free(&srdn);
         }
     } else {
         ee = slapi_str2entry( data.dptr, 0 );

+ 1 - 1
ldap/servers/slapd/back-ldbm/ldbm_attr.c

@@ -202,7 +202,7 @@ attr_index_config(
 	slapi_attr_init(&a->ai_sattr, attrValue->bv_val);
 	/*
 	 *  we can't just set a->ai_type to the type from a->ai_sattr
-	 *  if the type has attroptions or subtypes, ai_sattr.a_type will
+	 *  if the type has attr options or subtypes, ai_sattr.a_type will
 	 *  contain them - but for the purposes of indexing, we don't want them
 	 */
 	a->ai_type = slapi_attr_basetype( attrValue->bv_val, NULL, 0 );

+ 21 - 0
ldap/servers/slapd/back-ldbm/ldbm_config.c

@@ -872,6 +872,26 @@ static void *ldbm_config_db_private_import_mem_get(void *arg)
     return (void *) ((uintptr_t)li->li_dblayer_private->dblayer_private_import_mem);
 }
 
+static void *ldbm_config_idl_get_update(void *arg)
+{
+    struct ldbminfo *li = (struct ldbminfo *) arg;
+
+    return (void *) ((uintptr_t)li->li_idl_update);
+}
+
+static int ldbm_config_idl_set_update(void *arg, void *value, char *errorbuf, int phase, int apply)
+{
+    struct ldbminfo *li = (struct ldbminfo *) arg;
+    int retval = LDAP_SUCCESS;
+    int val = (int) ((uintptr_t)value);
+
+    if (apply) {
+        li->li_idl_update = val;
+    }
+
+    return retval;
+}
+
 static int ldbm_config_db_private_import_mem_set(void *arg, void *value, char *errorbuf, int phase, int apply) 
 {
     struct ldbminfo *li = (struct ldbminfo *) arg;
@@ -1350,6 +1370,7 @@ static config_info ldbm_config[] = {
     {CONFIG_CACHE_AUTOSIZE_SPLIT, CONFIG_TYPE_INT, "50", &ldbm_config_cache_autosize_split_get, &ldbm_config_cache_autosize_split_set, 0},
     {CONFIG_IMPORT_CACHESIZE, CONFIG_TYPE_SIZE_T, "20000000", &ldbm_config_import_cachesize_get, &ldbm_config_import_cachesize_set, CONFIG_FLAG_ALWAYS_SHOW|CONFIG_FLAG_ALLOW_RUNNING_CHANGE},
     {CONFIG_IDL_SWITCH, CONFIG_TYPE_STRING, "new", &ldbm_config_idl_get_idl_new, &ldbm_config_idl_set_tune, CONFIG_FLAG_ALWAYS_SHOW},
+    {CONFIG_IDL_UPDATE, CONFIG_TYPE_ONOFF, "on", &ldbm_config_idl_get_update, &ldbm_config_idl_set_update, 0},
     {CONFIG_BYPASS_FILTER_TEST, CONFIG_TYPE_STRING, "on", &ldbm_config_get_bypass_filter_test, &ldbm_config_set_bypass_filter_test, CONFIG_FLAG_ALWAYS_SHOW|CONFIG_FLAG_ALLOW_RUNNING_CHANGE},
     {CONFIG_USE_VLV_INDEX, CONFIG_TYPE_ONOFF, "on", &ldbm_config_get_use_vlv_index, &ldbm_config_set_use_vlv_index, CONFIG_FLAG_ALWAYS_SHOW|CONFIG_FLAG_ALLOW_RUNNING_CHANGE},
     {CONFIG_DB_LOCKDOWN, CONFIG_TYPE_ONOFF, "off", &ldbm_config_db_lockdown_get, &ldbm_config_db_lockdown_set, 0},

+ 1 - 0
ldap/servers/slapd/back-ldbm/ldbm_config.h

@@ -140,6 +140,7 @@ struct config_info {
 #define CONFIG_DB_TX_MAX "nsslapd-db-tx-max"
 
 #define CONFIG_IDL_SWITCH               "nsslapd-idl-switch"
+#define CONFIG_IDL_UPDATE               "nsslapd-idl-update"
 #define CONFIG_BYPASS_FILTER_TEST       "nsslapd-search-bypass-filter-test"
 #define CONFIG_USE_VLV_INDEX            "nsslapd-search-use-vlv-index"
 #define CONFIG_SERIAL_LOCK              "nsslapd-serial-lock"

+ 8 - 5
ldap/servers/slapd/back-ldbm/upgrade.c

@@ -321,6 +321,11 @@ adjust_idl_switch(char *ldbmversion, struct ldbminfo *li)
 {
     int rval = 0;
 
+    if( !li->li_idl_update ){
+        /* we are not overriding the idl type */
+        return rval;
+    }
+
     li->li_flags |= LI_FORCE_MOD_CONFIG;
     if ((0 == PL_strncasecmp(ldbmversion, BDB_IMPL, strlen(BDB_IMPL))) ||
         (0 == PL_strcmp(ldbmversion, LDBM_VERSION)))    /* db: new idl */
@@ -328,11 +333,9 @@ adjust_idl_switch(char *ldbmversion, struct ldbminfo *li)
         if (!idl_get_idl_new())   /* config: old idl */
         {
             replace_ldbm_config_value(CONFIG_IDL_SWITCH, "new", li);
-            LDAPDebug(LDAP_DEBUG_ANY, 
+            LDAPDebug(LDAP_DEBUG_ANY,
                 "Warning: Dbversion %s does not meet nsslapd-idl-switch: \"old\"; "
-                "nsslapd-idl-switch is updated to \"new\"\n",
-
-                ldbmversion, 0, 0);
+                "nsslapd-idl-switch is updated to \"new\"\n", ldbmversion, 0, 0);
         }
     }
     else if ((0 == strcmp(ldbmversion, LDBM_VERSION_OLD)) ||
@@ -354,7 +357,7 @@ adjust_idl_switch(char *ldbmversion, struct ldbminfo *li)
          LDAPDebug(LDAP_DEBUG_ANY, 
                    "Warning: Dbversion %s is not supported\n", 
                    ldbmversion, 0, 0);
-         rval = 1;
+         rval = -1;
     }
 
     /* ldbminfo is a common resource; should clean up when the job is done */