Search in sources :

Example 6 with TableStateManager

use of org.apache.hadoop.hbase.master.TableStateManager in project hbase by apache.

the class MasterProcedureTestingUtility method validateTableIsEnabled.

public static void validateTableIsEnabled(final HMaster master, final TableName tableName) throws IOException {
    TableStateManager tsm = master.getTableStateManager();
    assertTrue(tsm.getTableState(tableName).getState().equals(TableState.State.ENABLED));
}
Also used : TableStateManager(org.apache.hadoop.hbase.master.TableStateManager)

Example 7 with TableStateManager

use of org.apache.hadoop.hbase.master.TableStateManager in project hbase by apache.

the class MasterProcedureTestingUtility method validateTableIsDisabled.

public static void validateTableIsDisabled(final HMaster master, final TableName tableName) throws IOException {
    TableStateManager tsm = master.getTableStateManager();
    assertTrue(tsm.getTableState(tableName).getState().equals(TableState.State.DISABLED));
}
Also used : TableStateManager(org.apache.hadoop.hbase.master.TableStateManager)

Example 8 with TableStateManager

use of org.apache.hadoop.hbase.master.TableStateManager in project hbase by apache.

the class RSGroupInfoManagerImpl method getRSGroupAssignmentsByTable.

/**
 * This is an EXPENSIVE clone. Cloning though is the safest thing to do. Can't let out original
 * since it can change and at least the load balancer wants to iterate this exported list. Load
 * balancer should iterate over this list because cloned list will ignore disabled table and split
 * parent region cases. This method is invoked by {@link #balanceRSGroup}
 * @return A clone of current assignments for this group.
 */
Map<TableName, Map<ServerName, List<RegionInfo>>> getRSGroupAssignmentsByTable(TableStateManager tableStateManager, String groupName) throws IOException {
    Map<TableName, Map<ServerName, List<RegionInfo>>> result = Maps.newHashMap();
    Set<TableName> tablesInGroupCache = new HashSet<>();
    for (Map.Entry<RegionInfo, ServerName> entry : masterServices.getAssignmentManager().getRegionStates().getRegionAssignments().entrySet()) {
        RegionInfo region = entry.getKey();
        TableName tn = region.getTable();
        ServerName server = entry.getValue();
        if (isTableInGroup(tn, groupName, tablesInGroupCache)) {
            if (tableStateManager.isTableState(tn, TableState.State.DISABLED, TableState.State.DISABLING)) {
                continue;
            }
            if (region.isSplitParent()) {
                continue;
            }
            result.computeIfAbsent(tn, k -> new HashMap<>()).computeIfAbsent(server, k -> new ArrayList<>()).add(region);
        }
    }
    RSGroupInfo rsGroupInfo = getRSGroupInfo(groupName);
    for (ServerName serverName : masterServices.getServerManager().getOnlineServers().keySet()) {
        if (rsGroupInfo.containsServer(serverName.getAddress())) {
            for (Map<ServerName, List<RegionInfo>> map : result.values()) {
                map.computeIfAbsent(serverName, k -> Collections.emptyList());
            }
        }
    }
    return result;
}
Also used : Mutation(org.apache.hadoop.hbase.client.Mutation) SortedSet(java.util.SortedSet) Result(org.apache.hadoop.hbase.client.Result) MultiRowMutationService(org.apache.hadoop.hbase.shaded.protobuf.generated.MultiRowMutationProtos.MultiRowMutationService) LoggerFactory(org.slf4j.LoggerFactory) Shell(org.apache.hadoop.util.Shell) StringUtils(org.apache.commons.lang3.StringUtils) ServerManager(org.apache.hadoop.hbase.master.ServerManager) RegionState(org.apache.hadoop.hbase.master.RegionState) Future(java.util.concurrent.Future) CoprocessorDescriptorBuilder(org.apache.hadoop.hbase.client.CoprocessorDescriptorBuilder) Delete(org.apache.hadoop.hbase.client.Delete) ByteArrayInputStream(java.io.ByteArrayInputStream) ProcedureExecutor(org.apache.hadoop.hbase.procedure2.ProcedureExecutor) MutateRowsResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.MultiRowMutationProtos.MutateRowsResponse) Map(java.util.Map) Configuration(org.apache.hadoop.conf.Configuration) MasterServices(org.apache.hadoop.hbase.master.MasterServices) ZNodePaths(org.apache.hadoop.hbase.zookeeper.ZNodePaths) DeserializationException(org.apache.hadoop.hbase.exceptions.DeserializationException) Pair(org.apache.hadoop.hbase.util.Pair) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) Maps(org.apache.hbase.thirdparty.com.google.common.collect.Maps) TableStateManager(org.apache.hadoop.hbase.master.TableStateManager) Address(org.apache.hadoop.hbase.net.Address) ProtobufUtil(org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil) ZKUtil(org.apache.hadoop.hbase.zookeeper.ZKUtil) RSGroupProtos(org.apache.hadoop.hbase.shaded.protobuf.generated.RSGroupProtos) Collection(java.util.Collection) Get(org.apache.hadoop.hbase.client.Get) Set(java.util.Set) ZKWatcher(org.apache.hadoop.hbase.zookeeper.ZKWatcher) TableDescriptors(org.apache.hadoop.hbase.TableDescriptors) MasterProcedureEnv(org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv) Collectors(java.util.stream.Collectors) List(java.util.List) FutureUtils(org.apache.hadoop.hbase.util.FutureUtils) ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) Optional(java.util.Optional) AsyncTable(org.apache.hadoop.hbase.client.AsyncTable) ProtobufMagic(org.apache.hadoop.hbase.protobuf.ProtobufMagic) Coprocessor(org.apache.hadoop.hbase.Coprocessor) TableDescriptor(org.apache.hadoop.hbase.client.TableDescriptor) ServerListener(org.apache.hadoop.hbase.master.ServerListener) ImmutableMap(org.apache.hbase.thirdparty.com.google.common.collect.ImmutableMap) LoadBalancer(org.apache.hadoop.hbase.master.LoadBalancer) NamespaceDescriptor(org.apache.hadoop.hbase.NamespaceDescriptor) HashMap(java.util.HashMap) TableState(org.apache.hadoop.hbase.client.TableState) Function(java.util.function.Function) TreeSet(java.util.TreeSet) RegionStateNode(org.apache.hadoop.hbase.master.assignment.RegionStateNode) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) OptionalLong(java.util.OptionalLong) HConstants(org.apache.hadoop.hbase.HConstants) MasterProcedureUtil(org.apache.hadoop.hbase.master.procedure.MasterProcedureUtil) TableDescriptorBuilder(org.apache.hadoop.hbase.client.TableDescriptorBuilder) ColumnFamilyDescriptorBuilder(org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder) AsyncClusterConnection(org.apache.hadoop.hbase.client.AsyncClusterConnection) LinkedList(java.util.LinkedList) ServerName(org.apache.hadoop.hbase.ServerName) Threads(org.apache.hadoop.hbase.util.Threads) Bytes(org.apache.hadoop.hbase.util.Bytes) TableName(org.apache.hadoop.hbase.TableName) Logger(org.slf4j.Logger) KeeperException(org.apache.zookeeper.KeeperException) Put(org.apache.hadoop.hbase.client.Put) Sets(org.apache.hbase.thirdparty.com.google.common.collect.Sets) IOException(java.io.IOException) BalanceRequest(org.apache.hadoop.hbase.client.BalanceRequest) CreateTableProcedure(org.apache.hadoop.hbase.master.procedure.CreateTableProcedure) ProcedureSyncWait(org.apache.hadoop.hbase.master.procedure.ProcedureSyncWait) Procedure(org.apache.hadoop.hbase.procedure2.Procedure) Lists(org.apache.hbase.thirdparty.com.google.common.collect.Lists) MultiRowMutationEndpoint(org.apache.hadoop.hbase.coprocessor.MultiRowMutationEndpoint) RegionPlan(org.apache.hadoop.hbase.master.RegionPlan) DisabledRegionSplitPolicy(org.apache.hadoop.hbase.regionserver.DisabledRegionSplitPolicy) InterfaceAudience(org.apache.yetus.audience.InterfaceAudience) ConstraintException(org.apache.hadoop.hbase.constraint.ConstraintException) MutateRowsRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.MultiRowMutationProtos.MutateRowsRequest) MutationProto(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MutationProto) BalanceResponse(org.apache.hadoop.hbase.client.BalanceResponse) Collections(java.util.Collections) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) ArrayList(java.util.ArrayList) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) TableName(org.apache.hadoop.hbase.TableName) ServerName(org.apache.hadoop.hbase.ServerName) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) Map(java.util.Map) ImmutableMap(org.apache.hbase.thirdparty.com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) HashSet(java.util.HashSet)

Example 9 with TableStateManager

use of org.apache.hadoop.hbase.master.TableStateManager in project hbase by apache.

the class TestHbckChore method testForDisabledTable.

@Test
public void testForDisabledTable() throws Exception {
    TableName tableName = TableName.valueOf("testForDisabledTable");
    RegionInfo hri = createRegionInfo(tableName, 1);
    String regionName = hri.getRegionNameAsString();
    rsDispatcher.setMockRsExecutor(new GoodRsExecutor());
    Future<byte[]> future = submitProcedure(createAssignProcedure(hri));
    waitOnFuture(future);
    List<ServerName> serverNames = master.getServerManager().getOnlineServersList();
    assertEquals(NSERVERS, serverNames.size());
    hbckChore.choreForTesting();
    Map<String, Pair<ServerName, List<ServerName>>> inconsistentRegions = hbckChore.getInconsistentRegions();
    assertTrue(inconsistentRegions.containsKey(regionName));
    Pair<ServerName, List<ServerName>> pair = inconsistentRegions.get(regionName);
    ServerName locationInMeta = pair.getFirst();
    List<ServerName> reportedRegionServers = pair.getSecond();
    assertTrue(serverNames.contains(locationInMeta));
    assertEquals(0, reportedRegionServers.size());
    // Set table state to disabled, then not in inconsistent regions.
    TableStateManager tableStateManager = master.getTableStateManager();
    Mockito.when(tableStateManager.isTableState(tableName, TableState.State.DISABLED)).thenReturn(true);
    hbckChore.choreForTesting();
    inconsistentRegions = hbckChore.getInconsistentRegions();
    assertFalse(inconsistentRegions.containsKey(regionName));
}
Also used : TableName(org.apache.hadoop.hbase.TableName) TableStateManager(org.apache.hadoop.hbase.master.TableStateManager) ServerName(org.apache.hadoop.hbase.ServerName) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) List(java.util.List) Pair(org.apache.hadoop.hbase.util.Pair) Test(org.junit.Test)

Example 10 with TableStateManager

use of org.apache.hadoop.hbase.master.TableStateManager in project hbase by apache.

the class TestAddToSerialReplicationPeer method testEnablingTable.

@Test
public void testEnablingTable() throws Exception {
    TableName tableName = createTable();
    try (Table table = UTIL.getConnection().getTable(tableName)) {
        for (int i = 0; i < 100; i++) {
            table.put(new Put(Bytes.toBytes(i)).addColumn(CF, CQ, Bytes.toBytes(i)));
        }
    }
    RegionInfo region = UTIL.getAdmin().getRegions(tableName).get(0);
    HRegionServer rs = UTIL.getOtherRegionServer(UTIL.getRSForFirstRegionInTable(tableName));
    moveRegionAndArchiveOldWals(region, rs);
    TableStateManager tsm = UTIL.getMiniHBaseCluster().getMaster().getTableStateManager();
    tsm.setTableState(tableName, TableState.State.ENABLING);
    Thread t = new Thread(() -> {
        try {
            addPeer(true);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    });
    t.start();
    Thread.sleep(5000);
    // we will wait on the disabling table so the thread should still be alive.
    assertTrue(t.isAlive());
    tsm.setTableState(tableName, TableState.State.ENABLED);
    t.join();
    try (Table table = UTIL.getConnection().getTable(tableName)) {
        for (int i = 0; i < 100; i++) {
            table.put(new Put(Bytes.toBytes(i)).addColumn(CF, CQ, Bytes.toBytes(i)));
        }
    }
    waitUntilReplicationDone(100);
    checkOrder(100);
}
Also used : TableName(org.apache.hadoop.hbase.TableName) TableStateManager(org.apache.hadoop.hbase.master.TableStateManager) Table(org.apache.hadoop.hbase.client.Table) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) IOException(java.io.IOException) Put(org.apache.hadoop.hbase.client.Put) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer) Test(org.junit.Test)

Aggregations

TableStateManager (org.apache.hadoop.hbase.master.TableStateManager)11 TableName (org.apache.hadoop.hbase.TableName)6 IOException (java.io.IOException)4 Put (org.apache.hadoop.hbase.client.Put)3 RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)3 TableState (org.apache.hadoop.hbase.client.TableState)3 Test (org.junit.Test)3 List (java.util.List)2 ServerName (org.apache.hadoop.hbase.ServerName)2 TableNotDisabledException (org.apache.hadoop.hbase.TableNotDisabledException)2 TableNotEnabledException (org.apache.hadoop.hbase.TableNotEnabledException)2 TableNotFoundException (org.apache.hadoop.hbase.TableNotFoundException)2 Table (org.apache.hadoop.hbase.client.Table)2 Pair (org.apache.hadoop.hbase.util.Pair)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1