Skip to content

Commit a3ad97f

Browse files
authored
HBASE-26065 StripeStoreFileManager does not need to throw IOException for most methods (#3459)
Signed-off-by: Xiaolin Ha <[email protected]>
1 parent 1883889 commit a3ad97f

File tree

4 files changed

+59
-55
lines changed

4 files changed

+59
-55
lines changed

hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/DefaultStoreFileManager.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ public Collection<HStoreFile> getCompactedfiles() {
8888
}
8989

9090
@Override
91-
public void insertNewFiles(Collection<HStoreFile> sfs) throws IOException {
91+
public void insertNewFiles(Collection<HStoreFile> sfs) {
9292
this.storefiles =
93-
ImmutableList.sortedCopyOf(storeFileComparator, Iterables.concat(this.storefiles, sfs));
93+
ImmutableList.sortedCopyOf(storeFileComparator, Iterables.concat(this.storefiles, sfs));
9494
}
9595

9696
@Override
@@ -132,11 +132,10 @@ public void addCompactionResults(Collection<HStoreFile> newCompactedfiles,
132132
}
133133

134134
@Override
135-
public void removeCompactedFiles(Collection<HStoreFile> removedCompactedfiles)
136-
throws IOException {
135+
public void removeCompactedFiles(Collection<HStoreFile> removedCompactedfiles) {
137136
this.compactedfiles =
138-
this.compactedfiles.stream().filter(sf -> !removedCompactedfiles.contains(sf))
139-
.sorted(storeFileComparator).collect(ImmutableList.toImmutableList());
137+
this.compactedfiles.stream().filter(sf -> !removedCompactedfiles.contains(sf))
138+
.sorted(storeFileComparator).collect(ImmutableList.toImmutableList());
140139
}
141140

142141
@Override

hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/StoreFileManager.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,15 @@
3232
import org.apache.hbase.thirdparty.com.google.common.collect.ImmutableCollection;
3333

3434
/**
35-
* Manages the store files and basic metadata about that that determines the logical structure
36-
* (e.g. what files to return for scan, how to determine split point, and such).
37-
* Does NOT affect the physical structure of files in HDFS.
38-
* Example alternative structures - the default list of files by seqNum; levelDB one sorted
39-
* by level and seqNum.
40-
*
35+
* Manages the store files and basic metadata about that that determines the logical structure (e.g.
36+
* what files to return for scan, how to determine split point, and such). Does NOT affect the
37+
* physical structure of files in HDFS. Example alternative structures - the default list of files
38+
* by seqNum; levelDB one sorted by level and seqNum.
39+
* <p/>
40+
* Notice that, all the states are only in memory, we do not persist anything here. The only place
41+
* where we throw an {@link IOException} is the {@link #getSplitPoint()} method, where we need to
42+
* read startKey, endKey etc, which may lead to an {@link IOException}.
43+
* <p/>
4144
* Implementations are assumed to be not thread safe.
4245
*/
4346
@InterfaceAudience.Private
@@ -52,22 +55,20 @@ public interface StoreFileManager {
5255
* Adds new files, either for from MemStore flush or bulk insert, into the structure.
5356
* @param sfs New store files.
5457
*/
55-
void insertNewFiles(Collection<HStoreFile> sfs) throws IOException;
58+
void insertNewFiles(Collection<HStoreFile> sfs);
5659

5760
/**
5861
* Adds only the new compaction results into the structure.
5962
* @param compactedFiles The input files for the compaction.
6063
* @param results The resulting files for the compaction.
6164
*/
62-
void addCompactionResults(
63-
Collection<HStoreFile> compactedFiles, Collection<HStoreFile> results) throws IOException;
65+
void addCompactionResults(Collection<HStoreFile> compactedFiles, Collection<HStoreFile> results);
6466

6567
/**
6668
* Remove the compacted files
6769
* @param compactedFiles the list of compacted files
68-
* @throws IOException
6970
*/
70-
void removeCompactedFiles(Collection<HStoreFile> compactedFiles) throws IOException;
71+
void removeCompactedFiles(Collection<HStoreFile> compactedFiles);
7172

7273
/**
7374
* Clears all the files currently in use and returns them.
@@ -145,7 +146,6 @@ Iterator<HStoreFile> updateCandidateFilesForRowKeyBefore(Iterator<HStoreFile> ca
145146
/**
146147
* Gets the split point for the split of this set of store files (approx. middle).
147148
* @return The mid-point if possible.
148-
* @throws IOException
149149
*/
150150
Optional<byte[]> getSplitPoint() throws IOException;
151151

hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/StripeStoreFileManager.java

Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,9 @@ public int getCompactedFilesCount() {
152152
}
153153

154154
@Override
155-
public void insertNewFiles(Collection<HStoreFile> sfs) throws IOException {
155+
public void insertNewFiles(Collection<HStoreFile> sfs) {
156156
CompactionOrFlushMergeCopy cmc = new CompactionOrFlushMergeCopy(true);
157-
// Passing null does not cause NPE??
158-
cmc.mergeResults(null, sfs);
157+
cmc.mergeResults(Collections.emptyList(), sfs);
159158
debugDumpState("Added new files");
160159
}
161160

@@ -321,11 +320,11 @@ public Collection<HStoreFile> getFilesForScan(byte[] startRow, boolean includeSt
321320
}
322321

323322
@Override
324-
public void addCompactionResults(
325-
Collection<HStoreFile> compactedFiles, Collection<HStoreFile> results) throws IOException {
323+
public void addCompactionResults(Collection<HStoreFile> compactedFiles,
324+
Collection<HStoreFile> results) {
326325
// See class comment for the assumptions we make here.
327-
LOG.debug("Attempting to merge compaction results: " + compactedFiles.size()
328-
+ " files replaced by " + results.size());
326+
LOG.debug("Attempting to merge compaction results: " + compactedFiles.size() +
327+
" files replaced by " + results.size());
329328
// In order to be able to fail in the middle of the operation, we'll operate on lazy
330329
// copies and apply the result at the end.
331330
CompactionOrFlushMergeCopy cmc = new CompactionOrFlushMergeCopy(false);
@@ -345,7 +344,7 @@ private void markCompactedAway(Collection<HStoreFile> compactedFiles) {
345344
}
346345

347346
@Override
348-
public void removeCompactedFiles(Collection<HStoreFile> compactedFiles) throws IOException {
347+
public void removeCompactedFiles(Collection<HStoreFile> compactedFiles) {
349348
// See class comment for the assumptions we make here.
350349
LOG.debug("Attempting to delete compaction results: " + compactedFiles.size());
351350
// In order to be able to fail in the middle of the operation, we'll operate on lazy
@@ -728,13 +727,15 @@ public CompactionOrFlushMergeCopy(boolean isFlush) {
728727
this.isFlush = isFlush;
729728
}
730729

731-
private void mergeResults(Collection<HStoreFile> compactedFiles, Collection<HStoreFile> results)
732-
throws IOException {
730+
private void mergeResults(Collection<HStoreFile> compactedFiles,
731+
Collection<HStoreFile> results) {
733732
assert this.compactedFiles == null && this.results == null;
734733
this.compactedFiles = compactedFiles;
735734
this.results = results;
736735
// Do logical processing.
737-
if (!isFlush) removeCompactedFiles();
736+
if (!isFlush) {
737+
removeCompactedFiles();
738+
}
738739
TreeMap<byte[], HStoreFile> newStripes = processResults();
739740
if (newStripes != null) {
740741
processNewCandidateStripes(newStripes);
@@ -745,7 +746,7 @@ private void mergeResults(Collection<HStoreFile> compactedFiles, Collection<HSto
745746
updateMetadataMaps();
746747
}
747748

748-
private void deleteResults(Collection<HStoreFile> compactedFiles) throws IOException {
749+
private void deleteResults(Collection<HStoreFile> compactedFiles) {
749750
this.compactedFiles = compactedFiles;
750751
// Create new state and update parent.
751752
State state = createNewState(true);
@@ -828,11 +829,11 @@ private final ArrayList<HStoreFile> getLevel0Copy() {
828829
}
829830

830831
/**
831-
* Process new files, and add them either to the structure of existing stripes,
832-
* or to the list of new candidate stripes.
832+
* Process new files, and add them either to the structure of existing stripes, or to the list
833+
* of new candidate stripes.
833834
* @return New candidate stripes.
834835
*/
835-
private TreeMap<byte[], HStoreFile> processResults() throws IOException {
836+
private TreeMap<byte[], HStoreFile> processResults() {
836837
TreeMap<byte[], HStoreFile> newStripes = null;
837838
for (HStoreFile sf : this.results) {
838839
byte[] startRow = startOf(sf), endRow = endOf(sf);
@@ -859,8 +860,9 @@ private TreeMap<byte[], HStoreFile> processResults() throws IOException {
859860
}
860861
HStoreFile oldSf = newStripes.put(endRow, sf);
861862
if (oldSf != null) {
862-
throw new IOException("Compactor has produced multiple files for the stripe ending in ["
863-
+ Bytes.toString(endRow) + "], found " + sf.getPath() + " and " + oldSf.getPath());
863+
throw new IllegalStateException(
864+
"Compactor has produced multiple files for the stripe ending in [" +
865+
Bytes.toString(endRow) + "], found " + sf.getPath() + " and " + oldSf.getPath());
864866
}
865867
}
866868
return newStripes;
@@ -869,7 +871,7 @@ private TreeMap<byte[], HStoreFile> processResults() throws IOException {
869871
/**
870872
* Remove compacted files.
871873
*/
872-
private void removeCompactedFiles() throws IOException {
874+
private void removeCompactedFiles() {
873875
for (HStoreFile oldFile : this.compactedFiles) {
874876
byte[] oldEndRow = endOf(oldFile);
875877
List<HStoreFile> source = null;
@@ -878,13 +880,14 @@ private void removeCompactedFiles() throws IOException {
878880
} else {
879881
int stripeIndex = findStripeIndexByEndRow(oldEndRow);
880882
if (stripeIndex < 0) {
881-
throw new IOException("An allegedly compacted file [" + oldFile + "] does not belong"
882-
+ " to a known stripe (end row - [" + Bytes.toString(oldEndRow) + "])");
883+
throw new IllegalStateException(
884+
"An allegedly compacted file [" + oldFile + "] does not belong" +
885+
" to a known stripe (end row - [" + Bytes.toString(oldEndRow) + "])");
883886
}
884887
source = getStripeCopy(stripeIndex);
885888
}
886889
if (!source.remove(oldFile)) {
887-
throw new IOException("An allegedly compacted file [" + oldFile + "] was not found");
890+
LOG.warn("An allegedly compacted file [{}] was not found", oldFile);
888891
}
889892
}
890893
}
@@ -894,16 +897,15 @@ private void removeCompactedFiles() throws IOException {
894897
* new candidate stripes/removes old stripes; produces new set of stripe end rows.
895898
* @param newStripes New stripes - files by end row.
896899
*/
897-
private void processNewCandidateStripes(
898-
TreeMap<byte[], HStoreFile> newStripes) throws IOException {
900+
private void processNewCandidateStripes(TreeMap<byte[], HStoreFile> newStripes) {
899901
// Validate that the removed and added aggregate ranges still make for a full key space.
900902
boolean hasStripes = !this.stripeFiles.isEmpty();
901903
this.stripeEndRows = new ArrayList<>(Arrays.asList(StripeStoreFileManager.this.state.stripeEndRows));
902904
int removeFrom = 0;
903905
byte[] firstStartRow = startOf(newStripes.firstEntry().getValue());
904906
byte[] lastEndRow = newStripes.lastKey();
905907
if (!hasStripes && (!isOpen(firstStartRow) || !isOpen(lastEndRow))) {
906-
throw new IOException("Newly created stripes do not cover the entire key space.");
908+
throw new IllegalStateException("Newly created stripes do not cover the entire key space.");
907909
}
908910

909911
boolean canAddNewStripes = true;
@@ -915,11 +917,15 @@ private void processNewCandidateStripes(
915917
removeFrom = 0;
916918
} else {
917919
removeFrom = findStripeIndexByEndRow(firstStartRow);
918-
if (removeFrom < 0) throw new IOException("Compaction is trying to add a bad range.");
920+
if (removeFrom < 0) {
921+
throw new IllegalStateException("Compaction is trying to add a bad range.");
922+
}
919923
++removeFrom;
920924
}
921925
int removeTo = findStripeIndexByEndRow(lastEndRow);
922-
if (removeTo < 0) throw new IOException("Compaction is trying to add a bad range.");
926+
if (removeTo < 0) {
927+
throw new IllegalStateException("Compaction is trying to add a bad range.");
928+
}
923929
// See if there are files in the stripes we are trying to replace.
924930
ArrayList<HStoreFile> conflictingFiles = new ArrayList<>();
925931
for (int removeIndex = removeTo; removeIndex >= removeFrom; --removeIndex) {
@@ -961,7 +967,9 @@ private void processNewCandidateStripes(
961967
}
962968
}
963969

964-
if (!canAddNewStripes) return; // Files were already put into L0.
970+
if (!canAddNewStripes) {
971+
return; // Files were already put into L0.
972+
}
965973

966974
// Now, insert new stripes. The total ranges match, so we can insert where we removed.
967975
byte[] previousEndRow = null;
@@ -972,8 +980,8 @@ private void processNewCandidateStripes(
972980
assert !isOpen(previousEndRow);
973981
byte[] startRow = startOf(newStripe.getValue());
974982
if (!rowEquals(previousEndRow, startRow)) {
975-
throw new IOException("The new stripes produced by "
976-
+ (isFlush ? "flush" : "compaction") + " are not contiguous");
983+
throw new IllegalStateException("The new stripes produced by " +
984+
(isFlush ? "flush" : "compaction") + " are not contiguous");
977985
}
978986
}
979987
// Add the new stripe.

hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestStripeStoreFileManager.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@
2121
import static org.junit.Assert.assertArrayEquals;
2222
import static org.junit.Assert.assertEquals;
2323
import static org.junit.Assert.assertFalse;
24+
import static org.junit.Assert.assertThrows;
2425
import static org.junit.Assert.assertTrue;
25-
import static org.junit.Assert.fail;
26+
2627
import java.io.IOException;
2728
import java.util.ArrayList;
2829
import java.util.Arrays;
@@ -542,14 +543,10 @@ private void testPriorityScenario(int expectedPriority,
542543
}
543544

544545
private void verifyInvalidCompactionScenario(StripeStoreFileManager manager,
545-
ArrayList<HStoreFile> filesToCompact, ArrayList<HStoreFile> filesToInsert) throws Exception {
546+
ArrayList<HStoreFile> filesToCompact, ArrayList<HStoreFile> filesToInsert) throws Exception {
546547
Collection<HStoreFile> allFiles = manager.getStorefiles();
547-
try {
548-
manager.addCompactionResults(filesToCompact, filesToInsert);
549-
fail("Should have thrown");
550-
} catch (IOException ex) {
551-
// Ignore it.
552-
}
548+
assertThrows(IllegalStateException.class,
549+
() -> manager.addCompactionResults(filesToCompact, filesToInsert));
553550
verifyAllFiles(manager, allFiles); // must have the same files.
554551
}
555552

0 commit comments

Comments
 (0)