From 6e838af88027d06b239d346b4617db24b6e8e830 Mon Sep 17 00:00:00 2001 From: "K.V Suneelu Verma" Date: Tue, 16 Aug 2016 22:53:48 +0530 Subject: [PATCH] Bug 5555: Exception during operations on ReadWriteTransaction 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 --- .../md/TransactionInvokerImpl.java | 23 ++++++++++++++++--- .../md/TransactionInvokerImpl.java | 23 ++++++++++++++++--- 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transactions/md/TransactionInvokerImpl.java b/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transactions/md/TransactionInvokerImpl.java index 8f4ab7005..6be19c89e 100644 --- a/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transactions/md/TransactionInvokerImpl.java +++ b/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transactions/md/TransactionInvokerImpl.java @@ -80,10 +80,20 @@ public class TransactionInvokerImpl implements TransactionInvoker,TransactionCha public void run() { while (true) { forgetSuccessfulTransactions(); + + List commands = null; + try { + commands = extractCommands(); + } catch (InterruptedException e) { + LOG.warn("Extracting commands was interrupted.", e); + continue; + } + + ReadWriteTransaction transactionInFlight = null; try { - List 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() { @@ -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); } } } diff --git a/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/transactions/md/TransactionInvokerImpl.java b/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/transactions/md/TransactionInvokerImpl.java index ae8ea401a..66b589efb 100644 --- a/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/transactions/md/TransactionInvokerImpl.java +++ b/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/transactions/md/TransactionInvokerImpl.java @@ -77,10 +77,20 @@ public class TransactionInvokerImpl implements TransactionInvoker,TransactionCha public void run() { while (runTask.get()) { forgetSuccessfulTransactions(); + + List commands = null; + try { + commands = extractCommands(); + } catch (InterruptedException e) { + LOG.warn("Extracting commands was interrupted.", e); + continue; + } + + ReadWriteTransaction transactionInFlight = null; try { - List 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() { @@ -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); } } } -- 2.36.6