Search in sources :

Example 31 with GridLongList

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);
            }
        });
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridLongList(org.apache.ignite.internal.util.GridLongList) MvccActiveQueriesMessage(org.apache.ignite.internal.processors.cache.mvcc.msg.MvccActiveQueriesMessage)

Example 32 with GridLongList

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();
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) IgniteException(org.apache.ignite.IgniteException) GridLongList(org.apache.ignite.internal.util.GridLongList) RollbackRecord(org.apache.ignite.internal.pagemem.wal.record.RollbackRecord) WALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer)

Example 33 with GridLongList

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();
}
Also used : DataPageIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.DataPageIO) GridLongList(org.apache.ignite.internal.util.GridLongList) DataPagePayload(org.apache.ignite.internal.processors.cache.persistence.tree.io.DataPagePayload)

Example 34 with GridLongList

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);
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) GridLongList(org.apache.ignite.internal.util.GridLongList) FullPageId(org.apache.ignite.internal.pagemem.FullPageId)

Example 35 with GridLongList

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;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) HashMap(java.util.HashMap) GridLongList(org.apache.ignite.internal.util.GridLongList)

Aggregations

GridLongList (org.apache.ignite.internal.util.GridLongList)39 Test (org.junit.Test)11 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)6 ByteBuffer (java.nio.ByteBuffer)5 DirectMessageWriter (org.apache.ignite.internal.direct.DirectMessageWriter)5 MessageWriter (org.apache.ignite.plugin.extensions.communication.MessageWriter)5 Map (java.util.Map)4 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)4 ClusterNode (org.apache.ignite.cluster.ClusterNode)4 IgniteException (org.apache.ignite.IgniteException)3 PagesListAddPageRecord (org.apache.ignite.internal.pagemem.wal.record.delta.PagesListAddPageRecord)3 PagesListInitNewPageRecord (org.apache.ignite.internal.pagemem.wal.record.delta.PagesListInitNewPageRecord)3 PagesListSetNextRecord (org.apache.ignite.internal.pagemem.wal.record.delta.PagesListSetNextRecord)3 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 TreeMap (java.util.TreeMap)2 UUID (java.util.UUID)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 PagesListMetaIO (org.apache.ignite.internal.processors.cache.persistence.freelist.io.PagesListMetaIO)2