Skip to content

Commit 0b3918f

Browse files
authored
HBASE-24021 Fail fast when bulkLoadHFiles method catch some IOException (#1343)
Signed-off-by: Guanghao Zhang <zghao@apache.org>
1 parent 4ddf55d commit 0b3918f

File tree

2 files changed

+28
-15
lines changed

2 files changed

+28
-15
lines changed

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

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,6 @@
179179
import org.apache.hadoop.hbase.wal.WALKeyImpl;
180180
import org.apache.hadoop.hbase.wal.WALSplitUtil;
181181
import org.apache.hadoop.hbase.wal.WALSplitUtil.MutationReplay;
182-
import org.apache.hadoop.io.MultipleIOException;
183182
import org.apache.hadoop.util.StringUtils;
184183
import org.apache.htrace.core.TraceScope;
185184
import org.apache.yetus.audience.InterfaceAudience;
@@ -6315,8 +6314,8 @@ String prepareBulkLoad(byte[] family, String srcPath, boolean copyFile)
63156314
* @throws IOException if failed unrecoverably.
63166315
*/
63176316
public Map<byte[], List<Path>> bulkLoadHFiles(Collection<Pair<byte[], String>> familyPaths,
6318-
boolean assignSeqId, BulkLoadListener bulkLoadListener,
6319-
boolean copyFile, List<String> clusterIds, boolean replicate) throws IOException {
6317+
boolean assignSeqId, BulkLoadListener bulkLoadListener, boolean copyFile,
6318+
List<String> clusterIds, boolean replicate) throws IOException {
63206319
long seqId = -1;
63216320
Map<byte[], List<Path>> storeFiles = new TreeMap<>(Bytes.BYTES_COMPARATOR);
63226321
Map<String, Long> storeFilesSizes = new HashMap<>();
@@ -6328,19 +6327,18 @@ public Map<byte[], List<Path>> bulkLoadHFiles(Collection<Pair<byte[], String>> f
63286327
this.writeRequestsCount.increment();
63296328

63306329
// There possibly was a split that happened between when the split keys
6331-
// were gathered and before the HRegion's write lock was taken. We need
6330+
// were gathered and before the HRegion's write lock was taken. We need
63326331
// to validate the HFile region before attempting to bulk load all of them
6333-
List<IOException> ioes = new ArrayList<>();
6332+
IOException ioException = null;
63346333
List<Pair<byte[], String>> failures = new ArrayList<>();
63356334
for (Pair<byte[], String> p : familyPaths) {
63366335
byte[] familyName = p.getFirst();
63376336
String path = p.getSecond();
63386337

63396338
HStore store = getStore(familyName);
63406339
if (store == null) {
6341-
IOException ioe = new org.apache.hadoop.hbase.DoNotRetryIOException(
6340+
ioException = new org.apache.hadoop.hbase.DoNotRetryIOException(
63426341
"No such column family " + Bytes.toStringBinary(familyName));
6343-
ioes.add(ioe);
63446342
} else {
63456343
try {
63466344
store.assertBulkLoadHFileOk(new Path(path));
@@ -6349,18 +6347,16 @@ public Map<byte[], List<Path>> bulkLoadHFiles(Collection<Pair<byte[], String>> f
63496347
failures.add(p);
63506348
} catch (IOException ioe) {
63516349
// unrecoverable (hdfs problem)
6352-
ioes.add(ioe);
6350+
ioException = ioe;
63536351
}
63546352
}
6355-
}
63566353

6357-
// validation failed because of some sort of IO problem.
6358-
if (ioes.size() != 0) {
6359-
IOException e = MultipleIOException.createIOException(ioes);
6360-
LOG.error("There were one or more IO errors when checking if the bulk load is ok.", e);
6361-
throw e;
6354+
// validation failed because of some sort of IO problem.
6355+
if (ioException != null) {
6356+
LOG.error("There was IO error when checking if the bulk load is ok.", ioException);
6357+
throw ioException;
6358+
}
63626359
}
6363-
63646360
// validation failed, bail out before doing anything permanent.
63656361
if (failures.size() != 0) {
63666362
StringBuilder list = new StringBuilder();

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ public class TestBulkLoad {
9595
private final byte[] randomBytes = new byte[100];
9696
private final byte[] family1 = Bytes.toBytes("family1");
9797
private final byte[] family2 = Bytes.toBytes("family2");
98+
private final byte[] family3 = Bytes.toBytes("family3");
9899

99100
@Rule
100101
public TestName name = new TestName();
@@ -204,6 +205,13 @@ public void shouldCrashIfBulkLoadFamiliesNotInTable() throws IOException {
204205
null);
205206
}
206207

208+
// after HBASE-24021 will throw DoNotRetryIOException, not MultipleIOException
209+
@Test(expected = DoNotRetryIOException.class)
210+
public void shouldCrashIfBulkLoadMultiFamiliesNotInTable() throws IOException {
211+
testRegionWithFamilies(family1).bulkLoadHFiles(withFamilyPathsFor(family1, family2, family3),
212+
false, null);
213+
}
214+
207215
@Test(expected = DoNotRetryIOException.class)
208216
public void bulkHLogShouldThrowErrorWhenFamilySpecifiedAndHFileExistsButNotInTableDescriptor()
209217
throws IOException {
@@ -223,6 +231,15 @@ public void shouldThrowErrorIfHFileDoesNotExist() throws IOException {
223231
testRegionWithFamilies(family1).bulkLoadHFiles(list, false, null);
224232
}
225233

234+
// after HBASE-24021 will throw FileNotFoundException, not MultipleIOException
235+
@Test(expected = FileNotFoundException.class)
236+
public void shouldThrowErrorIfMultiHFileDoesNotExist() throws IOException {
237+
List<Pair<byte[], String>> list = new ArrayList<>();
238+
list.addAll(asList(withMissingHFileForFamily(family1)));
239+
list.addAll(asList(withMissingHFileForFamily(family2)));
240+
testRegionWithFamilies(family1, family2).bulkLoadHFiles(list, false, null);
241+
}
242+
226243
private Pair<byte[], String> withMissingHFileForFamily(byte[] family) {
227244
return new Pair<>(family, getNotExistFilePath());
228245
}

0 commit comments

Comments
 (0)