use of org.apache.ignite.IgniteCheckedException in project ignite by apache.
the class GridClusterStateProcessor method start.
/** {@inheritDoc} */
@Override
public void start(boolean activeOnStart) throws IgniteCheckedException {
super.start(activeOnStart);
globalState = activeOnStart ? ACTIVE : INACTIVE;
cacheProc = ctx.cache();
sharedCtx = cacheProc.context();
sharedCtx.io().addHandler(0, GridChangeGlobalStateMessageResponse.class, new CI2<UUID, GridChangeGlobalStateMessageResponse>() {
@Override
public void apply(UUID nodeId, GridChangeGlobalStateMessageResponse msg) {
processChangeGlobalStateResponse(nodeId, msg);
}
});
ctx.discovery().setCustomEventListener(ChangeGlobalStateMessage.class, new CustomEventListener<ChangeGlobalStateMessage>() {
@Override
public void onCustomEvent(AffinityTopologyVersion topVer, ClusterNode snd, ChangeGlobalStateMessage msg) {
assert topVer != null;
assert snd != null;
assert msg != null;
boolean activate = msg.activate();
ChangeGlobalStateContext actx = lastCgsCtx;
if (actx != null && globalState == TRANSITION) {
GridChangeGlobalStateFuture f = cgsLocFut.get();
if (log.isDebugEnabled())
log.debug("Concurrent " + prettyStr(activate) + " [id=" + ctx.localNodeId() + " topVer=" + topVer + " actx=" + actx + ", msg=" + msg + "]");
if (f != null && f.requestId.equals(msg.requestId()))
f.onDone(new IgniteCheckedException("Concurrent change state, now in progress=" + (activate) + ", initiatingNodeId=" + actx.initiatingNodeId + ", you try=" + (prettyStr(activate)) + ", locNodeId=" + ctx.localNodeId()));
msg.concurrentChangeState();
} else {
if (log.isInfoEnabled())
log.info("Create " + prettyStr(activate) + " context [id=" + ctx.localNodeId() + " topVer=" + topVer + ", reqId=" + msg.requestId() + ", initiatingNodeId=" + msg.initiatorNodeId() + "]");
lastCgsCtx = new ChangeGlobalStateContext(msg.requestId(), msg.initiatorNodeId(), msg.getDynamicCacheChangeBatch(), msg.activate());
globalState = TRANSITION;
}
}
});
ctx.event().addLocalEventListener(lsr, EVT_NODE_LEFT, EVT_NODE_FAILED);
}
use of org.apache.ignite.IgniteCheckedException in project ignite by apache.
the class DataStructuresProcessor method getAtomic.
/**
* @param c Closure creating data structure instance.
* @param dsInfo Data structure info.
* @param create Create flag.
* @param cls Expected data structure class.
* @return Data structure instance.
* @throws IgniteCheckedException If failed.
*/
@Nullable
private <T> T getAtomic(final IgniteOutClosureX<T> c, final DataStructureInfo dsInfo, final boolean create, Class<? extends T> cls) throws IgniteCheckedException {
Map<String, DataStructureInfo> dsMap = utilityCache.get(DATA_STRUCTURES_KEY);
if (!create && (dsMap == null || !dsMap.containsKey(dsInfo.name)))
return null;
IgniteCheckedException err = validateDataStructure(dsMap, dsInfo, create);
if (err != null)
throw err;
final GridCacheInternalKey key = new GridCacheInternalKeyImpl(dsInfo.name);
// Check type of structure received by key from local cache.
T dataStructure = cast(this.dsMap.get(key), cls);
if (dataStructure != null)
return dataStructure;
return retryTopologySafe(new IgniteOutClosureX<T>() {
@Override
public T applyx() throws IgniteCheckedException {
if (!create)
return c.applyx();
try (GridNearTxLocal tx = utilityCache.txStartEx(PESSIMISTIC, REPEATABLE_READ)) {
IgniteCheckedException err = utilityCache.invoke(DATA_STRUCTURES_KEY, new AddAtomicProcessor(dsInfo)).get();
if (err != null)
throw err;
T dataStructure = c.applyx();
tx.commit();
return dataStructure;
}
}
});
}
use of org.apache.ignite.IgniteCheckedException in project ignite by apache.
the class DataStructuresProcessor method removeDataStructure.
/**
* @param c Closure.
* @param name Data structure name.
* @param type Data structure type.
* @param afterRmv Optional closure to run after data structure removed.
* @throws IgniteCheckedException If failed.
*/
private <T> void removeDataStructure(final IgniteOutClosureX<T> c, String name, DataStructureType type, @Nullable final IgniteInClosureX<T> afterRmv) throws IgniteCheckedException {
Map<String, DataStructureInfo> dsMap = utilityCache.get(DATA_STRUCTURES_KEY);
if (dsMap == null || !dsMap.containsKey(name))
return;
final DataStructureInfo dsInfo = new DataStructureInfo(name, type, null);
IgniteCheckedException err = validateDataStructure(dsMap, dsInfo, false);
if (err != null)
throw err;
retryTopologySafe(new IgniteOutClosureX<Void>() {
@Override
public Void applyx() throws IgniteCheckedException {
try (GridNearTxLocal tx = utilityCache.txStartEx(PESSIMISTIC, REPEATABLE_READ)) {
T2<Boolean, IgniteCheckedException> res = utilityCache.invoke(DATA_STRUCTURES_KEY, new RemoveDataStructureProcessor(dsInfo)).get();
IgniteCheckedException err = res.get2();
if (err != null)
throw err;
assert res.get1() != null;
boolean exists = res.get1();
if (!exists)
return null;
T rmvInfo = c.applyx();
tx.commit();
if (afterRmv != null && rmvInfo != null)
afterRmv.applyx(rmvInfo);
return null;
}
}
});
}
use of org.apache.ignite.IgniteCheckedException in project ignite by apache.
the class DataStructuresProcessor method removeCountDownLatch.
/**
* Removes count down latch from cache.
*
* @param name Name of the latch.
* @throws IgniteCheckedException If operation failed.
*/
public void removeCountDownLatch(final String name) throws IgniteCheckedException {
assert name != null;
assert dsCacheCtx != null;
awaitInitialization();
removeDataStructure(new IgniteOutClosureX<Void>() {
@Override
public Void applyx() throws IgniteCheckedException {
GridCacheInternal key = new GridCacheInternalKeyImpl(name);
dsCacheCtx.gate().enter();
try (GridNearTxLocal tx = CU.txStartInternal(dsCacheCtx, dsView, PESSIMISTIC, REPEATABLE_READ)) {
// Check correctness type of removable object.
GridCacheCountDownLatchValue val = cast(dsView.get(key), GridCacheCountDownLatchValue.class);
if (val != null) {
if (val.get() > 0) {
throw new IgniteCheckedException("Failed to remove count down latch " + "with non-zero count: " + val.get());
}
dsView.remove(key);
tx.commit();
} else
tx.setRollbackOnly();
return null;
} finally {
dsCacheCtx.gate().leave();
}
}
}, name, COUNT_DOWN_LATCH, null);
}
use of org.apache.ignite.IgniteCheckedException in project ignite by apache.
the class GridJobProcessor method start.
/** {@inheritDoc} */
@Override
public void start(boolean activeOnStart) throws IgniteCheckedException {
if (metricsUpdateFreq < -1)
throw new IgniteCheckedException("Invalid value for 'metricsUpdateFrequency' configuration property " + "(should be greater than or equals to -1): " + metricsUpdateFreq);
if (metricsUpdateFreq == -1)
U.warn(log, "Job metrics are disabled (use with caution).");
if (!jobAlwaysActivate)
ctx.collision().setCollisionExternalListener(new CollisionExternalListener());
GridIoManager ioMgr = ctx.io();
ioMgr.addMessageListener(TOPIC_JOB_CANCEL, cancelLsnr);
ioMgr.addMessageListener(TOPIC_JOB, jobExecLsnr);
ctx.event().addLocalEventListener(discoLsnr, EVT_NODE_FAILED, EVT_NODE_LEFT, EVT_NODE_METRICS_UPDATED);
if (log.isDebugEnabled())
log.debug("Job processor started.");
}
Aggregations