Search in sources :

Example 21 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++) {
        Integer 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 22 with GridLongList

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

the class PagesList method putReuseBag.

/**
     * @param pageId Page ID.
     * @param page Page pointer.
     * @param pageAddr Page address.
     * @param io IO.
     * @param bag Reuse bag.
     * @param bucket Bucket.
     * @return {@code true} If succeeded.
     * @throws IgniteCheckedException if failed.
     */
@SuppressWarnings("ForLoopReplaceableByForEach")
private boolean putReuseBag(final long pageId, final long page, final long pageAddr, PagesListNodeIO io, ReuseBag bag, int bucket) throws IgniteCheckedException {
    if (io.getNextId(pageAddr) != 0L)
        // Splitted.
        return false;
    long nextId;
    long prevId = pageId;
    long prevPage = page;
    long prevAddr = pageAddr;
    Boolean walPlc = null;
    // TODO may be unlock right away and do not keep all these pages locked?
    GridLongList locked = null;
    try {
        while ((nextId = bag.pollFreePage()) != 0L) {
            int idx = io.addPage(prevAddr, nextId, pageSize());
            if (idx == -1) {
                // Attempt to add page failed: the node page is full.
                final long nextPage = acquirePage(nextId);
                try {
                    // Page from reuse bag can't be concurrently recycled.
                    long nextPageAddr = writeLock(nextId, nextPage);
                    assert nextPageAddr != 0L;
                    if (locked == null) {
                        locked = new GridLongList(6);
                    }
                    locked.add(nextId);
                    locked.add(nextPage);
                    locked.add(nextPageAddr);
                    setupNextPage(io, prevId, prevAddr, nextId, nextPageAddr);
                    if (needWalDeltaRecord(prevId, prevPage, walPlc))
                        wal.log(new PagesListSetNextRecord(cacheId, prevId, nextId));
                    // Here we should never write full page, because it is known to be new.
                    if (needWalDeltaRecord(nextId, nextPage, FALSE))
                        wal.log(new PagesListInitNewPageRecord(cacheId, nextId, io.getType(), io.getVersion(), nextId, prevId, 0L));
                    // In reuse bucket the page itself can be used as a free page.
                    if (isReuseBucket(bucket))
                        bucketsSize[bucket].incrementAndGet();
                    // Switch to this new page, which is now a part of our list
                    // to add the rest of the bag to the new page.
                    prevAddr = nextPageAddr;
                    prevId = nextId;
                    prevPage = nextPage;
                    // Starting from tis point all wal records are written for reused pages from the bag.
                    // This mean that we use delta records only.
                    walPlc = FALSE;
                } finally {
                    releasePage(nextId, nextPage);
                }
            } else {
                // TODO: use single WAL record for bag?
                if (needWalDeltaRecord(prevId, prevPage, walPlc))
                    wal.log(new PagesListAddPageRecord(cacheId, prevId, nextId));
                bucketsSize[bucket].incrementAndGet();
            }
        }
    } finally {
        if (locked != null) {
            // We have to update our bucket with the new tail.
            updateTail(bucket, pageId, prevId);
            // Release write.
            for (int i = 0; i < locked.size(); i += 3) {
                writeUnlock(locked.get(i), locked.get(i + 1), locked.get(i + 2), FALSE, true);
            }
        }
    }
    return true;
}
Also used : PagesListAddPageRecord(org.apache.ignite.internal.pagemem.wal.record.delta.PagesListAddPageRecord) GridLongList(org.apache.ignite.internal.util.GridLongList) PagesListSetNextRecord(org.apache.ignite.internal.pagemem.wal.record.delta.PagesListSetNextRecord) PagesListInitNewPageRecord(org.apache.ignite.internal.pagemem.wal.record.delta.PagesListInitNewPageRecord)

Example 23 with GridLongList

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

the class GridDhtAtomicCache method sendDeferredUpdateResponse.

/**
 * @param part Partition.
 * @param primaryId Primary ID.
 * @param futId Future ID.
 */
private void sendDeferredUpdateResponse(int part, UUID primaryId, long futId) {
    Map<UUID, GridDhtAtomicDeferredUpdateResponse> resMap = defRes.get();
    GridDhtAtomicDeferredUpdateResponse msg = resMap.get(primaryId);
    if (msg == null) {
        msg = new GridDhtAtomicDeferredUpdateResponse(ctx.cacheId(), new GridLongList(DEFERRED_UPDATE_RESPONSE_BUFFER_SIZE));
        if (DEFERRED_UPDATE_RESPONSE_TIMEOUT > 0) {
            GridTimeoutObject timeoutSnd = new DeferredUpdateTimeout(part, primaryId);
            msg.timeoutSender(timeoutSnd);
            ctx.time().addTimeoutObject(timeoutSnd);
        }
        resMap.put(primaryId, msg);
    }
    GridLongList futIds = msg.futureIds();
    assert futIds.size() < DEFERRED_UPDATE_RESPONSE_BUFFER_SIZE : futIds.size();
    futIds.add(futId);
    if (futIds.size() >= DEFERRED_UPDATE_RESPONSE_BUFFER_SIZE) {
        resMap.remove(primaryId);
        sendDeferredUpdateResponse(primaryId, msg);
    }
}
Also used : GridLongList(org.apache.ignite.internal.util.GridLongList) UUID(java.util.UUID) GridTimeoutObject(org.apache.ignite.internal.processors.timeout.GridTimeoutObject)

Example 24 with GridLongList

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

the class GridNearAtomicFullUpdateRequest method addUpdateEntry.

/**
 * {@inheritDoc}
 */
@Override
public void addUpdateEntry(KeyCacheObject key, @Nullable Object val, long conflictTtl, long conflictExpireTime, @Nullable GridCacheVersion conflictVer) {
    EntryProcessor<Object, Object, Object> entryProcessor = null;
    if (op == TRANSFORM) {
        assert val instanceof EntryProcessor : val;
        entryProcessor = (EntryProcessor<Object, Object, Object>) val;
    }
    assert val != null || op == DELETE;
    keys.add(key);
    if (entryProcessor != null) {
        if (entryProcessors == null)
            entryProcessors = new ArrayList<>(initSize);
        entryProcessors.add(entryProcessor);
    } else if (val != null) {
        assert val instanceof CacheObject : val;
        if (vals == null)
            vals = new ArrayList<>(initSize);
        vals.add((CacheObject) val);
    }
    // In case there is no conflict, do not create the list.
    if (conflictVer != null) {
        if (conflictVers == null) {
            conflictVers = new ArrayList<>(initSize);
            for (int i = 0; i < keys.size() - 1; i++) conflictVers.add(null);
        }
        conflictVers.add(conflictVer);
    } else if (conflictVers != null)
        conflictVers.add(null);
    if (conflictTtl >= 0) {
        if (conflictTtls == null) {
            conflictTtls = new GridLongList(keys.size());
            for (int i = 0; i < keys.size() - 1; i++) conflictTtls.add(CU.TTL_NOT_CHANGED);
        }
        conflictTtls.add(conflictTtl);
    }
    if (conflictExpireTime >= 0) {
        if (conflictExpireTimes == null) {
            conflictExpireTimes = new GridLongList(keys.size());
            for (int i = 0; i < keys.size() - 1; i++) conflictExpireTimes.add(CU.EXPIRE_TIME_CALCULATE);
        }
        conflictExpireTimes.add(conflictExpireTime);
    }
}
Also used : EntryProcessor(javax.cache.processor.EntryProcessor) ArrayList(java.util.ArrayList) GridLongList(org.apache.ignite.internal.util.GridLongList) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject)

Example 25 with GridLongList

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

the class CacheGroupAffinityMessage method createAssignments.

/**
 * @param assigns Nodes orders.
 * @param nodesByOrder Nodes by order cache.
 * @param discoCache Discovery data cache.
 * @return Nodes list.
 */
private List<List<ClusterNode>> createAssignments(List<GridLongList> assigns, Map<Long, ClusterNode> nodesByOrder, DiscoCache discoCache) {
    List<List<ClusterNode>> assignments0 = new ArrayList<>(assigns.size());
    for (int p = 0; p < assigns.size(); p++) {
        GridLongList assign = assigns.get(p);
        assignments0.add(toNodes(assign, nodesByOrder, discoCache));
    }
    return assignments0;
}
Also used : ArrayList(java.util.ArrayList) GridLongList(org.apache.ignite.internal.util.GridLongList) ArrayList(java.util.ArrayList) GridLongList(org.apache.ignite.internal.util.GridLongList) List(java.util.List)

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