use of org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition in project ignite by apache.
the class LoadAllWarmUpStrategy method loadDataInfo.
/**
* Calculation of cache groups, partitions and count of pages that can load
* into data region. Calculation starts and includes an index partition for
* each group.
*
* @param region Data region.
* @return Loadable groups and partitions.
* @throws IgniteCheckedException – if faild.
*/
protected Map<CacheGroupContext, List<LoadPartition>> loadDataInfo(DataRegion region) throws IgniteCheckedException {
// Get cache groups of data region.
List<CacheGroupContext> regionGrps = grpCtxSup.get().stream().filter(grpCtx -> region.equals(grpCtx.dataRegion())).collect(toList());
long availableLoadPageCnt = availableLoadPageCount(region);
// Computing groups, partitions, and pages to load into data region.
Map<CacheGroupContext, List<LoadPartition>> loadableGrps = new LinkedHashMap<>();
for (int i = 0; i < regionGrps.size() && availableLoadPageCnt > 0; i++) {
CacheGroupContext grp = regionGrps.get(i);
// Index partition in priority.
List<GridDhtLocalPartition> locParts = grp.topology().localPartitions();
for (int j = -1; j < locParts.size() && availableLoadPageCnt > 0; j++) {
int p = j == -1 ? INDEX_PARTITION : locParts.get(j).id();
long partPageCnt = grp.shared().pageStore().pages(grp.groupId(), p);
if (partPageCnt > 0) {
long pageCnt = (availableLoadPageCnt - partPageCnt) >= 0 ? partPageCnt : availableLoadPageCnt;
availableLoadPageCnt -= pageCnt;
loadableGrps.computeIfAbsent(grp, grpCtx -> new ArrayList<>()).add(new LoadPartition(p, pageCnt));
}
}
}
return loadableGrps;
}
use of org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition in project ignite by apache.
the class SchemaIndexCacheVisitorImpl method visit.
/**
* {@inheritDoc}
*/
@Override
public void visit(SchemaIndexCacheVisitorClosure clo) {
assert nonNull(clo);
List<GridDhtLocalPartition> locParts = cctx.topology().localPartitions();
if (locParts.isEmpty()) {
buildIdxFut.onDone();
return;
}
cctx.group().metrics().addIndexBuildCountPartitionsLeft(locParts.size());
cctx.cache().metrics0().resetIndexRebuildKeyProcessed();
beforeExecute();
AtomicInteger partsCnt = new AtomicInteger(locParts.size());
AtomicBoolean stop = new AtomicBoolean();
// To avoid a race between clearing pageMemory (on a cache stop ex. deactivation)
// and rebuilding indexes, which can lead to a fail of the node.
SchemaIndexCacheCompoundFuture buildIdxCompoundFut = new SchemaIndexCacheCompoundFuture();
for (GridDhtLocalPartition locPart : locParts) {
GridWorkerFuture<SchemaIndexCacheStat> workerFut = new GridWorkerFuture<>();
GridWorker worker = new SchemaIndexCachePartitionWorker(cctx, locPart, stop, cancelTok, clo, workerFut, partsCnt);
workerFut.setWorker(worker);
buildIdxCompoundFut.add(workerFut);
cctx.kernalContext().pools().buildIndexExecutorService().execute(worker);
}
buildIdxCompoundFut.listen(fut -> {
Throwable err = fut.error();
if (isNull(err) && collectStat && log.isInfoEnabled()) {
try {
GridCompoundFuture<SchemaIndexCacheStat, SchemaIndexCacheStat> compoundFut = (GridCompoundFuture<SchemaIndexCacheStat, SchemaIndexCacheStat>) fut;
SchemaIndexCacheStat resStat = new SchemaIndexCacheStat();
compoundFut.futures().stream().map(IgniteInternalFuture::result).filter(Objects::nonNull).forEach(resStat::accumulate);
log.info(indexStatStr(resStat));
} catch (Exception e) {
log.error("Error when trying to print index build/rebuild statistics [cacheName=" + cctx.cache().name() + ", grpName=" + cctx.group().name() + "]", e);
}
}
buildIdxFut.onDone(err);
});
buildIdxCompoundFut.markInitialized();
}
use of org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition in project ignite by apache.
the class GridDhtGetSingleFuture method map.
/**
* @param key Key.
* @return {@code True} if mapped.
*/
private boolean map(KeyCacheObject key, boolean forceKeys) {
try {
int keyPart = cctx.affinity().partition(key);
if (cctx.mvccEnabled()) {
boolean noOwners = cctx.topology().owners(keyPart, topVer).isEmpty();
// request with no results and therefore forceKeys flag may be set to true here.
if (noOwners)
forceKeys = true;
}
GridDhtLocalPartition part = topVer.topologyVersion() > 0 ? cache().topology().localPartition(keyPart, topVer, true) : cache().topology().localPartition(keyPart);
if (part == null)
return false;
assert this.part == -1;
// By reserving, we make sure that partition won't be unloaded while processed.
if (part.reserve()) {
if (forceKeys || (part.state() == OWNING || part.state() == LOST)) {
this.part = part.id();
return true;
} else {
part.release();
return false;
}
} else
return false;
} catch (GridDhtInvalidPartitionException ex) {
return false;
}
}
use of org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition in project ignite by apache.
the class GridDhtCacheAdapter method localEntriesIteratorEx.
/**
* @param primary If {@code true} includes primary entries.
* @param backup If {@code true} includes backup entries.
* @param topVer Specified affinity topology version.
* @return Local entries iterator.
*/
private Iterator<? extends GridCacheEntryEx> localEntriesIteratorEx(final boolean primary, final boolean backup, final AffinityTopologyVersion topVer) {
assert primary || backup;
if (primary && backup)
return entries().iterator();
else {
final Iterator<GridDhtLocalPartition> partIt = topology().currentLocalPartitions().iterator();
return new Iterator<GridCacheMapEntry>() {
private GridCacheMapEntry next;
private Iterator<GridCacheMapEntry> curIt;
{
advance();
}
@Override
public boolean hasNext() {
return next != null;
}
@Override
public GridCacheMapEntry next() {
if (next == null)
throw new NoSuchElementException();
GridCacheMapEntry e = next;
advance();
return e;
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
private void advance() {
next = null;
do {
if (curIt == null) {
while (partIt.hasNext()) {
GridDhtLocalPartition part = partIt.next();
if (primary == part.primary(topVer)) {
curIt = part.entries(ctx.cacheId()).iterator();
break;
}
}
}
if (curIt != null) {
if (curIt.hasNext()) {
next = curIt.next();
break;
} else
curIt = null;
}
} while (partIt.hasNext());
}
};
}
}
use of org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition in project ignite by apache.
the class GridDhtCacheAdapter method primarySizeLong.
/**
* {@inheritDoc}
*/
@Override
public long primarySizeLong() {
long sum = 0;
AffinityTopologyVersion topVer = ctx.affinity().affinityTopologyVersion();
for (GridDhtLocalPartition p : topology().currentLocalPartitions()) {
if (p.primary(topVer))
sum += p.dataStore().cacheSize(ctx.cacheId());
}
return sum;
}
Aggregations