use of org.infinispan.partitionhandling.AvailabilityMode in project infinispan by infinispan.
the class ScatteredPartitionHandlingManagerImpl method doCheck.
@Override
public void doCheck(Object key, boolean isWrite, long flagBitSet) {
AvailabilityMode availabilityMode = getAvailabilityMode();
if (log.isTraceEnabled())
log.tracef("Checking availability for key=%s, status=%s", key, availabilityMode);
if (availabilityMode == AvailabilityMode.AVAILABLE)
return;
LocalizedCacheTopology cacheTopology = distributionManager.getCacheTopology();
if (isKeyOperationAllowed(isWrite, flagBitSet, cacheTopology, key))
return;
if (log.isTraceEnabled())
log.tracef("Partition is in %s mode, access is not allowed for key %s", availabilityMode, key);
throw CONTAINER.degradedModeKeyUnavailable(key);
}
use of org.infinispan.partitionhandling.AvailabilityMode in project infinispan by infinispan.
the class LocalCacheStatus method getClusterAvailability.
@ManagedAttribute(description = "Cluster availability", displayName = "Cluster availability", dataType = DataType.TRAIT, writable = false)
public String getClusterAvailability() {
AvailabilityMode clusterAvailability = AvailabilityMode.AVAILABLE;
synchronized (runningCaches) {
for (LocalCacheStatus cacheStatus : runningCaches.values()) {
AvailabilityMode availabilityMode = cacheStatus.getPartitionHandlingManager().getAvailabilityMode();
clusterAvailability = clusterAvailability.min(availabilityMode);
}
}
return clusterAvailability.toString();
}
use of org.infinispan.partitionhandling.AvailabilityMode in project infinispan by infinispan.
the class LocalCacheStatus method doHandleTopologyUpdate.
/**
* Update the cache topology in the LocalCacheStatus and pass it to the CacheTopologyHandler.
*
* @return {@code true} if the topology was applied, {@code false} if it was ignored.
*/
private CompletionStage<Boolean> doHandleTopologyUpdate(String cacheName, CacheTopology cacheTopology, AvailabilityMode availabilityMode, int viewId, Address sender, LocalCacheStatus cacheStatus) {
CacheTopology existingTopology;
synchronized (cacheStatus) {
if (cacheTopology == null) {
// Still, return true because we don't want to re-send the join request.
return CompletableFutures.completedTrue();
}
// Register all persistent UUIDs locally
registerPersistentUUID(cacheTopology);
existingTopology = cacheStatus.getCurrentTopology();
if (existingTopology != null && cacheTopology.getTopologyId() <= existingTopology.getTopologyId()) {
log.debugf("Ignoring late consistent hash update for cache %s, current topology is %s: %s", cacheName, existingTopology.getTopologyId(), cacheTopology);
return CompletableFutures.completedFalse();
}
if (!updateCacheTopology(cacheName, cacheTopology, viewId, sender, cacheStatus))
return CompletableFutures.completedFalse();
}
CacheTopologyHandler handler = cacheStatus.getHandler();
ConsistentHash currentCH = cacheTopology.getCurrentCH();
ConsistentHash pendingCH = cacheTopology.getPendingCH();
ConsistentHash unionCH;
if (pendingCH != null) {
ConsistentHashFactory chf = cacheStatus.getJoinInfo().getConsistentHashFactory();
switch(cacheTopology.getPhase()) {
case READ_NEW_WRITE_ALL:
// When removing members from topology, we have to make sure that the unionCH has
// owners from pendingCH (which is used as the readCH in this phase) before
// owners from currentCH, as primary owners must match in readCH and writeCH.
unionCH = chf.union(pendingCH, currentCH);
break;
default:
unionCH = chf.union(currentCH, pendingCH);
}
} else {
unionCH = null;
}
List<PersistentUUID> persistentUUIDs = persistentUUIDManager.mapAddresses(cacheTopology.getActualMembers());
CacheTopology unionTopology = new CacheTopology(cacheTopology.getTopologyId(), cacheTopology.getRebalanceId(), currentCH, pendingCH, unionCH, cacheTopology.getPhase(), cacheTopology.getActualMembers(), persistentUUIDs);
boolean updateAvailabilityModeFirst = availabilityMode != AvailabilityMode.AVAILABLE;
CompletionStage<Void> stage = resetLocalTopologyBeforeRebalance(cacheName, cacheTopology, existingTopology, handler);
stage = stage.thenCompose(ignored -> {
unionTopology.logRoutingTableInformation(cacheName);
if (updateAvailabilityModeFirst && availabilityMode != null) {
return cacheStatus.getPartitionHandlingManager().setAvailabilityMode(availabilityMode);
}
return CompletableFutures.completedNull();
});
stage = stage.thenCompose(ignored -> {
boolean startConflictResolution = cacheTopology.getPhase() == CacheTopology.Phase.CONFLICT_RESOLUTION;
if (!startConflictResolution && unionCH != null && (existingTopology == null || existingTopology.getRebalanceId() != cacheTopology.getRebalanceId())) {
// This CH_UPDATE command was sent after a REBALANCE_START command, but arrived first.
// We will start the rebalance now and ignore the REBALANCE_START command when it arrives.
log.tracef("This topology update has a pending CH, starting the rebalance now");
return handler.rebalance(unionTopology);
} else {
return handler.updateConsistentHash(unionTopology);
}
});
if (!updateAvailabilityModeFirst) {
stage = stage.thenCompose(ignored -> cacheStatus.getPartitionHandlingManager().setAvailabilityMode(availabilityMode));
}
return stage.thenApply(ignored -> true);
}
use of org.infinispan.partitionhandling.AvailabilityMode in project infinispan by infinispan.
the class CacheResourceV2 method getCacheAvailability.
private CompletionStage<RestResponse> getCacheAvailability(RestRequest request) {
String cacheName = request.variables().get("cacheName");
// Use EmbeddedCacheManager directly to allow internal caches to be updated
if (!invocationHelper.getRestCacheManager().getInstance().isRunning(cacheName))
return notFoundResponseFuture();
AdvancedCache<?, ?> cache = invocationHelper.getRestCacheManager().getInstance().getCache(cacheName).getAdvancedCache();
if (cache == null) {
return notFoundResponseFuture();
}
AvailabilityMode availability = cache.getAvailability();
return CompletableFuture.completedFuture(new NettyRestResponse.Builder().entity(availability).contentType(TEXT_PLAIN).status(OK).build());
}
use of org.infinispan.partitionhandling.AvailabilityMode in project infinispan by infinispan.
the class CacheResourceV2 method setCacheAvailability.
private CompletionStage<RestResponse> setCacheAvailability(RestRequest request) {
String cacheName = request.variables().get("cacheName");
String availability = request.getParameter("availability");
// Use EmbeddedCacheManager directly to allow internal caches to be updated
if (!invocationHelper.getRestCacheManager().getInstance().isRunning(cacheName))
return notFoundResponseFuture();
AdvancedCache<?, ?> cache = invocationHelper.getRestCacheManager().getInstance().getCache(cacheName).getAdvancedCache();
if (cache == null) {
return notFoundResponseFuture();
}
try {
AvailabilityMode availabilityMode = AvailabilityMode.valueOf(availability.toUpperCase());
cache.setAvailability(availabilityMode);
return CompletableFuture.completedFuture(new NettyRestResponse.Builder().status(NO_CONTENT).build());
} catch (IllegalArgumentException e) {
return badRequestResponseFuture(String.format("Unknown AvailabilityMode '%s'", availability));
}
}
Aggregations