Skip to content

Commit

Permalink
Improve exception message when multiple primary providers are detected.
Browse files Browse the repository at this point in the history
  • Loading branch information
pferraro committed Nov 23, 2016
1 parent 07b758d commit f3c646c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
Expand Up @@ -82,8 +82,8 @@ public interface ClusteringServerLogger extends BasicLogger {
@Message(id = 7, value = "Just reached required quorum of %2$d for %1$s service. If this cluster loses another member, no node will be chosen to provide this service.")
void quorumJustReached(String service, int quorum);

@Message(id = 8, value = "Expected service %s value from singleton master only, but instead received %d results.")
IllegalStateException unexpectedResponseCount(String serviceName, int results);
@Message(id = 8, value = "Detected multiple primary providers for %s service: %s")
IllegalStateException multiplePrimaryProvidersDetected(String serviceName, Collection<Node> nodes);

@Message(id = 9, value = "Singleton service %s is not started.")
IllegalStateException notStarted(String serviceName);
Expand Down
Expand Up @@ -22,6 +22,7 @@

package org.wildfly.clustering.server.singleton;

import java.util.AbstractMap;
import java.util.Collections;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -64,24 +65,24 @@ public T getValue() {
CommandDispatcher<SingletonContext<T>> dispatcher = this.dispatcher.get();
ServiceProviderRegistration<ServiceName> registration = this.registration.get();
try {
List<T> result = Collections.emptyList();
List<Map.Entry<Node, Optional<T>>> result = Collections.emptyList();
while (result.isEmpty()) {
if (!this.started) {
throw ClusteringServerLogger.ROOT_LOGGER.notStarted(registration.getService().getCanonicalName());
}
Map<Node, CommandResponse<Optional<T>>> responses = dispatcher.executeOnCluster(new SingletonValueCommand<T>());
// Prune non-primary (i.e. null) results
result = responses.values().stream().map(response -> {
result = responses.entrySet().stream().map(entry -> {
try {
return response.get();
return new AbstractMap.SimpleImmutableEntry<>(entry.getKey(), entry.getValue().get());
} catch (ExecutionException e) {
throw new IllegalArgumentException(e);
}
}).filter(value -> value != null).map(value -> value.orElse(null)).collect(Collectors.toList());
}).filter(entry -> entry.getValue() != null).collect(Collectors.toList());
// We expect only 1 result
if (result.size() > 1) {
// This would mean there are multiple primary nodes!
throw ClusteringServerLogger.ROOT_LOGGER.unexpectedResponseCount(registration.getService().getCanonicalName(), result.size());
throw ClusteringServerLogger.ROOT_LOGGER.multiplePrimaryProvidersDetected(registration.getService().getCanonicalName(), result.stream().map(entry -> entry.getKey()).collect(Collectors.toList()));
}
if (result.isEmpty()) {
ClusteringServerLogger.ROOT_LOGGER.noResponseFromMaster(registration.getService().getCanonicalName());
Expand All @@ -96,7 +97,7 @@ public T getValue() {
Thread.yield();
}
}
return result.get(0);
return result.get(0).getValue().orElse(null);
} catch (CommandDispatcherException e) {
throw new IllegalStateException(e);
} catch (InterruptedException e) {
Expand Down

0 comments on commit f3c646c

Please sign in to comment.