use of org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLocalPartition in project ignite by apache.
the class GridDhtPartitionSupplier method clearContext.
/**
* Clear context.
*
* @param sc Supply context.
* @param log Logger.
*/
private static void clearContext(final SupplyContext sc, final IgniteLogger log) {
if (sc != null) {
final Iterator it = sc.entryIt;
if (it != null && it instanceof GridCloseableIterator && !((GridCloseableIterator) it).isClosed()) {
try {
((GridCloseableIterator) it).close();
} catch (IgniteCheckedException e) {
U.error(log, "Iterator close failed.", e);
}
}
final GridDhtLocalPartition loc = sc.loc;
if (loc != null) {
assert loc.reservations() > 0;
loc.release();
}
}
}
use of org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLocalPartition in project ignite by apache.
the class GridDhtPartitionDemander method handleSupplyMessage.
/**
* @param idx Index.
* @param id Node id.
* @param supply Supply.
*/
public void handleSupplyMessage(int idx, final UUID id, final GridDhtPartitionSupplyMessage supply) {
AffinityTopologyVersion topVer = supply.topologyVersion();
final RebalanceFuture fut = rebalanceFut;
ClusterNode node = cctx.node(id);
if (node == null)
return;
if (// Current future have another update sequence.
!fut.isActual(supply.updateSequence()))
// Supple message based on another future.
return;
if (// Topology already changed (for the future that supply message based on).
topologyChanged(fut))
return;
if (log.isDebugEnabled())
log.debug("Received supply message: " + supply);
// Check whether there were class loading errors on unmarshal
if (supply.classError() != null) {
U.warn(log, "Rebalancing from node cancelled [node=" + id + "]. Class got undeployed during preloading: " + supply.classError());
fut.cancel(id);
return;
}
final GridDhtPartitionTopology top = cctx.dht().topology();
try {
// Preload.
for (Map.Entry<Integer, CacheEntryInfoCollection> e : supply.infos().entrySet()) {
int p = e.getKey();
if (cctx.affinity().partitionLocalNode(p, topVer)) {
GridDhtLocalPartition part = top.localPartition(p, topVer, true);
assert part != null;
boolean last = supply.last().contains(p);
if (part.state() == MOVING) {
boolean reserved = part.reserve();
assert reserved : "Failed to reserve partition [igniteInstanceName=" + cctx.igniteInstanceName() + ", cacheName=" + cctx.name() + ", part=" + part + ']';
part.lock();
try {
// Loop through all received entries and try to preload them.
for (GridCacheEntryInfo entry : e.getValue().infos()) {
if (!part.preloadingPermitted(entry.key(), entry.version())) {
if (log.isDebugEnabled())
log.debug("Preloading is not permitted for entry due to " + "evictions [key=" + entry.key() + ", ver=" + entry.version() + ']');
continue;
}
if (!preloadEntry(node, p, entry, topVer)) {
if (log.isDebugEnabled())
log.debug("Got entries for invalid partition during " + "preloading (will skip) [p=" + p + ", entry=" + entry + ']');
break;
}
}
// then we take ownership.
if (last) {
top.own(part);
fut.partitionDone(id, p);
if (log.isDebugEnabled())
log.debug("Finished rebalancing partition: " + part);
}
} finally {
part.unlock();
part.release();
}
} else {
if (last)
fut.partitionDone(id, p);
if (log.isDebugEnabled())
log.debug("Skipping rebalancing partition (state is not MOVING): " + part);
}
} else {
fut.partitionDone(id, p);
if (log.isDebugEnabled())
log.debug("Skipping rebalancing partition (it does not belong on current node): " + p);
}
}
// Only request partitions based on latest topology version.
for (Integer miss : supply.missed()) {
if (cctx.affinity().partitionLocalNode(miss, topVer))
fut.partitionMissed(id, miss);
}
for (Integer miss : supply.missed()) fut.partitionDone(id, miss);
GridDhtPartitionDemandMessage d = new GridDhtPartitionDemandMessage(supply.updateSequence(), supply.topologyVersion(), cctx.cacheId());
d.timeout(cctx.config().getRebalanceTimeout());
d.topic(rebalanceTopics.get(idx));
if (!topologyChanged(fut) && !fut.isDone()) {
// Send demand message.
cctx.io().sendOrderedMessage(node, rebalanceTopics.get(idx), d, cctx.ioPolicy(), cctx.config().getRebalanceTimeout());
}
} catch (IgniteCheckedException e) {
if (log.isDebugEnabled())
log.debug("Node left during rebalancing [node=" + node.id() + ", msg=" + e.getMessage() + ']');
} catch (IgniteSpiException e) {
if (log.isDebugEnabled())
log.debug("Failed to send message to node (current node is stopping?) [node=" + node.id() + ", msg=" + e.getMessage() + ']');
}
}
use of org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLocalPartition in project ignite by apache.
the class GridCacheQueryManager method scanIterator.
/**
* @param qry Query.
* @param locNode Local node.
* @return Full-scan row iterator.
* @throws IgniteCheckedException If failed to get iterator.
*/
@SuppressWarnings({ "unchecked" })
private GridCloseableIterator<IgniteBiTuple<K, V>> scanIterator(final GridCacheQueryAdapter<?> qry, boolean locNode) throws IgniteCheckedException {
final IgniteBiPredicate<K, V> keyValFilter = qry.scanFilter();
try {
injectResources(keyValFilter);
Integer part = qry.partition();
if (cctx.isLocal())
part = null;
if (part != null && (part < 0 || part >= cctx.affinity().partitions()))
return new GridEmptyCloseableIterator<>();
final ExpiryPolicy plc = cctx.expiry();
AffinityTopologyVersion topVer = GridQueryProcessor.getRequestAffinityTopologyVersion();
if (topVer == null)
topVer = cctx.affinity().affinityTopologyVersion();
final boolean backups = qry.includeBackups() || cctx.isReplicated();
final GridDhtLocalPartition locPart;
final GridIterator<CacheDataRow> it;
if (part != null) {
final GridDhtCacheAdapter dht = cctx.isNear() ? cctx.near().dht() : cctx.dht();
GridDhtLocalPartition locPart0 = dht.topology().localPartition(part, topVer, false);
if (locPart0 == null || locPart0.state() != OWNING || !locPart0.reserve())
throw new GridDhtUnreservedPartitionException(part, cctx.affinity().affinityTopologyVersion(), "Partition can not be reserved");
if (locPart0.state() != OWNING) {
locPart0.release();
throw new GridDhtUnreservedPartitionException(part, cctx.affinity().affinityTopologyVersion(), "Partition can not be reserved");
}
locPart = locPart0;
it = cctx.offheap().iterator(part);
} else {
locPart = null;
it = cctx.offheap().iterator(true, backups, topVer);
}
return new PeekValueExpiryAwareIterator(it, plc, topVer, keyValFilter, qry.keepBinary(), locNode) {
@Override
protected void onClose() {
super.onClose();
if (locPart != null)
locPart.release();
closeScanFilter(keyValFilter);
}
};
} catch (IgniteCheckedException | RuntimeException e) {
closeScanFilter(keyValFilter);
throw e;
}
}
use of org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLocalPartition in project ignite by apache.
the class SchemaIndexCacheVisitorImpl method visit.
/** {@inheritDoc} */
@Override
public void visit(SchemaIndexCacheVisitorClosure clo) throws IgniteCheckedException {
assert clo != null;
FilteringVisitorClosure filterClo = new FilteringVisitorClosure(clo);
Collection<GridDhtLocalPartition> parts = cctx.topology().localPartitions();
for (GridDhtLocalPartition part : parts) processPartition(part, filterClo);
}
use of org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLocalPartition in project ignite by apache.
the class IgniteCacheLockPartitionOnAffinityRunAbstractTest method checkPartitionsReservations.
/**
* @param ignite Ignite.
* @param orgId Org id.
* @param expReservations Expected reservations.
* @throws Exception If failed.
*/
protected static void checkPartitionsReservations(final IgniteEx ignite, int orgId, final int expReservations) throws Exception {
int part = ignite.affinity(Organization.class.getSimpleName()).partition(orgId);
final GridDhtLocalPartition pPers = ignite.context().cache().internalCache(Person.class.getSimpleName()).context().topology().localPartition(part, AffinityTopologyVersion.NONE, false);
assertNotNull(pPers);
final GridDhtLocalPartition pOrgs = ignite.context().cache().internalCache(Organization.class.getSimpleName()).context().topology().localPartition(part, AffinityTopologyVersion.NONE, false);
assertNotNull(pOrgs);
GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
return expReservations == pOrgs.reservations() && expReservations == pPers.reservations();
}
}, 1000L);
assertEquals("Unexpected reservations count", expReservations, pOrgs.reservations());
assertEquals("Unexpected reservations count", expReservations, pPers.reservations());
}
Aggregations