Package org.apache.hadoop.hbase.quotas
Class FileArchiverNotifierImpl
java.lang.Object
org.apache.hadoop.hbase.quotas.FileArchiverNotifierImpl
- All Implemented Interfaces:
FileArchiverNotifier
Tracks file archiving and updates the hbase quota table.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
An Exception thrown when SnapshotSize updates to hbase:quota fail to be written.(package private) static class
A struct encapsulating the name of a snapshot and its "size" on the filesystem.(package private) static class
A reference to a collection of files in the archive directory for a single region. -
Field Summary
Modifier and TypeFieldDescriptionprivate final org.apache.hadoop.conf.Configuration
private final Connection
private final org.apache.hadoop.fs.FileSystem
private long
private static final org.slf4j.Logger
private final ReentrantReadWriteLock.ReadLock
private final TableName
private final ReentrantReadWriteLock.WriteLock
-
Constructor Summary
ConstructorDescriptionFileArchiverNotifierImpl
(Connection conn, org.apache.hadoop.conf.Configuration conf, org.apache.hadoop.fs.FileSystem fs, TableName tn) -
Method Summary
Modifier and TypeMethodDescriptionvoid
addArchivedFiles
(Set<Map.Entry<String, Long>> fileSizes) Records a file and its size in bytes being moved to the archive directory.(package private) void
bucketFilesToSnapshot
(String snapshotName, Map<String, Long> filesToUpdate, Map<String, Long> snapshotSizeChanges) For the given snapshot, find all files which thissnapshotName
references.long
computeAndStoreSnapshotSizes
(Collection<String> currentSnapshots) Computes the size of a table and all of its snapshots, recording new "full" sizes for each.(package private) List<FileArchiverNotifierImpl.SnapshotWithSize>
computeSnapshotSizes
(List<String> snapshots) Computes the size of each snapshot against the table referenced bythis
.(package private) long
Returns a strictly-increasing measure of time extracted bySystem.nanoTime()
.(package private) static Object
getLockForNamespace
(String namespace) (package private) long
getPreviousNamespaceSnapshotSize
(Table quotaTable, String namespace) Fetches the current size of all snapshots in the givennamespace
.(package private) long
getSizeOfStoreFile
(TableName tn, String regionName, String family, String storeFile) Computes the size of the store file given its name, region and family name in the archive directory.(package private) long
getSizeOfStoreFile
(TableName tn, FileArchiverNotifierImpl.StoreFileReference storeFileName) Computes the size of the store files for a single region.(package private) long
getSizeOfStoreFiles
(TableName tn, Set<FileArchiverNotifierImpl.StoreFileReference> storeFileNames) Computes the size of each store file instoreFileNames
(package private) long
Extracts the size component from a serializedSpaceQuotaSnapshot
protobuf.(package private) Set<FileArchiverNotifierImpl.StoreFileReference>
getStoreFilesFromSnapshot
(SnapshotManifest manifest, Predicate<String> filter) Extracts the names of the store files referenced by this snapshot which satisfy the given predicate (the predicate returnstrue
).(package private) void
groupArchivedFiledBySnapshotAndRecordSize
(List<String> snapshots, Set<Map.Entry<String, Long>> fileSizes) For each file in the map, this updates the first snapshot (lexicographic snapshot name) that references this file.(package private) void
persistSnapshotSizeChanges
(Map<String, Long> snapshotSizeChanges) Reads the current size for each snapshot to update, generates a new update based on that value, and then writes the new update.(package private) void
persistSnapshotSizes
(Table table, List<FileArchiverNotifierImpl.SnapshotWithSize> snapshotSizes) Writes the snapshot sizes to the providedtable
.toString()
-
Field Details
-
LOG
-
conn
-
conf
-
fs
-
tn
-
readLock
-
writeLock
-
lastFullCompute
-
currentSnapshots
-
NAMESPACE_LOCKS
-
-
Constructor Details
-
FileArchiverNotifierImpl
public FileArchiverNotifierImpl(Connection conn, org.apache.hadoop.conf.Configuration conf, org.apache.hadoop.fs.FileSystem fs, TableName tn)
-
-
Method Details
-
getLockForNamespace
-
getLastFullCompute
long getLastFullCompute()Returns a strictly-increasing measure of time extracted bySystem.nanoTime()
. -
addArchivedFiles
Description copied from interface:FileArchiverNotifier
Records a file and its size in bytes being moved to the archive directory.- Specified by:
addArchivedFiles
in interfaceFileArchiverNotifier
- Parameters:
fileSizes
- A collection of file name to size in bytes- Throws:
IOException
- If there was an IO-related error persisting the file size(s)
-
groupArchivedFiledBySnapshotAndRecordSize
void groupArchivedFiledBySnapshotAndRecordSize(List<String> snapshots, Set<Map.Entry<String, Long>> fileSizes) throws IOExceptionFor each file in the map, this updates the first snapshot (lexicographic snapshot name) that references this file. The result of this computation is serialized to the quota table.- Parameters:
snapshots
- A collection of HBase snapshots to group the files intofileSizes
- A map of file names to their sizes- Throws:
IOException
-
bucketFilesToSnapshot
void bucketFilesToSnapshot(String snapshotName, Map<String, Long> filesToUpdate, Map<String, throws IOExceptionLong> snapshotSizeChanges) For the given snapshot, find all files which thissnapshotName
references. After a file is found to be referenced by the snapshot, it is removed fromfilesToUpdate
andsnapshotSizeChanges
is updated in concert.- Parameters:
snapshotName
- The snapshot to checkfilesToUpdate
- A mapping of archived files to their sizesnapshotSizeChanges
- A mapping of snapshots and their change in size- Throws:
IOException
-
persistSnapshotSizeChanges
Reads the current size for each snapshot to update, generates a new update based on that value, and then writes the new update.- Parameters:
snapshotSizeChanges
- A map of snapshot name to size change- Throws:
IOException
-
getPreviousNamespaceSnapshotSize
Fetches the current size of all snapshots in the givennamespace
.- Parameters:
quotaTable
- The HBase quota tablenamespace
- Namespace to fetch the sum of snapshot sizes for- Returns:
- The size of all snapshot sizes for the namespace in bytes.
- Throws:
IOException
-
getSnapshotSizeFromResult
long getSnapshotSizeFromResult(Result r) throws org.apache.hbase.thirdparty.com.google.protobuf.InvalidProtocolBufferException Extracts the size component from a serializedSpaceQuotaSnapshot
protobuf.- Parameters:
r
- A Result containing one cell with a SpaceQuotaSnapshot protobuf- Returns:
- The size in bytes of the snapshot.
- Throws:
org.apache.hbase.thirdparty.com.google.protobuf.InvalidProtocolBufferException
-
computeAndStoreSnapshotSizes
Description copied from interface:FileArchiverNotifier
Computes the size of a table and all of its snapshots, recording new "full" sizes for each.- Specified by:
computeAndStoreSnapshotSizes
in interfaceFileArchiverNotifier
- Parameters:
currentSnapshots
- the current list of snapshots against this table- Returns:
- The total size of all snapshots against this table.
- Throws:
IOException
- If there was an IO-related error computing or persisting the sizes.
-
toString
-
computeSnapshotSizes
List<FileArchiverNotifierImpl.SnapshotWithSize> computeSnapshotSizes(List<String> snapshots) throws IOException Computes the size of each snapshot against the table referenced bythis
.- Parameters:
snapshots
- A sorted list of snapshots againsttn
.- Returns:
- A list of the size for each snapshot against
tn
. - Throws:
IOException
-
getSizeOfStoreFiles
long getSizeOfStoreFiles(TableName tn, Set<FileArchiverNotifierImpl.StoreFileReference> storeFileNames) Computes the size of each store file instoreFileNames
-
getSizeOfStoreFile
Computes the size of the store files for a single region. -
getSizeOfStoreFile
Computes the size of the store file given its name, region and family name in the archive directory. -
getStoreFilesFromSnapshot
Set<FileArchiverNotifierImpl.StoreFileReference> getStoreFilesFromSnapshot(SnapshotManifest manifest, Predicate<String> filter) Extracts the names of the store files referenced by this snapshot which satisfy the given predicate (the predicate returnstrue
). -
persistSnapshotSizes
void persistSnapshotSizes(Table table, List<FileArchiverNotifierImpl.SnapshotWithSize> snapshotSizes) throws IOException Writes the snapshot sizes to the providedtable
.- Throws:
IOException
-