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

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