Skip to content

Commit

Permalink
Fix issue with Datasource DevServices reload
Browse files Browse the repository at this point in the history
When a dev-services property was set, Quarkus would
stop and restart the database even if nothing changed.

Fixes: quarkusio#20346
Fixes: quarkusio#20214
(cherry picked from commit 236bc99)
  • Loading branch information
geoand committed Sep 28, 2021
1 parent 3613077 commit 0faa594
Showing 1 changed file with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class DevServicesDatasourceProcessor {

static volatile List<Closeable> databases;

static volatile Map<String, String> cachedProperties;
static volatile Map<String, Object> cachedProperties;

static volatile boolean first = true;

Expand All @@ -62,9 +62,9 @@ DevServicesDatasourceResultBuildItem launchDatabases(CurateOutcomeBuildItem cura
if (databases != null) {
boolean restartRequired = false;
if (!restartRequired) {
for (Map.Entry<String, String> i : cachedProperties.entrySet()) {
if (!Objects.equals(i.getValue(),
ConfigProvider.getConfig().getOptionalValue(i.getKey(), String.class).orElse(null))) {
for (Map.Entry<String, Object> entry : cachedProperties.entrySet()) {
if (!Objects.equals(entry.getValue().toString(),
ConfigProvider.getConfig().getOptionalValue(entry.getKey(), String.class).orElse(null))) {
restartRequired = true;
break;
}
Expand Down Expand Up @@ -102,7 +102,7 @@ DevServicesDatasourceResultBuildItem launchDatabases(CurateOutcomeBuildItem cura
//to keep things simpler for now we are only going to support this for the default datasource
//support for named datasources will come later

Map<String, String> propertiesMap = new HashMap<>();
Map<String, Object> propertiesMap = new HashMap<>();
List<Closeable> closeableList = new ArrayList<>();
Map<String, List<DevServicesDatasourceConfigurationHandlerBuildItem>> configHandlersByDbType = configurationHandlerBuildItems
.stream()
Expand Down Expand Up @@ -178,7 +178,7 @@ private DevServicesDatasourceResultBuildItem.DbResult startDevDb(String dbName,
boolean hasNamedDatasources,
Map<String, DevServicesDatasourceProvider> devDBProviders, DataSourceBuildTimeConfig dataSourceBuildTimeConfig,
Map<String, List<DevServicesDatasourceConfigurationHandlerBuildItem>> configurationHandlerBuildItems,
Map<String, String> propertiesMap, List<Closeable> closeableList,
Map<String, Object> propertiesMap, List<Closeable> closeableList,
LaunchMode launchMode, Optional<ConsoleInstalledBuildItem> consoleInstalledBuildItem,
LoggingSetupBuildItem loggingSetupBuildItem) {
boolean explicitlyDisabled = !(dataSourceBuildTimeConfig.devservices.enabled
Expand Down Expand Up @@ -262,8 +262,19 @@ private DevServicesDatasourceResultBuildItem.DbResult startDevDb(String dbName,
dataSourceBuildTimeConfig.devservices.port, launchMode);
closeableList.add(datasource.getCloseTask());

Map<String, String> devDebProperties = new HashMap<>();
propertiesMap.put(prefix + "db-kind", dataSourceBuildTimeConfig.dbKind.orElse(null));
String devServicesPrefix = prefix + "devservices.";
if (dataSourceBuildTimeConfig.devservices.imageName.isPresent()) {
propertiesMap.put(devServicesPrefix + "image-name", dataSourceBuildTimeConfig.devservices.imageName.get());
}
if (dataSourceBuildTimeConfig.devservices.port.isPresent()) {
propertiesMap.put(devServicesPrefix + "port", dataSourceBuildTimeConfig.devservices.port.getAsInt());
}
if (!dataSourceBuildTimeConfig.devservices.properties.isEmpty()) {
propertiesMap.put(devServicesPrefix + "port", dataSourceBuildTimeConfig.devservices.properties);
}

Map<String, String> devDebProperties = new HashMap<>();
for (DevServicesDatasourceConfigurationHandlerBuildItem devDbConfigurationHandlerBuildItem : configHandlers) {
devDebProperties.putAll(devDbConfigurationHandlerBuildItem.getConfigProviderFunction()
.apply(dbName, datasource));
Expand Down

0 comments on commit 0faa594

Please sign in to comment.