@ThreadSafe public class LocalCacheManager extends Object implements CacheManager
The idea of creating a client-side cache is followed after "Improving In-Memory File System Reading Performance by Fine-Grained User-Space Cache Mechanisms" by Gu et al, which illustrates performance benefits for various read workloads. This class also introduces paging as a caching unit.
Lock hierarchy in this class: All operations must follow this order to operate on pages:
CacheManager.Factory, CacheManager.State
Modifier and Type | Method and Description |
---|---|
boolean |
append(PageId pageId,
int appendAt,
byte[] page,
CacheContext cacheContext) |
void |
close() |
void |
commitFile(String fileId)
Commit the File.
|
static LocalCacheManager |
create(CacheManagerOptions options,
PageMetaStore pageMetaStore) |
boolean |
delete(PageId pageId)
Deletes a page from the cache.
|
boolean |
delete(PageId pageId,
boolean isTemporary)
delete the specified page.
|
void |
deleteFile(String fileId)
Deletes all pages of the given file.
|
void |
deleteTempFile(String fileId)
Deletes all temporary pages of the given file.
|
int |
get(PageId pageId,
int pageOffset,
int bytesToRead,
ReadTargetBuffer buffer,
CacheContext cacheContext)
Reads a part of a page if the queried page is found in the cache, stores the result in buffer.
|
int |
get(PageId pageId,
int pageOffset,
ReadTargetBuffer buffer,
CacheContext cacheContext)
Reads a part of a page if the queried page is found in the cache, stores the result in buffer.
|
int |
getAndLoad(PageId pageId,
int pageOffset,
int bytesToRead,
ReadTargetBuffer buffer,
CacheContext cacheContext,
java.util.function.Supplier<byte[]> externalDataSupplier)
Reads a part of a page if the queried page is found in the cache, stores the result in buffer.
|
List<PageId> |
getCachedPageIdsByFileId(String fileId,
long fileLength)
Get page ids by the given file id.
|
Optional<DataFileChannel> |
getDataFileChannel(PageId pageId,
int pageOffset,
int bytesToRead,
CacheContext cacheContext)
Get a
DataFileChannel which wraps a FileRegion . |
int |
getPageLockId(PageId pageId) |
Optional<CacheUsage> |
getUsage()
Gets cache usage.
|
void |
invalidate(java.util.function.Predicate<PageInfo> predicate)
Invalidate the pages that match the given predicate.
|
boolean |
put(PageId pageId,
ByteBuffer page,
CacheContext cacheContext)
Puts a page into the cache manager with scope and quota respected.
|
CacheManager.State |
state() |
public static LocalCacheManager create(CacheManagerOptions options, PageMetaStore pageMetaStore) throws IOException
options
- the options of local cache managerpageMetaStore
- the metadata store for local cacheLocalCacheManager
IOException
public Optional<DataFileChannel> getDataFileChannel(PageId pageId, int pageOffset, int bytesToRead, CacheContext cacheContext) throws PageNotFoundException
CacheManager
DataFileChannel
which wraps a FileRegion
.getDataFileChannel
in interface CacheManager
pageId
- the page idpageOffset
- the offset inside the pagebytesToRead
- the bytes to readcacheContext
- the cache contextDataFileChannel
PageNotFoundException
public int getPageLockId(PageId pageId)
pageId
- page identifierpublic boolean put(PageId pageId, ByteBuffer page, CacheContext cacheContext)
CacheManager
put
in interface CacheManager
pageId
- page identifierpage
- page datacacheContext
- cache related contextpublic void commitFile(String fileId)
CacheManager
commitFile
in interface CacheManager
fileId
- the file IDpublic int get(PageId pageId, int pageOffset, ReadTargetBuffer buffer, CacheContext cacheContext)
CacheManager
get
in interface CacheManager
pageId
- page identifierpageOffset
- offset into the pagebuffer
- destination buffer to writecacheContext
- cache related contextpublic int get(PageId pageId, int pageOffset, int bytesToRead, ReadTargetBuffer buffer, CacheContext cacheContext)
CacheManager
get
in interface CacheManager
pageId
- page identifierpageOffset
- offset into the pagebytesToRead
- number of bytes to read in this pagebuffer
- destination buffer to writecacheContext
- cache related contextpublic int getAndLoad(PageId pageId, int pageOffset, int bytesToRead, ReadTargetBuffer buffer, CacheContext cacheContext, java.util.function.Supplier<byte[]> externalDataSupplier)
CacheManager
getAndLoad
in interface CacheManager
pageId
- page identifierpageOffset
- offset into the pagebytesToRead
- number of bytes to read in this pagebuffer
- destination buffer to writecacheContext
- cache related contextexternalDataSupplier
- the external data supplier to read a pagepublic boolean delete(PageId pageId, boolean isTemporary)
pageId
- page identifierisTemporary
- whether is it temporary or notpublic boolean delete(PageId pageId)
CacheManager
delete
in interface CacheManager
pageId
- page identifierpublic CacheManager.State state()
state
in interface CacheManager
public boolean append(PageId pageId, int appendAt, byte[] page, CacheContext cacheContext)
append
in interface CacheManager
public List<PageId> getCachedPageIdsByFileId(String fileId, long fileLength)
CacheManager
getCachedPageIdsByFileId
in interface CacheManager
fileId
- file identifierfileLength
- file length (this will not be needed after we have per-file metadata)public void deleteFile(String fileId)
CacheManager
deleteFile
in interface CacheManager
fileId
- the file id of the target filepublic void deleteTempFile(String fileId)
CacheManager
deleteTempFile
in interface CacheManager
fileId
- the file id of the target filepublic void invalidate(java.util.function.Predicate<PageInfo> predicate)
CacheManager
invalidate
in interface CacheManager
public void close() throws Exception
close
in interface AutoCloseable
Exception
public Optional<CacheUsage> getUsage()
CacheStatus
getUsage
in interface CacheManager
getUsage
in interface CacheStatus
Copyright © 2023. All Rights Reserved.