use of org.apache.ignite.internal.util.future.GridFinishedFuture 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.util.future.GridFinishedFuture in project ignite by apache.
the class GridContinuousProcessor method startRoutine.
/**
* @param hnd Handler.
* @param bufSize Buffer size.
* @param interval Time interval.
* @param autoUnsubscribe Automatic unsubscribe flag.
* @param locOnly Local only flag.
* @param prjPred Projection predicate.
* @return Future.
*/
public IgniteInternalFuture<UUID> startRoutine(GridContinuousHandler hnd, boolean locOnly, int bufSize, long interval, boolean autoUnsubscribe, @Nullable IgnitePredicate<ClusterNode> prjPred) throws IgniteCheckedException {
assert hnd != null;
assert bufSize > 0;
assert interval >= 0;
// Generate ID.
final UUID routineId = UUID.randomUUID();
if (ctx.config().isPeerClassLoadingEnabled()) {
hnd.p2pMarshal(ctx);
assert !(hnd instanceof CacheContinuousQueryHandler) || ((CacheContinuousQueryHandler) hnd).isMarshalled();
}
// Register routine locally.
locInfos.put(routineId, new LocalRoutineInfo(ctx.localNodeId(), prjPred, hnd, bufSize, interval, autoUnsubscribe));
if (locOnly) {
try {
registerHandler(ctx.localNodeId(), routineId, hnd, bufSize, interval, autoUnsubscribe, true);
return new GridFinishedFuture<>(routineId);
} catch (IgniteCheckedException e) {
unregisterHandler(routineId, hnd, true);
return new GridFinishedFuture<>(e);
}
}
// Whether local node is included in routine.
boolean locIncluded = prjPred == null || prjPred.apply(ctx.discovery().localNode());
AbstractContinuousMessage msg;
try {
msg = createStartMessage(routineId, hnd, bufSize, interval, autoUnsubscribe, prjPred);
} catch (IgniteCheckedException e) {
return new GridFinishedFuture<>(e);
}
// Register per-routine notifications listener if ordered messaging is used.
registerMessageListener(hnd);
if (!lockStopping())
return new GridFinishedFuture<>(new NodeStoppingException("Failed to start continuous query (node is stopping)"));
try {
StartFuture fut = new StartFuture(routineId);
startFuts.put(routineId, fut);
try {
if (locIncluded || hnd.isQuery()) {
registerHandler(ctx.localNodeId(), routineId, hnd, bufSize, interval, autoUnsubscribe, true);
}
ctx.discovery().sendCustomEvent(msg);
} catch (IgniteCheckedException e) {
startFuts.remove(routineId);
locInfos.remove(routineId);
unregisterHandler(routineId, hnd, true);
fut.onDone(e);
return fut;
}
// Handler is registered locally.
fut.onLocalRegistered();
return fut;
} finally {
unlockStopping();
}
}
use of org.apache.ignite.internal.util.future.GridFinishedFuture in project ignite by apache.
the class IgniteServiceProcessor method deployAll.
/**
* @param cfgs Service configurations.
* @param dfltNodeFilter Default NodeFilter.
* @return Future for deployment.
*/
private IgniteInternalFuture<?> deployAll(@NotNull Collection<ServiceConfiguration> cfgs, @Nullable IgnitePredicate<ClusterNode> dfltNodeFilter) {
opsLock.readLock().lock();
try {
if (disconnected) {
return new GridFinishedFuture<>(new IgniteClientDisconnectedCheckedException(ctx.cluster().clientReconnectFuture(), "Failed to deploy services, " + "client node disconnected: " + cfgs));
}
if (ctx.isStopping()) {
return new GridFinishedFuture<>(new IgniteCheckedException("Failed to deploy services, " + "node is stopping: " + cfgs));
}
if (cfgs.isEmpty())
return new GridFinishedFuture<>();
PreparedConfigurations<IgniteUuid> srvcCfg = prepareServiceConfigurations(cfgs, dfltNodeFilter);
List<ServiceConfiguration> cfgsCp = srvcCfg.cfgs;
List<GridServiceDeploymentFuture<IgniteUuid>> failedFuts = srvcCfg.failedFuts;
GridServiceDeploymentCompoundFuture<IgniteUuid> res = new GridServiceDeploymentCompoundFuture<>();
if (!cfgsCp.isEmpty()) {
try {
Collection<ServiceChangeAbstractRequest> reqs = new ArrayList<>();
for (ServiceConfiguration cfg : cfgsCp) {
IgniteUuid srvcId = IgniteUuid.randomUuid();
GridServiceDeploymentFuture<IgniteUuid> fut = new GridServiceDeploymentFuture<>(cfg, srvcId);
res.add(fut, true);
reqs.add(new ServiceDeploymentRequest(srvcId, cfg));
depFuts.put(srvcId, fut);
}
ServiceChangeBatchRequest msg = new ServiceChangeBatchRequest(reqs);
ctx.discovery().sendCustomEvent(msg);
if (log.isDebugEnabled())
log.debug("Services have been sent to deploy, req=" + msg);
} catch (IgniteException | IgniteCheckedException e) {
for (IgniteUuid id : res.servicesToRollback()) depFuts.remove(id).onDone(e);
res.onDone(new IgniteCheckedException(new ServiceDeploymentException("Failed to deploy provided services.", e, cfgs)));
return res;
}
}
if (failedFuts != null) {
for (GridServiceDeploymentFuture<IgniteUuid> fut : failedFuts) res.add(fut, false);
}
res.markInitialized();
return res;
} finally {
opsLock.readLock().unlock();
}
}
use of org.apache.ignite.internal.util.future.GridFinishedFuture in project ignite by apache.
the class PageMemoryImplTest method testCheckpointProtocolCannotReplaceUnwrittenPage.
/**
* @throws Exception if failed.
*/
@Test
public void testCheckpointProtocolCannotReplaceUnwrittenPage() throws Exception {
TestPageStoreManager pageStoreMgr = new TestPageStoreManager();
// Create a 1 mb page memory.
PageMemoryImpl memory = createPageMemory(1, PageMemoryImpl.ThrottlingPolicy.TARGET_RATIO_BASED, pageStoreMgr, pageStoreMgr, null);
int initPageCnt = 500;
List<FullPageId> allocated = new ArrayList<>(initPageCnt);
for (int i = 0; i < initPageCnt; i++) {
long id = memory.allocatePage(1, INDEX_PARTITION, FLAG_IDX);
FullPageId fullId = new FullPageId(id, 1);
allocated.add(fullId);
writePage(memory, fullId, (byte) 1);
}
// CP Write lock.
memory.beginCheckpoint(new GridFinishedFuture());
// CP Write unlock.
byte[] buf = new byte[PAGE_SIZE];
memory.checkpointWritePage(allocated.get(0), ByteBuffer.wrap(buf), (fullPageId, buf0, tag) -> {
assertNotNull(tag);
boolean oom = false;
try {
// Try force page replacement.
while (true) {
memory.allocatePage(1, INDEX_PARTITION, FLAG_IDX);
}
} catch (IgniteOutOfMemoryException ex) {
oom = true;
}
assertTrue("Should oom before check replaced page.", oom);
assertTrue("Missing page: " + fullPageId, memory.hasLoadedPage(fullPageId));
}, null);
}
use of org.apache.ignite.internal.util.future.GridFinishedFuture in project ignite by apache.
the class PageMemoryImplTest method testCheckpointProtocolWriteDirtyPageAfterWriteUnlock.
/**
* @throws Exception if failed.
*/
@Test
public void testCheckpointProtocolWriteDirtyPageAfterWriteUnlock() throws Exception {
TestPageStoreManager pageStoreMgr = new TestPageStoreManager();
// Create a 1 mb page memory.
PageMemoryImpl memory = createPageMemory(1, PageMemoryImpl.ThrottlingPolicy.TARGET_RATIO_BASED, pageStoreMgr, pageStoreMgr, null);
int initPageCnt = 10;
List<FullPageId> allocated = new ArrayList<>(initPageCnt);
for (int i = 0; i < initPageCnt; i++) {
long id = memory.allocatePage(1, INDEX_PARTITION, FLAG_IDX);
FullPageId fullId = new FullPageId(id, 1);
allocated.add(fullId);
writePage(memory, fullId, (byte) 1);
}
doCheckpoint(memory.beginCheckpoint(new GridFinishedFuture()), memory, pageStoreMgr);
FullPageId cowPageId = allocated.get(0);
// Mark some pages as dirty.
writePage(memory, cowPageId, (byte) 2);
GridMultiCollectionWrapper<FullPageId> cpPages = memory.beginCheckpoint(new GridFinishedFuture());
assertEquals(1, cpPages.size());
// At this point COW mechanics kicks in.
writePage(memory, cowPageId, (byte) 3);
doCheckpoint(cpPages, memory, pageStoreMgr);
byte[] data = pageStoreMgr.storedPages.get(cowPageId);
for (int i = PageIO.COMMON_HEADER_END; i < PAGE_SIZE; i++) assertEquals(2, data[i]);
}
Aggregations