Search in sources :

Example 1 with IntArrayList

use of org.apache.hyracks.storage.common.arraylist.IntArrayList in project asterixdb by apache.

the class BTreeOpContext method setOperation.

@Override
public void setOperation(IndexOperation newOp) {
    if (newOp == IndexOperation.SEARCH || newOp == IndexOperation.DISKORDERSCAN) {
        if (cursorInitialState == null) {
            cursorInitialState = new BTreeCursorInitialState(null, searchCallback, accessor);
        }
    } else {
        // Insert, delete, update or upsert operation.
        if (smPages == null) {
            smPages = new IntArrayList(INIT_ARRAYLIST_SIZE, INIT_ARRAYLIST_SIZE);
        }
        if (freePages == null) {
            freePages = new IntArrayList(INIT_ARRAYLIST_SIZE, INIT_ARRAYLIST_SIZE);
        }
        if (getPred() == null) {
            setPred(new RangePredicate(null, null, true, true, null, null));
        }
        if (splitKey == null) {
            splitKey = new BTreeSplitKey(getLeafFrame().getTupleWriter().createTupleReference());
        }
    }
    op = newOp;
    smoCount = 0;
    exceptionHandled = false;
}
Also used : IntArrayList(org.apache.hyracks.storage.common.arraylist.IntArrayList)

Example 2 with IntArrayList

use of org.apache.hyracks.storage.common.arraylist.IntArrayList in project asterixdb by apache.

the class TreeIndexBufferCacheWarmup method warmup.

public void warmup(ITreeIndexFrame frame, ITreeIndexMetadataFrame metaFrame, int[] warmupTreeLevels, int[] warmupRepeats) throws HyracksDataException {
    bufferCache.openFile(fileId);
    // scan entire file to determine pages in each level
    int maxPageId = freePageManager.getMaxPageId(metaFrame);
    for (int pageId = 0; pageId <= maxPageId; pageId++) {
        ICachedPage page = bufferCache.pin(BufferedFileHandle.getDiskPageId(fileId, pageId), false);
        page.acquireReadLatch();
        try {
            frame.setPage(page);
            byte level = frame.getLevel();
            while (level >= pagesByLevel.size()) {
                pagesByLevel.add(new IntArrayList(100, 100));
            }
            if (level >= 0) {
                pagesByLevel.get(level).add(pageId);
            }
        } finally {
            page.releaseReadLatch();
            bufferCache.unpin(page);
        }
    }
    // pin certain pages again to simulate frequent access
    for (int i = 0; i < warmupTreeLevels.length; i++) {
        if (warmupTreeLevels[i] < pagesByLevel.size()) {
            int repeats = warmupRepeats[i];
            IntArrayList pageIds = pagesByLevel.get(warmupTreeLevels[i]);
            int[] remainingPageIds = new int[pageIds.size()];
            for (int r = 0; r < repeats; r++) {
                for (int j = 0; j < pageIds.size(); j++) {
                    remainingPageIds[j] = pageIds.get(j);
                }
                int remainingLength = pageIds.size();
                for (int j = 0; j < pageIds.size(); j++) {
                    int index = MathUtil.stripSignBit(rnd.nextInt()) % remainingLength;
                    int pageId = remainingPageIds[index];
                    // pin & latch then immediately unlatch & unpin
                    ICachedPage page = bufferCache.pin(BufferedFileHandle.getDiskPageId(fileId, pageId), false);
                    page.acquireReadLatch();
                    page.releaseReadLatch();
                    bufferCache.unpin(page);
                    remainingPageIds[index] = remainingPageIds[remainingLength - 1];
                    remainingLength--;
                }
            }
        }
    }
    bufferCache.closeFile(fileId);
}
Also used : ICachedPage(org.apache.hyracks.storage.common.buffercache.ICachedPage) IntArrayList(org.apache.hyracks.storage.common.arraylist.IntArrayList)

Aggregations

IntArrayList (org.apache.hyracks.storage.common.arraylist.IntArrayList)2 ICachedPage (org.apache.hyracks.storage.common.buffercache.ICachedPage)1