Search in sources :

Example 11 with StoredCacheData

use of org.apache.ignite.internal.processors.cache.StoredCacheData in project ignite by apache.

the class GridClusterStateProcessor method changeGlobalState.

/**
 * @param state New cluster state.
 * @param forceDeactivation If {@code true}, cluster deactivation will be forced.
 * @param baselineNodes New baseline nodes.
 * @param forceChangeBaselineTopology Force change baseline topology.
 * @param isAutoAdjust Auto adjusting baseline flag.
 * @return State change future.
 * @see ClusterState#INACTIVE
 */
public IgniteInternalFuture<?> changeGlobalState(ClusterState state, boolean forceDeactivation, Collection<? extends BaselineNode> baselineNodes, boolean forceChangeBaselineTopology, boolean isAutoAdjust) {
    if (ctx.maintenanceRegistry().isMaintenanceMode()) {
        return new GridFinishedFuture<>(new IgniteCheckedException("Failed to " + prettyStr(state) + " (node is in maintenance mode)."));
    }
    BaselineTopology blt = (compatibilityMode && !forceChangeBaselineTopology) ? null : calculateNewBaselineTopology(state, baselineNodes, forceChangeBaselineTopology);
    boolean isBaselineAutoAdjustEnabled = isBaselineAutoAdjustEnabled();
    if (forceChangeBaselineTopology && isBaselineAutoAdjustEnabled != isAutoAdjust)
        throw new BaselineAdjustForbiddenException(isBaselineAutoAdjustEnabled);
    if (ctx.isDaemon() || ctx.clientNode())
        return sendComputeChangeGlobalState(state, forceDeactivation, blt, forceChangeBaselineTopology);
    if (cacheProc.transactions().tx() != null || sharedCtx.lockedTopologyVersion(null) != null) {
        return new GridFinishedFuture<>(new IgniteCheckedException("Failed to " + prettyStr(state) + " (must invoke the method outside of an active transaction)."));
    }
    DiscoveryDataClusterState curState = globalState;
    if (!curState.transition() && curState.state() == state) {
        if (!state.active() || BaselineTopology.equals(curState.baselineTopology(), blt))
            return new GridFinishedFuture<>();
    }
    GridChangeGlobalStateFuture startedFut = null;
    GridChangeGlobalStateFuture fut = stateChangeFut.get();
    while (fut == null || fut.isDone()) {
        fut = new GridChangeGlobalStateFuture(UUID.randomUUID(), state, ctx);
        if (stateChangeFut.compareAndSet(null, fut)) {
            startedFut = fut;
            break;
        } else
            fut = stateChangeFut.get();
    }
    if (startedFut == null) {
        if (fut.state != state) {
            return new GridFinishedFuture<>(new IgniteCheckedException("Failed to " + prettyStr(state) + ", because another state change operation is currently in progress: " + prettyStr(fut.state)));
        } else
            return fut;
    }
    List<StoredCacheData> storedCfgs = null;
    if (activate(curState.state(), state) && !inMemoryMode) {
        try {
            Map<String, StoredCacheData> cfgs = ctx.cache().context().pageStore().readCacheConfigurations();
            if (!F.isEmpty(cfgs)) {
                storedCfgs = new ArrayList<>(cfgs.values());
                IgniteDiscoverySpi spi = (IgniteDiscoverySpi) ctx.discovery().getInjectedDiscoverySpi();
                boolean splittedCacheCfgs = spi.allNodesSupport(IgniteFeatures.SPLITTED_CACHE_CONFIGURATIONS);
                storedCfgs = storedCfgs.stream().map(storedCacheData -> splittedCacheCfgs ? storedCacheData.withSplittedCacheConfig(ctx.cache().splitter()) : storedCacheData.withOldCacheConfig(ctx.cache().enricher())).collect(Collectors.toList());
            }
        } catch (IgniteCheckedException e) {
            U.error(log, "Failed to read stored cache configurations: " + e, e);
            startedFut.onDone(e);
            return startedFut;
        }
    }
    ChangeGlobalStateMessage msg = new ChangeGlobalStateMessage(startedFut.requestId, ctx.localNodeId(), storedCfgs, state, forceDeactivation, blt, forceChangeBaselineTopology, System.currentTimeMillis());
    IgniteInternalFuture<?> resFut = wrapStateChangeFuture(startedFut, msg);
    try {
        U.log(log, "Sending " + prettyStr(state) + " request with BaselineTopology " + blt);
        ctx.discovery().sendCustomEvent(msg);
        if (ctx.isStopping()) {
            startedFut.onDone(new IgniteCheckedException("Failed to execute " + prettyStr(state) + " request , node is stopping."));
        }
    } catch (IgniteCheckedException e) {
        U.error(log, "Failed to send global state change request: " + prettyStr(state), e);
        startedFut.onDone(e);
    }
    return resFut;
}
Also used : StoredCacheData(org.apache.ignite.internal.processors.cache.StoredCacheData) GridFinishedFuture(org.apache.ignite.internal.util.future.GridFinishedFuture) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteDiscoverySpi(org.apache.ignite.internal.managers.discovery.IgniteDiscoverySpi)

Example 12 with StoredCacheData

use of org.apache.ignite.internal.processors.cache.StoredCacheData in project ignite by apache.

the class IgnitePdsCacheConfigurationFileConsistencyCheckTest method storeTmpCacheData.

/**
 * Store temp cache descriptor to PDS.
 *
 * @param cacheDescr Cache descr.
 * @throws IgniteCheckedException If fails.
 */
private void storeTmpCacheData(DynamicCacheDescriptor cacheDescr) throws Exception {
    Marshaller marshaller = new JdkMarshaller();
    for (int i = 0; i < NODES; i++) {
        IgniteEx ig = grid(i);
        GridCacheSharedContext sharedCtx = ig.context().cache().context();
        FilePageStoreManager pageStore = (FilePageStoreManager) sharedCtx.pageStore();
        StoredCacheData data = cacheDescr.toStoredData(ig.context().cache().splitter());
        data.config().setGroupName(ODD_GROUP_NAME);
        File tmp = new File(pageStore.cacheWorkDir(true, ODD_GROUP_NAME), data.config().getName() + CACHE_DATA_TMP_FILENAME);
        try (OutputStream stream = new BufferedOutputStream(new FileOutputStream(tmp))) {
            marshaller.marshal(data, stream);
        }
    }
}
Also used : JdkMarshaller(org.apache.ignite.marshaller.jdk.JdkMarshaller) Marshaller(org.apache.ignite.marshaller.Marshaller) IgniteEx(org.apache.ignite.internal.IgniteEx) BufferedOutputStream(java.io.BufferedOutputStream) DataOutputStream(java.io.DataOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) JdkMarshaller(org.apache.ignite.marshaller.jdk.JdkMarshaller) FilePageStoreManager(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager) GridCacheSharedContext(org.apache.ignite.internal.processors.cache.GridCacheSharedContext) StoredCacheData(org.apache.ignite.internal.processors.cache.StoredCacheData) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream)

Example 13 with StoredCacheData

use of org.apache.ignite.internal.processors.cache.StoredCacheData in project ignite by apache.

the class IgnitePdsCacheConfigurationFileConsistencyCheckTest method corruptCacheData.

/**
 * Store temp cache descriptor to PDS.
 *
 * @param cacheDescr Cache descr.
 * @throws IgniteCheckedException If fails.
 */
private void corruptCacheData(DynamicCacheDescriptor cacheDescr) throws Exception {
    for (int i = 0; i < NODES; i++) {
        IgniteEx ig = grid(i);
        GridCacheSharedContext sharedCtx = ig.context().cache().context();
        FilePageStoreManager pageStore = (FilePageStoreManager) sharedCtx.pageStore();
        StoredCacheData data = cacheDescr.toStoredData(ig.context().cache().splitter());
        data.config().setGroupName(ODD_GROUP_NAME);
        File config = new File(pageStore.cacheWorkDir(true, ODD_GROUP_NAME), data.config().getName() + CACHE_DATA_FILENAME);
        try (DataOutputStream os = new DataOutputStream(new FileOutputStream(config))) {
            os.writeLong(-1L);
        }
    }
}
Also used : DataOutputStream(java.io.DataOutputStream) IgniteEx(org.apache.ignite.internal.IgniteEx) FileOutputStream(java.io.FileOutputStream) FilePageStoreManager(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager) GridCacheSharedContext(org.apache.ignite.internal.processors.cache.GridCacheSharedContext) StoredCacheData(org.apache.ignite.internal.processors.cache.StoredCacheData) File(java.io.File)

Example 14 with StoredCacheData

use of org.apache.ignite.internal.processors.cache.StoredCacheData in project ignite by apache.

the class IgnitePdsCacheConfigurationFileConsistencyCheckTest method storeInvalidCacheData.

/**
 * Store cache descriptor to PDS with invalid group name.
 *
 * @param cacheDescr Cache descr.
 * @throws IgniteCheckedException If fails.
 */
private void storeInvalidCacheData(DynamicCacheDescriptor cacheDescr) throws IgniteCheckedException {
    for (int i = 0; i < NODES; i++) {
        IgniteEx ig = grid(i);
        GridCacheSharedContext sharedCtx = ig.context().cache().context();
        FilePageStoreManager pageStore = (FilePageStoreManager) sharedCtx.pageStore();
        StoredCacheData corrData = cacheDescr.toStoredData(ig.context().cache().splitter());
        corrData.config().setGroupName(ODD_GROUP_NAME);
        pageStore.storeCacheData(corrData, true);
    }
}
Also used : IgniteEx(org.apache.ignite.internal.IgniteEx) FilePageStoreManager(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager) GridCacheSharedContext(org.apache.ignite.internal.processors.cache.GridCacheSharedContext) StoredCacheData(org.apache.ignite.internal.processors.cache.StoredCacheData)

Aggregations

StoredCacheData (org.apache.ignite.internal.processors.cache.StoredCacheData)14 File (java.io.File)8 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)7 GridFinishedFuture (org.apache.ignite.internal.util.future.GridFinishedFuture)5 HashMap (java.util.HashMap)4 UUID (java.util.UUID)4 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 IgniteIllegalStateException (org.apache.ignite.IgniteIllegalStateException)4 NodeStoppingException (org.apache.ignite.internal.NodeStoppingException)4 GridCacheSharedContext (org.apache.ignite.internal.processors.cache.GridCacheSharedContext)4 FilePageStoreManager (org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 LinkedHashMap (java.util.LinkedHashMap)3 Map (java.util.Map)3 IgniteException (org.apache.ignite.IgniteException)3 IgniteInterruptedException (org.apache.ignite.IgniteInterruptedException)3 IgniteEx (org.apache.ignite.internal.IgniteEx)3 DataOutputStream (java.io.DataOutputStream)2