use of org.apache.ignite.internal.processors.affinity.GridAffinityAssignmentCache 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 affCalcVer != null || cctx.kernalContext().clientNode();
assert msg.topologyVersion() != null && msg.exchangeId() == null : msg;
assert affCalcVer == null || affCalcVer.equals(msg.topologyVersion());
final AffinityTopologyVersion topVer = exchFut.topologyVersion();
if (log.isDebugEnabled()) {
log.debug("Process affinity change message [exchVer=" + exchFut.topologyVersion() + ", affCalcVer=" + affCalcVer + ", 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<>();
forAllCaches(crd, new IgniteInClosureX<GridAffinityAssignmentCache>() {
@Override
public void applyx(GridAffinityAssignmentCache aff) throws IgniteCheckedException {
AffinityTopologyVersion affTopVer = aff.lastVersion();
assert affTopVer.topologyVersion() > 0 : affTopVer;
DynamicCacheDescriptor desc = registeredCaches.get(aff.cacheId());
assert desc != null : aff.cacheName();
IgniteUuid deploymentId = desc.deploymentId();
if (!deploymentId.equals(deploymentIds.get(aff.cacheId()))) {
aff.clientEventTopologyChange(exchFut.discoveryEvent(), topVer);
return;
}
Map<Integer, List<UUID>> change = affChange.get(aff.cacheId());
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 " + "[cache=" + aff.cacheName() + ", part=" + part + ", cur=" + F.nodeIds(assignment.get(part)) + ", new=" + F.nodeIds(nodes) + ", exchVer=" + exchFut.topologyVersion() + ", msgVer=" + msg.topologyVersion() + ']';
assignment.set(part, nodes);
}
aff.initialize(topVer, cachedAssignment(aff, assignment, affCache));
} else
aff.clientEventTopologyChange(exchFut.discoveryEvent(), topVer);
}
});
synchronized (mux) {
if (affCalcVer == null)
affCalcVer = msg.topologyVersion();
}
}
use of org.apache.ignite.internal.processors.affinity.GridAffinityAssignmentCache in project ignite by apache.
the class CacheAffinitySharedManager method initCoordinatorCaches.
/**
* @param fut Exchange future.
* @throws IgniteCheckedException If failed.
* @return Future completed when caches initialization is done.
*/
private IgniteInternalFuture<?> initCoordinatorCaches(final GridDhtPartitionsExchangeFuture fut) throws IgniteCheckedException {
final List<IgniteInternalFuture<AffinityTopologyVersion>> futs = new ArrayList<>();
forAllRegisteredCaches(new IgniteInClosureX<DynamicCacheDescriptor>() {
@Override
public void applyx(DynamicCacheDescriptor desc) throws IgniteCheckedException {
CacheHolder cache = caches.get(desc.cacheId());
if (cache != null) {
if (cache.client())
cache.affinity().calculate(fut.topologyVersion(), fut.discoveryEvent(), fut.discoCache());
return;
}
final Integer cacheId = desc.cacheId();
GridCacheContext cacheCtx = cctx.cacheContext(cacheId);
if (cacheCtx == null) {
cctx.io().addHandler(desc.cacheId(), GridDhtAffinityAssignmentResponse.class, new IgniteBiInClosure<UUID, GridDhtAffinityAssignmentResponse>() {
@Override
public void apply(UUID nodeId, GridDhtAffinityAssignmentResponse res) {
processAffinityAssignmentResponse(nodeId, res);
}
});
cache = CacheHolder2.create(cctx, desc, fut, null);
final GridAffinityAssignmentCache aff = cache.affinity();
List<GridDhtPartitionsExchangeFuture> exchFuts = cctx.exchange().exchangeFutures();
int idx = exchFuts.indexOf(fut);
assert idx >= 0 && idx < exchFuts.size() - 1 : "Invalid exchange futures state [cur=" + idx + ", total=" + exchFuts.size() + ']';
final GridDhtPartitionsExchangeFuture prev = exchFuts.get(idx + 1);
if (log.isDebugEnabled()) {
log.debug("Need initialize affinity on coordinator [" + "cache=" + desc.cacheConfiguration().getName() + "prevAff=" + prev.topologyVersion() + ']');
}
assert prev.topologyVersion().compareTo(fut.topologyVersion()) < 0 : prev;
GridDhtAssignmentFetchFuture fetchFut = new GridDhtAssignmentFetchFuture(cctx, desc, prev.topologyVersion(), prev.discoCache());
fetchFut.init();
final GridFutureAdapter<AffinityTopologyVersion> affFut = new GridFutureAdapter<>();
fetchFut.listen(new IgniteInClosureX<IgniteInternalFuture<GridDhtAffinityAssignmentResponse>>() {
@Override
public void applyx(IgniteInternalFuture<GridDhtAffinityAssignmentResponse> fetchFut) throws IgniteCheckedException {
fetchAffinity(prev, aff, (GridDhtAssignmentFetchFuture) fetchFut);
aff.calculate(fut.topologyVersion(), fut.discoveryEvent(), fut.discoCache());
affFut.onDone(fut.topologyVersion());
}
});
futs.add(affFut);
} else
cache = new CacheHolder1(cacheCtx, null);
CacheHolder old = caches.put(cache.cacheId(), cache);
assert old == null : old;
}
});
if (!futs.isEmpty()) {
GridCompoundFuture<AffinityTopologyVersion, ?> affFut = new GridCompoundFuture<>();
for (IgniteInternalFuture<AffinityTopologyVersion> f : futs) affFut.add(f);
affFut.markInitialized();
return affFut;
}
return null;
}
use of org.apache.ignite.internal.processors.affinity.GridAffinityAssignmentCache 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.topologyVersion() + ", msg=" + msg + ']');
}
assert exchFut.exchangeId().equals(msg.exchangeId()) : msg;
final AffinityTopologyVersion topVer = exchFut.topologyVersion();
final Map<Integer, Map<Integer, List<UUID>>> assignment = msg.assignmentChange();
assert assignment != null;
final Map<Object, List<List<ClusterNode>>> affCache = new HashMap<>();
forAllCaches(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.cacheId());
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.internal.processors.affinity.GridAffinityAssignmentCache in project ignite by apache.
the class GridCacheAffinityManager method start0.
/** {@inheritDoc} */
@Override
public void start0() throws IgniteCheckedException {
affFunction = cctx.config().getAffinity();
affMapper = cctx.config().getAffinityMapper();
aff = new GridAffinityAssignmentCache(cctx.kernalContext(), cctx.name(), affFunction, cctx.config().getNodeFilter(), cctx.config().getBackups(), cctx.isLocal());
}
use of org.apache.ignite.internal.processors.affinity.GridAffinityAssignmentCache in project ignite by apache.
the class GridDhtPartitionsExchangeFuture method clientOnlyExchange.
/**
* @throws IgniteCheckedException If failed.
*/
private void clientOnlyExchange() throws IgniteCheckedException {
clientOnlyExchange = true;
if (crd != null) {
if (crd.isLocal()) {
for (GridCacheContext cacheCtx : cctx.cacheContexts()) {
boolean updateTop = !cacheCtx.isLocal() && exchId.topologyVersion().equals(cacheCtx.startTopologyVersion());
if (updateTop) {
for (GridClientPartitionTopology top : cctx.exchange().clientTopologies()) {
if (top.cacheId() == cacheCtx.cacheId()) {
cacheCtx.topology().update(exchId, top.partitionMap(true), top.updateCounters(false));
break;
}
}
}
}
} else {
if (!centralizedAff)
sendLocalPartitions(crd);
initDone();
return;
}
} else {
if (centralizedAff) {
// Last server node failed.
for (GridCacheContext cacheCtx : cctx.cacheContexts()) {
GridAffinityAssignmentCache aff = cacheCtx.affinity().affinityCache();
aff.initialize(topologyVersion(), aff.idealAssignment());
}
}
}
onDone(topologyVersion());
}
Aggregations