Search in sources :

Example 6 with PageNotFoundException

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;
    }
}
Also used : PageNotFoundException(alluxio.exception.PageNotFoundException) LockResource(alluxio.resource.LockResource) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock)

Example 7 with PageNotFoundException

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;
    }
}
Also used : Path(java.nio.file.Path) PageNotFoundException(alluxio.exception.PageNotFoundException) RandomAccessFile(java.io.RandomAccessFile) IOException(java.io.IOException)

Example 8 with PageNotFoundException

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());
}
Also used : PageId(alluxio.client.file.cache.PageId) PageNotFoundException(alluxio.exception.PageNotFoundException)

Example 9 with PageNotFoundException

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;
}
Also used : PageId(alluxio.client.file.cache.PageId) PageNotFoundException(alluxio.exception.PageNotFoundException)

Example 10 with PageNotFoundException

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);
    }
}
Also used : RocksDBException(org.rocksdb.RocksDBException) PageNotFoundException(alluxio.exception.PageNotFoundException) ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException)

Aggregations

PageNotFoundException (alluxio.exception.PageNotFoundException)10 PageId (alluxio.client.file.cache.PageId)3 LockResource (alluxio.resource.LockResource)3 IOException (java.io.IOException)3 ReadWriteLock (java.util.concurrent.locks.ReadWriteLock)3 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)3 Path (java.nio.file.Path)2 RocksDBException (org.rocksdb.RocksDBException)2 CacheScope (alluxio.client.quota.CacheScope)1 ResourceExhaustedException (alluxio.exception.status.ResourceExhaustedException)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 RandomAccessFile (java.io.RandomAccessFile)1 Test (org.junit.Test)1