Class StripeStoreFileManager
java.lang.Object
org.apache.hadoop.hbase.regionserver.StripeStoreFileManager
- All Implemented Interfaces:
StripeCompactionPolicy.StripeInformationProvider,StoreFileManager
@Private
public class StripeStoreFileManager
extends Object
implements StoreFileManager, StripeCompactionPolicy.StripeInformationProvider
Stripe implementation of
StoreFileManager. Not thread safe - relies on external locking
(in HStore). Collections that this class returns are immutable or unique to the call, so they
should be safe. Stripe store splits the key space of the region into non-overlapping stripes, as
well as some recent files that have all the keys (level 0). Each stripe contains a set of files.
When L0 is compacted, it's split into the files corresponding to existing stripe boundaries, that
can thus be added to stripes. When scan or get happens, it only has to read the files from the
corresponding stripes. See StripeCompactionPolicy on how the stripes are determined; this
class doesn't care. This class should work together with StripeCompactionPolicy and
StripeCompactor. With regard to how they
work, we make at least the following (reasonable) assumptions: - Compaction produces one file per
new stripe (if any); that is easy to change. - Compaction has one contiguous set of stripes both
in and out, except if L0 is involved.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate classNon-static helper class for merging compaction or flush results.private static classAn extension of ConcatenatedLists that has several peculiar properties.private static classThe state class. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final intprivate final CellComparatorprivate StripeStoreConfigprivate HashMap<HStoreFile,byte[]> private HashMap<HStoreFile,byte[]> Cached file metadata (or overrides as the case may be)(package private) static final byte[]private static final byte[]Normally invalid key is null, but in the map null is the result for "no key"; so use the following constant value in these maps instead.private static final org.slf4j.Loggerprivate static final Bytes.RowEndKeyComparatorstatic final byte[]The key value used for range boundary, indicating that the boundary is open (i.e.private StripeStoreFileManager.Statestatic final byte[]static final byte[]The file metadata fields that contain the stripe information. -
Constructor Summary
ConstructorsConstructorDescriptionStripeStoreFileManager(CellComparator kvComparator, org.apache.hadoop.conf.Configuration conf, StripeStoreConfig config) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddCompactionResults(Collection<HStoreFile> compactedFiles, Collection<HStoreFile> results) Adds only the new compaction results into the structure.org.apache.hbase.thirdparty.com.google.common.collect.ImmutableCollection<HStoreFile>Clears all the compacted files and returns them.org.apache.hbase.thirdparty.com.google.common.collect.ImmutableCollection<HStoreFile>Clears all the files currently in use and returns them.private voiddebugDumpState(String string) private byte[]endOf(HStoreFile sf) private voidensureEdgeStripeMetadata(ArrayList<HStoreFile> stripe, boolean isFirst) private voidprivate Collection<HStoreFile>findExpiredFiles(org.apache.hbase.thirdparty.com.google.common.collect.ImmutableList<HStoreFile> stripe, long maxTs, List<HStoreFile> filesCompacting, Collection<HStoreFile> expiredStoreFiles) private final intfindStripeForRow(byte[] row, boolean isStart) Finds the stripe index for the stripe containing a row provided externally for get/scan.private final intfindStripeIndexByEndRow(byte[] endRow) Finds the stripe index by end row.getCandidateFilesForRowKeyBefore(KeyValue targetKey) SeeStoreFileManager.getCandidateFilesForRowKeyBefore(KeyValue)for details on this methods.List of compacted files inside this store that needs to be excluded in reads because further new reads will be using only the newly created files out of compaction.intReturns the number of compacted files.doublefinal byte[]getEndRow(int stripeIndex) Gets the end row for a given stripe.getFilesForScan(byte[] startRow, boolean includeStartRow, byte[] stopRow, boolean includeStopRow, boolean onlyLatestVersion) Gets the store files to scan for a Scan or Get request.Returns Level 0 files.private doublegetMidStripeSplitRatio(long smallerSize, long largerSize, long lastLargerSize) Optional<byte[]>Override of getSplitPoint that determines the split point as the boundary between two stripes, unless it causes significant imbalance between split sides' sizes.private Optional<byte[]>final byte[]getStartRow(int stripeIndex) Gets the start row for a given stripe.intReturns The store compaction priority.intReturns the number of files currently in use.Gets the snapshot of the store files currently in use.List<byte[]>Returns All stripe boundaries; including the open ones on both ends.intReturns Stripe count.private longgetStripeFilesSize(int stripeIndex) Gets the total size of all files in the stripe.ArrayList<org.apache.hbase.thirdparty.com.google.common.collect.ImmutableList<HStoreFile>>Returns The stripes.getUnneededFiles(long maxTs, List<HStoreFile> filesCompacting) private static voidinsertFileIntoStripe(ArrayList<HStoreFile> stripe, HStoreFile sf) Inserts a file in the correct place (by seqnum) in a stripe copy.voidAdds new files, either for from MemStore flush or bulk insert, into the structure.private static final booleanisInvalid(byte[] key) Checks whether the key is invalid (e.g.private static final booleanisOpen(byte[] key) Checks whether the key indicates an open interval boundary (i.e.private static final booleanvoidloadFiles(List<HStoreFile> storeFiles) Loads the initial store files into empty StoreFileManager.private voidloadUnclassifiedStoreFiles(List<HStoreFile> storeFiles) Loads initial store files that were picked up from some physical location pertaining to this store (presumably).private voidmarkCompactedAway(Collection<HStoreFile> compactedFiles) private final intnonOpenRowCompare(byte[] k1, byte[] k2) Compare two keys.private final intnonOpenRowCompare(Cell k1, byte[] k2) voidremoveCompactedFiles(Collection<HStoreFile> compactedFiles) Remove the compacted filesprivate final booleanrowEquals(byte[] k1, byte[] k2) Compare two keys for equality.private byte[]startOf(HStoreFile sf) updateCandidateFilesForRowKeyBefore(Iterator<HStoreFile> candidateFiles, KeyValue targetKey, Cell candidate) SeeStoreFileManager.getCandidateFilesForRowKeyBefore(KeyValue)andStoreFileManager.updateCandidateFilesForRowKeyBefore(Iterator, KeyValue, Cell)for details on this methods.
-
Field Details
-
LOG
-
STRIPE_START_KEY
The file metadata fields that contain the stripe information. -
STRIPE_END_KEY
-
MAP_COMPARATOR
-
OPEN_KEY
The key value used for range boundary, indicating that the boundary is open (i.e. +-inf). -
INVALID_KEY
-
state
-
fileStarts
Cached file metadata (or overrides as the case may be) -
fileEnds
-
INVALID_KEY_IN_MAP
Normally invalid key is null, but in the map null is the result for "no key"; so use the following constant value in these maps instead. Note that this is a constant and we use it to compare by reference when we read from the map. -
cellComparator
-
config
-
blockingFileCount
-
-
Constructor Details
-
StripeStoreFileManager
public StripeStoreFileManager(CellComparator kvComparator, org.apache.hadoop.conf.Configuration conf, StripeStoreConfig config)
-
-
Method Details
-
loadFiles
Description copied from interface:StoreFileManagerLoads the initial store files into empty StoreFileManager.- Specified by:
loadFilesin interfaceStoreFileManager- Parameters:
storeFiles- The files to load.
-
getStoreFiles
Description copied from interface:StoreFileManagerGets the snapshot of the store files currently in use. Can be used for things like metrics and checks; should not assume anything about relations between store files in the list.- Specified by:
getStoreFilesin interfaceStoreFileManager- Specified by:
getStoreFilesin interfaceStripeCompactionPolicy.StripeInformationProvider- Returns:
- The list of StoreFiles.
-
getCompactedfiles
Description copied from interface:StoreFileManagerList of compacted files inside this store that needs to be excluded in reads because further new reads will be using only the newly created files out of compaction. These compacted files will be deleted/cleared once all the existing readers on these compacted files are done.- Specified by:
getCompactedfilesin interfaceStoreFileManager- Returns:
- the list of compacted files
-
getCompactedFilesCount
Description copied from interface:StoreFileManagerReturns the number of compacted files.- Specified by:
getCompactedFilesCountin interfaceStoreFileManager- Returns:
- The number of files.
-
insertNewFiles
Description copied from interface:StoreFileManagerAdds new files, either for from MemStore flush or bulk insert, into the structure.- Specified by:
insertNewFilesin interfaceStoreFileManager- Parameters:
sfs- New store files.
-
clearFiles
public org.apache.hbase.thirdparty.com.google.common.collect.ImmutableCollection<HStoreFile> clearFiles()Description copied from interface:StoreFileManagerClears all the files currently in use and returns them.- Specified by:
clearFilesin interfaceStoreFileManager- Returns:
- The files previously in use.
-
clearCompactedFiles
public org.apache.hbase.thirdparty.com.google.common.collect.ImmutableCollection<HStoreFile> clearCompactedFiles()Description copied from interface:StoreFileManagerClears all the compacted files and returns them. This method is expected to be accessed single threaded.- Specified by:
clearCompactedFilesin interfaceStoreFileManager- Returns:
- The files compacted previously.
-
getStorefileCount
Description copied from interface:StoreFileManagerReturns the number of files currently in use.- Specified by:
getStorefileCountin interfaceStoreFileManager- Returns:
- The number of files.
-
getCandidateFilesForRowKeyBefore
SeeStoreFileManager.getCandidateFilesForRowKeyBefore(KeyValue)for details on this methods.- Specified by:
getCandidateFilesForRowKeyBeforein interfaceStoreFileManager- Parameters:
targetKey- The key that is the basis of the search.- Returns:
- The files that may have the key less than or equal to targetKey, in reverse order of new-ness, and preference for target key.
-
updateCandidateFilesForRowKeyBefore
public Iterator<HStoreFile> updateCandidateFilesForRowKeyBefore(Iterator<HStoreFile> candidateFiles, KeyValue targetKey, Cell candidate) SeeStoreFileManager.getCandidateFilesForRowKeyBefore(KeyValue)andStoreFileManager.updateCandidateFilesForRowKeyBefore(Iterator, KeyValue, Cell)for details on this methods.- Specified by:
updateCandidateFilesForRowKeyBeforein interfaceStoreFileManager- Parameters:
candidateFiles- The candidate files not yet checked for better candidates - return value fromStoreFileManager.getCandidateFilesForRowKeyBefore(KeyValue), with some files already removed.targetKey- The key to search for.candidate- The current best candidate found.- Returns:
- The list to replace candidateFiles.
-
getSplitPoint
Override of getSplitPoint that determines the split point as the boundary between two stripes, unless it causes significant imbalance between split sides' sizes. In that case, the split boundary will be chosen from the middle of one of the stripes to minimize imbalance.- Specified by:
getSplitPointin interfaceStoreFileManager- Returns:
- The split point, or null if no split is possible.
- Throws:
IOException
-
getSplitPointFromAllFiles
- Throws:
IOException
-
getMidStripeSplitRatio
-
getFilesForScan
public Collection<HStoreFile> getFilesForScan(byte[] startRow, boolean includeStartRow, byte[] stopRow, boolean includeStopRow, boolean onlyLatestVersion) Description copied from interface:StoreFileManagerGets the store files to scan for a Scan or Get request.- Specified by:
getFilesForScanin interfaceStoreFileManager- Parameters:
startRow- Start row of the request.stopRow- Stop row of the request.onlyLatestVersion- Scan only latest live version cells.- Returns:
- The list of files that are to be read for this request.
-
addCompactionResults
public void addCompactionResults(Collection<HStoreFile> compactedFiles, Collection<HStoreFile> results) Description copied from interface:StoreFileManagerAdds only the new compaction results into the structure.- Specified by:
addCompactionResultsin interfaceStoreFileManager- Parameters:
compactedFiles- The input files for the compaction.results- The resulting files for the compaction.
-
markCompactedAway
-
removeCompactedFiles
Description copied from interface:StoreFileManagerRemove the compacted files- Specified by:
removeCompactedFilesin interfaceStoreFileManager- Parameters:
compactedFiles- the list of compacted files
-
getStoreCompactionPriority
Description copied from interface:StoreFileManagerReturns The store compaction priority.- Specified by:
getStoreCompactionPriorityin interfaceStoreFileManager
-
getStripeFilesSize
Gets the total size of all files in the stripe.- Parameters:
stripeIndex- Stripe index.- Returns:
- Size.
-
loadUnclassifiedStoreFiles
Loads initial store files that were picked up from some physical location pertaining to this store (presumably). Unlike adding files after compaction, assumes empty initial sets, and is forgiving with regard to stripe constraints - at worst, many/all files will go to level 0.- Parameters:
storeFiles- Store files to add.
-
ensureEdgeStripeMetadata
-
ensureLevel0Metadata
-
debugDumpState
-
isOpen
Checks whether the key indicates an open interval boundary (i.e. infinity). -
isOpen
-
isInvalid
Checks whether the key is invalid (e.g. from an L0 file, or non-stripe-compacted files). -
rowEquals
Compare two keys for equality. -
nonOpenRowCompare
Compare two keys. Keys must not be open (isOpen(row) == false). -
nonOpenRowCompare
-
findStripeIndexByEndRow
Finds the stripe index by end row. -
findStripeForRow
Finds the stripe index for the stripe containing a row provided externally for get/scan. -
getStartRow
Description copied from interface:StripeCompactionPolicy.StripeInformationProviderGets the start row for a given stripe.- Specified by:
getStartRowin interfaceStripeCompactionPolicy.StripeInformationProvider- Parameters:
stripeIndex- Stripe index.- Returns:
- Start row. May be an open key.
-
getEndRow
Description copied from interface:StripeCompactionPolicy.StripeInformationProviderGets the end row for a given stripe.- Specified by:
getEndRowin interfaceStripeCompactionPolicy.StripeInformationProvider- Parameters:
stripeIndex- Stripe index.- Returns:
- End row. May be an open key.
-
startOf
-
endOf
-
insertFileIntoStripe
Inserts a file in the correct place (by seqnum) in a stripe copy.- Parameters:
stripe- Stripe copy to insert into.sf- File to insert.
-
getLevel0Files
Description copied from interface:StripeCompactionPolicy.StripeInformationProviderReturns Level 0 files.- Specified by:
getLevel0Filesin interfaceStripeCompactionPolicy.StripeInformationProvider
-
getStripeBoundaries
Description copied from interface:StripeCompactionPolicy.StripeInformationProviderReturns All stripe boundaries; including the open ones on both ends.- Specified by:
getStripeBoundariesin interfaceStripeCompactionPolicy.StripeInformationProvider
-
getStripes
public ArrayList<org.apache.hbase.thirdparty.com.google.common.collect.ImmutableList<HStoreFile>> getStripes()Description copied from interface:StripeCompactionPolicy.StripeInformationProviderReturns The stripes.- Specified by:
getStripesin interfaceStripeCompactionPolicy.StripeInformationProvider
-
getStripeCount
Description copied from interface:StripeCompactionPolicy.StripeInformationProviderReturns Stripe count.- Specified by:
getStripeCountin interfaceStripeCompactionPolicy.StripeInformationProvider
-
getUnneededFiles
- Specified by:
getUnneededFilesin interfaceStoreFileManager- Parameters:
maxTs- Maximum expired timestamp.filesCompacting- Files that are currently compacting.- Returns:
- The files which don't have any necessary data according to TTL and other criteria.
-
findExpiredFiles
private Collection<HStoreFile> findExpiredFiles(org.apache.hbase.thirdparty.com.google.common.collect.ImmutableList<HStoreFile> stripe, long maxTs, List<HStoreFile> filesCompacting, Collection<HStoreFile> expiredStoreFiles) -
getCompactionPressure
- Specified by:
getCompactionPressurein interfaceStoreFileManager- Returns:
- the compaction pressure used for compaction throughput tuning.
- See Also:
-
getStoreFileComparator
- Specified by:
getStoreFileComparatorin interfaceStoreFileManager- Returns:
- the comparator used to sort storefiles. Usually, the
HStoreFile.getMaxSequenceId()is the first priority.
-