Class SnapshotFileCache
- All Implemented Interfaces:
Stoppable
A cache of files is kept to avoid querying the FileSystem
frequently. If there is a cache
miss the directory modification time is used to ensure that we don't rescan directories that we
already have in cache. We only check the modification times of the snapshot directories
(/hbase/.snapshot/[snapshot_name]) to determine if the files need to be loaded into the cache.
New snapshots will be added to the cache and deleted snapshots will be removed when we refresh the cache. If the files underneath a snapshot directory are changed, but not the snapshot itself, we will ignore updates to that snapshot's files.
This is sufficient because each snapshot has its own directory and is added via an atomic rename once, when the snapshot is created. We don't need to worry about the data in the snapshot being run.
Further, the cache is periodically refreshed ensure that files in snapshots that were deleted are also removed from the cache.
A SnapshotFileCache.SnapshotFileInspector
must be passed when creating this to
allow extraction of files under /hbase/.snapshot/[snapshot name] directory, for each snapshot.
This allows you to only cache files under, for instance, all the logs in the .logs directory or
all the files under all the regions.
this also considers all running snapshots (those under /hbase/.snapshot/.tmp) as valid snapshots and will attempt to cache files from those snapshots as well.
Queries about a given file are thread-safe with respect to multiple queries and cache refreshes.
-
Nested Class Summary
Modifier and TypeClassDescriptionclass
Simple helper task that just periodically attempts to refresh the cacheprivate static class
Information about a snapshot directory(package private) static interface
-
Field Summary
Modifier and TypeFieldDescriptionprivate org.apache.hbase.thirdparty.com.google.common.collect.ImmutableSet<String>
private final SnapshotFileCache.SnapshotFileInspector
private final org.apache.hadoop.fs.FileSystem
private static final int
private static final org.slf4j.Logger
private final Timer
private final org.apache.hadoop.fs.Path
private org.apache.hbase.thirdparty.com.google.common.collect.ImmutableMap<String,
SnapshotFileCache.SnapshotDirectoryInfo> This is a helper map of information about the snapshot directories so we don't need to rescan them if they haven't changed since the last time we looked.private boolean
private final org.apache.hadoop.fs.FileSystem
private final org.apache.hadoop.fs.Path
-
Constructor Summary
ConstructorDescriptionSnapshotFileCache
(org.apache.hadoop.conf.Configuration conf, long cacheRefreshPeriod, long cacheRefreshDelay, String refreshThreadName, SnapshotFileCache.SnapshotFileInspector inspectSnapshotFiles) Create a snapshot file cache for all snapshots under the specified [root]/.snapshot on the filesystem.SnapshotFileCache
(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path rootDir, org.apache.hadoop.fs.FileSystem workingFs, org.apache.hadoop.fs.Path workingDir, long cacheRefreshPeriod, long cacheRefreshDelay, String refreshThreadName, SnapshotFileCache.SnapshotFileInspector inspectSnapshotFiles) Create a snapshot file cache for all snapshots under the specified [root]/.snapshot on the filesystem -
Method Summary
Modifier and TypeMethodDescriptionIterable<org.apache.hadoop.fs.FileStatus>
getUnreferencedFiles
(List<org.apache.hadoop.fs.FileStatus> files, SnapshotManager snapshotManager) Check to see if any of the passed file names is contained in any of the snapshots.boolean
Returns True ifStoppable.stop(String)
has been closed.private void
void
Stop this service.void
Trigger a cache refresh, even if its before the next cache refresh.
-
Field Details
-
LOG
-
stop
-
fs
-
workingFs
-
fileInspector
-
snapshotDir
-
workingSnapshotDir
-
cache
-
snapshots
private org.apache.hbase.thirdparty.com.google.common.collect.ImmutableMap<String,SnapshotFileCache.SnapshotDirectoryInfo> snapshotsThis is a helper map of information about the snapshot directories so we don't need to rescan them if they haven't changed since the last time we looked. -
refreshTimer
-
LOCK_TIMEOUT_MS
- See Also:
-
-
Constructor Details
-
SnapshotFileCache
public SnapshotFileCache(org.apache.hadoop.conf.Configuration conf, long cacheRefreshPeriod, long cacheRefreshDelay, String refreshThreadName, SnapshotFileCache.SnapshotFileInspector inspectSnapshotFiles) throws IOException Create a snapshot file cache for all snapshots under the specified [root]/.snapshot on the filesystem.Immediately loads the file cache.
- Parameters:
conf
- to extract the configuredFileSystem
where the snapshots are stored and hbase root directorycacheRefreshPeriod
- frequency (ms) with which the cache should be refreshedcacheRefreshDelay
- amount of time to wait for the cache to be refreshedrefreshThreadName
- name of the cache refresh threadinspectSnapshotFiles
- Filter to apply to each snapshot to extract the files.- Throws:
IOException
- if theFileSystem
or root directory cannot be loaded
-
SnapshotFileCache
public SnapshotFileCache(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path rootDir, org.apache.hadoop.fs.FileSystem workingFs, org.apache.hadoop.fs.Path workingDir, long cacheRefreshPeriod, long cacheRefreshDelay, String refreshThreadName, SnapshotFileCache.SnapshotFileInspector inspectSnapshotFiles) Create a snapshot file cache for all snapshots under the specified [root]/.snapshot on the filesystem- Parameters:
fs
-FileSystem
where the snapshots are storedrootDir
- hbase root directoryworkingFs
-FileSystem
where ongoing snapshot mainifest files are storedworkingDir
- Location to store ongoing snapshot manifest filescacheRefreshPeriod
- period (ms) with which the cache should be refreshedcacheRefreshDelay
- amount of time to wait for the cache to be refreshedrefreshThreadName
- name of the cache refresh threadinspectSnapshotFiles
- Filter to apply to each snapshot to extract the files.
-
-
Method Details
-
triggerCacheRefreshForTesting
Trigger a cache refresh, even if its before the next cache refresh. Does not affect pending cache refreshes. Blocks until the cache is refreshed. Exposed for TESTING. -
getUnreferencedFiles
public Iterable<org.apache.hadoop.fs.FileStatus> getUnreferencedFiles(List<org.apache.hadoop.fs.FileStatus> files, SnapshotManager snapshotManager) throws IOException Check to see if any of the passed file names is contained in any of the snapshots. First checks an in-memory cache of the files to keep. If its not in the cache, then the cache is refreshed and the cache checked again for that file. This ensures that we never return files that exist.Note this may lead to periodic false positives for the file being referenced. Periodically, the cache is refreshed even if there are no requests to ensure that the false negatives get removed eventually. For instance, suppose you have a file in the snapshot and it gets loaded into the cache. Then at some point later that snapshot is deleted. If the cache has not been refreshed at that point, cache will still think the file system contains that file and return true, even if it is no longer present (false positive). However, if the file never was on the filesystem, we will never find it and always return false.
- Parameters:
files
- file to check- Returns:
- unReferencedFiles the collection of files that do not have snapshot references
- Throws:
IOException
- if there is an unexpected error reaching the filesystem.
-
refreshCache
- Throws:
IOException
-
getSnapshotsInProgress
- Throws:
IOException
-
stop
Description copied from interface:Stoppable
Stop this service. Implementers should favor logging errors over throwing RuntimeExceptions. -
isStopped
Description copied from interface:Stoppable
Returns True ifStoppable.stop(String)
has been closed.
-