use of org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture 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.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture in project ignite by apache.
the class GridCachePartitionExchangeManager method forceRebalance.
/**
* Forces preload exchange.
*
* @param exchFut Exchange future.
*/
public IgniteInternalFuture<Boolean> forceRebalance(GridDhtPartitionsExchangeFuture exchFut) {
GridFutureAdapter<Boolean> fut = new GridFutureAdapter<>();
exchWorker.addExchangeFuture(new GridDhtPartitionsExchangeFuture(cctx, exchFut.discoveryEvent(), exchFut.exchangeId(), fut));
return fut;
}
use of org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture in project ignite by apache.
the class GridCachePartitionExchangeManager method exchangeFuture.
/**
* @param exchId Exchange ID.
* @param discoEvt Discovery event.
* @param cache Discovery data cache.
* @param exchActions Cache change actions.
* @param affChangeMsg Affinity change message.
* @return Exchange future.
*/
private GridDhtPartitionsExchangeFuture exchangeFuture(GridDhtPartitionExchangeId exchId, @Nullable DiscoveryEvent discoEvt, @Nullable DiscoCache cache, @Nullable ExchangeActions exchActions, @Nullable CacheAffinityChangeMessage affChangeMsg) {
GridDhtPartitionsExchangeFuture fut;
GridDhtPartitionsExchangeFuture old = exchFuts.addx(fut = new GridDhtPartitionsExchangeFuture(cctx, busyLock, exchId, exchActions, affChangeMsg));
if (old != null) {
fut = old;
if (exchActions != null)
fut.exchangeActions(exchActions);
if (affChangeMsg != null)
fut.affinityChangeMessage(affChangeMsg);
}
if (discoEvt != null)
fut.onEvent(exchId, discoEvt, cache);
if (stopErr != null)
fut.onDone(stopErr);
return fut;
}
use of org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture in project ignite by apache.
the class GridCachePartitionExchangeManager method processSinglePartitionUpdate.
/**
* @param node Node ID.
* @param msg Message.
*/
private void processSinglePartitionUpdate(final ClusterNode node, final GridDhtPartitionsSingleMessage msg) {
if (!enterBusy())
return;
try {
if (msg.exchangeId() == null) {
if (log.isDebugEnabled())
log.debug("Received local partition update [nodeId=" + node.id() + ", parts=" + msg + ']');
boolean updated = false;
for (Map.Entry<Integer, GridDhtPartitionMap> entry : msg.partitions().entrySet()) {
Integer cacheId = entry.getKey();
GridCacheContext<K, V> cacheCtx = cctx.cacheContext(cacheId);
if (cacheCtx != null && cacheCtx.startTopologyVersion().compareTo(entry.getValue().topologyVersion()) > 0)
continue;
GridDhtPartitionTopology top = null;
if (cacheCtx == null)
top = clientTops.get(cacheId);
else if (!cacheCtx.isLocal())
top = cacheCtx.topology();
if (top != null) {
updated |= top.update(null, entry.getValue()) != null;
cctx.affinity().checkRebalanceState(top, cacheId);
}
}
if (updated)
scheduleResendPartitions();
} else {
if (msg.client()) {
final GridDhtPartitionsExchangeFuture exchFut = exchangeFuture(msg.exchangeId(), null, null, null, null);
exchFut.listen(new CI1<IgniteInternalFuture<AffinityTopologyVersion>>() {
@Override
public void apply(IgniteInternalFuture<AffinityTopologyVersion> fut) {
// Finished future should reply only to sender client node.
exchFut.onReceive(node, msg);
}
});
} else
exchangeFuture(msg.exchangeId(), null, null, null, null).onReceive(node, msg);
}
} finally {
leaveBusy();
}
}
use of org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture in project ignite by apache.
the class GridCachePartitionExchangeManager method refreshPartitions.
/**
* Partition refresh callback.
*/
private void refreshPartitions() {
ClusterNode oldest = cctx.discovery().oldestAliveCacheServerNode(AffinityTopologyVersion.NONE);
if (oldest == null) {
if (log.isDebugEnabled())
log.debug("Skip partitions refresh, there are no server nodes [loc=" + cctx.localNodeId() + ']');
return;
}
if (log.isDebugEnabled())
log.debug("Refreshing partitions [oldest=" + oldest.id() + ", loc=" + cctx.localNodeId() + ']');
// If this is the oldest node.
if (oldest.id().equals(cctx.localNodeId())) {
// Check rebalance state & send CacheAffinityChangeMessage if need.
for (GridCacheContext cacheCtx : cctx.cacheContexts()) {
if (!cacheCtx.isLocal()) {
if (cacheCtx == null)
continue;
GridDhtPartitionTopology top = null;
if (!cacheCtx.isLocal())
top = cacheCtx.topology();
if (top != null)
cctx.affinity().checkRebalanceState(top, cacheCtx.cacheId());
}
}
GridDhtPartitionsExchangeFuture lastFut = lastInitializedFut;
// No need to send to nodes which did not finish their first exchange.
AffinityTopologyVersion rmtTopVer = lastFut != null ? lastFut.topologyVersion() : AffinityTopologyVersion.NONE;
Collection<ClusterNode> rmts = CU.remoteNodes(cctx, AffinityTopologyVersion.NONE);
if (log.isDebugEnabled())
log.debug("Refreshing partitions from oldest node: " + cctx.localNodeId());
sendAllPartitions(rmts);
} else {
if (log.isDebugEnabled())
log.debug("Refreshing local partitions from non-oldest node: " + cctx.localNodeId());
sendLocalPartitions(oldest, null);
}
}
Aggregations