Search in sources :

Example 6 with GridLongList

use of org.apache.ignite.internal.util.GridLongList in project ignite by apache.

the class GridDhtAtomicCache method processDhtAtomicDeferredUpdateResponse.

/**
 * @param nodeId Sender node ID.
 * @param res Deferred atomic update response.
 */
private void processDhtAtomicDeferredUpdateResponse(UUID nodeId, GridDhtAtomicDeferredUpdateResponse res) {
    GridLongList futIds = res.futureIds();
    assert futIds != null && !futIds.isEmpty() : futIds;
    for (int i = 0; i < futIds.size(); i++) {
        long id = futIds.get(i);
        GridDhtAtomicAbstractUpdateFuture updateFut = (GridDhtAtomicAbstractUpdateFuture) ctx.mvcc().atomicFuture(id);
        if (updateFut != null) {
            if (msgLog.isDebugEnabled()) {
                msgLog.debug("Received DHT atomic deferred update response [futId=" + id + ", writeVer=" + res + ", node=" + nodeId + ']');
            }
            updateFut.onDeferredResponse(nodeId);
        } else {
            U.warn(msgLog, "Failed to find DHT update future for deferred update response [futId=" + id + ", nodeId=" + nodeId + ", res=" + res + ']');
        }
    }
}
Also used : GridLongList(org.apache.ignite.internal.util.GridLongList)

Example 7 with GridLongList

use of org.apache.ignite.internal.util.GridLongList in project ignite by apache.

the class PagesList method flushBucketsCache.

/**
 * Flush onheap cached pages lists to page memory.
 *
 * @param statHolder Statistic holder.
 * @throws IgniteCheckedException If failed to write a page.
 */
private void flushBucketsCache(IoStatisticsHolder statHolder) throws IgniteCheckedException {
    if (!isCachingApplicable() || !pageCacheChanged)
        return;
    pageCacheChanged = false;
    onheapListCachingEnabled = false;
    int lockedPages = 0;
    try {
        for (int bucket = 0; bucket < buckets; bucket++) {
            PagesCache pagesCache = getBucketCache(bucket, false);
            if (pagesCache == null)
                continue;
            GridLongList pages = pagesCache.flush();
            if (pages != null) {
                if (log.isDebugEnabled()) {
                    log.debug("Move pages from heap to PageMemory [list=" + name() + ", bucket=" + bucket + ", pages=" + pages + ']');
                }
                for (int i = 0; i < pages.size(); i++) {
                    long pageId = pages.get(i);
                    if (log.isDebugEnabled()) {
                        log.debug("Move page from heap to PageMemory [list=" + name() + ", bucket=" + bucket + ", pageId=" + pageId + ']');
                    }
                    Boolean res = write(pageId, putBucket, bucket, null, statHolder);
                    if (res == null) {
                        // Return page to onheap pages list if can't lock it.
                        pagesCache.add(pageId);
                        lockedPages++;
                    }
                }
            }
        }
    } finally {
        onheapListCachingEnabled = true;
    }
    if (lockedPages != 0) {
        if (log.isInfoEnabled())
            log.info("Several pages were locked and weren't flushed on disk [grp=" + grpName + ", lockedPages=" + lockedPages + ']');
        pageCacheChanged = true;
    }
}
Also used : GridLongList(org.apache.ignite.internal.util.GridLongList)

Example 8 with GridLongList

use of org.apache.ignite.internal.util.GridLongList in project ignite by apache.

the class PagesList method init.

/**
 * @param metaPageId Metadata page ID.
 * @param initNew {@code True} if new list if created, {@code false} if should be initialized from metadata.
 * @throws IgniteCheckedException If failed.
 */
protected final void init(long metaPageId, boolean initNew) throws IgniteCheckedException {
    if (metaPageId != 0L) {
        if (initNew)
            init(metaPageId, PagesListMetaIO.VERSIONS.latest());
        else {
            Map<Integer, GridLongList> bucketsData = new HashMap<>();
            long nextId = metaPageId;
            while (nextId != 0) {
                final long pageId = nextId;
                final long page = acquirePage(pageId, IoStatisticsHolderNoOp.INSTANCE);
                try {
                    // No concurrent recycling on init.
                    long pageAddr = readLock(pageId, page);
                    assert pageAddr != 0L;
                    try {
                        PagesListMetaIO io = PagesListMetaIO.VERSIONS.forPage(pageAddr);
                        io.getBucketsData(pageAddr, bucketsData);
                        nextId = io.getNextMetaPageId(pageAddr);
                        assert nextId != pageId : "Loop detected [next=" + U.hexLong(nextId) + ", cur=" + U.hexLong(pageId) + ']';
                    } finally {
                        readUnlock(pageId, page, pageAddr);
                    }
                } finally {
                    releasePage(pageId, page);
                }
            }
            for (Map.Entry<Integer, GridLongList> e : bucketsData.entrySet()) {
                int bucket = e.getKey();
                long bucketSize = 0;
                Stripe[] old = getBucket(bucket);
                assert old == null;
                long[] upd = e.getValue().array();
                Stripe[] tails = new Stripe[upd.length];
                for (int i = 0; i < upd.length; i++) {
                    long tailId = upd[i];
                    long prevId = tailId;
                    int cnt = 0;
                    while (prevId != 0L) {
                        final long pageId = prevId;
                        final long page = acquirePage(pageId, IoStatisticsHolderNoOp.INSTANCE);
                        try {
                            long pageAddr = readLock(pageId, page);
                            assert pageAddr != 0L;
                            try {
                                PagesListNodeIO io = PagesListNodeIO.VERSIONS.forPage(pageAddr);
                                cnt += io.getCount(pageAddr);
                                prevId = io.getPreviousId(pageAddr);
                                // In reuse bucket the page itself can be used as a free page.
                                if (isReuseBucket(bucket) && prevId != 0L)
                                    cnt++;
                            } finally {
                                readUnlock(pageId, page, pageAddr);
                            }
                        } finally {
                            releasePage(pageId, page);
                        }
                    }
                    Stripe stripe = new Stripe(tailId, cnt == 0);
                    tails[i] = stripe;
                    bucketSize += cnt;
                }
                boolean ok = casBucket(bucket, null, tails);
                assert ok;
                bucketsSize.set(bucket, bucketSize);
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) PagesListMetaIO(org.apache.ignite.internal.processors.cache.persistence.freelist.io.PagesListMetaIO) GridLongList(org.apache.ignite.internal.util.GridLongList) PagesListNodeIO(org.apache.ignite.internal.processors.cache.persistence.freelist.io.PagesListNodeIO) Map(java.util.Map) HashMap(java.util.HashMap)

Example 9 with GridLongList

use of org.apache.ignite.internal.util.GridLongList in project ignite by apache.

the class PagesListMetaIO method getBucketsData.

/**
 * @param pageAddr Page address.
 * @param res Results map.
 */
public void getBucketsData(long pageAddr, Map<Integer, GridLongList> res) {
    int cnt = getCount(pageAddr);
    assert cnt >= 0 && cnt <= Short.MAX_VALUE : cnt;
    if (cnt == 0)
        return;
    int off = offset(0);
    for (int i = 0; i < cnt; i++) {
        int bucket = (int) PageUtils.getShort(pageAddr, off);
        assert bucket >= 0 && bucket <= Short.MAX_VALUE : bucket;
        long tailId = PageUtils.getLong(pageAddr, off + 2);
        assert tailId != 0;
        GridLongList list = res.get(bucket);
        if (list == null)
            res.put(bucket, list = new GridLongList());
        list.add(tailId);
        off += ITEM_SIZE;
    }
}
Also used : GridLongList(org.apache.ignite.internal.util.GridLongList)

Example 10 with GridLongList

use of org.apache.ignite.internal.util.GridLongList in project ignite by apache.

the class FullPageIdTable method removeIf.

/**
 * {@inheritDoc}
 */
@Override
public GridLongList removeIf(int startIdxToClear, int endIdxToClear, KeyPredicate keyPred) {
    assert endIdxToClear > startIdxToClear : "Start and end indexes are not consistent: {" + startIdxToClear + ", " + endIdxToClear + "}";
    int sz = endIdxToClear - startIdxToClear;
    GridLongList list = new GridLongList(sz);
    for (int idx = startIdxToClear; idx < endIdxToClear; idx++) {
        long base = entryBase(idx);
        int grpId = GridUnsafe.getInt(base);
        long pageId = GridUnsafe.getLong(base + PAGE_ID_OFFSET);
        if (isRemoved(grpId, pageId) || isEmpty(grpId, pageId))
            continue;
        if (!keyPred.test(grpId, pageId))
            continue;
        long res = valueAt(idx);
        setRemoved(idx);
        list.add(res);
    }
    return list;
}
Also used : 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