use of org.apache.ignite.internal.util.GridLongList in project ignite by apache.
the class MvccProcessorImpl method processActiveQueries.
/**
*/
private void processActiveQueries(Collection<ClusterNode> nodes, MvccCoordinator newCrd, boolean sndQrys) {
GridLongList qryIds = sndQrys ? new GridLongList(Stream.concat(activeTrackers.values().stream(), ctx.cache().context().tm().activeTransactions().stream().filter(tx -> tx.near() && tx.local())).mapToLong(q -> ((MvccCoordinatorChangeAware) q).onMvccCoordinatorChange(newCrd)).filter(ID_FILTER).toArray()) : new GridLongList();
if (newCrd.local()) {
prevQueries.addActiveQueries(ctx.localNodeId(), qryIds);
prevQueries.init(nodes, ctx.discovery()::alive);
} else if (sndQrys) {
ctx.pools().getSystemExecutorService().submit(() -> {
try {
sendMessage(newCrd.nodeId(), new MvccActiveQueriesMessage(qryIds));
} catch (IgniteCheckedException e) {
U.error(log, "Failed to send active queries to mvcc coordinator: " + e);
}
});
}
}
use of org.apache.ignite.internal.util.GridLongList in project ignite by apache.
the class GridDhtPartitionTopologyImpl method finalizeUpdateCounters.
/**
* {@inheritDoc}
*/
@Override
public void finalizeUpdateCounters(Set<Integer> parts) {
// It is need to acquire checkpoint lock before topology lock acquiring.
ctx.database().checkpointReadLock();
try {
WALPointer ptr = null;
lock.readLock().lock();
try {
for (int p : parts) {
GridDhtLocalPartition part = locParts.get(p);
if (part != null && part.state().active()) {
// We need to close all gaps in partition update counters sequence. We assume this finalizing is
// happened on exchange and hence all txs are completed. Therefore each gap in update counters
// sequence is a result of undelivered DhtTxFinishMessage on backup (sequences on primary nodes
// do not have gaps). Here we close these gaps and asynchronously notify continuous query engine
// about the skipped events.
AffinityTopologyVersion topVer = ctx.exchange().readyAffinityVersion();
GridLongList gaps = part.finalizeUpdateCounters();
if (gaps != null) {
for (int j = 0; j < gaps.size() / 2; j++) {
long gapStart = gaps.get(j * 2);
long gapStop = gaps.get(j * 2 + 1);
if (part.group().persistenceEnabled() && part.group().walEnabled() && !part.group().mvccEnabled()) {
// Rollback record tracks applied out-of-order updates while finalizeUpdateCounters
// return gaps (missing updates). The code below transforms gaps to updates.
RollbackRecord rec = new RollbackRecord(part.group().groupId(), part.id(), gapStart - 1, gapStop - gapStart + 1);
try {
ptr = ctx.wal().log(rec);
} catch (IgniteCheckedException e) {
throw new IgniteException(e);
}
}
}
for (GridCacheContext ctx0 : grp.caches()) ctx0.continuousQueries().closeBackupUpdateCountersGaps(ctx0, part.id(), topVer, gaps);
}
}
}
} finally {
try {
if (ptr != null)
ctx.wal().flush(ptr, false);
} catch (IgniteCheckedException e) {
throw new IgniteException(e);
} finally {
lock.readLock().unlock();
}
}
} finally {
ctx.database().checkpointReadUnlock();
}
}
use of org.apache.ignite.internal.util.GridLongList in project ignite by apache.
the class CacheDataRowAdapter method relatedPageIds.
/**
* @param grpId Group id.
* @param link Link.
* @param pageId PageId.
* @param pageMem Page memory.
* @param statHolder Status holder.
* @return Array of page ids from link to pageId.
* @throws IgniteCheckedException If failed.
*/
private long[] relatedPageIds(int grpId, long link, long pageId, PageMemory pageMem, IoStatisticsHolder statHolder) throws IgniteCheckedException {
GridLongList pageIds = new GridLongList();
long nextLink = link;
long nextLinkPageId = pageId(nextLink);
while (nextLinkPageId != pageId) {
pageIds.add(nextLinkPageId);
long page = pageMem.acquirePage(grpId, nextLinkPageId, statHolder);
try {
long pageAddr = pageMem.readLock(grpId, nextLinkPageId, page);
try {
DataPageIO io = DataPageIO.VERSIONS.forPage(pageAddr);
int itemId = itemId(nextLink);
DataPagePayload data = io.readPayload(pageAddr, itemId, pageMem.realPageSize(grpId));
nextLink = data.nextLink();
nextLinkPageId = pageId(nextLink);
} finally {
pageMem.readUnlock(grpId, nextLinkPageId, page);
}
} finally {
pageMem.releasePage(grpId, nextLinkPageId, page);
}
}
pageIds.add(pageId);
return pageIds.array();
}
use of org.apache.ignite.internal.util.GridLongList in project ignite by apache.
the class RobinHoodBackwardShiftHashMapTest method doRemovalTests.
/**
* @param cap capacity of map
* @param pred predicate to filter entries to be removed.
*/
private void doRemovalTests(int cap, LoadedPagesMap.KeyPredicate pred) {
withMap(map -> {
Map<FullPageId, Long> check = new HashMap<>();
// fill with 1 space left;
int elems = cap - 1;
for (int i = 0; i < elems; i++) {
int grpId = i + 1;
long val = grpId * grpId;
int pageId = 1;
map.put(grpId, pageId, val, i);
check.put(new FullPageId(pageId, grpId), val);
}
int sz = map.size();
GridLongList list = map.removeIf(pred);
for (int i = 0; i < list.size(); i++) {
long val = list.get(i);
assertTrue(val > 0);
}
assertEquals(sz - map.size(), list.size());
Map<FullPageId, Long> res = new HashMap<>();
map.forEach(res::put);
for (int i = 0; i < cap; i++) {
GridLongList list1 = map.removeIf(i, i + 1, pred);
// clear should not be successful.
assertTrue(list1.isEmpty());
}
check.keySet().removeIf(entry -> pred.test(entry.groupId(), entry.pageId()));
assertEquals(res, check);
}, cap);
}
use of org.apache.ignite.internal.util.GridLongList in project ignite by apache.
the class IgnitePdsPageReplacementDuringPartitionClearTest method allPartitions.
/**
* Calculates mapping from nodes to partitions.
*
* @param ig Ignite instance.
* @return Map.
*/
private Map<ClusterNode, GridLongList> allPartitions(Ignite ig) {
Map<ClusterNode, GridLongList> res = new HashMap<>(ig.cluster().nodes().size(), 1.f);
Affinity<Object> aff = ig.affinity(CACHE_NAME);
for (int i = 0; i < PARTS; i++) {
Collection<ClusterNode> nodes = aff.mapPartitionToPrimaryAndBackups(i);
for (ClusterNode node : nodes) res.computeIfAbsent(node, k -> new GridLongList(2)).add(i);
}
return res;
}
Aggregations