Browse Source

Ticket 47358 - implement backend optimazation levels

Bug Description:  it is an enhancement to be able to test different
	otimizations and have the default bahaviour as fallback.

Fix Description:   As described in the ticket, this fix introduces
	three optimization switches.
	1] bypass ruv update inside transaction, might be replaced by
	   fix for ticket 564
	2] reverse order of txn begin/commit and backen lock/unlock
	   to benefit from fix #568
	3] find and lock entry to modify before taking backend lock
	   to decrease time backend lock is held

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

Reviewed by: Rich, thanks
Ludwig Krispenz 12 years ago
parent
commit
a154ecfc9b

+ 9 - 0
ldap/servers/slapd/back-ldbm/back-ldbm.h

@@ -654,8 +654,17 @@ struct ldbminfo {
     int li_reslimit_rangelookthrough_handle;
     int li_idl_update;
     int li_old_idl_maxids;
+#define BACKEND_OPT_NO_RUV_UPDATE	0x01
+#define BACKEND_OPT_DBLOCK_INSIDE_TXN	0x02
+#define BACKEND_OPT_MANAGE_ENTRY_BEFORE_DBLOCK 0x04
+    int li_backend_opt_level;
 };
 
+
+#define NO_RUV_UPDATE(li)		(li->li_backend_opt_level & BACKEND_OPT_NO_RUV_UPDATE)
+#define DBLOCK_INSIDE_TXN(li)		(li->li_backend_opt_level & BACKEND_OPT_DBLOCK_INSIDE_TXN)
+#define MANAGE_ENTRY_BEFORE_DBLOCK(li)	(li->li_backend_opt_level & BACKEND_OPT_MANAGE_ENTRY_BEFORE_DBLOCK)
+
 /* li_flags could store these bits defined in ../slapi-plugin.h
  * task flag (pb_task_flags) *
  *   SLAPI_TASK_RUNNING_AS_TASK

+ 35 - 12
ldap/servers/slapd/back-ldbm/dblayer.c

@@ -3610,12 +3610,19 @@ dblayer_txn_begin(backend *be, back_txnid parent_txn, back_txn *txn)
 {
     struct ldbminfo *li = (struct ldbminfo *)be->be_database->plg_private;
     int rc = 0;
-    if (SERIALLOCK(li)) {
-        dblayer_lock_backend(be);
-    }
-    rc = dblayer_txn_begin_ext(li,parent_txn,txn,PR_TRUE);
-    if (rc && SERIALLOCK(li)) {
-        dblayer_unlock_backend(be);
+    if (DBLOCK_INSIDE_TXN(li)) {
+    	rc = dblayer_txn_begin_ext(li,parent_txn,txn,PR_TRUE);
+	if (!rc && SERIALLOCK(li)) {
+            dblayer_lock_backend(be);
+    	}
+    } else {
+    	if (SERIALLOCK(li)) {
+            dblayer_lock_backend(be);
+    	}
+    	rc = dblayer_txn_begin_ext(li,parent_txn,txn,PR_TRUE);
+    	if (rc && SERIALLOCK(li)) {
+            dblayer_unlock_backend(be);
+        }
     }
     return rc;
 }
@@ -3721,9 +3728,17 @@ int
 dblayer_txn_commit(backend *be, back_txn *txn)
 {
     struct ldbminfo *li = (struct ldbminfo *)be->be_database->plg_private;
-    int rc = dblayer_txn_commit_ext(li,txn,PR_TRUE);
-    if (SERIALLOCK(li)) {
-        dblayer_unlock_backend(be);
+    int rc;
+    if (DBLOCK_INSIDE_TXN(li)) {
+    	if (SERIALLOCK(li)) {
+    	    dblayer_unlock_backend(be);
+        }
+	rc  = dblayer_txn_commit_ext(li,txn,PR_TRUE);
+    } else {
+	rc  = dblayer_txn_commit_ext(li,txn,PR_TRUE);
+    	if (SERIALLOCK(li)) {
+            dblayer_unlock_backend(be);
+	}
     }
     return rc;
 }
@@ -3803,9 +3818,17 @@ int
 dblayer_txn_abort(backend *be, back_txn *txn)
 {
     struct ldbminfo *li = (struct ldbminfo *)be->be_database->plg_private;
-    int rc = dblayer_txn_abort_ext(li, txn, PR_TRUE);
-    if (SERIALLOCK(li)) {
-        dblayer_unlock_backend(be);
+    int rc;
+    if (DBLOCK_INSIDE_TXN(li)) {
+        if (SERIALLOCK(li)) {
+    	    dblayer_unlock_backend(be);
+	}
+	rc = dblayer_txn_abort_ext(li, txn, PR_TRUE);
+    } else {
+	rc = dblayer_txn_abort_ext(li, txn, PR_TRUE);
+        if (SERIALLOCK(li)) {
+    	    dblayer_unlock_backend(be);
+	}
     }
     return rc;
 }

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

@@ -759,7 +759,7 @@ ldbm_back_add( Slapi_PBlock *pb )
 				parententry = NULL;
 			}
 		
-			if (!is_ruv && !is_fixup_operation) {
+			if (!is_ruv && !is_fixup_operation && !NO_RUV_UPDATE(li)) {
 				ruv_c_init = ldbm_txn_ruv_modify_context( pb, &ruv_c );
 				if (-1 == ruv_c_init) {
 					LDAPDebug( LDAP_DEBUG_ANY,

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

@@ -209,6 +209,27 @@ static int ldbm_config_rangelookthroughlimit_set(void *arg, void *value, char *e
     return retval;
 }
 
+static void *ldbm_config_backend_opt_level_get(void *arg) 
+{
+    struct ldbminfo *li = (struct ldbminfo *) arg;
+
+    return (void *) ((uintptr_t)(li->li_backend_opt_level));
+}
+
+static int ldbm_config_backend_opt_level_set(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);
+
+    /* Do whatever we can to make sure the data is ok. */
+
+    if (apply) {
+        li->li_backend_opt_level = val;
+    }
+
+    return retval;
+}
 static void *ldbm_config_mode_get(void *arg) 
 {
     struct ldbminfo *li = (struct ldbminfo *) arg;
@@ -1415,6 +1436,7 @@ static config_info ldbm_config[] = {
     {CONFIG_PAGEDLOOKTHROUGHLIMIT, CONFIG_TYPE_INT, "0", &ldbm_config_pagedlookthroughlimit_get, &ldbm_config_pagedlookthroughlimit_set, CONFIG_FLAG_ALWAYS_SHOW|CONFIG_FLAG_ALLOW_RUNNING_CHANGE},
     {CONFIG_PAGEDIDLISTSCANLIMIT, CONFIG_TYPE_INT, "0", &ldbm_config_pagedallidsthreshold_get, &ldbm_config_pagedallidsthreshold_set, CONFIG_FLAG_ALWAYS_SHOW|CONFIG_FLAG_ALLOW_RUNNING_CHANGE},
     {CONFIG_RANGELOOKTHROUGHLIMIT, CONFIG_TYPE_INT, "5000", &ldbm_config_rangelookthroughlimit_get, &ldbm_config_rangelookthroughlimit_set, CONFIG_FLAG_ALWAYS_SHOW|CONFIG_FLAG_ALLOW_RUNNING_CHANGE},
+    {CONFIG_BACKEND_OPT_LEVEL, CONFIG_TYPE_INT, "0", &ldbm_config_backend_opt_level_get, &ldbm_config_backend_opt_level_set, CONFIG_FLAG_ALWAYS_SHOW},
     {NULL, 0, NULL, NULL, NULL, 0}
 };
 

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

@@ -145,6 +145,7 @@ struct config_info {
 #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"
+#define CONFIG_BACKEND_OPT_LEVEL 	"nsslapd-backend-opt-level"
 
 #define CONFIG_ENTRYRDN_SWITCH          "nsslapd-subtree-rename-switch"
 /* nsslapd-noancestorid is ignored unless nsslapd-subtree-rename-switch is on */

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

@@ -551,7 +551,7 @@ ldbm_back_delete( Slapi_PBlock *pb )
 				}
 			}
 
-			if (!is_ruv && !is_fixup_operation && !delete_tombstone_entry) {
+			if (!is_ruv && !is_fixup_operation && !delete_tombstone_entry && !NO_RUV_UPDATE(li)) {
 				ruv_c_init = ldbm_txn_ruv_modify_context( pb, &ruv_c );
 				if (-1 == ruv_c_init) {
 					LDAPDebug( LDAP_DEBUG_ANY,

+ 15 - 5
ldap/servers/slapd/back-ldbm/ldbm_modify.c

@@ -410,6 +410,14 @@ ldbm_back_modify( Slapi_PBlock *pb )
 		dblock_acquired= 1;
 	}
 	 */
+	if ( MANAGE_ENTRY_BEFORE_DBLOCK(li)) {
+		/* find and lock the entry we are about to modify */
+		if ( (e = find_entry2modify( pb, be, addr, &txn )) == NULL ) {
+			ldap_result_code= -1;
+			goto error_return;	  /* error result sent by find_entry2modify() */
+		}
+	}
+
 	txn.back_txn_txn = NULL; /* ready to create the child transaction */
 	for (retry_count = 0; retry_count < RETRY_TIMES; retry_count++) {
 		int cache_rc = 0;
@@ -467,10 +475,12 @@ ldbm_back_modify( Slapi_PBlock *pb )
 		slapi_pblock_set(pb, SLAPI_TXN, txn.back_txn_txn);
 
 		if (0 == retry_count) { /* just once */
-			/* find and lock the entry we are about to modify */
-			if ( (e = find_entry2modify( pb, be, addr, &txn )) == NULL ) {
-				ldap_result_code= -1;
-				goto error_return;	  /* error result sent by find_entry2modify() */
+			if ( !MANAGE_ENTRY_BEFORE_DBLOCK(li)) {
+				/* find and lock the entry we are about to modify */
+				if ( (e = find_entry2modify( pb, be, addr, &txn )) == NULL ) {
+					ldap_result_code= -1;
+					goto error_return;	  /* error result sent by find_entry2modify() */
+				}
 			}
 		
 			if ( !is_fixup_operation )
@@ -543,7 +553,7 @@ ldbm_back_modify( Slapi_PBlock *pb )
 				goto error_return;
 			}
 		
-			if (!is_ruv && !is_fixup_operation) {
+			if (!is_ruv && !is_fixup_operation && !NO_RUV_UPDATE(li)) {
 				ruv_c_init = ldbm_txn_ruv_modify_context( pb, &ruv_c );
 				if (-1 == ruv_c_init) {
 					LDAPDebug( LDAP_DEBUG_ANY,

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

@@ -839,7 +839,7 @@ ldbm_back_modrdn( Slapi_PBlock *pb )
                 /* JCM - A subtree move could break ACIs, static groups, and dynamic groups. */
             }
         
-            if (!is_ruv && !is_fixup_operation) {
+	    if (!is_ruv && !is_fixup_operation && !NO_RUV_UPDATE(li)) {
                 ruv_c_init = ldbm_txn_ruv_modify_context( pb, &ruv_c );
                 if (-1 == ruv_c_init) {
                     LDAPDebug( LDAP_DEBUG_ANY,