Search in sources :

Example 1 with VirtualPage

use of org.apache.hyracks.storage.common.buffercache.VirtualPage in project asterixdb by apache.

the class VirtualBufferCache method getOrAllocPage.

private VirtualPage getOrAllocPage(long dpid) {
    VirtualPage page;
    synchronized (pages) {
        if (nextFree >= pages.size()) {
            page = new VirtualPage(allocator.allocate(pageSize, 1)[0], pageSize);
            page.multiplier(1);
            pages.add(page);
        } else {
            page = pages.get(nextFree);
        }
        ++nextFree;
        page.dpid(dpid);
    }
    return page;
}
Also used : VirtualPage(org.apache.hyracks.storage.common.buffercache.VirtualPage)

Example 2 with VirtualPage

use of org.apache.hyracks.storage.common.buffercache.VirtualPage in project asterixdb by apache.

the class VirtualBufferCache method resizePage.

@Override
public void resizePage(ICachedPage cPage, int multiplier, IExtraPageBlockHelper extraPageBlockHelper) {
    ByteBuffer oldBuffer = cPage.getBuffer();
    int origMultiplier = cPage.getFrameSizeMultiplier();
    if (origMultiplier == multiplier) {
        // no-op
        return;
    }
    if (origMultiplier == 1) {
        synchronized (pages) {
            pages.remove(cPage);
            nextFree--;
        }
    }
    ByteBuffer newBuffer = allocator.allocate(pageSize * multiplier, 1)[0];
    oldBuffer.position(0);
    if (multiplier < origMultiplier) {
        oldBuffer.limit(newBuffer.capacity());
    }
    newBuffer.put(oldBuffer);
    if (origMultiplier == 1) {
        largePages.getAndAdd(multiplier);
    } else if (multiplier == 1) {
        largePages.getAndAdd(-origMultiplier);
        pages.add(0, (VirtualPage) cPage);
        nextFree++;
    } else {
        largePages.getAndAdd(multiplier - origMultiplier);
    }
    ((VirtualPage) cPage).buffer(newBuffer);
    ((VirtualPage) cPage).multiplier(multiplier);
}
Also used : VirtualPage(org.apache.hyracks.storage.common.buffercache.VirtualPage) ByteBuffer(java.nio.ByteBuffer)

Example 3 with VirtualPage

use of org.apache.hyracks.storage.common.buffercache.VirtualPage in project asterixdb by apache.

the class VirtualBufferCache method deleteFile.

@Override
public void deleteFile(int fileId, boolean flushDirtyPages) throws HyracksDataException {
    synchronized (fileMapManager) {
        if (!fileMapManager.isMapped(fileId)) {
            throw new HyracksDataException("File with id " + fileId + " is not mapped");
        }
        fileMapManager.unregisterFile(fileId);
    }
    for (int i = 0; i < buckets.length; i++) {
        final CacheBucket bucket = buckets[i];
        bucket.bucketLock.lock();
        try {
            VirtualPage prev = null;
            VirtualPage curr = bucket.cachedPage;
            while (curr != null) {
                if (BufferedFileHandle.getFileId(curr.dpid()) == fileId) {
                    if (curr.getFrameSizeMultiplier() > 1) {
                        largePages.getAndAdd(-curr.getFrameSizeMultiplier());
                    }
                    if (prev == null) {
                        bucket.cachedPage = curr.next();
                        curr.reset();
                        curr = bucket.cachedPage;
                    } else {
                        prev.next(curr.next());
                        curr.reset();
                        curr = prev.next();
                    }
                } else {
                    prev = curr;
                    curr = curr.next();
                }
            }
        } finally {
            bucket.bucketLock.unlock();
        }
    }
    defragPageList();
}
Also used : VirtualPage(org.apache.hyracks.storage.common.buffercache.VirtualPage) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Example 4 with VirtualPage

use of org.apache.hyracks.storage.common.buffercache.VirtualPage in project asterixdb by apache.

the class VirtualBufferCache method pin.

@Override
public ICachedPage pin(long dpid, boolean newPage) throws HyracksDataException {
    VirtualPage page = null;
    int hash = hash(dpid);
    CacheBucket bucket = buckets[hash];
    bucket.bucketLock.lock();
    try {
        page = bucket.cachedPage;
        while (page != null) {
            if (page.dpid() == dpid) {
                return page;
            }
            page = page.next();
        }
        if (!newPage) {
            throw new HyracksDataException("Page " + BufferedFileHandle.getPageId(dpid) + " does not exist in file " + fileMapManager.lookupFileName(BufferedFileHandle.getFileId(dpid)));
        }
        page = getOrAllocPage(dpid);
        page.next(bucket.cachedPage);
        bucket.cachedPage = page;
    } finally {
        bucket.bucketLock.unlock();
    }
    return page;
}
Also used : VirtualPage(org.apache.hyracks.storage.common.buffercache.VirtualPage) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Example 5 with VirtualPage

use of org.apache.hyracks.storage.common.buffercache.VirtualPage in project asterixdb by apache.

the class VirtualBufferCache method defragPageList.

private void defragPageList() {
    synchronized (pages) {
        int start = 0;
        int end = nextFree - 1;
        while (start < end) {
            VirtualPage lastUsed = pages.get(end);
            while (end > 0 && lastUsed.dpid() == -1) {
                --end;
                lastUsed = pages.get(end);
            }
            if (end == 0) {
                nextFree = lastUsed.dpid() == -1 ? 0 : 1;
                break;
            }
            VirtualPage firstUnused = pages.get(start);
            while (start < end && firstUnused.dpid() != -1) {
                ++start;
                firstUnused = pages.get(start);
            }
            if (start >= end) {
                break;
            }
            Collections.swap(pages, start, end);
            nextFree = end;
            --end;
            ++start;
        }
    }
}
Also used : VirtualPage(org.apache.hyracks.storage.common.buffercache.VirtualPage)

Aggregations

VirtualPage (org.apache.hyracks.storage.common.buffercache.VirtualPage)6 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)2 ByteBuffer (java.nio.ByteBuffer)1 LongPointable (org.apache.hyracks.data.std.primitive.LongPointable)1 MutableArrayValueReference (org.apache.hyracks.storage.am.common.freepage.MutableArrayValueReference)1 Test (org.junit.Test)1