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;
}
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);
}
}
}
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);
}
}
}
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);
}
}
Aggregations