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);
}
}
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);
}
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;
}
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;
}
}
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()));
}
Aggregations