Search in sources :

Example 16 with PageId

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

the class PageStoreTest method thousandGetTest.

void thousandGetTest(PageStore store) throws Exception {
    int numPages = 1000;
    int numTrials = 3;
    // Fill the cache
    List<Integer> pages = new ArrayList<>(numPages);
    byte[] b = new byte[Constants.MB];
    Arrays.fill(b, (byte) 0x7a);
    Random r = new Random();
    for (int i = 0; i < numPages; i++) {
        int pind = r.nextInt();
        store.put(new PageId("0", pind), b);
        pages.add(pind);
    }
    ByteArrayOutputStream bos = new ByteArrayOutputStream(Constants.MB);
    ArrayList<Long> times = new ArrayList<>();
    byte[] buf = new byte[Constants.MB];
    for (int i = 0; i < numTrials; i++) {
        Collections.shuffle(pages);
        long start = System.nanoTime();
        bos.reset();
        for (Integer pageIndex : pages) {
            store.get(new PageId("0", pageIndex), buf);
        }
        long end = System.nanoTime();
        times.add(end - start);
    }
    double avg = (double) times.stream().mapToLong(Long::longValue).sum() / numTrials;
    System.out.println(String.format("Finished thousand get for %7s : %.2fns", mOptions, avg));
}
Also used : PageId(alluxio.client.file.cache.PageId) Random(java.util.Random) ArrayList(java.util.ArrayList) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 17 with PageId

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

the class PageStoreTest method getSmallBuffer.

@Test
public void getSmallBuffer() throws Exception {
    int len = 32;
    PageId id = new PageId("0", 0);
    mPageStore.put(id, BufferUtils.getIncreasingByteArray(len));
    for (int b = 1; b < len; b++) {
        byte[] buf = new byte[b];
        int bytesRead = mPageStore.get(id, 0, len, buf, 0);
        assertEquals(b, bytesRead);
        assertArrayEquals(BufferUtils.getIncreasingByteArray(b), Arrays.copyOfRange(buf, 0, bytesRead));
    }
}
Also used : PageId(alluxio.client.file.cache.PageId) Test(org.junit.Test)

Example 18 with PageId

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

the class LocalCacheManagerIntegrationTest method loadCacheAndEvict.

@Test
public void loadCacheAndEvict() throws Exception {
    loadFullCache();
    mCacheManager.close();
    // creates with same configuration
    mCacheManager = LocalCacheManager.create(mConf);
    // evicts half of the pages
    for (int i = 0; i < PAGE_COUNT / 2; i++) {
        mCacheManager.put(new PageId("1", i), PAGE);
    }
    int evicted = 0;
    for (int i = 0; i < PAGE_COUNT; i++) {
        PageId pageId = new PageId("0", i);
        int ret = mCacheManager.get(pageId, PAGE_SIZE_BYTES, mBuffer, 0);
        assertArrayEquals(PAGE, mBuffer);
        if (ret <= 0) {
            evicted++;
            continue;
        }
        assertEquals(PAGE_SIZE_BYTES, mCacheManager.get(pageId, PAGE_SIZE_BYTES, mBuffer, 0));
    }
    // verifies half of the loaded pages are evicted
    assertEquals(PAGE_COUNT / 2, evicted);
    // verifies the newly added pages are cached
    for (int i = 0; i < PAGE_COUNT / 2; i++) {
        testPageCached(new PageId("1", i));
    }
}
Also used : PageId(alluxio.client.file.cache.PageId) Test(org.junit.Test) BaseIntegrationTest(alluxio.testutils.BaseIntegrationTest)

Example 19 with PageId

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

the class NondeterministicLRUCacheEvictor method evict.

@Nullable
@Override
public PageId evict() {
    synchronized (mLRUCache) {
        if (mLRUCache.isEmpty()) {
            return null;
        }
        Iterator<PageId> it = mLRUCache.keySet().iterator();
        PageId evictionCandidate = it.next();
        int numMoveFromTail = ThreadLocalRandom.current().nextInt(mNumOfCandidate);
        for (int i = 0; it.hasNext() && i < numMoveFromTail; ++i) {
            evictionCandidate = it.next();
        }
        return evictionCandidate;
    }
}
Also used : PageId(alluxio.client.file.cache.PageId) Nullable(javax.annotation.Nullable)

Example 20 with PageId

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

the class LocalPageStore method getPageInfo.

/**
 * @param path path of a file
 * @return the corresponding page info for the file otherwise null
 */
@Nullable
private PageInfo getPageInfo(Path path) {
    PageId pageId = getPageId(path);
    long pageSize;
    if (pageId == null) {
        LOG.error("Unrecognized page file" + path);
        return null;
    }
    try {
        pageSize = Files.size(path);
    } catch (IOException e) {
        LOG.error("Failed to get file size for " + path, e);
        return null;
    }
    return new PageInfo(pageId, pageSize);
}
Also used : PageId(alluxio.client.file.cache.PageId) PageInfo(alluxio.client.file.cache.PageInfo) IOException(java.io.IOException) Nullable(javax.annotation.Nullable)

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