Bug 5555: Exception during operations on ReadWriteTransaction 90/44090/2
authorK.V Suneelu Verma <k.v.suneelu.verma@ericsson.com>
Tue, 16 Aug 2016 17:23:48 +0000 (22:53 +0530)
committerHideyuki Tai <Hideyuki.Tai@necam.com>
Wed, 24 Aug 2016 13:43:02 +0000 (06:43 -0700)
An IllegalStateException can be happened during operations on
ReadWriteTransaction. This was resulting in system not being able to
process any southbound ovsdb events, since the code didn't handle this
exception.

Change-Id: I24ab3acc01fd5fb4d9380ccc8bcc7d332738d242
Signed-off-by: K.V Suneelu Verma <k.v.suneelu.verma@ericsson.com>
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transactions/md/TransactionInvokerImpl.java
southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/transactions/md/TransactionInvokerImpl.java

index 8f4ab70059b9d8e5c462f6dc59b85c6b253ce5fb..6be19c89e01da10df5b24995f011482ab53a34eb 100644 (file)
@@ -80,10 +80,20 @@ public class TransactionInvokerImpl implements TransactionInvoker,TransactionCha
     public void run() {
         while (true) {
             forgetSuccessfulTransactions();
+
+            List<TransactionCommand> commands = null;
+            try {
+                commands = extractCommands();
+            } catch (InterruptedException e) {
+                LOG.warn("Extracting commands was interrupted.", e);
+                continue;
+            }
+
+            ReadWriteTransaction transactionInFlight = null;
             try {
-                List<TransactionCommand> commands = extractCommands();
                 for (TransactionCommand command: commands) {
                     final ReadWriteTransaction transaction = chain.newReadWriteTransaction();
+                    transactionInFlight = transaction;
                     recordPendingTransaction(command, transaction);
                     command.execute(transaction);
                     Futures.addCallback(transaction.submit(), new FutureCallback<Void>() {
@@ -98,8 +108,15 @@ public class TransactionInvokerImpl implements TransactionInvoker,TransactionCha
                         }
                     });
                 }
-            } catch (Exception e) {
-                LOG.warn("Exception invoking Transaction: ", e);
+            } catch (IllegalStateException e) {
+                if (transactionInFlight != null) {
+                    // TODO: This method should distinguish exceptions on which the command should be
+                    // retried from exceptions on which the command should NOT be retried.
+                    // Then it should retry only the commands which should be retried, otherwise
+                    // this method will retry commands which will never be successful forever.
+                    failedTransactionQueue.offer(transactionInFlight);
+                }
+                LOG.warn("Failed to process an update notification from OVS.", e);
             }
         }
     }
index ae8ea401ac50f5755e1a98610ef00571a0867dcd..66b589efb68fe7cb4765fc602eec6caa844db104 100644 (file)
@@ -77,10 +77,20 @@ public class TransactionInvokerImpl implements TransactionInvoker,TransactionCha
     public void run() {
         while (runTask.get()) {
             forgetSuccessfulTransactions();
+
+            List<TransactionCommand> commands = null;
+            try {
+                commands = extractCommands();
+            } catch (InterruptedException e) {
+                LOG.warn("Extracting commands was interrupted.", e);
+                continue;
+            }
+
+            ReadWriteTransaction transactionInFlight = null;
             try {
-                List<TransactionCommand> commands = extractCommands();
                 for (TransactionCommand command: commands) {
                     final ReadWriteTransaction transaction = chain.newReadWriteTransaction();
+                    transactionInFlight = transaction;
                     recordPendingTransaction(command, transaction);
                     command.execute(transaction);
                     Futures.addCallback(transaction.submit(), new FutureCallback<Void>() {
@@ -95,8 +105,15 @@ public class TransactionInvokerImpl implements TransactionInvoker,TransactionCha
                         }
                     });
                 }
-            } catch (InterruptedException e) {
-                LOG.warn("Exception invoking Transaction: ", e);
+            } catch (IllegalStateException e) {
+                if (transactionInFlight != null) {
+                    // TODO: This method should distinguish exceptions on which the command should be
+                    // retried from exceptions on which the command should NOT be retried.
+                    // Then it should retry only the commands which should be retried, otherwise
+                    // this method will retry commands which will never be successful forever.
+                    failedTransactionQueue.offer(transactionInFlight);
+                }
+                LOG.warn("Failed to process an update notification from OVS.", e);
             }
         }
     }