HBASE-23177 If fail to open reference because FNFE, make it plain it is a Reference

Signed-off-by: Duo Zhang <zhangduo@apache.org>
Signed-off-by: Sean Busbey <busbey@apache.org>
Signed-off-by: Viraj Jasani <virajjasani007@gmail.com>
This commit is contained in:
stack 2019-10-15 15:32:56 -07:00
parent 395cfceb0b
commit 820a416f04
4 changed files with 62 additions and 8 deletions

View File

@ -362,7 +362,7 @@ public class FileLink {
@Override @Override
public String toString() { public String toString() {
StringBuilder str = new StringBuilder(getClass().getName()); StringBuilder str = new StringBuilder(getClass().getSimpleName());
str.append(" locations=["); str.append(" locations=[");
for (int i = 0; i < locations.length; ++i) { for (int i = 0; i < locations.length; ++i) {
if (i > 0) str.append(", "); if (i > 0) str.append(", ");
@ -393,7 +393,7 @@ public class FileLink {
return locations[i]; return locations[i];
} }
} }
throw new FileNotFoundException("Unable to open link: " + this); throw new FileNotFoundException(toString());
} }
/** /**
@ -416,7 +416,7 @@ public class FileLink {
} }
/** /**
* Handle exceptions which are threw when access locations of file link * Handle exceptions which are thrown when access locations of file link
* @param fileLink the file link * @param fileLink the file link
* @param newException the exception caught by access the current location * @param newException the exception caught by access the current location
* @param previousException the previous exception caught by access the other locations * @param previousException the previous exception caught by access the other locations
@ -436,7 +436,7 @@ public class FileLink {
if (newException instanceof FileNotFoundException) { if (newException instanceof FileNotFoundException) {
// Try another file location // Try another file location
if (previousException == null) { if (previousException == null) {
previousException = new FileNotFoundException("Unable to open link: " + fileLink); previousException = new FileNotFoundException(fileLink.toString());
} }
} else if (newException instanceof AccessControlException) { } else if (newException instanceof AccessControlException) {
// Try another file location // Try another file location

View File

@ -70,6 +70,9 @@ public class HFileLink extends FileLink {
* Region name is ([a-f0-9]+), so '-' is an invalid character for the region name. * Region name is ([a-f0-9]+), so '-' is an invalid character for the region name.
* HFile is ([0-9a-f]+(?:_SeqId_[0-9]+_)?) covering the plain hfiles (uuid) * HFile is ([0-9a-f]+(?:_SeqId_[0-9]+_)?) covering the plain hfiles (uuid)
* and the bulk loaded (_SeqId_[0-9]+_) hfiles. * and the bulk loaded (_SeqId_[0-9]+_) hfiles.
*
* <p>Here is an example name: /hbase/test/0123/cf/testtb=4567-abcd where 'testtb' is table name
* and '4567' is region name and 'abcd' is filename.
*/ */
public static final String LINK_NAME_REGEX = public static final String LINK_NAME_REGEX =
String.format("(?:(?:%s=)?)%s=%s-%s", String.format("(?:(?:%s=)?)%s=%s-%s",

View File

@ -285,7 +285,16 @@ public class StoreFileInfo {
} else if (this.reference != null) { } else if (this.reference != null) {
// HFile Reference // HFile Reference
Path referencePath = getReferredToFile(this.getPath()); Path referencePath = getReferredToFile(this.getPath());
in = new FSDataInputStreamWrapper(fs, referencePath, doDropBehind, readahead); try {
in = new FSDataInputStreamWrapper(fs, referencePath, doDropBehind, readahead);
} catch (FileNotFoundException fnfe) {
// Intercept the exception so can insert more info about the Reference; otherwise
// exception just complains about some random file -- operator doesn't realize it
// other end of a Reference
FileNotFoundException newFnfe = new FileNotFoundException(toString());
newFnfe.initCause(fnfe);
throw newFnfe;
}
status = fs.getFileStatus(referencePath); status = fs.getFileStatus(referencePath);
} else { } else {
in = new FSDataInputStreamWrapper(fs, this.getPath(), doDropBehind, readahead); in = new FSDataInputStreamWrapper(fs, this.getPath(), doDropBehind, readahead);

View File

@ -1,4 +1,4 @@
/** /*
* Licensed to the Apache Software Foundation (ASF) under one * Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file * or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information * distributed with this work for additional information
@ -17,19 +17,27 @@
*/ */
package org.apache.hadoop.hbase.regionserver; package org.apache.hadoop.hbase.regionserver;
import static org.junit.Assert.*; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.io.HFileLink; import org.apache.hadoop.hbase.io.HFileLink;
import org.apache.hadoop.hbase.io.Reference;
import org.apache.hadoop.hbase.testclassification.RegionServerTests; import org.apache.hadoop.hbase.testclassification.RegionServerTests;
import org.apache.hadoop.hbase.testclassification.SmallTests; import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.junit.ClassRule; import org.junit.ClassRule;
import org.junit.Test; import org.junit.Test;
import org.junit.experimental.categories.Category; import org.junit.experimental.categories.Category;
import static junit.framework.TestCase.assertTrue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
/** /**
* Test HStoreFile * Test HStoreFile
*/ */
@ -88,5 +96,39 @@ public class TestStoreFileInfo {
assertEquals(info1, info2); assertEquals(info1, info2);
assertEquals(info1.hashCode(), info2.hashCode()); assertEquals(info1.hashCode(), info2.hashCode());
} }
@Test
public void testOpenErrorMessageHFileLink() throws IOException, IllegalStateException {
// Test file link exception
// Try to open nonsense hfilelink. Make sure exception is from HFileLink.
Path p = new Path("/hbase/test/0123/cf/testtb=4567-abcd");
try (FileSystem fs = FileSystem.get(TEST_UTIL.getConfiguration())) {
StoreFileInfo sfi = new StoreFileInfo(TEST_UTIL.getConfiguration(), fs, p);
try {
sfi.open(fs, null, false, 1000, true, new AtomicInteger(), false);
throw new IllegalStateException();
} catch (FileNotFoundException fnfe) {
assertTrue(fnfe.getMessage().contains(HFileLink.class.getSimpleName()));
}
}
}
@Test
public void testOpenErrorMessageReference() throws IOException {
// Test file link exception
// Try to open nonsense hfilelink. Make sure exception is from HFileLink.
Path p = new Path(TEST_UTIL.getDataTestDirOnTestFS(),"4567.abcd");
FileSystem fs = FileSystem.get(TEST_UTIL.getConfiguration());
fs.mkdirs(p.getParent());
Reference r = Reference.createBottomReference(HConstants.EMPTY_START_ROW);
r.write(fs, p);
StoreFileInfo sfi = new StoreFileInfo(TEST_UTIL.getConfiguration(), fs, p);
try {
sfi.open(fs, null, false, 1000, true, new AtomicInteger(), false);
throw new IllegalStateException();
} catch (FileNotFoundException fnfe) {
assertTrue(fnfe.getMessage().contains("->"));
}
}
} }