Search in sources :

Example 1 with CoordinatedStateManager

use of org.apache.hadoop.hbase.CoordinatedStateManager in project hbase by apache.

the class TestMasterNoCluster method testFailover.

/**
   * Test master failover.
   * Start up three fake regionservers and a master.
   * @throws IOException
   * @throws KeeperException
   * @throws InterruptedException
   * @throws org.apache.hadoop.hbase.shaded.com.google.protobuf.ServiceException 
   */
@Test
public void testFailover() throws Exception {
    final long now = System.currentTimeMillis();
    // Names for our three servers.  Make the port numbers match hostname.
    // Will come in use down in the server when we need to figure how to respond.
    final ServerName sn0 = ServerName.valueOf("0.example.org", 0, now);
    final ServerName sn1 = ServerName.valueOf("1.example.org", 1, now);
    final ServerName sn2 = ServerName.valueOf("2.example.org", 2, now);
    final ServerName[] sns = new ServerName[] { sn0, sn1, sn2 };
    // Put up the mock servers
    final Configuration conf = TESTUTIL.getConfiguration();
    final MockRegionServer rs0 = new MockRegionServer(conf, sn0);
    final MockRegionServer rs1 = new MockRegionServer(conf, sn1);
    final MockRegionServer rs2 = new MockRegionServer(conf, sn2);
    // Put some data into the servers.  Make it look like sn0 has the metaH
    // Put data into sn2 so it looks like it has a few regions for a table named 't'.
    MetaTableLocator.setMetaLocation(rs0.getZooKeeper(), rs0.getServerName(), RegionState.State.OPEN);
    final TableName tableName = TableName.valueOf(name.getMethodName());
    Result[] results = new Result[] { MetaMockingUtil.getMetaTableRowResult(new HRegionInfo(tableName, HConstants.EMPTY_START_ROW, HBaseTestingUtility.KEYS[1]), rs2.getServerName()), MetaMockingUtil.getMetaTableRowResult(new HRegionInfo(tableName, HBaseTestingUtility.KEYS[1], HBaseTestingUtility.KEYS[2]), rs2.getServerName()), MetaMockingUtil.getMetaTableRowResult(new HRegionInfo(tableName, HBaseTestingUtility.KEYS[2], HConstants.EMPTY_END_ROW), rs2.getServerName()) };
    rs1.setNextResults(HRegionInfo.FIRST_META_REGIONINFO.getRegionName(), results);
    // Create master.  Subclass to override a few methods so we can insert mocks
    // and get notification on transitions.  We need to fake out any rpcs the
    // master does opening/closing regions.  Also need to fake out the address
    // of the 'remote' mocked up regionservers.
    CoordinatedStateManager cp = CoordinatedStateManagerFactory.getCoordinatedStateManager(TESTUTIL.getConfiguration());
    // Insert a mock for the connection, use TESTUTIL.getConfiguration rather than
    // the conf from the master; the conf will already have an ClusterConnection
    // associate so the below mocking of a connection will fail.
    final ClusterConnection mockedConnection = HConnectionTestingUtility.getMockedConnectionAndDecorate(TESTUTIL.getConfiguration(), rs0, rs0, rs0.getServerName(), HRegionInfo.FIRST_META_REGIONINFO);
    HMaster master = new HMaster(conf, cp) {

        InetAddress getRemoteInetAddress(final int port, final long serverStartCode) throws UnknownHostException {
            // Return different address dependent on port passed.
            if (port > sns.length) {
                return super.getRemoteInetAddress(port, serverStartCode);
            }
            ServerName sn = sns[port];
            return InetAddress.getByAddress(sn.getHostname(), new byte[] { 10, 0, 0, (byte) sn.getPort() });
        }

        @Override
        void initClusterSchemaService() throws IOException, InterruptedException {
        }

        @Override
        ServerManager createServerManager(MasterServices master) throws IOException {
            ServerManager sm = super.createServerManager(master);
            // Spy on the created servermanager
            ServerManager spy = Mockito.spy(sm);
            // Fake a successful close.
            Mockito.doReturn(true).when(spy).sendRegionClose((ServerName) Mockito.any(), (HRegionInfo) Mockito.any(), (ServerName) Mockito.any());
            return spy;
        }

        @Override
        public ClusterConnection getConnection() {
            return mockedConnection;
        }

        @Override
        public ClusterConnection getClusterConnection() {
            return mockedConnection;
        }
    };
    master.start();
    try {
        // Wait till master is up ready for RPCs.
        while (!master.serviceStarted) Threads.sleep(10);
        // Fake master that there are regionservers out there.  Report in.
        for (int i = 0; i < sns.length; i++) {
            RegionServerReportRequest.Builder request = RegionServerReportRequest.newBuilder();
            ;
            ServerName sn = ServerName.parseVersionedServerName(sns[i].getVersionedBytes());
            request.setServer(ProtobufUtil.toServerName(sn));
            request.setLoad(ServerLoad.EMPTY_SERVERLOAD.obtainServerLoadPB());
            master.getMasterRpcServices().regionServerReport(null, request.build());
        }
        // Master should now come up.
        while (!master.isInitialized()) {
            Threads.sleep(100);
        }
        assertTrue(master.isInitialized());
    } finally {
        rs0.stop("Test is done");
        rs1.stop("Test is done");
        rs2.stop("Test is done");
        master.stopMaster();
        master.join();
    }
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) RegionServerReportRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos.RegionServerReportRequest) CoordinatedStateManager(org.apache.hadoop.hbase.CoordinatedStateManager) Result(org.apache.hadoop.hbase.client.Result) HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) TableName(org.apache.hadoop.hbase.TableName) ClusterConnection(org.apache.hadoop.hbase.client.ClusterConnection) ServerName(org.apache.hadoop.hbase.ServerName) Test(org.junit.Test)

Example 2 with CoordinatedStateManager

use of org.apache.hadoop.hbase.CoordinatedStateManager in project hbase by apache.

the class TestMasterNoCluster method testNotPullingDeadRegionServerFromZK.

@Test
public void testNotPullingDeadRegionServerFromZK() throws IOException, KeeperException, InterruptedException {
    final Configuration conf = TESTUTIL.getConfiguration();
    final ServerName newServer = ServerName.valueOf("test.sample", 1, 101);
    final ServerName deadServer = ServerName.valueOf("test.sample", 1, 100);
    final MockRegionServer rs0 = new MockRegionServer(conf, newServer);
    CoordinatedStateManager cp = CoordinatedStateManagerFactory.getCoordinatedStateManager(TESTUTIL.getConfiguration());
    HMaster master = new HMaster(conf, cp) {

        @Override
        MasterMetaBootstrap createMetaBootstrap(final HMaster master, final MonitoredTask status) {
            return new MasterMetaBootstrap(this, status) {

                @Override
                protected void assignMeta(Set<ServerName> previouslyFailedMeatRSs, int replicaId) {
                }
            };
        }

        @Override
        void initClusterSchemaService() throws IOException, InterruptedException {
        }

        @Override
        void initializeZKBasedSystemTrackers() throws IOException, InterruptedException, KeeperException, CoordinatedStateException {
            super.initializeZKBasedSystemTrackers();
            // Record a newer server in server manager at first
            getServerManager().recordNewServerWithLock(newServer, ServerLoad.EMPTY_SERVERLOAD);
            List<ServerName> onlineServers = new ArrayList<>();
            onlineServers.add(deadServer);
            onlineServers.add(newServer);
            // Mock the region server tracker to pull the dead server from zk
            regionServerTracker = Mockito.spy(regionServerTracker);
            Mockito.doReturn(onlineServers).when(regionServerTracker).getOnlineServers();
        }

        @Override
        public ClusterConnection getConnection() {
            // associate so the below mocking of a connection will fail.
            try {
                return HConnectionTestingUtility.getMockedConnectionAndDecorate(TESTUTIL.getConfiguration(), rs0, rs0, rs0.getServerName(), HRegionInfo.FIRST_META_REGIONINFO);
            } catch (IOException e) {
                return null;
            }
        }
    };
    master.start();
    try {
        // Wait till master is initialized.
        while (!master.isInitialized()) Threads.sleep(10);
        LOG.info("Master is initialized");
        assertFalse("The dead server should not be pulled in", master.getServerManager().isServerOnline(deadServer));
    } finally {
        master.stopMaster();
        master.join();
    }
}
Also used : Set(java.util.Set) Configuration(org.apache.hadoop.conf.Configuration) ServerName(org.apache.hadoop.hbase.ServerName) ArrayList(java.util.ArrayList) IOException(java.io.IOException) CoordinatedStateManager(org.apache.hadoop.hbase.CoordinatedStateManager) MonitoredTask(org.apache.hadoop.hbase.monitoring.MonitoredTask) Test(org.junit.Test)

Example 3 with CoordinatedStateManager

use of org.apache.hadoop.hbase.CoordinatedStateManager in project hbase by apache.

the class TestMasterNoCluster method testStopDuringStart.

/**
   * Test starting master then stopping it before its fully up.
   * @throws IOException
   * @throws KeeperException
   * @throws InterruptedException
   */
@Test
public void testStopDuringStart() throws IOException, KeeperException, InterruptedException {
    CoordinatedStateManager cp = CoordinatedStateManagerFactory.getCoordinatedStateManager(TESTUTIL.getConfiguration());
    HMaster master = new HMaster(TESTUTIL.getConfiguration(), cp);
    master.start();
    // Immediately have it stop.  We used hang in assigning meta.
    master.stopMaster();
    master.join();
}
Also used : CoordinatedStateManager(org.apache.hadoop.hbase.CoordinatedStateManager) Test(org.junit.Test)

Example 4 with CoordinatedStateManager

use of org.apache.hadoop.hbase.CoordinatedStateManager in project hbase by apache.

the class TestPriorityRpc method setup.

@Before
public void setup() {
    Configuration conf = HBaseConfiguration.create();
    // No need to do ZK
    conf.setBoolean("hbase.testing.nocluster", true);
    final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(conf);
    TEST_UTIL.getDataTestDir(this.getClass().getName());
    CoordinatedStateManager cp = CoordinatedStateManagerFactory.getCoordinatedStateManager(conf);
    regionServer = HRegionServer.constructRegionServer(HRegionServer.class, conf, cp);
    priority = regionServer.rpcServices.getPriority();
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) HBaseTestingUtility(org.apache.hadoop.hbase.HBaseTestingUtility) CoordinatedStateManager(org.apache.hadoop.hbase.CoordinatedStateManager) Before(org.junit.Before)

Aggregations

CoordinatedStateManager (org.apache.hadoop.hbase.CoordinatedStateManager)4 Configuration (org.apache.hadoop.conf.Configuration)3 Test (org.junit.Test)3 ServerName (org.apache.hadoop.hbase.ServerName)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Set (java.util.Set)1 HBaseConfiguration (org.apache.hadoop.hbase.HBaseConfiguration)1 HBaseTestingUtility (org.apache.hadoop.hbase.HBaseTestingUtility)1 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)1 TableName (org.apache.hadoop.hbase.TableName)1 ClusterConnection (org.apache.hadoop.hbase.client.ClusterConnection)1 Result (org.apache.hadoop.hbase.client.Result)1 MonitoredTask (org.apache.hadoop.hbase.monitoring.MonitoredTask)1 RegionServerReportRequest (org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos.RegionServerReportRequest)1 Before (org.junit.Before)1