use of alluxio.exception.PageNotFoundException in project alluxio by Alluxio.
the class LocalCacheManager method delete.
@Override
public boolean delete(PageId pageId) {
LOG.debug("delete({}) enters", pageId);
if (mState.get() != READ_WRITE) {
Metrics.DELETE_NOT_READY_ERRORS.inc();
Metrics.DELETE_ERRORS.inc();
return false;
}
ReadWriteLock pageLock = getPageLock(pageId);
try (LockResource r = new LockResource(pageLock.writeLock())) {
try (LockResource r1 = new LockResource(mMetaLock.writeLock())) {
try {
mMetaStore.removePage(pageId);
} catch (PageNotFoundException e) {
LOG.error("Failed to delete page {} from metaStore ", pageId, e);
Metrics.DELETE_NON_EXISTING_PAGE_ERRORS.inc();
Metrics.DELETE_ERRORS.inc();
return false;
}
}
boolean ok = deletePage(pageId);
LOG.debug("delete({}) exits, success: {}", pageId, ok);
if (!ok) {
Metrics.DELETE_STORE_DELETE_ERRORS.inc();
Metrics.DELETE_ERRORS.inc();
}
return ok;
}
}
use of alluxio.exception.PageNotFoundException in project alluxio by Alluxio.
the class LocalPageStore method get.
@Override
public int get(PageId pageId, int pageOffset, int bytesToRead, byte[] buffer, int bufferOffset) throws IOException, PageNotFoundException {
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);
Path p = getFilePath(pageId);
if (!Files.exists(p)) {
throw new PageNotFoundException(p.toString());
}
long pageLength = p.toFile().length();
Preconditions.checkArgument(pageOffset <= pageLength, "page offset %s exceeded page size %s", pageOffset, pageLength);
try (RandomAccessFile localFile = new RandomAccessFile(p.toString(), "r")) {
int bytesSkipped = localFile.skipBytes(pageOffset);
if (pageOffset != bytesSkipped) {
throw new IOException(String.format("Failed to read page %s (%s) from offset %s: %s bytes skipped", pageId, p, pageOffset, bytesSkipped));
}
int bytesRead = 0;
int bytesLeft = (int) Math.min(pageLength - pageOffset, buffer.length - bufferOffset);
bytesLeft = Math.min(bytesLeft, bytesToRead);
while (bytesLeft >= 0) {
int bytes = localFile.read(buffer, bufferOffset + bytesRead, bytesLeft);
if (bytes <= 0) {
break;
}
bytesRead += bytes;
bytesLeft -= bytes;
}
return bytesRead;
}
}
use of alluxio.exception.PageNotFoundException 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());
}
use of alluxio.exception.PageNotFoundException 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;
}
use of alluxio.exception.PageNotFoundException in project alluxio by Alluxio.
the class RocksPageStore method get.
@Override
public int get(PageId pageId, int pageOffset, int bytesToRead, byte[] buffer, int bufferOffset) throws IOException, PageNotFoundException {
Preconditions.checkArgument(pageOffset >= 0, "page offset should be non-negative");
try {
byte[] page = mDb.get(getKeyFromPageId(pageId));
if (page == null) {
throw new PageNotFoundException(new String(getKeyFromPageId(pageId)));
}
Preconditions.checkArgument(pageOffset <= page.length, "page offset %s exceeded page size %s", pageOffset, page.length);
try (ByteArrayInputStream bais = new ByteArrayInputStream(page)) {
int bytesSkipped = (int) bais.skip(pageOffset);
if (pageOffset != bytesSkipped) {
throw new IOException(String.format("Failed to read page %s from offset %s: %s bytes skipped", pageId, pageOffset, bytesSkipped));
}
int bytesRead = 0;
int bytesLeft = Math.min(page.length - pageOffset, buffer.length - bufferOffset);
bytesLeft = Math.min(bytesLeft, bytesToRead);
while (bytesLeft >= 0) {
int bytes = bais.read(buffer, bufferOffset + bytesRead, bytesLeft);
if (bytes <= 0) {
break;
}
bytesRead += bytes;
bytesLeft -= bytes;
}
return bytesRead;
}
} catch (RocksDBException e) {
throw new IOException("Failed to retrieve page", e);
}
}
Aggregations