1 /**
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19 package org.apache.hadoop.hbase.regionserver;
20
21 import java.io.IOException;
22 import java.util.Collection;
23 import java.util.Comparator;
24 import java.util.Iterator;
25 import java.util.List;
26
27 import com.google.common.collect.ImmutableCollection;
28
29 import org.apache.hadoop.hbase.Cell;
30 import org.apache.hadoop.hbase.KeyValue;
31 import org.apache.hadoop.hbase.classification.InterfaceAudience;
32
33 /**
34 * Manages the store files and basic metadata about that that determines the logical structure
35 * (e.g. what files to return for scan, how to determine split point, and such).
36 * Does NOT affect the physical structure of files in HDFS.
37 * Example alternative structures - the default list of files by seqNum; levelDB one sorted
38 * by level and seqNum.
39 *
40 * Implementations are assumed to be not thread safe.
41 */
42 @InterfaceAudience.Private
43 public interface StoreFileManager {
44 /**
45 * Loads the initial store files into empty StoreFileManager.
46 * @param storeFiles The files to load.
47 */
48 void loadFiles(List<StoreFile> storeFiles);
49
50 /**
51 * Adds new files, either for from MemStore flush or bulk insert, into the structure.
52 * @param sfs New store files.
53 */
54 void insertNewFiles(Collection<StoreFile> sfs) throws IOException;
55
56 /**
57 * Adds only the new compaction results into the structure.
58 * @param compactedFiles The input files for the compaction.
59 * @param results The resulting files for the compaction.
60 */
61 void addCompactionResults(
62 Collection<StoreFile> compactedFiles, Collection<StoreFile> results) throws IOException;
63
64 /**
65 * Remove the compacted files
66 * @param compactedFiles the list of compacted files
67 * @throws IOException
68 */
69 void removeCompactedFiles(Collection<StoreFile> compactedFiles) throws IOException;
70
71 /**
72 * Clears all the files currently in use and returns them.
73 * @return The files previously in use.
74 */
75 ImmutableCollection<StoreFile> clearFiles();
76
77 /**
78 * Clears all the compacted files and returns them. This method is expected to be
79 * accessed single threaded.
80 * @return The files compacted previously.
81 */
82 Collection<StoreFile> clearCompactedFiles();
83
84 /**
85 * Gets the snapshot of the store files currently in use. Can be used for things like metrics
86 * and checks; should not assume anything about relations between store files in the list.
87 * @return The list of StoreFiles.
88 */
89 Collection<StoreFile> getStorefiles();
90
91 /**
92 * List of compacted files inside this store that needs to be excluded in reads
93 * because further new reads will be using only the newly created files out of compaction.
94 * These compacted files will be deleted/cleared once all the existing readers on these
95 * compacted files are done.
96 * @return the list of compacted files
97 */
98 Collection<StoreFile> getCompactedfiles();
99
100 /**
101 * Returns the number of files currently in use.
102 * @return The number of files.
103 */
104 int getStorefileCount();
105
106 /**
107 * Gets the store files to scan for a Scan or Get request.
108 * @param isGet Whether it's a get.
109 * @param startRow Start row of the request.
110 * @param stopRow Stop row of the request.
111 * @return The list of files that are to be read for this request.
112 */
113 Collection<StoreFile> getFilesForScanOrGet(
114 boolean isGet, byte[] startRow, byte[] stopRow
115 );
116
117 /**
118 * Gets initial, full list of candidate store files to check for row-key-before.
119 * @param targetKey The key that is the basis of the search.
120 * @return The files that may have the key less than or equal to targetKey, in reverse
121 * order of new-ness, and preference for target key.
122 */
123 Iterator<StoreFile> getCandidateFilesForRowKeyBefore(
124 KeyValue targetKey
125 );
126
127 /**
128 * Updates the candidate list for finding row key before. Based on the list of candidates
129 * remaining to check from getCandidateFilesForRowKeyBefore, targetKey and current candidate,
130 * may trim and reorder the list to remove the files where a better candidate cannot be found.
131 * @param candidateFiles The candidate files not yet checked for better candidates - return
132 * value from {@link #getCandidateFilesForRowKeyBefore(KeyValue)},
133 * with some files already removed.
134 * @param targetKey The key to search for.
135 * @param candidate The current best candidate found.
136 * @return The list to replace candidateFiles.
137 */
138 Iterator<StoreFile> updateCandidateFilesForRowKeyBefore(
139 Iterator<StoreFile> candidateFiles, KeyValue targetKey, Cell candidate
140 );
141
142
143 /**
144 * Gets the split point for the split of this set of store files (approx. middle).
145 * @return The mid-point, or null if no split is possible.
146 * @throws IOException
147 */
148 byte[] getSplitPoint() throws IOException;
149
150 /**
151 * @return The store compaction priority.
152 */
153 int getStoreCompactionPriority();
154
155 /**
156 * @param maxTs Maximum expired timestamp.
157 * @param filesCompacting Files that are currently compacting.
158 * @return The files which don't have any necessary data according to TTL and other criteria.
159 */
160 Collection<StoreFile> getUnneededFiles(long maxTs, List<StoreFile> filesCompacting);
161
162 /**
163 * @return the compaction pressure used for compaction throughput tuning.
164 * @see Store#getCompactionPressure()
165 */
166 double getCompactionPressure();
167
168 /**
169 * @return the comparator used to sort storefiles. Usually, the
170 * {@link StoreFile#getMaxSequenceId()} is the first priority.
171 */
172 Comparator<StoreFile> getStoreFileComparator();
173 }