Search in sources :

Example 1 with PageId

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

the class MemoryPageStore method put.

@Override
public void put(PageId pageId, byte[] page) throws ResourceExhaustedException, IOException {
    PageId pageKey = getKeyFromPageId(pageId);
    try {
        byte[] mPage = new byte[page.length];
        System.arraycopy(page, 0, mPage, 0, page.length);
        mPageStoreMap.put(pageKey, mPage);
    } catch (Exception e) {
        throw new IOException("Failed to put cached data in memory for page " + pageId);
    }
}
Also used : PageId(alluxio.client.file.cache.PageId) IOException(java.io.IOException) PageNotFoundException(alluxio.exception.PageNotFoundException) IOException(java.io.IOException) ResourceExhaustedException(alluxio.exception.status.ResourceExhaustedException)

Example 2 with PageId

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

the class RocksPageStore method getPageIdFromKey.

/**
 * @param key key of a record
 * @return the corresponding page id, or null if the key does not match the pattern
 */
@Nullable
private static PageId getPageIdFromKey(byte[] key) {
    if (key.length < Long.BYTES) {
        return null;
    }
    ByteBuffer buf = ByteBuffer.wrap(key);
    long pageIndex = buf.getLong();
    String fileId = Charset.defaultCharset().decode(buf).toString();
    return new PageId(fileId, pageIndex);
}
Also used : PageId(alluxio.client.file.cache.PageId) ByteBuffer(java.nio.ByteBuffer) Nullable(javax.annotation.Nullable)

Example 3 with PageId

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

the class LFUCacheEvictor method evict.

@Nullable
@Override
public synchronized PageId evict() {
    Map<PageId, Boolean> lruMap = mBucketMap.get(mMinBucket);
    if (lruMap == null) {
        LOG.debug("cannot evict page - bucket {} is empty", mMinBucket);
        return null;
    }
    PageId pageToEvict = lruMap.keySet().iterator().next();
    LOG.debug("plan to evict page {} ", pageToEvict);
    return pageToEvict;
}
Also used : PageId(alluxio.client.file.cache.PageId) Nullable(javax.annotation.Nullable)

Example 4 with PageId

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

the class LocalPageStore method getPageId.

/**
 * @param path path of a file
 * @return the corresponding page id, or null if the file name does not match the pattern
 */
@Nullable
private PageId getPageId(Path path) {
    Matcher matcher = mPagePattern.matcher(path.toString());
    if (!matcher.matches()) {
        return null;
    }
    try {
        String fileBucket = Preconditions.checkNotNull(matcher.group(2));
        String fileId = Preconditions.checkNotNull(matcher.group(3));
        if (!fileBucket.equals(getFileBucket(fileId))) {
            return null;
        }
        String fileName = Preconditions.checkNotNull(matcher.group(4));
        long pageIndex = Long.parseLong(fileName);
        return new PageId(fileId, pageIndex);
    } catch (NumberFormatException e) {
        return null;
    }
}
Also used : PageId(alluxio.client.file.cache.PageId) Matcher(java.util.regex.Matcher) Nullable(javax.annotation.Nullable)

Example 5 with PageId

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

the class LocalPageStoreTest method cleanFileAndDirectory.

@Test
public void cleanFileAndDirectory() throws Exception {
    LocalPageStore pageStore = new LocalPageStore(mOptions);
    PageId pageId = new PageId("0", 0);
    pageStore.put(pageId, "test".getBytes());
    Path p = pageStore.getFilePath(pageId);
    assertTrue(Files.exists(p));
    pageStore.delete(pageId);
    assertFalse(Files.exists(p));
    assertFalse(Files.exists(p.getParent()));
}
Also used : PageId(alluxio.client.file.cache.PageId) Path(java.nio.file.Path) Test(org.junit.Test)

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