HBASE-12243 HBaseFsck should auto set ignorePreCheckPermission to true if no fix option is set (Yi Deng)

Signed-off-by: Jonathan M Hsieh <jmhsieh@apache.org>
This commit is contained in:
Yi Deng 2014-10-13 18:31:04 -07:00 committed by Jonathan M Hsieh
parent 6c70f4f7f7
commit e545953c32
2 changed files with 34 additions and 5 deletions

View File

@ -78,7 +78,6 @@ import org.apache.hadoop.hbase.ServerName;
import org.apache.hadoop.hbase.TableDescriptor; import org.apache.hadoop.hbase.TableDescriptor;
import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.ZooKeeperConnectionException; import org.apache.hadoop.hbase.ZooKeeperConnectionException;
import org.apache.hadoop.hbase.MetaTableAccessor;
import org.apache.hadoop.hbase.client.Admin; import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.Delete; import org.apache.hadoop.hbase.client.Delete;
import org.apache.hadoop.hbase.client.Get; import org.apache.hadoop.hbase.client.Get;
@ -119,7 +118,6 @@ import org.apache.hadoop.hbase.security.AccessDeniedException;
import org.apache.hadoop.hdfs.protocol.AlreadyBeingCreatedException; import org.apache.hadoop.hdfs.protocol.AlreadyBeingCreatedException;
import org.apache.hadoop.io.IOUtils; import org.apache.hadoop.io.IOUtils;
import org.apache.hadoop.ipc.RemoteException; import org.apache.hadoop.ipc.RemoteException;
import org.apache.hadoop.security.AccessControlException;
import org.apache.hadoop.security.UserGroupInformation; import org.apache.hadoop.security.UserGroupInformation;
import org.apache.hadoop.util.ReflectionUtils; import org.apache.hadoop.util.ReflectionUtils;
import org.apache.hadoop.util.Tool; import org.apache.hadoop.util.Tool;
@ -228,6 +226,7 @@ public class HBaseFsck extends Configured {
private boolean fixReferenceFiles = false; // fix lingering reference store file private boolean fixReferenceFiles = false; // fix lingering reference store file
private boolean fixEmptyMetaCells = false; // fix (remove) empty REGIONINFO_QUALIFIER rows private boolean fixEmptyMetaCells = false; // fix (remove) empty REGIONINFO_QUALIFIER rows
private boolean fixTableLocks = false; // fix table locks which are expired private boolean fixTableLocks = false; // fix table locks which are expired
private boolean fixAny = false; // Set to true if any of the fix is required.
// limit checking/fixes to listed tables, if empty attempt to check/fix all // limit checking/fixes to listed tables, if empty attempt to check/fix all
// hbase:meta are always checked // hbase:meta are always checked
@ -380,6 +379,7 @@ public class HBaseFsck extends Configured {
// kill the hbck with a ctrl-c, we want to cleanup the lock so that // kill the hbck with a ctrl-c, we want to cleanup the lock so that
// it is available for further calls // it is available for further calls
Runtime.getRuntime().addShutdownHook(new Thread() { Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() { public void run() {
unlockHbck(); unlockHbck();
} }
@ -1133,7 +1133,7 @@ public class HBaseFsck extends Configured {
FSTableDescriptors fstd = new FSTableDescriptors(getConf()); FSTableDescriptors fstd = new FSTableDescriptors(getConf());
while (iter.hasNext()) { while (iter.hasNext()) {
Entry<TableName, Set<String>> entry = Entry<TableName, Set<String>> entry =
(Entry<TableName, Set<String>>) iter.next(); iter.next();
TableName tableName = entry.getKey(); TableName tableName = entry.getKey();
LOG.info("Trying to fix orphan table error: " + tableName); LOG.info("Trying to fix orphan table error: " + tableName);
if (j < htds.length) { if (j < htds.length) {
@ -3401,7 +3401,7 @@ public class HBaseFsck extends Configured {
static ErrorReporter getErrorReporter( static ErrorReporter getErrorReporter(
final Configuration conf) throws ClassNotFoundException { final Configuration conf) throws ClassNotFoundException {
Class<? extends ErrorReporter> reporter = conf.getClass("hbasefsck.errorreporter", PrintingErrorReporter.class, ErrorReporter.class); Class<? extends ErrorReporter> reporter = conf.getClass("hbasefsck.errorreporter", PrintingErrorReporter.class, ErrorReporter.class);
return (ErrorReporter)ReflectionUtils.newInstance(reporter, conf); return ReflectionUtils.newInstance(reporter, conf);
} }
public interface ErrorReporter { public interface ErrorReporter {
@ -3776,6 +3776,7 @@ public class HBaseFsck extends Configured {
*/ */
public void setFixTableLocks(boolean shouldFix) { public void setFixTableLocks(boolean shouldFix) {
fixTableLocks = shouldFix; fixTableLocks = shouldFix;
fixAny |= shouldFix;
} }
/** /**
@ -3798,6 +3799,7 @@ public class HBaseFsck extends Configured {
*/ */
public void setFixAssignments(boolean shouldFix) { public void setFixAssignments(boolean shouldFix) {
fixAssignments = shouldFix; fixAssignments = shouldFix;
fixAny |= shouldFix;
} }
boolean shouldFixAssignments() { boolean shouldFixAssignments() {
@ -3806,6 +3808,7 @@ public class HBaseFsck extends Configured {
public void setFixMeta(boolean shouldFix) { public void setFixMeta(boolean shouldFix) {
fixMeta = shouldFix; fixMeta = shouldFix;
fixAny |= shouldFix;
} }
boolean shouldFixMeta() { boolean shouldFixMeta() {
@ -3814,6 +3817,7 @@ public class HBaseFsck extends Configured {
public void setFixEmptyMetaCells(boolean shouldFix) { public void setFixEmptyMetaCells(boolean shouldFix) {
fixEmptyMetaCells = shouldFix; fixEmptyMetaCells = shouldFix;
fixAny |= shouldFix;
} }
boolean shouldFixEmptyMetaCells() { boolean shouldFixEmptyMetaCells() {
@ -3830,6 +3834,7 @@ public class HBaseFsck extends Configured {
public void setFixHdfsHoles(boolean shouldFix) { public void setFixHdfsHoles(boolean shouldFix) {
fixHdfsHoles = shouldFix; fixHdfsHoles = shouldFix;
fixAny |= shouldFix;
} }
boolean shouldFixHdfsHoles() { boolean shouldFixHdfsHoles() {
@ -3838,6 +3843,7 @@ public class HBaseFsck extends Configured {
public void setFixTableOrphans(boolean shouldFix) { public void setFixTableOrphans(boolean shouldFix) {
fixTableOrphans = shouldFix; fixTableOrphans = shouldFix;
fixAny |= shouldFix;
} }
boolean shouldFixTableOrphans() { boolean shouldFixTableOrphans() {
@ -3846,6 +3852,7 @@ public class HBaseFsck extends Configured {
public void setFixHdfsOverlaps(boolean shouldFix) { public void setFixHdfsOverlaps(boolean shouldFix) {
fixHdfsOverlaps = shouldFix; fixHdfsOverlaps = shouldFix;
fixAny |= shouldFix;
} }
boolean shouldFixHdfsOverlaps() { boolean shouldFixHdfsOverlaps() {
@ -3854,6 +3861,7 @@ public class HBaseFsck extends Configured {
public void setFixHdfsOrphans(boolean shouldFix) { public void setFixHdfsOrphans(boolean shouldFix) {
fixHdfsOrphans = shouldFix; fixHdfsOrphans = shouldFix;
fixAny |= shouldFix;
} }
boolean shouldFixHdfsOrphans() { boolean shouldFixHdfsOrphans() {
@ -3862,6 +3870,7 @@ public class HBaseFsck extends Configured {
public void setFixVersionFile(boolean shouldFix) { public void setFixVersionFile(boolean shouldFix) {
fixVersionFile = shouldFix; fixVersionFile = shouldFix;
fixAny |= shouldFix;
} }
public boolean shouldFixVersionFile() { public boolean shouldFixVersionFile() {
@ -3878,6 +3887,7 @@ public class HBaseFsck extends Configured {
public void setFixSplitParents(boolean shouldFix) { public void setFixSplitParents(boolean shouldFix) {
fixSplitParents = shouldFix; fixSplitParents = shouldFix;
fixAny |= shouldFix;
} }
boolean shouldFixSplitParents() { boolean shouldFixSplitParents() {
@ -3886,6 +3896,7 @@ public class HBaseFsck extends Configured {
public void setFixReferenceFiles(boolean shouldFix) { public void setFixReferenceFiles(boolean shouldFix) {
fixReferenceFiles = shouldFix; fixReferenceFiles = shouldFix;
fixAny |= shouldFix;
} }
boolean shouldFixReferenceFiles() { boolean shouldFixReferenceFiles() {
@ -3893,7 +3904,7 @@ public class HBaseFsck extends Configured {
} }
public boolean shouldIgnorePreCheckPermission() { public boolean shouldIgnorePreCheckPermission() {
return ignorePreCheckPermission; return !fixAny || ignorePreCheckPermission;
} }
public void setIgnorePreCheckPermission(boolean ignorePreCheckPermission) { public void setIgnorePreCheckPermission(boolean ignorePreCheckPermission) {

View File

@ -110,6 +110,7 @@ import org.apache.hadoop.hbase.util.hbck.HbckTestingUtil;
import org.apache.hadoop.hbase.zookeeper.MetaTableLocator; import org.apache.hadoop.hbase.zookeeper.MetaTableLocator;
import org.apache.zookeeper.KeeperException; import org.apache.zookeeper.KeeperException;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Ignore; import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
@ -553,6 +554,7 @@ public class TestHBaseFsck {
class RunHbck implements Callable<HBaseFsck>{ class RunHbck implements Callable<HBaseFsck>{
boolean fail = true; boolean fail = true;
@Override
public HBaseFsck call(){ public HBaseFsck call(){
try{ try{
return doFsck(conf, false); return doFsck(conf, false);
@ -2553,4 +2555,20 @@ public class TestHBaseFsck {
@org.junit.Rule @org.junit.Rule
public TestName name = new TestName(); public TestName name = new TestName();
@Test
public void testReadOnlyProperty() throws Exception {
HBaseFsck hbck = doFsck(conf, false);
Assert.assertEquals("shouldIgnorePreCheckPermission", true,
hbck.shouldIgnorePreCheckPermission());
hbck = doFsck(conf, true);
Assert.assertEquals("shouldIgnorePreCheckPermission", false,
hbck.shouldIgnorePreCheckPermission());
hbck = doFsck(conf, true);
hbck.setIgnorePreCheckPermission(true);
Assert.assertEquals("shouldIgnorePreCheckPermission", true,
hbck.shouldIgnorePreCheckPermission());
}
} }