Search in sources :

Example 21 with PageId

use of alluxio.client.file.cache.PageId in project alluxio by Alluxio.

the class MemoryPageStore method delete.

@Override
public void delete(PageId pageId) throws IOException, PageNotFoundException {
    PageId pageKey = getKeyFromPageId(pageId);
    if (!mPageStoreMap.containsKey(pageKey)) {
        throw new PageNotFoundException(pageId.getFileId() + "_" + pageId.getPageIndex());
    }
    mPageStoreMap.remove(pageKey);
    LOG.info("Remove cached page, size: {}", mPageStoreMap.size());
}
Also used : PageId(alluxio.client.file.cache.PageId) PageNotFoundException(alluxio.exception.PageNotFoundException)

Example 22 with PageId

use of alluxio.client.file.cache.PageId in project alluxio by Alluxio.

the class MemoryPageStore method get.

@Override
public int get(PageId pageId, int pageOffset, int bytesToRead, byte[] buffer, int bufferOffset) throws IOException, PageNotFoundException {
    Preconditions.checkArgument(buffer != null, "buffer is null");
    Preconditions.checkArgument(pageOffset >= 0, "page offset should be non-negative");
    Preconditions.checkArgument(buffer.length >= bufferOffset, "page offset %s should be " + "less or equal than buffer length %s", bufferOffset, buffer.length);
    PageId pageKey = getKeyFromPageId(pageId);
    if (!mPageStoreMap.containsKey(pageKey)) {
        throw new PageNotFoundException(pageId.getFileId() + "_" + pageId.getPageIndex());
    }
    byte[] mPage = mPageStoreMap.get(pageKey);
    Preconditions.checkArgument(pageOffset <= mPage.length, "page offset %s exceeded page size %s", pageOffset, mPage.length);
    int bytesLeft = (int) Math.min(mPage.length - pageOffset, buffer.length - bufferOffset);
    bytesLeft = Math.min(bytesLeft, bytesToRead);
    System.arraycopy(mPage, pageOffset, buffer, bufferOffset, bytesLeft);
    return bytesLeft;
}
Also used : PageId(alluxio.client.file.cache.PageId) PageNotFoundException(alluxio.exception.PageNotFoundException)

Aggregations

PageId (alluxio.client.file.cache.PageId)22 Test (org.junit.Test)11 Nullable (javax.annotation.Nullable)5 PageNotFoundException (alluxio.exception.PageNotFoundException)4 PageInfo (alluxio.client.file.cache.PageInfo)3 Path (java.nio.file.Path)3 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 ResourceExhaustedException (alluxio.exception.status.ResourceExhaustedException)1 BaseIntegrationTest (alluxio.testutils.BaseIntegrationTest)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 Random (java.util.Random)1 Matcher (java.util.regex.Matcher)1