Search in sources :

Example 1 with AvailabilityMode

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);
}
Also used : AvailabilityMode(org.infinispan.partitionhandling.AvailabilityMode) LocalizedCacheTopology(org.infinispan.distribution.LocalizedCacheTopology)

Example 2 with AvailabilityMode

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();
}
Also used : AvailabilityMode(org.infinispan.partitionhandling.AvailabilityMode) ManagedAttribute(org.infinispan.jmx.annotations.ManagedAttribute)

Example 3 with AvailabilityMode

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);
}
Also used : GlobalStateManager(org.infinispan.globalstate.GlobalStateManager) ScheduledFuture(java.util.concurrent.ScheduledFuture) ComponentName(org.infinispan.factories.annotations.ComponentName) LogFactory(org.infinispan.util.logging.LogFactory) CONFIG(org.infinispan.util.logging.Log.CONFIG) Stop(org.infinispan.factories.annotations.Stop) Scopes(org.infinispan.factories.scopes.Scopes) RebalancePhaseConfirmCommand(org.infinispan.commands.topology.RebalancePhaseConfirmCommand) ActionSequencer(org.infinispan.util.concurrent.ActionSequencer) GlobalStateProvider(org.infinispan.globalstate.GlobalStateProvider) MBean(org.infinispan.jmx.annotations.MBean) CompletableFutures(org.infinispan.util.concurrent.CompletableFutures) Map(java.util.Map) Scope(org.infinispan.factories.scopes.Scope) CacheShutdownRequestCommand(org.infinispan.commands.topology.CacheShutdownRequestCommand) ConsistentHash(org.infinispan.distribution.ch.ConsistentHash) CompletionStages.handleAndCompose(org.infinispan.util.concurrent.CompletionStages.handleAndCompose) GlobalComponentRegistry(org.infinispan.factories.GlobalComponentRegistry) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) GlobalStateManagerImpl(org.infinispan.globalstate.impl.GlobalStateManagerImpl) ConsistentHashFactory(org.infinispan.distribution.ch.ConsistentHashFactory) List(java.util.List) CompletionStage(java.util.concurrent.CompletionStage) CLUSTER(org.infinispan.util.logging.Log.CLUSTER) GuardedBy(net.jcip.annotations.GuardedBy) PartitionHandlingManager(org.infinispan.partitionhandling.impl.PartitionHandlingManager) RebalanceStatusRequestCommand(org.infinispan.commands.topology.RebalanceStatusRequestCommand) AvailabilityMode(org.infinispan.partitionhandling.AvailabilityMode) TimeoutException(org.infinispan.util.concurrent.TimeoutException) TIMEOUT_SCHEDULE_EXECUTOR(org.infinispan.factories.KnownComponentNames.TIMEOUT_SCHEDULE_EXECUTOR) CompletableFutures.completedNull(org.infinispan.util.concurrent.CompletableFutures.completedNull) HashMap(java.util.HashMap) Callable(java.util.concurrent.Callable) CompletableFuture(java.util.concurrent.CompletableFuture) CompletionStages(org.infinispan.util.concurrent.CompletionStages) DataType(org.infinispan.jmx.annotations.DataType) Start(org.infinispan.factories.annotations.Start) Version(org.infinispan.commons.util.Version) Log(org.infinispan.util.logging.Log) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) VoidResponseCollector(org.infinispan.remoting.transport.impl.VoidResponseCollector) ExecutorService(java.util.concurrent.ExecutorService) Address(org.infinispan.remoting.transport.Address) ReplicableCommand(org.infinispan.commands.ReplicableCommand) Transport(org.infinispan.remoting.transport.Transport) ScopedPersistentState(org.infinispan.globalstate.ScopedPersistentState) NON_BLOCKING_EXECUTOR(org.infinispan.factories.KnownComponentNames.NON_BLOCKING_EXECUTOR) CacheJoinCommand(org.infinispan.commands.topology.CacheJoinCommand) Inject(org.infinispan.factories.annotations.Inject) TimeUnit(java.util.concurrent.TimeUnit) RebalancePolicyUpdateCommand(org.infinispan.commands.topology.RebalancePolicyUpdateCommand) IllegalLifecycleStateException(org.infinispan.commons.IllegalLifecycleStateException) ManagedAttribute(org.infinispan.jmx.annotations.ManagedAttribute) CacheAvailabilityUpdateCommand(org.infinispan.commands.topology.CacheAvailabilityUpdateCommand) ScopedPersistentStateImpl(org.infinispan.globalstate.impl.ScopedPersistentStateImpl) BlockingManager(org.infinispan.util.concurrent.BlockingManager) Collections(java.util.Collections) TimeService(org.infinispan.commons.time.TimeService) CacheLeaveCommand(org.infinispan.commands.topology.CacheLeaveCommand) SuspectException(org.infinispan.remoting.transport.jgroups.SuspectException) ConsistentHash(org.infinispan.distribution.ch.ConsistentHash) ConsistentHashFactory(org.infinispan.distribution.ch.ConsistentHashFactory)

Example 4 with AvailabilityMode

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());
}
Also used : AvailabilityMode(org.infinispan.partitionhandling.AvailabilityMode) NettyRestResponse(org.infinispan.rest.NettyRestResponse)

Example 5 with AvailabilityMode

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));
    }
}
Also used : AvailabilityMode(org.infinispan.partitionhandling.AvailabilityMode) NettyRestResponse(org.infinispan.rest.NettyRestResponse)

Aggregations

AvailabilityMode (org.infinispan.partitionhandling.AvailabilityMode)7 ConsistentHash (org.infinispan.distribution.ch.ConsistentHash)3 ManagedAttribute (org.infinispan.jmx.annotations.ManagedAttribute)2 NettyRestResponse (org.infinispan.rest.NettyRestResponse)2 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Callable (java.util.concurrent.Callable)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CompletionStage (java.util.concurrent.CompletionStage)1 ExecutorService (java.util.concurrent.ExecutorService)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 ScheduledFuture (java.util.concurrent.ScheduledFuture)1 TimeUnit (java.util.concurrent.TimeUnit)1 MILLISECONDS (java.util.concurrent.TimeUnit.MILLISECONDS)1 GuardedBy (net.jcip.annotations.GuardedBy)1 ReplicableCommand (org.infinispan.commands.ReplicableCommand)1