BUG6595: Adding a retry for getting a transactionsafely 49/45049/1
authorShuva Kar <shuva.jyoti.kar@ericsson.com>
Fri, 2 Sep 2016 05:21:41 +0000 (10:51 +0530)
committerShuva Jyoti Kar <shuva.jyoti.kar@ericsson.com>
Fri, 2 Sep 2016 06:14:21 +0000 (06:14 +0000)
since the RCA for the issue pointed to the fact that the
mastership of the switch hadnot been established while
the port status is processed.

Change-Id: If243a051b8417b35160144213dd268f1c2bf4225
Signed-off-by: Shuva Kar <shuva.jyoti.kar@ericsson.com>
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/TransactionChainManager.java

index dcb7f70bbb8ca2237745298d22667f81cc0de3a2..38b561314dddd773b4a557d07dc094e10c7f61c0 100644 (file)
@@ -17,6 +17,7 @@ import com.google.common.util.concurrent.ListenableFuture;
 
 import java.util.Objects;
 import java.util.concurrent.CancellationException;
+import java.util.concurrent.TimeUnit;
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 import javax.annotation.concurrent.GuardedBy;
@@ -52,6 +53,8 @@ import org.slf4j.LoggerFactory;
 class TransactionChainManager implements TransactionChainListener, AutoCloseable {
 
     private static final Logger LOG = LoggerFactory.getLogger(TransactionChainManager.class);
+    private static final Long RETRY_DELAY = 100L;
+    private static final int RETRY_COUNT = 3;
 
     private final Object txLock = new Object();
     private final KeyedInstanceIdentifier<Node, NodeKey> nodeII;
@@ -258,9 +261,20 @@ class TransactionChainManager implements TransactionChainListener, AutoCloseable
     @Nullable
     private WriteTransaction getTransactionSafely() {
             synchronized (txLock) {
-                if (wTx == null && TransactionChainManagerStatus.WORKING.equals(transactionChainManagerStatus)) {
-                    if (wTx == null && txChainFactory != null) {
-                        wTx = txChainFactory.newWriteOnlyTransaction();
+                int trial = 0;
+                while(trial <=RETRY_COUNT) {
+                    if (wTx == null && TransactionChainManagerStatus.WORKING.equals(transactionChainManagerStatus)) {
+                        if (wTx == null && txChainFactory != null) {
+                            wTx = txChainFactory.newWriteOnlyTransaction();
+                            break;
+                        }
+                    } else {
+                        try {
+                            TimeUnit.MILLISECONDS.sleep(RETRY_DELAY);
+                        } catch (InterruptedException e) {
+                            LOG.debug("Timer interrupted in getTransactionSafely : {}", e);
+                        }
+                        trial++;
                     }
                 }
             }
@@ -326,4 +340,4 @@ class TransactionChainManager implements TransactionChainListener, AutoCloseable
         /** txChainManager is trying to be closed - device disconnecting */
         SHUTTING_DOWN;
     }
-}
+}
\ No newline at end of file