use of org.apache.ignite.IgniteCheckedException in project ignite by apache.
the class CacheAffinitySharedManager method checkRebalanceState.
/**
* @param top Topology.
* @param checkGrpId Group ID.
*/
void checkRebalanceState(GridDhtPartitionTopology top, Integer checkGrpId) {
CacheAffinityChangeMessage msg = null;
synchronized (mux) {
if (waitInfo == null || !waitInfo.topVer.equals(lastAffVer))
return;
Map<Integer, UUID> partWait = waitInfo.waitGrps.get(checkGrpId);
boolean rebalanced = true;
if (partWait != null) {
CacheGroupHolder grpHolder = grpHolders.get(checkGrpId);
if (grpHolder != null) {
for (Iterator<Map.Entry<Integer, UUID>> it = partWait.entrySet().iterator(); it.hasNext(); ) {
Map.Entry<Integer, UUID> e = it.next();
Integer part = e.getKey();
UUID waitNode = e.getValue();
GridDhtPartitionState state = top.partitionState(waitNode, part);
if (state != GridDhtPartitionState.OWNING) {
rebalanced = false;
break;
} else
it.remove();
}
}
if (rebalanced) {
waitInfo.waitGrps.remove(checkGrpId);
if (waitInfo.waitGrps.isEmpty()) {
msg = affinityChangeMessage(waitInfo);
waitInfo = null;
}
}
}
try {
if (msg != null)
cctx.discovery().sendCustomEvent(msg);
} catch (IgniteCheckedException e) {
U.error(log, "Failed to send affinity change message.", e);
}
}
}
use of org.apache.ignite.IgniteCheckedException in project ignite by apache.
the class CacheAffinitySharedManager method onChangeAffinityMessage.
/**
* Called on exchange initiated by {@link CacheAffinityChangeMessage} which sent after rebalance finished.
*
* @param exchFut Exchange future.
* @param crd Coordinator flag.
* @param msg Message.
* @throws IgniteCheckedException If failed.
*/
public void onChangeAffinityMessage(final GridDhtPartitionsExchangeFuture exchFut, boolean crd, final CacheAffinityChangeMessage msg) throws IgniteCheckedException {
assert msg.topologyVersion() != null && msg.exchangeId() == null : msg;
final AffinityTopologyVersion topVer = exchFut.initialVersion();
if (log.isDebugEnabled()) {
log.debug("Process affinity change message [exchVer=" + topVer + ", msgVer=" + msg.topologyVersion() + ']');
}
final Map<Integer, Map<Integer, List<UUID>>> affChange = msg.assignmentChange();
assert !F.isEmpty(affChange) : msg;
final Map<Integer, IgniteUuid> deploymentIds = msg.cacheDeploymentIds();
final Map<Object, List<List<ClusterNode>>> affCache = new HashMap<>();
forAllCacheGroups(crd, new IgniteInClosureX<GridAffinityAssignmentCache>() {
@Override
public void applyx(GridAffinityAssignmentCache aff) throws IgniteCheckedException {
AffinityTopologyVersion affTopVer = aff.lastVersion();
assert affTopVer.topologyVersion() > 0 : affTopVer;
CacheGroupDescriptor desc = caches.group(aff.groupId());
assert desc != null : aff.cacheOrGroupName();
IgniteUuid deploymentId = desc.deploymentId();
if (!deploymentId.equals(deploymentIds.get(aff.groupId()))) {
aff.clientEventTopologyChange(exchFut.firstEvent(), topVer);
return;
}
Map<Integer, List<UUID>> change = affChange.get(aff.groupId());
if (change != null) {
assert !change.isEmpty() : msg;
List<List<ClusterNode>> curAff = aff.assignments(affTopVer);
List<List<ClusterNode>> assignment = new ArrayList<>(curAff);
for (Map.Entry<Integer, List<UUID>> e : change.entrySet()) {
Integer part = e.getKey();
List<ClusterNode> nodes = toNodes(topVer, e.getValue());
assert !nodes.equals(assignment.get(part)) : "Assignment did not change " + "[cacheGrp=" + aff.cacheOrGroupName() + ", part=" + part + ", cur=" + F.nodeIds(assignment.get(part)) + ", new=" + F.nodeIds(nodes) + ", exchVer=" + exchFut.initialVersion() + ", msgVer=" + msg.topologyVersion() + ']';
assignment.set(part, nodes);
}
aff.initialize(topVer, cachedAssignment(aff, assignment, affCache));
} else
aff.clientEventTopologyChange(exchFut.firstEvent(), topVer);
}
});
}
use of org.apache.ignite.IgniteCheckedException in project ignite by apache.
the class CacheAffinitySharedManager method onExchangeChangeAffinityMessage.
/**
* Called when received {@link CacheAffinityChangeMessage} which should complete exchange.
*
* @param exchFut Exchange future.
* @param crd Coordinator flag.
* @param msg Affinity change message.
*/
public void onExchangeChangeAffinityMessage(GridDhtPartitionsExchangeFuture exchFut, boolean crd, CacheAffinityChangeMessage msg) {
if (log.isDebugEnabled()) {
log.debug("Process exchange affinity change message [exchVer=" + exchFut.initialVersion() + ", msg=" + msg + ']');
}
assert exchFut.exchangeId().equals(msg.exchangeId()) : msg;
final AffinityTopologyVersion topVer = exchFut.initialVersion();
final Map<Integer, Map<Integer, List<UUID>>> assignment = msg.assignmentChange();
assert assignment != null;
final Map<Object, List<List<ClusterNode>>> affCache = new HashMap<>();
forAllCacheGroups(crd, new IgniteInClosureX<GridAffinityAssignmentCache>() {
@Override
public void applyx(GridAffinityAssignmentCache aff) throws IgniteCheckedException {
List<List<ClusterNode>> idealAssignment = aff.idealAssignment();
assert idealAssignment != null;
Map<Integer, List<UUID>> cacheAssignment = assignment.get(aff.groupId());
List<List<ClusterNode>> newAssignment;
if (cacheAssignment != null) {
newAssignment = new ArrayList<>(idealAssignment);
for (Map.Entry<Integer, List<UUID>> e : cacheAssignment.entrySet()) newAssignment.set(e.getKey(), toNodes(topVer, e.getValue()));
} else
newAssignment = idealAssignment;
aff.initialize(topVer, cachedAssignment(aff, newAssignment, affCache));
}
});
}
use of org.apache.ignite.IgniteCheckedException in project ignite by apache.
the class CacheObjectImpl method value.
/**
* {@inheritDoc}
*/
@SuppressWarnings("unchecked")
@Nullable
@Override
public <T> T value(CacheObjectValueContext ctx, boolean cpy) {
cpy = cpy && needCopy(ctx);
try {
GridKernalContext kernalCtx = ctx.kernalContext();
IgniteCacheObjectProcessor proc = ctx.kernalContext().cacheObjects();
if (cpy) {
if (valBytes == null) {
assert val != null;
valBytes = proc.marshal(ctx, val);
}
ClassLoader clsLdr;
if (val != null)
clsLdr = val.getClass().getClassLoader();
else if (kernalCtx.config().isPeerClassLoadingEnabled())
clsLdr = kernalCtx.cache().context().deploy().globalLoader();
else
clsLdr = null;
return (T) proc.unmarshal(ctx, valBytes, clsLdr);
}
if (val != null)
return (T) val;
assert valBytes != null;
Object val = proc.unmarshal(ctx, valBytes, kernalCtx.config().isPeerClassLoadingEnabled() ? kernalCtx.cache().context().deploy().globalLoader() : null);
if (ctx.storeValue())
this.val = val;
return (T) val;
} catch (IgniteCheckedException e) {
throw new IgniteException("Failed to unmarshall object.", e);
}
}
use of org.apache.ignite.IgniteCheckedException in project ignite by apache.
the class OdbcConnectionContext method initializeFromHandshake.
/**
* {@inheritDoc}
*/
@Override
public void initializeFromHandshake(ClientListenerProtocolVersion ver, BinaryReaderExImpl reader) throws IgniteCheckedException {
assert SUPPORTED_VERS.contains(ver) : "Unsupported ODBC protocol version.";
boolean distributedJoins = reader.readBoolean();
boolean enforceJoinOrder = reader.readBoolean();
boolean replicatedOnly = reader.readBoolean();
boolean collocated = reader.readBoolean();
boolean lazy = false;
if (ver.compareTo(VER_2_1_5) >= 0)
lazy = reader.readBoolean();
boolean skipReducerOnUpdate = false;
if (ver.compareTo(VER_2_3_0) >= 0)
skipReducerOnUpdate = reader.readBoolean();
String user = null;
String passwd = null;
if (ver.compareTo(VER_2_5_0) >= 0) {
user = reader.readString();
passwd = reader.readString();
}
AuthorizationContext actx = null;
try {
if (ctx.authentication().enabled()) {
if (F.isEmpty(user))
throw new IgniteCheckedException("Unauthenticated sessions are prohibited");
actx = ctx.authentication().authenticate(user, passwd);
if (actx == null)
throw new IgniteCheckedException("Unknown authentication error");
} else {
if (!F.isEmpty(user))
throw new IgniteCheckedException("Authentication is disabled for the node.");
}
} catch (Exception e) {
throw new IgniteCheckedException("Handshake error: " + e.getMessage(), e);
}
handler = new OdbcRequestHandler(ctx, busyLock, maxCursors, distributedJoins, enforceJoinOrder, replicatedOnly, collocated, lazy, skipReducerOnUpdate, actx);
parser = new OdbcMessageParser(ctx, ver);
}
Aggregations