X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fconfig%2Fconfig-manager%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fmanager%2Fimpl%2Fosgi%2FBlankTransactionServiceTracker.java;h=720b7197ea6100b0890ee0fd4a89d5f5de9157bd;hb=aae447eb2ce6272e1bfd2517a6493bf2ea40ed7a;hp=106a7fbb2be8ced7bfb2d054b296b9a86e0462d7;hpb=33ea0032f0837333a9181dd7556faa3266155080;p=controller.git diff --git a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/BlankTransactionServiceTracker.java b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/BlankTransactionServiceTracker.java index 106a7fbb2b..720b7197ea 100644 --- a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/BlankTransactionServiceTracker.java +++ b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/BlankTransactionServiceTracker.java @@ -7,6 +7,8 @@ */ package org.opendaylight.controller.config.manager.impl.osgi; +import org.opendaylight.controller.config.api.ConflictingVersionException; +import org.opendaylight.controller.config.api.ValidationException; import org.opendaylight.controller.config.api.jmx.CommitStatus; import org.opendaylight.controller.config.manager.impl.ConfigRegistryImpl; import org.opendaylight.controller.config.spi.ModuleFactory; @@ -19,7 +21,7 @@ import javax.management.ObjectName; /** * Every time factory is added or removed, blank transaction is triggered to handle - * {@link org.opendaylight.controller.config.spi.ModuleFactory#getDefaultModules(org.opendaylight.controller.config.api.DependencyResolverFactory)} + * {@link org.opendaylight.controller.config.spi.ModuleFactory#getDefaultModules(org.opendaylight.controller.config.api.DependencyResolverFactory, org.osgi.framework.BundleContext)} * functionality. */ public class BlankTransactionServiceTracker implements ServiceTrackerCustomizer { @@ -37,15 +39,37 @@ public class BlankTransactionServiceTracker implements ServiceTrackerCustomizer< return null; } - private void blankTransaction() { - // create transaction - ObjectName tx = configRegistry.beginConfig(); - CommitStatus commitStatus = configRegistry.commitConfig(tx); - logger.debug("Committed blank transaction with status {}", commitStatus); + synchronized void blankTransaction() { + // race condition check: config-persister might push new configuration while server is starting up. + ConflictingVersionException lastException = null; + int maxAttempts = 10; + for (int i = 0; i < maxAttempts; i++) { + try { + // create transaction + boolean blankTransaction = true; + ObjectName tx = configRegistry.beginConfig(blankTransaction); + CommitStatus commitStatus = configRegistry.commitConfig(tx); + logger.debug("Committed blank transaction with status {}", commitStatus); + return; + } catch (ConflictingVersionException e) { + lastException = e; + try { + Thread.sleep(1000); + } catch (InterruptedException interruptedException) { + Thread.currentThread().interrupt(); + throw new IllegalStateException(interruptedException); + } + } catch (ValidationException e) { + logger.error("Validation exception while running blank transaction indicates programming error", e); + throw new RuntimeException("Validation exception while running blank transaction indicates programming error", e); + } + } + throw new RuntimeException("Maximal number of attempts reached and still cannot get optimistic lock from " + + "config manager",lastException); } @Override - public void modifiedService(ServiceReference moduleFactoryServiceReference, Object o) { + public void modifiedService(ServiceReference moduleFactoryServiceReference, Object o) { blankTransaction(); }