qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kw...@apache.org
Subject svn commit: r1786723 - in /qpid/java/trunk/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb: AbstractBDBMessageStore.java BDBConfigurationStore.java BDBUtils.java
Date Mon, 13 Mar 2017 16:21:04 GMT
Author: kwall
Date: Mon Mar 13 16:21:04 2017
New Revision: 1786723

URL: http://svn.apache.org/viewvc?rev=1786723&view=rev
Log:
QPID-7684: [Java Broker, BDB] Adhere to recommended practice for retrying after a LockConflictException

Also used try-with-resources to simplify coding

Modified:
    qpid/java/trunk/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/AbstractBDBMessageStore.java
    qpid/java/trunk/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBConfigurationStore.java
    qpid/java/trunk/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBUtils.java

Modified: qpid/java/trunk/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/AbstractBDBMessageStore.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/AbstractBDBMessageStore.java?rev=1786723&r1=1786722&r2=1786723&view=diff
==============================================================================
--- qpid/java/trunk/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/AbstractBDBMessageStore.java
(original)
+++ qpid/java/trunk/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/AbstractBDBMessageStore.java
Mon Mar 13 16:21:04 2017
@@ -20,7 +20,6 @@ package org.apache.qpid.server.store.ber
 
 import static org.apache.qpid.server.store.berkeleydb.BDBUtils.DEFAULT_DATABASE_CONFIG;
 import static org.apache.qpid.server.store.berkeleydb.BDBUtils.abortTransactionSafely;
-import static org.apache.qpid.server.store.berkeleydb.BDBUtils.closeCursorSafely;
 
 import java.nio.ByteBuffer;
 import java.nio.charset.Charset;
@@ -413,10 +412,8 @@ public abstract class AbstractBDBMessage
 
     private void visitMessagesInternal(MessageHandler handler, EnvironmentFacade environmentFacade)
     {
-        Cursor cursor = null;
-        try
+        try(Cursor cursor = getMessageMetaDataDb().openCursor(null, null))
         {
-            cursor = getMessageMetaDataDb().openCursor(null, null);
             DatabaseEntry key = new DatabaseEntry();
             DatabaseEntry value = new DatabaseEntry();
             MessageMetaDataBinding valueBinding = MessageMetaDataBinding.getInstance();
@@ -450,20 +447,6 @@ public abstract class AbstractBDBMessage
         {
             throw environmentFacade.handleDatabaseException("Cannot visit messages", e);
         }
-        finally
-        {
-            if (cursor != null)
-            {
-                try
-                {
-                    cursor.close();
-                }
-                catch(RuntimeException e)
-                {
-                    throw environmentFacade.handleDatabaseException("Cannot close cursor",
e);
-                }
-            }
-        }
     }
 
     private void sleepOrThrowOnLockConflict(int attempts, String throwMessage, LockConflictException
cause)
@@ -1520,25 +1503,25 @@ public abstract class AbstractBDBMessage
         {
             checkMessageStoreOpen();
 
-            Cursor cursor = null;
-            List<QueueEntryKey> entries = new ArrayList<QueueEntryKey>();
+            final List<QueueEntryKey> entries = new ArrayList<>();
             try
             {
-                cursor = getDeliveryDb().openCursor(null, null);
-                DatabaseEntry key = new DatabaseEntry();
-                DatabaseEntry value = new DatabaseEntry();
-                value.setPartial(0, 0, true);
-
-                QueueEntryBinding keyBinding = QueueEntryBinding.getInstance();
-                keyBinding.objectToEntry(new QueueEntryKey(queue.getId(),0l), key);
-
-                boolean searchCompletedSuccessfully = false;
                 int attempts = 0;
                 boolean completed = false;
                 do
                 {
-                    try
+                    try(Cursor cursor = getDeliveryDb().openCursor(null, null))
                     {
+                        boolean searchCompletedSuccessfully = false;
+                        entries.clear();
+
+                        DatabaseEntry key = new DatabaseEntry();
+                        DatabaseEntry value = new DatabaseEntry();
+                        value.setPartial(0, 0, true);
+
+                        QueueEntryBinding keyBinding = QueueEntryBinding.getInstance();
+                        keyBinding.objectToEntry(new QueueEntryKey(queue.getId(),0l), key);
+
                         if (!searchCompletedSuccessfully && (searchCompletedSuccessfully
= cursor.getSearchKeyRange(key,value, LockMode.DEFAULT) == OperationStatus.SUCCESS))
                         {
                             QueueEntryKey entry = keyBinding.entryToObject(key);
@@ -1567,7 +1550,7 @@ public abstract class AbstractBDBMessage
                     }
                     catch (LockConflictException e)
                     {
-                        sleepOrThrowOnLockConflict(attempts++, "Cannot visit messages", e);
+                        sleepOrThrowOnLockConflict(attempts++, "Cannot visit message instances",
e);
                     }
                 }
                 while (!completed);
@@ -1576,10 +1559,6 @@ public abstract class AbstractBDBMessage
             {
                 throw getEnvironmentFacade().handleDatabaseException("Cannot visit message
instances", e);
             }
-            finally
-            {
-                closeCursorSafely(cursor, getEnvironmentFacade());
-            }
 
             for(QueueEntryKey entry : entries)
             {
@@ -1600,11 +1579,9 @@ public abstract class AbstractBDBMessage
         {
             checkMessageStoreOpen();
 
-            Cursor cursor = null;
-            List<QueueEntryKey> entries = new ArrayList<QueueEntryKey>();
-            try
+            List<QueueEntryKey> entries = new ArrayList<>();
+            try(Cursor cursor = getDeliveryDb().openCursor(null, null))
             {
-                cursor = getDeliveryDb().openCursor(null, null);
                 DatabaseEntry key = new DatabaseEntry();
                 QueueEntryBinding keyBinding = QueueEntryBinding.getInstance();
 
@@ -1620,10 +1597,6 @@ public abstract class AbstractBDBMessage
             {
                 throw getEnvironmentFacade().handleDatabaseException("Cannot visit message
instances", e);
             }
-            finally
-            {
-                closeCursorSafely(cursor, getEnvironmentFacade());
-            }
 
             for(QueueEntryKey entry : entries)
             {
@@ -1642,10 +1615,8 @@ public abstract class AbstractBDBMessage
         {
             checkMessageStoreOpen();
 
-            Cursor cursor = null;
-            try
+            try(Cursor cursor = getXidDb().openCursor(null, null))
             {
-                cursor = getXidDb().openCursor(null, null);
                 DatabaseEntry key = new DatabaseEntry();
                 XidBinding keyBinding = XidBinding.getInstance();
                 PreparedTransactionBinding valueBinding = new PreparedTransactionBinding();
@@ -1667,10 +1638,6 @@ public abstract class AbstractBDBMessage
             {
                 throw getEnvironmentFacade().handleDatabaseException("Cannot recover distributed
transactions", e);
             }
-            finally
-            {
-                closeCursorSafely(cursor, getEnvironmentFacade());
-            }
         }
 
 

Modified: qpid/java/trunk/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBConfigurationStore.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBConfigurationStore.java?rev=1786723&r1=1786722&r2=1786723&view=diff
==============================================================================
--- qpid/java/trunk/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBConfigurationStore.java
(original)
+++ qpid/java/trunk/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBConfigurationStore.java
Mon Mar 13 16:21:04 2017
@@ -25,7 +25,6 @@ import static org.apache.qpid.server.sto
 import static org.apache.qpid.server.store.berkeleydb.BDBConfigurationStore.State.OPEN;
 import static org.apache.qpid.server.store.berkeleydb.BDBUtils.DEFAULT_DATABASE_CONFIG;
 import static org.apache.qpid.server.store.berkeleydb.BDBUtils.abortTransactionSafely;
-import static org.apache.qpid.server.store.berkeleydb.BDBUtils.closeCursorSafely;
 
 import java.io.File;
 import java.util.ArrayList;
@@ -229,11 +228,8 @@ public class BDBConfigurationStore imple
     private Collection<? extends ConfiguredObjectRecord> doVisitAllConfiguredObjectRecords()
     {
         Map<UUID, BDBConfiguredObjectRecord> configuredObjects = new HashMap<UUID,
BDBConfiguredObjectRecord>();
-        Cursor objectsCursor = null;
-        Cursor hierarchyCursor = null;
-        try
+        try(Cursor objectsCursor = getConfiguredObjectsDb().openCursor(null, null))
         {
-            objectsCursor = getConfiguredObjectsDb().openCursor(null, null);
             DatabaseEntry key = new DatabaseEntry();
             DatabaseEntry value = new DatabaseEntry();
 
@@ -248,27 +244,24 @@ public class BDBConfigurationStore imple
             }
 
             // set parents
-            hierarchyCursor = getConfiguredObjectHierarchyDb().openCursor(null, null);
-            while (hierarchyCursor.getNext(key, value, LockMode.RMW) == OperationStatus.SUCCESS)
+            try(Cursor hierarchyCursor = getConfiguredObjectHierarchyDb().openCursor(null,
null))
             {
-                HierarchyKey hk = HierarchyKeyBinding.getInstance().entryToObject(key);
-                UUID parentId = UUIDTupleBinding.getInstance().entryToObject(value);
-                BDBConfiguredObjectRecord child = configuredObjects.get(hk.getChildId());
-                if(child != null)
+                while (hierarchyCursor.getNext(key, value, LockMode.RMW) == OperationStatus.SUCCESS)
                 {
-                    ConfiguredObjectRecord parent = configuredObjects.get(parentId);
-                    if(parent != null)
+                    HierarchyKey hk = HierarchyKeyBinding.getInstance().entryToObject(key);
+                    UUID parentId = UUIDTupleBinding.getInstance().entryToObject(value);
+                    BDBConfiguredObjectRecord child = configuredObjects.get(hk.getChildId());
+                    if(child != null)
                     {
-                        child.addParent(hk.getParentType(), parent);
+                        ConfiguredObjectRecord parent = configuredObjects.get(parentId);
+                        if(parent != null)
+                        {
+                            child.addParent(hk.getParentType(), parent);
+                        }
                     }
                 }
             }
         }
-        finally
-        {
-            closeCursorSafely(objectsCursor, _environmentFacade);
-            closeCursorSafely(hierarchyCursor, _environmentFacade);
-        }
         return configuredObjects.values();
 
     }

Modified: qpid/java/trunk/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBUtils.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBUtils.java?rev=1786723&r1=1786722&r2=1786723&view=diff
==============================================================================
--- qpid/java/trunk/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBUtils.java
(original)
+++ qpid/java/trunk/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBUtils.java
Mon Mar 13 16:21:04 2017
@@ -47,22 +47,6 @@ public class BDBUtils
     private static final Pattern NON_REP_JE_PARAM_PATTERN = Pattern.compile("^je\\.(?!rep\\.).*");
     private static final Pattern REP_JE_PARAM_PATTERN = Pattern.compile("^je\\.rep\\..*");
 
-    public static void closeCursorSafely(Cursor cursor, final EnvironmentFacade environmentFacade)
throws StoreException
-    {
-        if (cursor != null)
-        {
-            try
-            {
-                cursor.close();
-            }
-            catch (RuntimeException e)
-            {
-                // We need the possible side effect of the facade restarting the environment
but don't care about the exception
-                throw environmentFacade.handleDatabaseException("Cannot close cursor", e);
-            }
-        }
-    }
-
     public static void abortTransactionSafely(Transaction tx, EnvironmentFacade environmentFacade)
     {
         try



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message