001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.apache.hadoop.hbase.regionserver; 019 020import com.google.errorprone.annotations.RestrictedApi; 021import java.io.IOException; 022import java.util.Collection; 023import java.util.Comparator; 024import java.util.Iterator; 025import java.util.List; 026import java.util.Optional; 027import org.apache.hadoop.hbase.Cell; 028import org.apache.hadoop.hbase.KeyValue; 029import org.apache.yetus.audience.InterfaceAudience; 030 031import org.apache.hbase.thirdparty.com.google.common.collect.ImmutableCollection; 032 033/** 034 * Manages the store files and basic metadata about that that determines the logical structure (e.g. 035 * what files to return for scan, how to determine split point, and such). Does NOT affect the 036 * physical structure of files in HDFS. Example alternative structures - the default list of files 037 * by seqNum; levelDB one sorted by level and seqNum. 038 * <p/> 039 * Notice that, all the states are only in memory, we do not persist anything here. The only place 040 * where we throw an {@link IOException} is the {@link #getSplitPoint()} method, where we need to 041 * read startKey, endKey etc, which may lead to an {@link IOException}. 042 * <p/> 043 * Implementations are assumed to be not thread safe. 044 */ 045@InterfaceAudience.Private 046public interface StoreFileManager { 047 /** 048 * Loads the initial store files into empty StoreFileManager. 049 * @param storeFiles The files to load. 050 */ 051 @RestrictedApi(explanation = "Should only be called in StoreEngine", link = "", 052 allowedOnPath = ".*(/org/apache/hadoop/hbase/regionserver/StoreEngine.java|/src/test/.*)") 053 void loadFiles(List<HStoreFile> storeFiles); 054 055 /** 056 * Adds new files, either for from MemStore flush or bulk insert, into the structure. 057 * @param sfs New store files. 058 */ 059 @RestrictedApi(explanation = "Should only be called in StoreEngine", link = "", 060 allowedOnPath = ".*(/org/apache/hadoop/hbase/regionserver/StoreEngine.java|/src/test/.*)") 061 void insertNewFiles(Collection<HStoreFile> sfs); 062 063 /** 064 * Adds only the new compaction results into the structure. 065 * @param compactedFiles The input files for the compaction. 066 * @param results The resulting files for the compaction. 067 */ 068 @RestrictedApi(explanation = "Should only be called in StoreEngine", link = "", 069 allowedOnPath = ".*(/org/apache/hadoop/hbase/regionserver/StoreEngine.java|/src/test/.*)") 070 void addCompactionResults(Collection<HStoreFile> compactedFiles, Collection<HStoreFile> results); 071 072 /** 073 * Remove the compacted files 074 * @param compactedFiles the list of compacted files 075 */ 076 @RestrictedApi(explanation = "Should only be called in StoreEngine", link = "", 077 allowedOnPath = ".*(/org/apache/hadoop/hbase/regionserver/StoreEngine.java|/src/test/.*)") 078 void removeCompactedFiles(Collection<HStoreFile> compactedFiles); 079 080 /** 081 * Clears all the files currently in use and returns them. 082 * @return The files previously in use. 083 */ 084 ImmutableCollection<HStoreFile> clearFiles(); 085 086 /** 087 * Clears all the compacted files and returns them. This method is expected to be accessed single 088 * threaded. 089 * @return The files compacted previously. 090 */ 091 Collection<HStoreFile> clearCompactedFiles(); 092 093 /** 094 * Gets the snapshot of the store files currently in use. Can be used for things like metrics and 095 * checks; should not assume anything about relations between store files in the list. 096 * @return The list of StoreFiles. 097 */ 098 Collection<HStoreFile> getStorefiles(); 099 100 /** 101 * List of compacted files inside this store that needs to be excluded in reads because further 102 * new reads will be using only the newly created files out of compaction. These compacted files 103 * will be deleted/cleared once all the existing readers on these compacted files are done. 104 * @return the list of compacted files 105 */ 106 Collection<HStoreFile> getCompactedfiles(); 107 108 /** 109 * Returns the number of files currently in use. 110 * @return The number of files. 111 */ 112 int getStorefileCount(); 113 114 /** 115 * Returns the number of compacted files. 116 * @return The number of files. 117 */ 118 int getCompactedFilesCount(); 119 120 /** 121 * Gets the store files to scan for a Scan or Get request. 122 * @param startRow Start row of the request. 123 * @param stopRow Stop row of the request. 124 * @return The list of files that are to be read for this request. 125 */ 126 Collection<HStoreFile> getFilesForScan(byte[] startRow, boolean includeStartRow, byte[] stopRow, 127 boolean includeStopRow); 128 129 /** 130 * Gets initial, full list of candidate store files to check for row-key-before. 131 * @param targetKey The key that is the basis of the search. 132 * @return The files that may have the key less than or equal to targetKey, in reverse order of 133 * new-ness, and preference for target key. 134 */ 135 Iterator<HStoreFile> getCandidateFilesForRowKeyBefore(KeyValue targetKey); 136 137 /** 138 * Updates the candidate list for finding row key before. Based on the list of candidates 139 * remaining to check from getCandidateFilesForRowKeyBefore, targetKey and current candidate, may 140 * trim and reorder the list to remove the files where a better candidate cannot be found. 141 * @param candidateFiles The candidate files not yet checked for better candidates - return value 142 * from {@link #getCandidateFilesForRowKeyBefore(KeyValue)}, with some files 143 * already removed. 144 * @param targetKey The key to search for. 145 * @param candidate The current best candidate found. 146 * @return The list to replace candidateFiles. 147 */ 148 Iterator<HStoreFile> updateCandidateFilesForRowKeyBefore(Iterator<HStoreFile> candidateFiles, 149 KeyValue targetKey, Cell candidate); 150 151 /** 152 * Gets the split point for the split of this set of store files (approx. middle). 153 * @return The mid-point if possible. 154 */ 155 Optional<byte[]> getSplitPoint() throws IOException; 156 157 /** Returns The store compaction priority. */ 158 int getStoreCompactionPriority(); 159 160 /** 161 * @param maxTs Maximum expired timestamp. 162 * @param filesCompacting Files that are currently compacting. 163 * @return The files which don't have any necessary data according to TTL and other criteria. 164 */ 165 Collection<HStoreFile> getUnneededFiles(long maxTs, List<HStoreFile> filesCompacting); 166 167 /** 168 * @return the compaction pressure used for compaction throughput tuning. 169 * @see HStore#getCompactionPressure() 170 */ 171 double getCompactionPressure(); 172 173 /** 174 * @return the comparator used to sort storefiles. Usually, the 175 * {@link HStoreFile#getMaxSequenceId()} is the first priority. 176 */ 177 Comparator<HStoreFile> getStoreFileComparator(); 178}