use of org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor in project ignite by apache.
the class GridDiscoveryManager method resolveDiscoCache.
/**
* Gets discovery cache for given topology version.
*
* @param cacheId Cache ID (participates in exception message).
* @param topVer Topology version.
* @return Discovery cache.
*/
private DiscoCache resolveDiscoCache(int cacheId, AffinityTopologyVersion topVer) {
Snapshot snap = topSnap.get();
DiscoCache cache = AffinityTopologyVersion.NONE.equals(topVer) || topVer.equals(snap.topVer) ? snap.discoCache : discoCacheHist.get(topVer);
if (cache == null) {
DynamicCacheDescriptor desc = ctx.cache().cacheDescriptor(cacheId);
throw new IgniteException("Failed to resolve nodes topology [" + "cacheName=" + (desc != null ? desc.cacheConfiguration().getName() : "N/A") + ", topVer=" + topVer + ", history=" + discoCacheHist.keySet() + ", snap=" + snap + ", locNode=" + ctx.discovery().localNode() + ']');
}
return cache;
}
use of org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor in project ignite by apache.
the class GridDhtPartitionsExchangeFuture method init.
/**
* Starts activity.
*
* @throws IgniteInterruptedCheckedException If interrupted.
*/
public void init() throws IgniteInterruptedCheckedException {
if (isDone())
return;
initTs = U.currentTimeMillis();
U.await(evtLatch);
assert discoEvt != null : this;
assert exchId.nodeId().equals(discoEvt.eventNode().id()) : this;
assert !dummy && !forcePreload : this;
try {
discoCache.updateAlives(cctx.discovery());
AffinityTopologyVersion topVer = topologyVersion();
srvNodes = new ArrayList<>(discoCache.serverNodes());
remaining.addAll(F.nodeIds(F.view(srvNodes, F.remoteNodes(cctx.localNodeId()))));
crd = srvNodes.isEmpty() ? null : srvNodes.get(0);
boolean crdNode = crd != null && crd.isLocal();
skipPreload = cctx.kernalContext().clientNode();
ExchangeType exchange;
if (discoEvt.type() == EVT_DISCOVERY_CUSTOM_EVT) {
DiscoveryCustomMessage msg = ((DiscoveryCustomEvent) discoEvt).customMessage();
if (msg instanceof DynamicCacheChangeBatch) {
assert exchActions != null && !exchActions.empty();
exchange = onCacheChangeRequest(crdNode);
} else if (msg instanceof StartFullSnapshotAckDiscoveryMessage)
exchange = CU.clientNode(discoEvt.eventNode()) ? onClientNodeEvent(crdNode) : onServerNodeEvent(crdNode);
else {
assert affChangeMsg != null : this;
exchange = onAffinityChangeRequest(crdNode);
}
} else {
if (discoEvt.type() == EVT_NODE_JOINED) {
if (!discoEvt.eventNode().isLocal()) {
Collection<DynamicCacheDescriptor> receivedCaches = cctx.cache().startReceivedCaches(discoEvt.eventNode().id(), topVer);
cctx.affinity().initStartedCaches(crdNode, this, receivedCaches);
} else
cctx.cache().startCachesOnLocalJoin(topVer);
}
exchange = CU.clientNode(discoEvt.eventNode()) ? onClientNodeEvent(crdNode) : onServerNodeEvent(crdNode);
}
updateTopologies(crdNode);
if (exchActions != null && exchActions.hasStop())
cctx.cache().context().database().beforeCachesStop();
switch(exchange) {
case ALL:
{
distributedExchange();
break;
}
case CLIENT:
{
initTopologies();
clientOnlyExchange();
break;
}
case NONE:
{
initTopologies();
onDone(topVer);
break;
}
default:
assert false;
}
} catch (IgniteInterruptedCheckedException e) {
onDone(e);
throw e;
} catch (IgniteNeedReconnectException e) {
onDone(e);
} catch (Throwable e) {
if (reconnectOnError(e))
onDone(new IgniteNeedReconnectException(cctx.localNode(), e));
else {
U.error(log, "Failed to reinitialize local partitions (preloading will be stopped): " + exchId, e);
onDone(e);
}
if (e instanceof Error)
throw (Error) e;
}
}
use of org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor in project ignite by apache.
the class GridQueryProcessor method onSchemaFinishDiscovery.
/**
* Process schema finish message from discovery thread.
*
* @param msg Message.
*/
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
private void onSchemaFinishDiscovery(SchemaFinishDiscoveryMessage msg) {
UUID opId = msg.operation().id();
if (log.isDebugEnabled())
log.debug("Received schema finish message (discovery) [opId=" + opId + ", msg=" + msg + ']');
synchronized (stateMux) {
if (disconnected)
return;
boolean completedOpAdded = completedOpIds.add(opId);
assert completedOpAdded;
// Remove propose message so that it will not be shared with joining nodes.
SchemaProposeDiscoveryMessage proposeMsg = activeProposals.remove(opId);
assert proposeMsg != null;
// Apply changes to public cache schema if operation is successful and original cache is still there.
if (!msg.hasError()) {
DynamicCacheDescriptor cacheDesc = ctx.cache().cacheDescriptor(msg.operation().cacheName());
if (cacheDesc != null && F.eq(cacheDesc.deploymentId(), proposeMsg.deploymentId()))
cacheDesc.schemaChangeFinish(msg);
}
// Propose message will be used from exchange thread to
msg.proposeMessage(proposeMsg);
if (exchangeReady) {
SchemaOperation op = schemaOps.get(proposeMsg.schemaName());
if (F.eq(op.id(), opId)) {
// Completed top operation.
op.finishMessage(msg);
if (op.started())
op.doFinish();
} else {
// Completed operation in the middle, will schedule completion later.
while (op != null) {
if (F.eq(op.id(), opId))
break;
op = op.next();
}
assert op != null;
assert !op.started();
op.finishMessage(msg);
}
} else {
// Set next operation as top-level one.
String schemaName = proposeMsg.schemaName();
SchemaOperation op = schemaOps.remove(schemaName);
assert op != null;
assert F.eq(op.id(), opId);
// Chain to the next operation (if any).
SchemaOperation nextOp = op.next();
if (nextOp != null)
schemaOps.put(schemaName, nextOp);
}
// Clean stale IO messages from just-joined nodes.
cleanStaleStatusMessages(opId);
}
// Complete client future (if any).
SchemaOperationClientFuture cliFut = schemaCliFuts.remove(opId);
if (cliFut != null) {
if (msg.hasError())
cliFut.onDone(msg.error());
else
cliFut.onDone();
}
}
use of org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor in project ignite by apache.
the class GridQueryProcessor method startSchemaChange.
/**
* Initiate actual schema change operation.
*
* @param schemaOp Schema operation.
*/
@SuppressWarnings({ "unchecked", "ThrowableInstanceNeverThrown" })
private void startSchemaChange(SchemaOperation schemaOp) {
assert Thread.holdsLock(stateMux);
assert !schemaOp.started();
// Get current cache state.
SchemaProposeDiscoveryMessage msg = schemaOp.proposeMessage();
String cacheName = msg.operation().cacheName();
DynamicCacheDescriptor cacheDesc = ctx.cache().cacheDescriptor(cacheName);
boolean cacheExists = cacheDesc != null && F.eq(msg.deploymentId(), cacheDesc.deploymentId());
boolean cacheRegistered = cacheExists && cacheNames.contains(cacheName);
// Validate schema state and decide whether we should proceed or not.
SchemaAbstractOperation op = msg.operation();
QueryTypeDescriptorImpl type = null;
SchemaOperationException err;
boolean nop = false;
if (cacheExists) {
if (cacheRegistered) {
// If cache is started, we perform validation against real schema.
T3<QueryTypeDescriptorImpl, Boolean, SchemaOperationException> res = prepareChangeOnStartedCache(op);
assert res.get2() != null;
type = res.get1();
nop = res.get2();
err = res.get3();
} else {
// If cache is not started yet, there is no schema. Take schema from cache descriptor and validate.
QuerySchema schema = cacheDesc.schema();
T2<Boolean, SchemaOperationException> res = prepareChangeOnNotStartedCache(op, schema);
assert res.get1() != null;
type = null;
nop = res.get1();
err = res.get2();
}
} else
err = new SchemaOperationException(SchemaOperationException.CODE_CACHE_NOT_FOUND, cacheName);
// Start operation.
SchemaOperationWorker worker = new SchemaOperationWorker(ctx, this, msg.deploymentId(), op, nop, err, cacheRegistered, type);
SchemaOperationManager mgr = new SchemaOperationManager(ctx, this, worker, ctx.clientNode() ? null : coordinator());
schemaOp.manager(mgr);
mgr.start();
// Unwind pending IO messages.
if (!ctx.clientNode() && coordinator().isLocal())
unwindPendingMessages(schemaOp.id(), mgr);
// Schedule operation finish handling if needed.
if (schemaOp.hasFinishMessage())
schemaOp.doFinish();
}
use of org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor in project ignite by apache.
the class AbstractSchemaSelfTest method assertIndexDescriptor.
/**
* Make sure index exists in cache descriptor.
*
* @param node Node.
* @param cacheName Cache name.
* @param tblName Table name.
* @param idxName Index name.
* @param fields Fields.
*/
protected static void assertIndexDescriptor(IgniteEx node, String cacheName, String tblName, String idxName, IgniteBiTuple<String, Boolean>... fields) {
awaitCompletion();
DynamicCacheDescriptor desc = node.context().cache().cacheDescriptor(cacheName);
assert desc != null;
for (QueryEntity entity : desc.schema().entities()) {
if (F.eq(tblName, entity.getTableName())) {
for (QueryIndex idx : entity.getIndexes()) {
if (F.eq(QueryUtils.indexName(entity, idx), idxName)) {
LinkedHashMap<String, Boolean> idxFields = idx.getFields();
assertEquals(idxFields.size(), fields.length);
int i = 0;
for (String idxField : idxFields.keySet()) {
assertEquals(idxField.toLowerCase(), fields[i].get1().toLowerCase());
assertEquals(idxFields.get(idxField), fields[i].get2());
i++;
}
return;
}
}
}
}
fail("Index not found [node=" + node.name() + ", cacheName=" + cacheName + ", tlbName=" + tblName + ", idxName=" + idxName + ']');
}
Aggregations