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
Modifier and TypeClassDescriptionprivate class
Non-static helper class for merging compaction or flush results.private static class
An extension of ConcatenatedLists that has several peculiar properties.private static class
The state class. -
Field Summary
Modifier and TypeFieldDescriptionprivate final int
private final CellComparator
private StripeStoreConfig
private 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.Logger
private static final Bytes.RowEndKeyComparator
static final byte[]
The key value used for range boundary, indicating that the boundary is open (i.e.private StripeStoreFileManager.State
static final byte[]
static final byte[]
The file metadata fields that contain the stripe information. -
Constructor Summary
ConstructorDescriptionStripeStoreFileManager
(CellComparator kvComparator, org.apache.hadoop.conf.Configuration conf, StripeStoreConfig config) -
Method Summary
Modifier and TypeMethodDescriptionvoid
addCompactionResults
(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 void
debugDumpState
(String string) private byte[]
endOf
(HStoreFile sf) private void
ensureEdgeStripeMetadata
(ArrayList<HStoreFile> stripe, boolean isFirst) private void
private Collection<HStoreFile>
findExpiredFiles
(org.apache.hbase.thirdparty.com.google.common.collect.ImmutableList<HStoreFile> stripe, long maxTs, List<HStoreFile> filesCompacting, Collection<HStoreFile> expiredStoreFiles) private final int
findStripeForRow
(byte[] row, boolean isStart) Finds the stripe index for the stripe containing a row provided externally for get/scan.private final int
findStripeIndexByEndRow
(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.int
Returns the number of compacted files.double
final 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 double
getMidStripeSplitRatio
(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.int
Returns The store compaction priority.int
Returns 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.int
Returns Stripe count.private long
getStripeFilesSize
(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 void
insertFileIntoStripe
(ArrayList<HStoreFile> stripe, HStoreFile sf) Inserts a file in the correct place (by seqnum) in a stripe copy.void
Adds new files, either for from MemStore flush or bulk insert, into the structure.private static final boolean
isInvalid
(byte[] key) Checks whether the key is invalid (e.g.private static final boolean
isOpen
(byte[] key) Checks whether the key indicates an open interval boundary (i.e.private static final boolean
void
loadFiles
(List<HStoreFile> storeFiles) Loads the initial store files into empty StoreFileManager.private void
loadUnclassifiedStoreFiles
(List<HStoreFile> storeFiles) Loads initial store files that were picked up from some physical location pertaining to this store (presumably).private void
markCompactedAway
(Collection<HStoreFile> compactedFiles) private final int
nonOpenRowCompare
(byte[] k1, byte[] k2) Compare two keys.private final int
nonOpenRowCompare
(Cell k1, byte[] k2) void
removeCompactedFiles
(Collection<HStoreFile> compactedFiles) Remove the compacted filesprivate final boolean
rowEquals
(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:StoreFileManager
Loads the initial store files into empty StoreFileManager.- Specified by:
loadFiles
in interfaceStoreFileManager
- Parameters:
storeFiles
- The files to load.
-
getStoreFiles
Description copied from interface:StoreFileManager
Gets 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:
getStoreFiles
in interfaceStoreFileManager
- Specified by:
getStoreFiles
in interfaceStripeCompactionPolicy.StripeInformationProvider
- Returns:
- The list of StoreFiles.
-
getCompactedfiles
Description copied from interface:StoreFileManager
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. These compacted files will be deleted/cleared once all the existing readers on these compacted files are done.- Specified by:
getCompactedfiles
in interfaceStoreFileManager
- Returns:
- the list of compacted files
-
getCompactedFilesCount
Description copied from interface:StoreFileManager
Returns the number of compacted files.- Specified by:
getCompactedFilesCount
in interfaceStoreFileManager
- Returns:
- The number of files.
-
insertNewFiles
Description copied from interface:StoreFileManager
Adds new files, either for from MemStore flush or bulk insert, into the structure.- Specified by:
insertNewFiles
in interfaceStoreFileManager
- Parameters:
sfs
- New store files.
-
clearFiles
public org.apache.hbase.thirdparty.com.google.common.collect.ImmutableCollection<HStoreFile> clearFiles()Description copied from interface:StoreFileManager
Clears all the files currently in use and returns them.- Specified by:
clearFiles
in interfaceStoreFileManager
- Returns:
- The files previously in use.
-
clearCompactedFiles
public org.apache.hbase.thirdparty.com.google.common.collect.ImmutableCollection<HStoreFile> clearCompactedFiles()Description copied from interface:StoreFileManager
Clears all the compacted files and returns them. This method is expected to be accessed single threaded.- Specified by:
clearCompactedFiles
in interfaceStoreFileManager
- Returns:
- The files compacted previously.
-
getStorefileCount
Description copied from interface:StoreFileManager
Returns the number of files currently in use.- Specified by:
getStorefileCount
in interfaceStoreFileManager
- Returns:
- The number of files.
-
getCandidateFilesForRowKeyBefore
SeeStoreFileManager.getCandidateFilesForRowKeyBefore(KeyValue)
for details on this methods.- Specified by:
getCandidateFilesForRowKeyBefore
in 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:
updateCandidateFilesForRowKeyBefore
in 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:
getSplitPoint
in 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:StoreFileManager
Gets the store files to scan for a Scan or Get request.- Specified by:
getFilesForScan
in 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:StoreFileManager
Adds only the new compaction results into the structure.- Specified by:
addCompactionResults
in interfaceStoreFileManager
- Parameters:
compactedFiles
- The input files for the compaction.results
- The resulting files for the compaction.
-
markCompactedAway
-
removeCompactedFiles
Description copied from interface:StoreFileManager
Remove the compacted files- Specified by:
removeCompactedFiles
in interfaceStoreFileManager
- Parameters:
compactedFiles
- the list of compacted files
-
getStoreCompactionPriority
Description copied from interface:StoreFileManager
Returns The store compaction priority.- Specified by:
getStoreCompactionPriority
in 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.StripeInformationProvider
Gets the start row for a given stripe.- Specified by:
getStartRow
in interfaceStripeCompactionPolicy.StripeInformationProvider
- Parameters:
stripeIndex
- Stripe index.- Returns:
- Start row. May be an open key.
-
getEndRow
Description copied from interface:StripeCompactionPolicy.StripeInformationProvider
Gets the end row for a given stripe.- Specified by:
getEndRow
in 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.StripeInformationProvider
Returns Level 0 files.- Specified by:
getLevel0Files
in interfaceStripeCompactionPolicy.StripeInformationProvider
-
getStripeBoundaries
Description copied from interface:StripeCompactionPolicy.StripeInformationProvider
Returns All stripe boundaries; including the open ones on both ends.- Specified by:
getStripeBoundaries
in interfaceStripeCompactionPolicy.StripeInformationProvider
-
getStripes
public ArrayList<org.apache.hbase.thirdparty.com.google.common.collect.ImmutableList<HStoreFile>> getStripes()Description copied from interface:StripeCompactionPolicy.StripeInformationProvider
Returns The stripes.- Specified by:
getStripes
in interfaceStripeCompactionPolicy.StripeInformationProvider
-
getStripeCount
Description copied from interface:StripeCompactionPolicy.StripeInformationProvider
Returns Stripe count.- Specified by:
getStripeCount
in interfaceStripeCompactionPolicy.StripeInformationProvider
-
getUnneededFiles
- Specified by:
getUnneededFiles
in 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:
getCompactionPressure
in interfaceStoreFileManager
- Returns:
- the compaction pressure used for compaction throughput tuning.
- See Also:
-
getStoreFileComparator
- Specified by:
getStoreFileComparator
in interfaceStoreFileManager
- Returns:
- the comparator used to sort storefiles. Usually, the
HStoreFile.getMaxSequenceId()
is the first priority.
-