From 324a2cfeb4ee7f85c53635d1bb068a2bd0780163 Mon Sep 17 00:00:00 2001 From: Michael Stack Date: Thu, 1 Mar 2012 06:59:51 +0000 Subject: [PATCH] HBASE-5454 Refuse operations from Admin before master is initialized git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1295433 13f79535-47bb-0310-9956-ffa450edef68 --- .../hadoop/hbase/PleaseHoldException.java | 7 ++++--- .../apache/hadoop/hbase/master/HMaster.java | 18 ++++++++++++++++-- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/apache/hadoop/hbase/PleaseHoldException.java b/src/main/java/org/apache/hadoop/hbase/PleaseHoldException.java index e3a9315fd49..309dca41343 100644 --- a/src/main/java/org/apache/hadoop/hbase/PleaseHoldException.java +++ b/src/main/java/org/apache/hadoop/hbase/PleaseHoldException.java @@ -22,9 +22,10 @@ package org.apache.hadoop.hbase; import java.io.IOException; /** - * This exception is thrown by the master when a region server was shut down - * and restarted so fast that the master still hasn't processed the server - * shutdown of the first instance. + * This exception is thrown by the master when a region server was shut down and + * restarted so fast that the master still hasn't processed the server shutdown + * of the first instance, or when master is initializing and client call admin + * operations */ @SuppressWarnings("serial") public class PleaseHoldException extends IOException { diff --git a/src/main/java/org/apache/hadoop/hbase/master/HMaster.java b/src/main/java/org/apache/hadoop/hbase/master/HMaster.java index fe102ab3bc9..3e4b4d048cf 100644 --- a/src/main/java/org/apache/hadoop/hbase/master/HMaster.java +++ b/src/main/java/org/apache/hadoop/hbase/master/HMaster.java @@ -26,16 +26,15 @@ import java.net.InetAddress; import java.net.InetSocketAddress; import java.util.ArrayList; import java.util.HashMap; -import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.util.concurrent.Executors; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicReference; import javax.management.ObjectName; @@ -50,6 +49,7 @@ import org.apache.hadoop.hbase.HRegionInfo; import org.apache.hadoop.hbase.HServerLoad; import org.apache.hadoop.hbase.HTableDescriptor; import org.apache.hadoop.hbase.MasterNotRunningException; +import org.apache.hadoop.hbase.PleaseHoldException; import org.apache.hadoop.hbase.Server; import org.apache.hadoop.hbase.ServerName; import org.apache.hadoop.hbase.TableDescriptors; @@ -1178,6 +1178,7 @@ Server { @Override public void deleteTable(final byte [] tableName) throws IOException { + checkInitialized(); if (cpHost != null) { cpHost.preDeleteTable(tableName); } @@ -1240,6 +1241,7 @@ Server { public void addColumn(byte [] tableName, HColumnDescriptor column) throws IOException { + checkInitialized(); if (cpHost != null) { if (cpHost.preAddColumn(tableName, column)) { return; @@ -1254,6 +1256,7 @@ Server { public void modifyColumn(byte [] tableName, HColumnDescriptor descriptor) throws IOException { + checkInitialized(); if (cpHost != null) { if (cpHost.preModifyColumn(tableName, descriptor)) { return; @@ -1268,6 +1271,7 @@ Server { public void deleteColumn(final byte [] tableName, final byte [] c) throws IOException { + checkInitialized(); if (cpHost != null) { if (cpHost.preDeleteColumn(tableName, c)) { return; @@ -1281,6 +1285,7 @@ Server { } public void enableTable(final byte [] tableName) throws IOException { + checkInitialized(); if (cpHost != null) { cpHost.preEnableTable(tableName); } @@ -1293,6 +1298,7 @@ Server { } public void disableTable(final byte [] tableName) throws IOException { + checkInitialized(); if (cpHost != null) { cpHost.preDisableTable(tableName); } @@ -1342,6 +1348,7 @@ Server { @Override public void modifyTable(final byte[] tableName, HTableDescriptor htd) throws IOException { + checkInitialized(); if (cpHost != null) { cpHost.preModifyTable(tableName, htd); } @@ -1648,6 +1655,11 @@ Server { return this.abort; } + void checkInitialized() throws PleaseHoldException { + if (!this.initialized) { + throw new PleaseHoldException("Master is initializing"); + } + } /** * Report whether this master is currently the active master or not. @@ -1683,6 +1695,7 @@ Server { @Override public void assign(final byte [] regionName)throws IOException { + checkInitialized(); Pair pair = MetaReader.getRegion(this.catalogTracker, regionName); if (pair == null) throw new UnknownRegionException(Bytes.toString(regionName)); @@ -1706,6 +1719,7 @@ Server { @Override public void unassign(final byte [] regionName, final boolean force) throws IOException { + checkInitialized(); Pair pair = MetaReader.getRegion(this.catalogTracker, regionName); if (pair == null) throw new UnknownRegionException(Bytes.toString(regionName));