Skip to content

ARTEMIS-6043 updating divert w/mngmnt API can persist invalid config#6406

Merged
clebertsuconic merged 1 commit intoapache:mainfrom
jbertram:ARTEMIS-6043
May 1, 2026
Merged

ARTEMIS-6043 updating divert w/mngmnt API can persist invalid config#6406
clebertsuconic merged 1 commit intoapache:mainfrom
jbertram:ARTEMIS-6043

Conversation

@jbertram
Copy link
Copy Markdown
Contributor

@jbertram jbertram commented May 1, 2026

This commit fixes two related issues:

  • Ensures the broker can still start if recovering a persisted divert configuration fails
  • Ensures the broker does not persist an invalid divert configuration


storageManager.storeDivertConfiguration(new PersistedDivertConfiguration(config));
if (onDiskDivert != null) {
storageManager.storeDivertConfiguration(new PersistedDivertConfiguration(onDiskDivert));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add comments for two things I had to dive in to realize:

I - The fact that storeDiverConfiguration will replace the old one by the new record you are sending now.
II - updateDivert is called for both in XML configuration and in Journal configurations. That object is used to verify if it's coming from storage or not.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

}
}
} catch (Exception e) {
ActiveMQServerLogger.LOGGER.failedToRecoverStoredDivertConfiguration(persistedDivertConfiguration.getName(), e);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My suggestion for this method:

private void recoverStoredDiverts() throws Exception {
      if (storageManager.recoverDivertConfigurations() != null) {

         for (PersistedDivertConfiguration persistedDivertConfiguration : storageManager.recoverDivertConfigurations()) {
            try {
               //has it been removed from config
               boolean deleted = configuration.getDivertConfigurations().stream().noneMatch(divertConfiguration -> divertConfiguration.getName().equals(persistedDivertConfiguration.getName()));
               // if it has remove it if configured to do so
               if (deleted) {
                  if (addressSettingsRepository.getMatch(persistedDivertConfiguration.getDivertConfiguration().getAddress()).getConfigDeleteDiverts() == DeletionPolicy.FORCE) {
                     storageManager.deleteDivertConfiguration(persistedDivertConfiguration.getName());
                  } else {
                     deployDivert(persistedDivertConfiguration.getDivertConfiguration());
                  }
               }
            } catch (Exception e) {
               logger.debug(e.getMessage(), e);
               ActiveMQServerLogger.LOGGER.failedToRecoverStoredDivertConfiguration(persistedDivertConfiguration.getName(), String.valueOf(persistedDivertConfiguration.getDivertConfiguration()));
            }
         }
      }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it.

This commit fixes two related issues:
 - Ensures the broker can still start if recovering a persisted divert
   configuration fails
 - Ensures the broker does not persist an invalid divert configuration
@clebertsuconic
Copy link
Copy Markdown
Contributor

LGTM

@clebertsuconic clebertsuconic merged commit 546b1ac into apache:main May 1, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants