From 0a9f8b5b08f995ee284445bc0afffc8556df6f03 Mon Sep 17 00:00:00 2001
From: abobrov <abobrov@localhost>
Date: Thu, 26 Mar 2009 16:44:59 +0000
Subject: [PATCH] - [Issue 3894] possible data corruption issues when writing binary attributes/blobs : move blobs to active state before writing the actual data, use new writeData API, optimize add operation to invoke execute/NoCommit past insert only when necessary ie when batching.

---
 opends/src/server/org/opends/server/backends/ndb/EntryContainer.java |   31 +++++++++++++++++++------------
 1 files changed, 19 insertions(+), 12 deletions(-)

diff --git a/opends/src/server/org/opends/server/backends/ndb/EntryContainer.java b/opends/src/server/org/opends/server/backends/ndb/EntryContainer.java
index 0379c05..196afa7 100644
--- a/opends/src/server/org/opends/server/backends/ndb/EntryContainer.java
+++ b/opends/src/server/org/opends/server/backends/ndb/EntryContainer.java
@@ -661,7 +661,7 @@
       try
       {
         // Invoke the operation.
-        operation.invokeOperation(txn);
+        operation.invokeOperation(txn, commit);
 
         // One last check before committing.
         if (ldapOperation != null) {
@@ -734,12 +734,13 @@
      * Invoke the operation under the given transaction.
      *
      * @param txn The transaction to be used to perform the operation.
+     * @param willCommit Indicates whether or not the caller will commit.
      * @throws NdbApiException If an error occurs in the NDB database.
      * @throws DirectoryException If a Directory Server error occurs.
      * @throws NDBException If an error occurs in the NDB backend.
      */
-    public abstract void invokeOperation(AbstractTransaction txn)
-        throws NdbApiException, DirectoryException,
+    public abstract void invokeOperation(AbstractTransaction txn,
+      boolean willCommit) throws NdbApiException, DirectoryException,
         CanceledOperationException, NDBException;
 
     /**
@@ -785,11 +786,12 @@
      * Invoke the operation under the given transaction.
      *
      * @param txn The transaction to be used to perform the operation.
+     * @param willCommit Indicates whether or not the caller will commit.
      * @throws NdbApiException If an error occurs in the NDB database.
      * @throws DirectoryException If a Directory Server error occurs.
      * @throws NDBException If an error occurs in the NDB backend.
      */
-    public void invokeOperation(AbstractTransaction txn)
+    public void invokeOperation(AbstractTransaction txn, boolean willCommit)
         throws NdbApiException, DirectoryException, NDBException
     {
       // Check that the parent entry exists.
@@ -816,7 +818,9 @@
       // Insert.
       try {
         dn2id.insert(txn, entry.getDN(), entryID, entry);
-        txn.execute();
+        if (!willCommit) {
+          txn.execute();
+        }
       } catch (NdbApiException ne) {
         if (ne.getErrorObj().getClassification() ==
           NdbError.Classification.ConstraintViolation)
@@ -1129,11 +1133,12 @@
      * Invoke the operation under the given transaction.
      *
      * @param txn The transaction to be used to perform the operation.
+     * @param willCommit Indicates whether or not the caller will commit.
      * @throws NdbApiException If an error occurs in the NDB database.
      * @throws DirectoryException If a Directory Server error occurs.
      * @throws NDBException If an error occurs in the NDB backend.
      */
-    public void invokeOperation(AbstractTransaction txn)
+    public void invokeOperation(AbstractTransaction txn, boolean willCommit)
         throws CanceledOperationException, NdbApiException,
         DirectoryException, NDBException
     {
@@ -1412,12 +1417,13 @@
     /**
      * Invoke the operation under the given transaction.
      *
-     * @param txn The transaction to be used to perform the operation
+     * @param txn The transaction to be used to perform the operation.
+     * @param willCommit Indicates whether or not the caller will commit.
      * @throws NdbApiException If an error occurs in the NDB database.
      * @throws DirectoryException If a Directory Server error occurs.
      * @throws NDBException If an error occurs in the NDB backend.
      */
-    public void invokeOperation(AbstractTransaction txn)
+    public void invokeOperation(AbstractTransaction txn, boolean willCommit)
       throws NdbApiException, DirectoryException, NDBException
     {
       entry = dn2id.get(txn, entryDN, lockMode);
@@ -1510,13 +1516,13 @@
      * Invoke the operation under the given transaction.
      *
      * @param txn The transaction to be used to perform the operation.
+     * @param willCommit Indicates whether or not the caller will commit.
      * @throws NdbApiException If an error occurs in the NDB database.
      * @throws DirectoryException If a Directory Server error occurs.
      * @throws NDBException If an error occurs in the NDB backend.
      */
-    public void invokeOperation(AbstractTransaction txn) throws NdbApiException,
-                                                        DirectoryException,
-                                                        NDBException
+    public void invokeOperation(AbstractTransaction txn, boolean willCommit)
+      throws NdbApiException, DirectoryException, NDBException
     {
       DN entryDN = newEntry.getDN();
       entryID = (Long) oldEntry.getAttachment();
@@ -1645,11 +1651,12 @@
      * Invoke the operation under the given transaction.
      *
      * @param txn The transaction to be used to perform the operation.
+     * @param willCommit Indicates whether or not the caller will commit.
      * @throws NdbApiException If an error occurs in the NDB database.
      * @throws DirectoryException If a Directory Server error occurs.
      * @throws NDBException If an error occurs in the NDB backend.
      */
-    public void invokeOperation(AbstractTransaction txn)
+    public void invokeOperation(AbstractTransaction txn, boolean willCommit)
       throws NdbApiException, DirectoryException,
       CanceledOperationException, NDBException
     {

--
Gitblit v1.10.0