- private synchronized 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);