use of org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtUnreservedPartitionException 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.GridDhtUnreservedPartitionException in project ignite by apache.
the class GridCacheQueryManager method scanIterator.
/**
* @param qry Query.
* @param transformer Transformer.
* @param locNode Local node.
* @return Full-scan row iterator.
* @throws IgniteCheckedException If failed to get iterator.
*/
@SuppressWarnings({ "unchecked" })
private GridCloseableIterator scanIterator(final GridCacheQueryAdapter<?> qry, IgniteClosure transformer, boolean locNode) throws IgniteCheckedException {
assert !cctx.mvccEnabled() || qry.mvccSnapshot() != null;
final IgniteBiPredicate<K, V> keyValFilter = qry.scanFilter();
final InternalScanFilter<K, V> intFilter = keyValFilter != null ? new InternalScanFilter<>(keyValFilter) : null;
try {
if (keyValFilter instanceof PlatformCacheEntryFilter)
((PlatformCacheEntryFilter) keyValFilter).cacheContext(cctx);
else
injectResources(keyValFilter);
Integer part = cctx.isLocal() ? null : qry.partition();
if (part != null && (part < 0 || part >= cctx.affinity().partitions()))
return new GridEmptyCloseableIterator() {
@Override
public void close() throws IgniteCheckedException {
if (intFilter != null)
intFilter.close();
super.close();
}
};
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 locPart0 != null && locPart0.state() == LOST ? new CacheInvalidStateException("Failed to execute scan query because cache partition has been " + "lost [cacheName=" + cctx.name() + ", part=" + part + "]") : new GridDhtUnreservedPartitionException(part, cctx.affinity().affinityTopologyVersion(), "Partition can not be reserved");
}
locPart = locPart0;
it = cctx.offheap().cachePartitionIterator(cctx.cacheId(), part, qry.mvccSnapshot(), qry.isDataPageScanEnabled());
} else {
locPart = null;
if (!cctx.isLocal()) {
final GridDhtCacheAdapter dht = cctx.isNear() ? cctx.near().dht() : cctx.dht();
Set<Integer> lostParts = dht.topology().lostPartitions();
if (!lostParts.isEmpty()) {
throw new CacheInvalidStateException("Failed to execute scan query because cache partition " + "has been lost [cacheName=" + cctx.name() + ", part=" + lostParts.iterator().next() + "]");
}
}
it = cctx.offheap().cacheIterator(cctx.cacheId(), true, backups, topVer, qry.mvccSnapshot(), qry.isDataPageScanEnabled());
}
ScanQueryIterator iter = new ScanQueryIterator(it, qry, topVer, locPart, SecurityUtils.sandboxedProxy(cctx.kernalContext(), IgniteBiPredicate.class, keyValFilter), SecurityUtils.sandboxedProxy(cctx.kernalContext(), IgniteClosure.class, transformer), locNode, locNode ? locIters : null, cctx, log);
if (locNode) {
ScanQueryIterator old = locIters.addx(iter);
assert old == null;
}
return iter;
} catch (IgniteCheckedException | RuntimeException e) {
if (intFilter != null)
intFilter.close();
throw e;
}
}
Aggregations