amoralej / rpms / 389-ds-base

Forked from rpms/389-ds-base 5 years ago
Clone

Blame SOURCES/0013-Ticket-49076-To-debug-DB_DEADLOCK-condition-allow-to.patch

61f723
From 1a66f5f232d6c2869ef4e439eafe5a820f61a976 Mon Sep 17 00:00:00 2001
61f723
From: Thierry Bordaz <tbordaz@redhat.com>
61f723
Date: Wed, 15 Feb 2017 11:31:27 +0100
61f723
Subject: [PATCH] Ticket 49076 - To debug DB_DEADLOCK condition, allow to reset
61f723
 DB_TXN_NOWAIT flag on txn_begin
61f723
61f723
Bug Description:
61f723
    For debug reason it is interesting to have a new configuration ldbm backend config
61f723
    option (nsslapd-db-transaction-wait) that allows to hang on deadlock
61f723
    rather to let the server handling retries.
61f723
61f723
Fix Description:
61f723
    The fix introduce a new attribute nsslapd-db-transaction-wait under
61f723
    "cn=config,cn=ldbm database,cn=plugins,cn=config".
61f723
    By default it is "off" (ldbm returns DB_DEADLOCK) and can be changed
61f723
    online.
61f723
    It is taken into account when a new transcation begin.
61f723
61f723
https://pagure.io/389-ds-base/issue/49076
61f723
61f723
Reviewed by: William Brown, Ludwig Krispenz
61f723
61f723
Platforms tested: F23
61f723
61f723
Flag Day: no
61f723
61f723
Doc impact: no
61f723
---
61f723
 dirsrvtests/tests/tickets/ticket49076_test.py | 103 ++++++++++++++++++++++++++
61f723
 ldap/servers/slapd/back-ldbm/dblayer.c        |   9 ++-
61f723
 ldap/servers/slapd/back-ldbm/dblayer.h        |   3 +
61f723
 ldap/servers/slapd/back-ldbm/ldbm_config.c    |  22 ++++++
61f723
 ldap/servers/slapd/back-ldbm/ldbm_config.h    |   1 +
61f723
 5 files changed, 137 insertions(+), 1 deletion(-)
61f723
 create mode 100644 dirsrvtests/tests/tickets/ticket49076_test.py
61f723
61f723
diff --git a/dirsrvtests/tests/tickets/ticket49076_test.py b/dirsrvtests/tests/tickets/ticket49076_test.py
61f723
new file mode 100644
61f723
index 0000000..c4a2c1b
61f723
--- /dev/null
61f723
+++ b/dirsrvtests/tests/tickets/ticket49076_test.py
61f723
@@ -0,0 +1,103 @@
61f723
+import time
61f723
+import ldap
61f723
+import logging
61f723
+import pytest
61f723
+from lib389 import DirSrv, Entry, tools, tasks
61f723
+from lib389.tools import DirSrvTools
61f723
+from lib389._constants import *
61f723
+from lib389.properties import *
61f723
+from lib389.tasks import *
61f723
+from lib389.utils import *
61f723
+from lib389.topologies import topology_st as topo
61f723
+
61f723
+DEBUGGING = os.getenv("DEBUGGING", default=False)
61f723
+if DEBUGGING:
61f723
+    logging.getLogger(__name__).setLevel(logging.DEBUG)
61f723
+else:
61f723
+    logging.getLogger(__name__).setLevel(logging.INFO)
61f723
+log = logging.getLogger(__name__)
61f723
+
61f723
+ldbm_config = "cn=config,%s" % (DN_LDBM)
61f723
+txn_begin_flag = "nsslapd-db-transaction-wait"
61f723
+TEST_USER_DN = 'cn=test,%s' % SUFFIX
61f723
+TEST_USER = "test"
61f723
+
61f723
+def _check_configured_value(topology_st, attr=txn_begin_flag, expected_value=None, required=False):
61f723
+    entries = topology_st.standalone.search_s(ldbm_config, ldap.SCOPE_BASE, 'cn=config')
61f723
+    if required:
61f723
+        assert (entries[0].hasValue(attr))
61f723
+    if entries[0].hasValue(attr):
61f723
+        topology_st.standalone.log.info('Current value is %s' % entries[0].getValue(attr))
61f723
+        assert (entries[0].getValue(attr) == expected_value)
61f723
+        
61f723
+def _update_db(topology_st):
61f723
+    topology_st.standalone.add_s(
61f723
+        Entry((TEST_USER_DN, {'objectclass': "top person organizationalPerson inetOrgPerson".split(),
61f723
+                              'cn': TEST_USER,
61f723
+                              'sn': TEST_USER,
61f723
+                              'givenname': TEST_USER})))
61f723
+    topology_st.standalone.delete_s(TEST_USER_DN)
61f723
+
61f723
+def test_ticket49076(topo):
61f723
+    """Write your testcase here...
61f723
+
61f723
+    Also, if you need any testcase initialization,
61f723
+    please, write additional fixture for that(include finalizer).
61f723
+    """
61f723
+    
61f723
+    # check default value is DB_TXN_NOWAIT
61f723
+    _check_configured_value(topo, expected_value="off")
61f723
+    
61f723
+    # tests we are able to update DB
61f723
+    _update_db(topo)
61f723
+    
61f723
+    # switch to wait mode
61f723
+    topo.standalone.modify_s(ldbm_config,
61f723
+                                    [(ldap.MOD_REPLACE, txn_begin_flag, "on")])
61f723
+                                    # check default value is DB_TXN_NOWAIT
61f723
+    _check_configured_value(topo, expected_value="on")
61f723
+    _update_db(topo)
61f723
+    
61f723
+    
61f723
+    # switch back to "normal mode"
61f723
+    topo.standalone.modify_s(ldbm_config,
61f723
+                                    [(ldap.MOD_REPLACE, txn_begin_flag, "off")])
61f723
+    # check default value is DB_TXN_NOWAIT
61f723
+    _check_configured_value(topo, expected_value="off")
61f723
+    # tests we are able to update DB
61f723
+    _update_db(topo)
61f723
+    
61f723
+    # check that settings are not reset by restart
61f723
+    topo.standalone.modify_s(ldbm_config,
61f723
+                                    [(ldap.MOD_REPLACE, txn_begin_flag, "on")])
61f723
+                                    # check default value is DB_TXN_NOWAIT
61f723
+    _check_configured_value(topo, expected_value="on")
61f723
+    _update_db(topo)
61f723
+    topo.standalone.restart(timeout=10)
61f723
+    _check_configured_value(topo, expected_value="on")
61f723
+    _update_db(topo)
61f723
+    
61f723
+    # switch default value
61f723
+    topo.standalone.modify_s(ldbm_config,
61f723
+                                    [(ldap.MOD_DELETE, txn_begin_flag, None)])
61f723
+    # check default value is DB_TXN_NOWAIT
61f723
+    _check_configured_value(topo, expected_value="off")
61f723
+    # tests we are able to update DB
61f723
+    _update_db(topo)
61f723
+    topo.standalone.restart(timeout=10)
61f723
+    _check_configured_value(topo, expected_value="off")
61f723
+    # tests we are able to update DB
61f723
+    _update_db(topo)    
61f723
+                              
61f723
+
61f723
+    if DEBUGGING:
61f723
+        # Add debugging steps(if any)...
61f723
+        pass
61f723
+
61f723
+
61f723
+if __name__ == '__main__':
61f723
+    # Run isolated
61f723
+    # -s for DEBUG mode
61f723
+    CURRENT_FILE = os.path.realpath(__file__)
61f723
+    pytest.main("-s %s" % CURRENT_FILE)
61f723
+
61f723
diff --git a/ldap/servers/slapd/back-ldbm/dblayer.c b/ldap/servers/slapd/back-ldbm/dblayer.c
61f723
index 683994f..507a3cc 100644
61f723
--- a/ldap/servers/slapd/back-ldbm/dblayer.c
61f723
+++ b/ldap/servers/slapd/back-ldbm/dblayer.c
61f723
@@ -3374,6 +3374,8 @@ dblayer_txn_begin_ext(struct ldbminfo *li, back_txnid parent_txn, back_txn *txn,
61f723
 
61f723
     if (priv->dblayer_enable_transactions)
61f723
     {
61f723
+        int txn_begin_flags;
61f723
+
61f723
         dblayer_private_env *pEnv = priv->dblayer_env;
61f723
         if(use_lock) slapi_rwlock_rdlock(pEnv->dblayer_env_lock);
61f723
         if (!parent_txn)
61f723
@@ -3383,11 +3385,16 @@ dblayer_txn_begin_ext(struct ldbminfo *li, back_txnid parent_txn, back_txn *txn,
61f723
             if (par_txn_txn) {
61f723
                 parent_txn = par_txn_txn->back_txn_txn;
61f723
             }
61f723
+                }
61f723
+        if (priv->dblayer_txn_wait) {
61f723
+                txn_begin_flags = 0;
61f723
+        } else {
61f723
+                txn_begin_flags = DB_TXN_NOWAIT;
61f723
         }
61f723
         return_value = TXN_BEGIN(pEnv->dblayer_DB_ENV,
61f723
                                  (DB_TXN*)parent_txn,
61f723
                                  &new_txn.back_txn_txn,
61f723
-                                 DB_TXN_NOWAIT);
61f723
+                                 txn_begin_flags);
61f723
         if (0 != return_value) 
61f723
         {
61f723
             if(use_lock) slapi_rwlock_unlock(priv->dblayer_env->dblayer_env_lock);
61f723
diff --git a/ldap/servers/slapd/back-ldbm/dblayer.h b/ldap/servers/slapd/back-ldbm/dblayer.h
61f723
index e02e6e0..e4307fc 100644
61f723
--- a/ldap/servers/slapd/back-ldbm/dblayer.h
61f723
+++ b/ldap/servers/slapd/back-ldbm/dblayer.h
61f723
@@ -104,6 +104,9 @@ struct dblayer_private
61f723
                                         * the mpool */
61f723
     int dblayer_recovery_required;
61f723
     int dblayer_enable_transactions;
61f723
+    int dblayer_txn_wait;           /* Default is "off" (DB_TXN_NOWAIT) but for
61f723
+                                     * support purpose it could be helpful to set
61f723
+                                     * "on" so that backend hang on deadlock */
61f723
     int dblayer_durable_transactions;
61f723
     int dblayer_checkpoint_interval;
61f723
     int dblayer_circular_logging;
61f723
diff --git a/ldap/servers/slapd/back-ldbm/ldbm_config.c b/ldap/servers/slapd/back-ldbm/ldbm_config.c
61f723
index 8541224..dfe7a13 100644
61f723
--- a/ldap/servers/slapd/back-ldbm/ldbm_config.c
61f723
+++ b/ldap/servers/slapd/back-ldbm/ldbm_config.c
61f723
@@ -636,6 +636,27 @@ static int ldbm_config_db_transaction_logging_set(void *arg, void *value, char *
61f723
     return retval;
61f723
 }
61f723
 
61f723
+
61f723
+static void *ldbm_config_db_transaction_wait_get(void *arg)
61f723
+{
61f723
+    struct ldbminfo *li = (struct ldbminfo *) arg;
61f723
+
61f723
+    return (void *) ((uintptr_t)li->li_dblayer_private->dblayer_txn_wait);
61f723
+}
61f723
+
61f723
+static int ldbm_config_db_transaction_wait_set(void *arg, void *value, char *errorbuf, int phase, int apply)
61f723
+{
61f723
+    struct ldbminfo *li = (struct ldbminfo *) arg;
61f723
+    int retval = LDAP_SUCCESS;
61f723
+    int val = (int) ((uintptr_t)value);
61f723
+
61f723
+    if (apply) {
61f723
+        li->li_dblayer_private->dblayer_txn_wait = val;
61f723
+    }
61f723
+
61f723
+    return retval;
61f723
+}
61f723
+
61f723
 static void *ldbm_config_db_logbuf_size_get(void *arg) 
61f723
 {
61f723
     struct ldbminfo *li = (struct ldbminfo *) arg;
61f723
@@ -1517,6 +1538,7 @@ static config_info ldbm_config[] = {
61f723
     {CONFIG_DB_DURABLE_TRANSACTIONS, CONFIG_TYPE_ONOFF, "on", &ldbm_config_db_durable_transactions_get, &ldbm_config_db_durable_transactions_set, CONFIG_FLAG_ALWAYS_SHOW},
61f723
     {CONFIG_DB_CIRCULAR_LOGGING, CONFIG_TYPE_ONOFF, "on", &ldbm_config_db_circular_logging_get, &ldbm_config_db_circular_logging_set, 0},
61f723
     {CONFIG_DB_TRANSACTION_LOGGING, CONFIG_TYPE_ONOFF, "on", &ldbm_config_db_transaction_logging_get, &ldbm_config_db_transaction_logging_set, 0},
61f723
+    {CONFIG_DB_TRANSACTION_WAIT, CONFIG_TYPE_ONOFF, "off", &ldbm_config_db_transaction_wait_get, &ldbm_config_db_transaction_wait_set, CONFIG_FLAG_ALWAYS_SHOW|CONFIG_FLAG_ALLOW_RUNNING_CHANGE},
61f723
     {CONFIG_DB_CHECKPOINT_INTERVAL, CONFIG_TYPE_INT, "60", &ldbm_config_db_checkpoint_interval_get, &ldbm_config_db_checkpoint_interval_set, CONFIG_FLAG_ALWAYS_SHOW|CONFIG_FLAG_ALLOW_RUNNING_CHANGE},
61f723
     {CONFIG_DB_COMPACTDB_INTERVAL, CONFIG_TYPE_INT, "2592000"/*30days*/, &ldbm_config_db_compactdb_interval_get, &ldbm_config_db_compactdb_interval_set, CONFIG_FLAG_ALWAYS_SHOW|CONFIG_FLAG_ALLOW_RUNNING_CHANGE},
61f723
     {CONFIG_DB_TRANSACTION_BATCH, CONFIG_TYPE_INT, "0", &dblayer_get_batch_transactions, &dblayer_set_batch_transactions, CONFIG_FLAG_ALWAYS_SHOW|CONFIG_FLAG_ALLOW_RUNNING_CHANGE},
61f723
diff --git a/ldap/servers/slapd/back-ldbm/ldbm_config.h b/ldap/servers/slapd/back-ldbm/ldbm_config.h
61f723
index f481937..ddec3a8 100644
61f723
--- a/ldap/servers/slapd/back-ldbm/ldbm_config.h
61f723
+++ b/ldap/servers/slapd/back-ldbm/ldbm_config.h
61f723
@@ -80,6 +80,7 @@ struct config_info {
61f723
 #define CONFIG_DB_DURABLE_TRANSACTIONS "nsslapd-db-durable-transaction"
61f723
 #define CONFIG_DB_CIRCULAR_LOGGING "nsslapd-db-circular-logging"
61f723
 #define CONFIG_DB_TRANSACTION_LOGGING "nsslapd-db-transaction-logging"
61f723
+#define CONFIG_DB_TRANSACTION_WAIT "nsslapd-db-transaction-wait"
61f723
 #define CONFIG_DB_CHECKPOINT_INTERVAL "nsslapd-db-checkpoint-interval"
61f723
 #define CONFIG_DB_COMPACTDB_INTERVAL "nsslapd-db-compactdb-interval"
61f723
 #define CONFIG_DB_TRANSACTION_BATCH  "nsslapd-db-transaction-batch-val"
61f723
-- 
61f723
2.9.3
61f723