Browse Source

Ticket 47329 - Improve slapi_back_transaction_begin() return code when transactions are not available

    Bug Description:  The slapi_back_transaction_begin() function needs it's return codes
                      to be changed to be more friendly for plug-in writers when
                      transactions are not available.

    Fix Description:  Added new error code SLAPI_BACK_TRANSACTION_NOT_SUPPORTED, and
                      updated the slapi_plugin.h

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

    Reviewed by: Noriko, Ludwig, and Rich(Thanks!!!)
Mark Reynolds 12 years ago
parent
commit
8879ed2efa
2 changed files with 23 additions and 5 deletions
  1. 21 5
      ldap/servers/slapd/backend.c
  2. 2 0
      ldap/servers/slapd/slapi-plugin.h

+ 21 - 5
ldap/servers/slapd/backend.c

@@ -648,8 +648,13 @@ int
 slapi_back_transaction_begin(Slapi_PBlock *pb)
 {
     IFP txn_begin;
-    slapi_pblock_get(pb, SLAPI_PLUGIN_DB_BEGIN_FN, (void*)&txn_begin);
-    return txn_begin(pb);
+    if(slapi_pblock_get(pb, SLAPI_PLUGIN_DB_BEGIN_FN, (void*)&txn_begin) ||
+       !txn_begin)
+    {
+        return SLAPI_BACK_TRANSACTION_NOT_SUPPORTED;
+    } else {
+        return txn_begin(pb);
+    }
 }
 
 /* API to expose DB transaction commit */
@@ -657,7 +662,13 @@ int
 slapi_back_transaction_commit(Slapi_PBlock *pb)
 {
     IFP txn_commit;
-    slapi_pblock_get(pb, SLAPI_PLUGIN_DB_COMMIT_FN, (void*)&txn_commit);
+    if(slapi_pblock_get(pb, SLAPI_PLUGIN_DB_COMMIT_FN, (void*)&txn_commit) ||
+        !txn_commit)
+    {
+        return SLAPI_BACK_TRANSACTION_NOT_SUPPORTED;
+    } else {
+        return txn_commit(pb);
+    }
     return txn_commit(pb);
 }
 
@@ -666,6 +677,11 @@ int
 slapi_back_transaction_abort(Slapi_PBlock *pb)
 {
     IFP txn_abort;
-    slapi_pblock_get(pb, SLAPI_PLUGIN_DB_ABORT_FN, (void*)&txn_abort);
-    return txn_abort(pb);
+    if(slapi_pblock_get(pb, SLAPI_PLUGIN_DB_ABORT_FN, (void*)&txn_abort) ||
+        !txn_abort)
+    {
+        return SLAPI_BACK_TRANSACTION_NOT_SUPPORTED;
+    } else {
+        return txn_abort(pb);
+    }
 }

+ 2 - 0
ldap/servers/slapd/slapi-plugin.h

@@ -6061,6 +6061,7 @@ const char * slapi_be_gettype(Slapi_Backend *be);
  *
  * \param pb Pblock which is supposed to set (Slapi_Backend *) to SLAPI_BACKEND
  * \return 0 if successful
+ * \return SLAPI_BACK_TRANSACTION_NOT_SUPPORTED if transaction support is not available for this backend
  * \return Non-zero if an error occurred
  *
  * \see slapi_back_transaction_commit
@@ -6908,6 +6909,7 @@ typedef struct slapi_plugindesc {
 #define SLAPI_PARENT_TXN			190
 #define SLAPI_TXN				191
 #define SLAPI_TXN_RUV_MODS_FN			1901
+#define SLAPI_BACK_TRANSACTION_NOT_SUPPORTED	1902
 
 /*
  * The following are used to pass information back and forth