Search in sources :

Example 26 with GridLongList

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

the class GridDhtAtomicUpdateRequest method addNearWriteValue.

/**
 * {@inheritDoc}
 */
@Override
public void addNearWriteValue(KeyCacheObject key, @Nullable CacheObject val, EntryProcessor<Object, Object, Object> entryProcessor, long ttl, long expireTime) {
    assert key.partition() >= 0 : key;
    if (hasKey(key)) {
        if (obsoleteIndexes == null)
            obsoleteIndexes = new GridIntList();
        obsoleteIndexes.add(keys.indexOf(key));
        return;
    }
    if (nearKeys == null) {
        nearKeys = new ArrayList<>();
        if (forceTransformBackups) {
            nearEntryProcessors = new ArrayList<>();
            nearEntryProcessorsBytes = new ArrayList<>();
        } else
            nearVals = new ArrayList<>();
    }
    nearKeys.add(key);
    if (forceTransformBackups) {
        assert entryProcessor != null;
        nearEntryProcessors.add(entryProcessor);
    } else
        nearVals.add(val);
    if (ttl >= 0) {
        if (nearTtls == null) {
            nearTtls = new GridLongList(nearKeys.size());
            for (int i = 0; i < nearKeys.size() - 1; i++) nearTtls.add(CU.TTL_NOT_CHANGED);
        }
    }
    if (nearTtls != null)
        nearTtls.add(ttl);
    if (expireTime >= 0) {
        if (nearExpireTimes == null) {
            nearExpireTimes = new GridLongList(nearKeys.size());
            for (int i = 0; i < nearKeys.size() - 1; i++) nearExpireTimes.add(CU.EXPIRE_TIME_CALCULATE);
        }
    }
    if (nearExpireTimes != null)
        nearExpireTimes.add(expireTime);
}
Also used : ArrayList(java.util.ArrayList) GridLongList(org.apache.ignite.internal.util.GridLongList) GridIntList(org.apache.ignite.internal.util.GridIntList)

Example 27 with GridLongList

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

the class GridDhtAtomicUpdateRequest method addWriteValue.

/**
 * {@inheritDoc}
 */
@Override
public void addWriteValue(KeyCacheObject key, @Nullable CacheObject val, EntryProcessor<Object, Object, Object> entryProcessor, long ttl, long conflictExpireTime, @Nullable GridCacheVersion conflictVer, boolean addPrevVal, @Nullable CacheObject prevVal, long updateCntr, GridCacheOperation cacheOp) {
    assert key.partition() >= 0 : key;
    keys.add(key);
    if (forceTransformBackups) {
        assert entryProcessor != null;
        entryProcessors.add(entryProcessor);
    } else
        vals.add(val);
    if (addPrevVal) {
        if (prevVals == null)
            prevVals = new ArrayList<>();
        prevVals.add(prevVal);
    }
    if (updateCntrs == null)
        updateCntrs = new GridLongList();
    updateCntrs.add(updateCntr);
    // In case there is no conflict, do not create the list.
    if (conflictVer != null) {
        if (conflictVers == null) {
            conflictVers = new ArrayList<>();
            for (int i = 0; i < keys.size() - 1; i++) conflictVers.add(null);
        }
        conflictVers.add(conflictVer);
    } else if (conflictVers != null)
        conflictVers.add(null);
    if (ttl >= 0) {
        if (ttls == null) {
            ttls = new GridLongList(keys.size());
            for (int i = 0; i < keys.size() - 1; i++) ttls.add(CU.TTL_NOT_CHANGED);
        }
    }
    if (ttls != null)
        ttls.add(ttl);
    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);
        }
    }
    if (conflictExpireTimes != null)
        conflictExpireTimes.add(conflictExpireTime);
}
Also used : ArrayList(java.util.ArrayList) GridLongList(org.apache.ignite.internal.util.GridLongList)

Example 28 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.
 * @param statHolder Statistics holder to track IO operations.
 * @return {@code true} If succeeded.
 * @throws IgniteCheckedException if failed.
 */
private boolean putReuseBag(final long pageId, final long page, final long pageAddr, PagesListNodeIO io, ReuseBag bag, int bucket, IoStatisticsHolder statHolder) throws IgniteCheckedException {
    assert bag != null : "bag is null";
    assert !bag.isEmpty() : "bag is empty";
    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) {
            assert PageIdUtils.itemId(nextId) > 0 && PageIdUtils.itemId(nextId) <= MAX_ITEMID_NUM : U.hexLong(nextId);
            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, statHolder);
                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(grpId, 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(grpId, nextId, io.getType(), io.getVersion(), nextId, prevId, 0L));
                    // In reuse bucket the page itself can be used as a free page.
                    if (isReuseBucket(bucket))
                        incrementBucketSize(bucket);
                    // 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(grpId, prevId, nextId));
                incrementBucketSize(bucket);
            }
        }
    } 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 29 with GridLongList

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

the class PartitionUpdateCounterTrackingImpl method finalizeUpdateCounters.

/**
 * {@inheritDoc}
 */
@Override
public synchronized GridLongList finalizeUpdateCounters() {
    Map.Entry<Long, Item> item = queue.pollFirstEntry();
    GridLongList gaps = null;
    while (item != null) {
        if (gaps == null)
            gaps = new GridLongList((queue.size() + 1) * 2);
        long start = cntr.get() + 1;
        long end = item.getValue().start;
        gaps.add(start);
        gaps.add(end);
        // Close pending ranges.
        cntr.set(item.getValue().absolute());
        item = queue.pollFirstEntry();
    }
    reserveCntr.set(get());
    return gaps;
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) GridLongList(org.apache.ignite.internal.util.GridLongList) NavigableMap(java.util.NavigableMap) TreeMap(java.util.TreeMap) Map(java.util.Map)

Example 30 with GridLongList

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

the class MvccProcessorImpl method processActiveQueriesMessage.

/**
 * @param nodeId Node ID.
 * @param msg Message.
 */
private void processActiveQueriesMessage(UUID nodeId, MvccActiveQueriesMessage msg) {
    GridLongList queryIds = msg.activeQueries();
    assert queryIds != null;
    prevQueries.addActiveQueries(nodeId, queryIds);
}
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