|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.hadoop.hbase.master.snapshot.SnapshotFileCache
@InterfaceAudience.Private @InterfaceStability.Evolving public class SnapshotFileCache
Intelligently keep track of all the files for all the snapshots.
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 SnapshotFileInspector must be passed when creating this to allow extraction of files under the /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 | |
---|---|
class |
SnapshotFileCache.RefreshCacheTask
Simple helper task that just periodically attempts to refresh the cache |
Constructor Summary | |
---|---|
SnapshotFileCache(org.apache.hadoop.conf.Configuration conf,
long cacheRefreshPeriod,
String refreshThreadName,
org.apache.hadoop.hbase.master.snapshot.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,
long cacheRefreshPeriod,
long cacheRefreshDelay,
String refreshThreadName,
org.apache.hadoop.hbase.master.snapshot.SnapshotFileCache.SnapshotFileInspector inspectSnapshotFiles)
Create a snapshot file cache for all snapshots under the specified [root]/.snapshot on the filesystem |
Method Summary | |
---|---|
boolean |
contains(String fileName)
Check to see if the passed file name is contained in any of the snapshots. |
boolean |
isStopped()
|
void |
stop(String why)
Stop this service. |
void |
triggerCacheRefreshForTesting()
Trigger a cache refresh, even if its before the next cache refresh. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public SnapshotFileCache(org.apache.hadoop.conf.Configuration conf, long cacheRefreshPeriod, String refreshThreadName, org.apache.hadoop.hbase.master.snapshot.SnapshotFileCache.SnapshotFileInspector inspectSnapshotFiles) throws IOException
Immediately loads the file cache.
conf
- to extract the configured FileSystem
where the snapshots are stored and
hbase root directorycacheRefreshPeriod
- frequency (ms) with which the cache should be refreshedrefreshThreadName
- name of the cache refresh threadinspectSnapshotFiles
- Filter to apply to each snapshot to extract the files.
IOException
- if the FileSystem
or root directory cannot be loadedpublic SnapshotFileCache(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path rootDir, long cacheRefreshPeriod, long cacheRefreshDelay, String refreshThreadName, org.apache.hadoop.hbase.master.snapshot.SnapshotFileCache.SnapshotFileInspector inspectSnapshotFiles)
fs
- FileSystem
where the snapshots are storedrootDir
- hbase root directorycacheRefreshPeriod
- 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 Detail |
---|
public void triggerCacheRefreshForTesting()
Blocks until the cache is refreshed.
Exposed for TESTING.
public boolean contains(String fileName) throws IOException
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.
fileName
- file to check
IOException
- if there is an unexpected error reaching the filesystem.public void stop(String why)
Stoppable
stop
in interface Stoppable
why
- Why we're stopping.public boolean isStopped()
isStopped
in interface Stoppable
Stoppable.stop(String)
has been closed.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |