@Test public void getNotEnoughSpaceException() throws Exception { byte[] buf = new byte[PAGE1.length - 1]; mThrown.expect(IllegalArgumentException.class); mCacheManager.get(PAGE_ID1, PAGE1.length, buf, 0); }
@Override public int get(PageId pageId, int pageOffset, int bytesToRead, byte[] buffer, int offsetInBuffer) { Preconditions.checkArgument(pageOffset <= mPageSize, "Read exceeds page boundary: offset=%s size=%s", pageOffset, mPageSize); Preconditions.checkArgument(bytesToRead <= buffer.length - offsetInBuffer, "buffer does not have enough space: bufferLength=%s offsetInBuffer=%s bytesToRead=%s", buffer.length, offsetInBuffer, bytesToRead); LOG.debug("get({},pageOffset={}) enters", pageId, pageOffset); if (mState.get() == NOT_IN_USE) { Metrics.GET_NOT_READY_ERRORS.inc(); Metrics.GET_ERRORS.inc(); return -1; } boolean hasPage; ReadWriteLock pageLock = getPageLock(pageId); try (LockResource r = new LockResource(pageLock.readLock())) { try (LockResource r2 = new LockResource(mMetaLock.readLock())) { hasPage = mMetaStore.hasPage(pageId); } if (!hasPage) { LOG.debug("get({},pageOffset={}) fails due to page not found", pageId, pageOffset); return 0; } int bytesRead = getPage(pageId, pageOffset, bytesToRead, buffer, offsetInBuffer); if (bytesRead <= 0) { Metrics.GET_ERRORS.inc(); Metrics.GET_STORE_READ_ERRORS.inc(); try (LockResource r2 = new LockResource(mMetaLock.writeLock())) { mMetaStore.removePage(pageId); } catch (PageNotFoundException e) { Metrics.CLEANUP_GET_ERRORS.inc(); } return -1; } LOG.debug("get({},pageOffset={}) exits", pageId, pageOffset); return bytesRead; } }
LocalCacheManager implements CacheManager { @Override public int get(PageId pageId, int pageOffset, int bytesToRead, byte[] buffer, int offsetInBuffer) { Preconditions.checkArgument(pageOffset <= mPageSize, "Read exceeds page boundary: offset=%s size=%s", pageOffset, mPageSize); Preconditions.checkArgument(bytesToRead <= buffer.length - offsetInBuffer, "buffer does not have enough space: bufferLength=%s offsetInBuffer=%s bytesToRead=%s", buffer.length, offsetInBuffer, bytesToRead); LOG.debug("get({},pageOffset={}) enters", pageId, pageOffset); if (mState.get() == NOT_IN_USE) { Metrics.GET_NOT_READY_ERRORS.inc(); Metrics.GET_ERRORS.inc(); return -1; } boolean hasPage; ReadWriteLock pageLock = getPageLock(pageId); try (LockResource r = new LockResource(pageLock.readLock())) { try (LockResource r2 = new LockResource(mMetaLock.readLock())) { hasPage = mMetaStore.hasPage(pageId); } if (!hasPage) { LOG.debug("get({},pageOffset={}) fails due to page not found", pageId, pageOffset); return 0; } int bytesRead = getPage(pageId, pageOffset, bytesToRead, buffer, offsetInBuffer); if (bytesRead <= 0) { Metrics.GET_ERRORS.inc(); Metrics.GET_STORE_READ_ERRORS.inc(); try (LockResource r2 = new LockResource(mMetaLock.writeLock())) { mMetaStore.removePage(pageId); } catch (PageNotFoundException e) { Metrics.CLEANUP_GET_ERRORS.inc(); } return -1; } LOG.debug("get({},pageOffset={}) exits", pageId, pageOffset); return bytesRead; } } }
LocalCacheManager implements CacheManager { @Override public int get(PageId pageId, int pageOffset, int bytesToRead, byte[] buffer, int offsetInBuffer) { Preconditions.checkArgument(pageOffset <= mPageSize, "Read exceeds page boundary: offset=%s size=%s", pageOffset, mPageSize); Preconditions.checkArgument(bytesToRead <= buffer.length - offsetInBuffer, "buffer does not have enough space: bufferLength=%s offsetInBuffer=%s bytesToRead=%s", buffer.length, offsetInBuffer, bytesToRead); LOG.debug("get({},pageOffset={}) enters", pageId, pageOffset); if (mState.get() == NOT_IN_USE) { Metrics.GET_NOT_READY_ERRORS.inc(); Metrics.GET_ERRORS.inc(); return -1; } boolean hasPage; ReadWriteLock pageLock = getPageLock(pageId); try (LockResource r = new LockResource(pageLock.readLock())) { try (LockResource r2 = new LockResource(mMetaLock.readLock())) { hasPage = mMetaStore.hasPage(pageId); } if (!hasPage) { LOG.debug("get({},pageOffset={}) fails due to page not found", pageId, pageOffset); return 0; } int bytesRead = getPage(pageId, pageOffset, bytesToRead, buffer, offsetInBuffer); if (bytesRead <= 0) { Metrics.GET_ERRORS.inc(); Metrics.GET_STORE_READ_ERRORS.inc(); try (LockResource r2 = new LockResource(mMetaLock.writeLock())) { mMetaStore.removePage(pageId); } catch (PageNotFoundException e) { Metrics.CLEANUP_GET_ERRORS.inc(); } return -1; } LOG.debug("get({},pageOffset={}) exits", pageId, pageOffset); return bytesRead; } } private  LocalCacheManager(AlluxioConfiguration conf, MetaStore metaStore, PageStore pageStore); }
LocalCacheManager implements CacheManager { @Override public int get(PageId pageId, int pageOffset, int bytesToRead, byte[] buffer, int offsetInBuffer) { Preconditions.checkArgument(pageOffset <= mPageSize, "Read exceeds page boundary: offset=%s size=%s", pageOffset, mPageSize); Preconditions.checkArgument(bytesToRead <= buffer.length - offsetInBuffer, "buffer does not have enough space: bufferLength=%s offsetInBuffer=%s bytesToRead=%s", buffer.length, offsetInBuffer, bytesToRead); LOG.debug("get({},pageOffset={}) enters", pageId, pageOffset); if (mState.get() == NOT_IN_USE) { Metrics.GET_NOT_READY_ERRORS.inc(); Metrics.GET_ERRORS.inc(); return -1; } boolean hasPage; ReadWriteLock pageLock = getPageLock(pageId); try (LockResource r = new LockResource(pageLock.readLock())) { try (LockResource r2 = new LockResource(mMetaLock.readLock())) { hasPage = mMetaStore.hasPage(pageId); } if (!hasPage) { LOG.debug("get({},pageOffset={}) fails due to page not found", pageId, pageOffset); return 0; } int bytesRead = getPage(pageId, pageOffset, bytesToRead, buffer, offsetInBuffer); if (bytesRead <= 0) { Metrics.GET_ERRORS.inc(); Metrics.GET_STORE_READ_ERRORS.inc(); try (LockResource r2 = new LockResource(mMetaLock.writeLock())) { mMetaStore.removePage(pageId); } catch (PageNotFoundException e) { Metrics.CLEANUP_GET_ERRORS.inc(); } return -1; } LOG.debug("get({},pageOffset={}) exits", pageId, pageOffset); return bytesRead; } } private  LocalCacheManager(AlluxioConfiguration conf, MetaStore metaStore, PageStore pageStore); static LocalCacheManager create(AlluxioConfiguration conf); @Override boolean put(PageId pageId, byte[] page); @Override int get(PageId pageId, int pageOffset, int bytesToRead, byte[] buffer,
      int offsetInBuffer); @Override boolean delete(PageId pageId); @Override State state(); @Override void close(); }
LocalCacheManager implements CacheManager { @Override public int get(PageId pageId, int pageOffset, int bytesToRead, byte[] buffer, int offsetInBuffer) { Preconditions.checkArgument(pageOffset <= mPageSize, "Read exceeds page boundary: offset=%s size=%s", pageOffset, mPageSize); Preconditions.checkArgument(bytesToRead <= buffer.length - offsetInBuffer, "buffer does not have enough space: bufferLength=%s offsetInBuffer=%s bytesToRead=%s", buffer.length, offsetInBuffer, bytesToRead); LOG.debug("get({},pageOffset={}) enters", pageId, pageOffset); if (mState.get() == NOT_IN_USE) { Metrics.GET_NOT_READY_ERRORS.inc(); Metrics.GET_ERRORS.inc(); return -1; } boolean hasPage; ReadWriteLock pageLock = getPageLock(pageId); try (LockResource r = new LockResource(pageLock.readLock())) { try (LockResource r2 = new LockResource(mMetaLock.readLock())) { hasPage = mMetaStore.hasPage(pageId); } if (!hasPage) { LOG.debug("get({},pageOffset={}) fails due to page not found", pageId, pageOffset); return 0; } int bytesRead = getPage(pageId, pageOffset, bytesToRead, buffer, offsetInBuffer); if (bytesRead <= 0) { Metrics.GET_ERRORS.inc(); Metrics.GET_STORE_READ_ERRORS.inc(); try (LockResource r2 = new LockResource(mMetaLock.writeLock())) { mMetaStore.removePage(pageId); } catch (PageNotFoundException e) { Metrics.CLEANUP_GET_ERRORS.inc(); } return -1; } LOG.debug("get({},pageOffset={}) exits", pageId, pageOffset); return bytesRead; } } private  LocalCacheManager(AlluxioConfiguration conf, MetaStore metaStore, PageStore pageStore); static LocalCacheManager create(AlluxioConfiguration conf); @Override boolean put(PageId pageId, byte[] page); @Override int get(PageId pageId, int pageOffset, int bytesToRead, byte[] buffer,
      int offsetInBuffer); @Override boolean delete(PageId pageId); @Override State state(); @Override void close();  }