HBASE-15688 Use MasterServices directly instead of casting to HMaster when possible
This commit is contained in:
parent
bfca2a4606
commit
1ecb10ce07
|
@ -101,7 +101,7 @@ public interface MasterServices extends Server {
|
|||
* @return Master's instance of {@link MasterQuotaManager}
|
||||
*/
|
||||
MasterQuotaManager getMasterQuotaManager();
|
||||
|
||||
|
||||
/**
|
||||
* @return Master's instance of {@link RegionNormalizer}
|
||||
*/
|
||||
|
@ -287,6 +287,11 @@ public interface MasterServices extends Server {
|
|||
final HRegionInfo region_a, final HRegionInfo region_b, final boolean forcible, final User user
|
||||
) throws IOException;
|
||||
|
||||
/**
|
||||
* @return true if master is the active one
|
||||
*/
|
||||
boolean isActiveMaster();
|
||||
|
||||
/**
|
||||
* @return true if master is initialized
|
||||
*/
|
||||
|
@ -297,7 +302,7 @@ public interface MasterServices extends Server {
|
|||
* @param procId ID of the procedure
|
||||
* @param mayInterruptIfRunning if the proc completed at least one step, should it be aborted?
|
||||
* @return true if aborted, false if procedure already completed or does not exist
|
||||
* @throws IOException
|
||||
* @throws IOException
|
||||
*/
|
||||
public boolean abortProcedure(final long procId, final boolean mayInterruptIfRunning)
|
||||
throws IOException;
|
||||
|
|
|
@ -430,7 +430,7 @@ public class ServerManager {
|
|||
}
|
||||
// remove dead server with same hostname and port of newly checking in rs after master
|
||||
// initialization.See HBASE-5916 for more information.
|
||||
if ((this.services == null || ((HMaster) this.services).isInitialized())
|
||||
if ((this.services == null || this.services.isInitialized())
|
||||
&& this.deadservers.cleanPreviousInstance(serverName)) {
|
||||
// This server has now become alive after we marked it as dead.
|
||||
// We removed it's previous entry from the dead list to reflect it.
|
||||
|
|
|
@ -47,9 +47,9 @@ public class MasterProcedureEnv {
|
|||
|
||||
@InterfaceAudience.Private
|
||||
public static class WALStoreLeaseRecovery implements WALProcedureStore.LeaseRecovery {
|
||||
private final HMaster master;
|
||||
private final MasterServices master;
|
||||
|
||||
public WALStoreLeaseRecovery(final HMaster master) {
|
||||
public WALStoreLeaseRecovery(final MasterServices master) {
|
||||
this.master = master;
|
||||
}
|
||||
|
||||
|
@ -70,9 +70,9 @@ public class MasterProcedureEnv {
|
|||
@InterfaceAudience.Private
|
||||
public static class MasterProcedureStoreListener
|
||||
implements ProcedureStore.ProcedureStoreListener {
|
||||
private final HMaster master;
|
||||
private final MasterServices master;
|
||||
|
||||
public MasterProcedureStoreListener(final HMaster master) {
|
||||
public MasterProcedureStoreListener(final MasterServices master) {
|
||||
this.master = master;
|
||||
}
|
||||
|
||||
|
@ -83,7 +83,7 @@ public class MasterProcedureEnv {
|
|||
|
||||
@Override
|
||||
public void abortProcess() {
|
||||
master.abort("The Procedure Store lost the lease");
|
||||
master.abort("The Procedure Store lost the lease", null);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,329 @@
|
|||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.hadoop.hbase.master;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.hadoop.conf.Configuration;
|
||||
import org.apache.hadoop.hbase.ChoreService;
|
||||
import org.apache.hadoop.hbase.CoordinatedStateManager;
|
||||
import org.apache.hadoop.hbase.HColumnDescriptor;
|
||||
import org.apache.hadoop.hbase.HRegionInfo;
|
||||
import org.apache.hadoop.hbase.HTableDescriptor;
|
||||
import org.apache.hadoop.hbase.ProcedureInfo;
|
||||
import org.apache.hadoop.hbase.Server;
|
||||
import org.apache.hadoop.hbase.ServerName;
|
||||
import org.apache.hadoop.hbase.TableDescriptors;
|
||||
import org.apache.hadoop.hbase.TableName;
|
||||
import org.apache.hadoop.hbase.client.ClusterConnection;
|
||||
import org.apache.hadoop.hbase.executor.ExecutorService;
|
||||
import org.apache.hadoop.hbase.master.normalizer.RegionNormalizer;
|
||||
import org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv;
|
||||
import org.apache.hadoop.hbase.master.snapshot.SnapshotManager;
|
||||
import org.apache.hadoop.hbase.procedure.MasterProcedureManagerHost;
|
||||
import org.apache.hadoop.hbase.procedure2.ProcedureExecutor;
|
||||
import org.apache.hadoop.hbase.quotas.MasterQuotaManager;
|
||||
import org.apache.hadoop.hbase.security.User;
|
||||
import org.apache.hadoop.hbase.zookeeper.MetaTableLocator;
|
||||
import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import com.google.protobuf.Service;
|
||||
|
||||
public class MockNoopMasterServices implements MasterServices, Server {
|
||||
private final Configuration conf;
|
||||
|
||||
public MockNoopMasterServices() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
public MockNoopMasterServices(final Configuration conf) {
|
||||
this.conf = conf;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkTableModifiable(TableName tableName) throws IOException {
|
||||
//no-op
|
||||
}
|
||||
|
||||
@Override
|
||||
public long createTable(
|
||||
final HTableDescriptor desc,
|
||||
final byte[][] splitKeys,
|
||||
final long nonceGroup,
|
||||
final long nonce) throws IOException {
|
||||
// no-op
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AssignmentManager getAssignmentManager() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExecutorService getExecutorService() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChoreService getChoreService() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RegionNormalizer getRegionNormalizer() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MasterFileSystem getMasterFileSystem() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MasterCoprocessorHost getMasterCoprocessorHost() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MasterQuotaManager getMasterQuotaManager() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProcedureExecutor<MasterProcedureEnv> getMasterProcedureExecutor() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerManager getServerManager() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ZooKeeperWatcher getZooKeeper() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CoordinatedStateManager getCoordinatedStateManager() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetaTableLocator getMetaTableLocator() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClusterConnection getConnection() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Configuration getConfiguration() {
|
||||
return conf;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerName getServerName() {
|
||||
return ServerName.valueOf("mock.master", 12345, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void abort(String why, Throwable e) {
|
||||
//no-op
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAborted() {
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean stopped = false;
|
||||
|
||||
@Override
|
||||
public void stop(String why) {
|
||||
stopped = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStopped() {
|
||||
return stopped;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TableDescriptors getTableDescriptors() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isServerCrashProcessingEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean registerService(Service instance) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean abortProcedure(final long procId, final boolean mayInterruptIfRunning)
|
||||
throws IOException {
|
||||
return false; //To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ProcedureInfo> listProcedures() throws IOException {
|
||||
return null; //To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<HTableDescriptor> listTableDescriptorsByNamespace(String name) throws IOException {
|
||||
return null; //To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TableName> listTableNamesByNamespace(String name) throws IOException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long deleteTable(
|
||||
final TableName tableName,
|
||||
final long nonceGroup,
|
||||
final long nonce) throws IOException {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long truncateTable(
|
||||
final TableName tableName,
|
||||
final boolean preserveSplits,
|
||||
final long nonceGroup,
|
||||
final long nonce) throws IOException {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public long modifyTable(
|
||||
final TableName tableName,
|
||||
final HTableDescriptor descriptor,
|
||||
final long nonceGroup,
|
||||
final long nonce) throws IOException {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long enableTable(
|
||||
final TableName tableName,
|
||||
final long nonceGroup,
|
||||
final long nonce) throws IOException {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long disableTable(
|
||||
TableName tableName,
|
||||
final long nonceGroup,
|
||||
final long nonce) throws IOException {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long addColumn(final TableName tableName, final HColumnDescriptor columnDescriptor,
|
||||
final long nonceGroup, final long nonce) throws IOException {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long modifyColumn(final TableName tableName, final HColumnDescriptor descriptor,
|
||||
final long nonceGroup, final long nonce) throws IOException {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long deleteColumn(final TableName tableName, final byte[] columnName,
|
||||
final long nonceGroup, final long nonce) throws IOException {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TableLockManager getTableLockManager() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TableStateManager getTableStateManager() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispatchMergingRegions(HRegionInfo region_a, HRegionInfo region_b,
|
||||
boolean forcible, User user) throws IOException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActiveMaster() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInitialized() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getLastMajorCompactionTimestamp(TableName table) throws IOException {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getLastMajorCompactionTimestampForRegion(byte[] regionName) throws IOException {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClusterSchema getClusterSchema() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClusterConnection getClusterConnection() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LoadBalancer getLoadBalancer() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SnapshotManager getSnapshotManager() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MasterProcedureManagerHost getMasterProcedureManagerHost() {
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -64,8 +64,6 @@ import org.apache.hadoop.hbase.io.Reference;
|
|||
import org.apache.hadoop.hbase.master.CatalogJanitor.SplitParentFirstComparator;
|
||||
import org.apache.hadoop.hbase.master.normalizer.RegionNormalizer;
|
||||
import org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv;
|
||||
import org.apache.hadoop.hbase.master.snapshot.SnapshotManager;
|
||||
import org.apache.hadoop.hbase.procedure.MasterProcedureManagerHost;
|
||||
import org.apache.hadoop.hbase.procedure2.ProcedureExecutor;
|
||||
import org.apache.hadoop.hbase.protobuf.ProtobufUtil;
|
||||
import org.apache.hadoop.hbase.protobuf.generated.AdminProtos;
|
||||
|
@ -220,7 +218,7 @@ public class TestCatalogJanitor {
|
|||
/**
|
||||
* Mock MasterServices for tests below.
|
||||
*/
|
||||
class MockMasterServices implements MasterServices {
|
||||
class MockMasterServices extends MockNoopMasterServices {
|
||||
private final MasterFileSystem mfs;
|
||||
private final AssignmentManager asm;
|
||||
|
||||
|
@ -229,128 +227,21 @@ public class TestCatalogJanitor {
|
|||
this.asm = Mockito.mock(AssignmentManager.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkTableModifiable(TableName tableName) throws IOException {
|
||||
//no-op
|
||||
}
|
||||
|
||||
@Override
|
||||
public long createTable(
|
||||
final HTableDescriptor desc,
|
||||
final byte[][] splitKeys,
|
||||
final long nonceGroup,
|
||||
final long nonce) throws IOException {
|
||||
// no-op
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SnapshotManager getSnapshotManager() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MasterProcedureManagerHost getMasterProcedureManagerHost() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AssignmentManager getAssignmentManager() {
|
||||
return this.asm;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExecutorService getExecutorService() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChoreService getChoreService() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RegionNormalizer getRegionNormalizer() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MasterFileSystem getMasterFileSystem() {
|
||||
return this.mfs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MasterCoprocessorHost getMasterCoprocessorHost() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MasterQuotaManager getMasterQuotaManager() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProcedureExecutor<MasterProcedureEnv> getMasterProcedureExecutor() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerManager getServerManager() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ZooKeeperWatcher getZooKeeper() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CoordinatedStateManager getCoordinatedStateManager() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetaTableLocator getMetaTableLocator() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClusterConnection getConnection() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Configuration getConfiguration() {
|
||||
return mfs.conf;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerName getServerName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void abort(String why, Throwable e) {
|
||||
//no-op
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAborted() {
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean stopped = false;
|
||||
|
||||
@Override
|
||||
public void stop(String why) {
|
||||
stopped = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStopped() {
|
||||
return stopped;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TableDescriptors getTableDescriptors() {
|
||||
return new TableDescriptors() {
|
||||
|
@ -407,142 +298,6 @@ public class TestCatalogJanitor {
|
|||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isServerCrashProcessingEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean registerService(Service instance) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean abortProcedure(final long procId, final boolean mayInterruptIfRunning)
|
||||
throws IOException {
|
||||
return false; //To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ProcedureInfo> listProcedures() throws IOException {
|
||||
return null; //To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<HTableDescriptor> listTableDescriptorsByNamespace(String name) throws IOException {
|
||||
return null; //To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TableName> listTableNamesByNamespace(String name) throws IOException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long deleteTable(
|
||||
final TableName tableName,
|
||||
final long nonceGroup,
|
||||
final long nonce) throws IOException {
|
||||
return -1;
|
||||
}
|
||||
public LoadBalancer getLoadBalancer() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long truncateTable(
|
||||
final TableName tableName,
|
||||
final boolean preserveSplits,
|
||||
final long nonceGroup,
|
||||
final long nonce) throws IOException {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public long modifyTable(
|
||||
final TableName tableName,
|
||||
final HTableDescriptor descriptor,
|
||||
final long nonceGroup,
|
||||
final long nonce) throws IOException {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long enableTable(
|
||||
final TableName tableName,
|
||||
final long nonceGroup,
|
||||
final long nonce) throws IOException {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long disableTable(
|
||||
TableName tableName,
|
||||
final long nonceGroup,
|
||||
final long nonce) throws IOException {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long addColumn(final TableName tableName, final HColumnDescriptor columnDescriptor,
|
||||
final long nonceGroup, final long nonce) throws IOException {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long modifyColumn(final TableName tableName, final HColumnDescriptor descriptor,
|
||||
final long nonceGroup, final long nonce) throws IOException {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long deleteColumn(final TableName tableName, final byte[] columnName,
|
||||
final long nonceGroup, final long nonce) throws IOException {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TableLockManager getTableLockManager() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TableStateManager getTableStateManager() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispatchMergingRegions(HRegionInfo region_a, HRegionInfo region_b,
|
||||
boolean forcible, User user) throws IOException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInitialized() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getLastMajorCompactionTimestamp(TableName table) throws IOException {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getLastMajorCompactionTimestampForRegion(byte[] regionName) throws IOException {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClusterSchema getClusterSchema() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClusterConnection getClusterConnection() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue