Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,13 @@ default List<TableDescriptor> listTableDescriptors(Pattern pattern) throws IOExc
List<TableDescriptor> listTableDescriptors(Pattern pattern, boolean includeSysTables)
throws IOException;

/**
* List all enabled or disabled tables
* @param isEnabled is true means return enabled tables, false means return disabled tables
* @return a list of enabled or disabled tables
*/
List<TableDescriptor> listTableDescriptorsByState(boolean isEnabled) throws IOException;

/**
* List all of the names of userspace tables.
* @return TableName[] table names
Expand All @@ -184,6 +191,14 @@ default TableName[] listTableNames(Pattern pattern) throws IOException {
*/
TableName[] listTableNames(Pattern pattern, boolean includeSysTables) throws IOException;

/**
* List all enabled or disabled table names
* @param isEnabled is true means return enabled table names, false means return disabled table
* names
* @return a list of enabled or disabled table names
*/
List<TableName> listTableNamesByState(boolean isEnabled) throws IOException;

/**
* Get a table descriptor.
* @param tableName as a {@link TableName}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ public List<TableDescriptor> listTableDescriptors(Pattern pattern, boolean inclu
return get(admin.listTableDescriptors(pattern, includeSysTables));
}

@Override
public List<TableDescriptor> listTableDescriptorsByState(boolean isEnabled) throws IOException {
return get(admin.listTableDescriptorsByState(isEnabled));
}

@Override
public TableName[] listTableNames() throws IOException {
return get(admin.listTableNames()).toArray(new TableName[0]);
Expand All @@ -156,6 +161,11 @@ public TableName[] listTableNames(Pattern pattern, boolean includeSysTables) thr
return get(admin.listTableNames(pattern, includeSysTables)).toArray(new TableName[0]);
}

@Override
public List<TableName> listTableNamesByState(boolean isEnabled) throws IOException {
return get(admin.listTableNamesByState(isEnabled));
}

@Override
public TableDescriptor getDescriptor(TableName tableName)
throws TableNotFoundException, IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ CompletableFuture<List<TableDescriptor>> listTableDescriptors(Pattern pattern,
*/
CompletableFuture<List<TableDescriptor>> listTableDescriptorsByNamespace(String name);

/**
* List all enabled or disabled table descriptors
* @param isEnabled is true means return enabled table descriptors, false means return disabled
* table descriptors
* @return a list of table names wrapped by a {@link CompletableFuture}.
*/
CompletableFuture<List<TableDescriptor>> listTableDescriptorsByState(boolean isEnabled);

/**
* List all of the names of userspace tables.
* @return a list of table names wrapped by a {@link CompletableFuture}.
Expand All @@ -135,6 +143,14 @@ default CompletableFuture<List<TableName>> listTableNames() {
*/
CompletableFuture<List<TableName>> listTableNames(Pattern pattern, boolean includeSysTables);

/**
* List all enabled or disabled table names
* @param isEnabled is true means return enabled table names, false means return disabled table
* names
* @return a list of table names wrapped by a {@link CompletableFuture}.
*/
CompletableFuture<List<TableName>> listTableNamesByState(boolean isEnabled);

/**
* Get list of table names by namespace.
* @param name namespace name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ public CompletableFuture<List<TableDescriptor>> listTableDescriptorsByNamespace(
return wrap(rawAdmin.listTableDescriptorsByNamespace(name));
}

@Override
public CompletableFuture<List<TableDescriptor>> listTableDescriptorsByState(boolean isEnabled) {
return wrap(rawAdmin.listTableDescriptorsByState(isEnabled));
}

@Override
public CompletableFuture<List<TableName>> listTableNames(boolean includeSysTables) {
return wrap(rawAdmin.listTableNames(includeSysTables));
Expand All @@ -115,6 +120,11 @@ public CompletableFuture<List<TableName>> listTableNames(Pattern pattern,
return wrap(rawAdmin.listTableNames(pattern, includeSysTables));
}

@Override
public CompletableFuture<List<TableName>> listTableNamesByState(boolean isEnabled) {
return wrap(rawAdmin.listTableNamesByState(isEnabled));
}

@Override
public CompletableFuture<List<TableName>> listTableNamesByNamespace(String name) {
return wrap(rawAdmin.listTableNamesByNamespace(name));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,12 @@
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListNamespacesResponse;
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListTableDescriptorsByNamespaceRequest;
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListTableDescriptorsByNamespaceResponse;
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListTableDescriptorsByStateRequest;
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListTableDescriptorsByStateResponse;
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListTableNamesByNamespaceRequest;
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListTableNamesByNamespaceResponse;
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListTableNamesByStateRequest;
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListTableNamesByStateResponse;
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.MajorCompactionTimestampForRegionRequest;
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.MajorCompactionTimestampRequest;
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.MajorCompactionTimestampResponse;
Expand Down Expand Up @@ -561,6 +565,17 @@ public CompletableFuture<List<TableName>> listTableNames(Pattern pattern,
return getTableNames(RequestConverter.buildGetTableNamesRequest(pattern, includeSysTables));
}

@Override
public CompletableFuture<List<TableName>> listTableNamesByState(boolean isEnabled) {
return this.<List<TableName>> newMasterCaller()
.action((controller, stub) -> this.<ListTableNamesByStateRequest,
ListTableNamesByStateResponse, List<TableName>> call(controller, stub,
ListTableNamesByStateRequest.newBuilder().setIsEnabled(isEnabled).build(),
(s, c, req, done) -> s.listTableNamesByState(c, req, done),
(resp) -> ProtobufUtil.toTableNameList(resp.getTableNamesList())))
.call();
}

private CompletableFuture<List<TableName>> getTableNames(GetTableNamesRequest request) {
return this.<List<TableName>> newMasterCaller()
.action((controller, stub) -> this.<GetTableNamesRequest, GetTableNamesResponse,
Expand All @@ -581,6 +596,17 @@ ListTableDescriptorsByNamespaceResponse, List<TableDescriptor>> call(controller,
.call();
}

@Override
public CompletableFuture<List<TableDescriptor>> listTableDescriptorsByState(boolean isEnabled) {
return this.<List<TableDescriptor>> newMasterCaller()
.action((controller, stub) -> this.<ListTableDescriptorsByStateRequest,
ListTableDescriptorsByStateResponse, List<TableDescriptor>> call(controller, stub,
ListTableDescriptorsByStateRequest.newBuilder().setIsEnabled(isEnabled).build(),
(s, c, req, done) -> s.listTableDescriptorsByState(c, req, done),
(resp) -> ProtobufUtil.toTableDescriptorList(resp)))
.call();
}

@Override
public CompletableFuture<List<TableName>> listTableNamesByNamespace(String name) {
return this.<List<TableName>> newMasterCaller()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetTableDescriptorsResponse;
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListNamespaceDescriptorsResponse;
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListTableDescriptorsByNamespaceResponse;
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListTableDescriptorsByStateResponse;
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.MajorCompactionTimestampResponse;
import org.apache.hadoop.hbase.shaded.protobuf.generated.ProcedureProtos;
import org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos;
Expand Down Expand Up @@ -506,6 +507,18 @@ public static List<TableDescriptor> toTableDescriptorList(GetTableDescriptorsRes
.collect(Collectors.toList());
}

/**
* Get a list of TableDescriptor from ListTableDescriptorsByNamespaceResponse protobuf
* @param proto the ListTableDescriptorsByNamespaceResponse
* @return a list of TableDescriptor
*/
public static List<TableDescriptor>
toTableDescriptorList(ListTableDescriptorsByStateResponse proto) {
if (proto == null) return new ArrayList<>();
return proto.getTableSchemaList().stream().map(ProtobufUtil::toTableDescriptor)
.collect(Collectors.toList());
}

/**
* get the split keys in form "byte [][]" from a CreateTableRequest proto
* @param proto the CreateTableRequest
Expand Down
24 changes: 24 additions & 0 deletions hbase-protocol-shaded/src/main/protobuf/server/master/Master.proto
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,14 @@ message GetTableDescriptorsResponse {
repeated TableSchema table_schema = 1;
}

message ListTableDescriptorsByStateRequest {
required bool is_enabled = 1;
}

message ListTableDescriptorsByStateResponse {
repeated TableSchema table_schema = 1;
}

message GetTableNamesRequest {
optional string regex = 1;
optional bool include_sys_tables = 2 [default=false];
Expand All @@ -522,6 +530,14 @@ message GetTableNamesResponse {
repeated TableName table_names = 1;
}

message ListTableNamesByStateRequest {
required bool is_enabled = 1;
}

message ListTableNamesByStateResponse {
repeated TableName table_names = 1;
}

message GetTableStateRequest {
required TableName table_name = 1;
}
Expand Down Expand Up @@ -770,10 +786,18 @@ service MasterService {
rpc GetTableDescriptors(GetTableDescriptorsRequest)
returns(GetTableDescriptorsResponse);

/** List all enabled or disabled table descriptors. */
rpc ListTableDescriptorsByState(ListTableDescriptorsByStateRequest)
returns(ListTableDescriptorsByStateResponse);

/** Get the list of table names. */
rpc GetTableNames(GetTableNamesRequest)
returns(GetTableNamesResponse);

/** List all enabled or disabled table names. */
rpc ListTableNamesByState(ListTableNamesByStateRequest)
returns(ListTableNamesByStateResponse);

/** Return cluster status. */
rpc GetClusterStatus(GetClusterStatusRequest)
returns(GetClusterStatusResponse);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,12 @@
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListNamespacesResponse;
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListTableDescriptorsByNamespaceRequest;
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListTableDescriptorsByNamespaceResponse;
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListTableDescriptorsByStateRequest;
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListTableDescriptorsByStateResponse;
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListTableNamesByNamespaceRequest;
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListTableNamesByNamespaceResponse;
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListTableNamesByStateRequest;
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListTableNamesByStateResponse;
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.MajorCompactionTimestampForRegionRequest;
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.MajorCompactionTimestampRequest;
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.MajorCompactionTimestampResponse;
Expand Down Expand Up @@ -1171,6 +1175,31 @@ public GetTableDescriptorsResponse getTableDescriptors(RpcController c,
}
}

@Override
public ListTableDescriptorsByStateResponse listTableDescriptorsByState(RpcController controller,
ListTableDescriptorsByStateRequest request) throws ServiceException {
try {
server.checkInitialized();
List<TableDescriptor> descriptors = server.listTableDescriptors(null, null, null, false);

ListTableDescriptorsByStateResponse.Builder builder =
ListTableDescriptorsByStateResponse.newBuilder();
if (descriptors != null && descriptors.size() > 0) {
// Add the table descriptors to the response
TableState.State state =
request.getIsEnabled() ? TableState.State.ENABLED : TableState.State.DISABLED;
for (TableDescriptor htd : descriptors) {
if (server.getTableStateManager().isTableState(htd.getTableName(), state)) {
builder.addTableSchema(ProtobufUtil.toTableSchema(htd));
}
}
}
return builder.build();
} catch (IOException ioe) {
throw new ServiceException(ioe);
}
}

/**
* Get list of userspace table names
* @param controller Unused (set to null).
Expand Down Expand Up @@ -1200,6 +1229,29 @@ public GetTableNamesResponse getTableNames(RpcController controller, GetTableNam
}
}

@Override
public ListTableNamesByStateResponse listTableNamesByState(RpcController controller,
ListTableNamesByStateRequest request) throws ServiceException {
try {
server.checkServiceStarted();
List<TableName> tableNames = server.listTableNames(null, null, false);
ListTableNamesByStateResponse.Builder builder = ListTableNamesByStateResponse.newBuilder();
if (tableNames != null && tableNames.size() > 0) {
// Add the disabled table names to the response
TableState.State state =
request.getIsEnabled() ? TableState.State.ENABLED : TableState.State.DISABLED;
for (TableName table : tableNames) {
if (server.getTableStateManager().isTableState(table, state)) {
builder.addTableNames(ProtobufUtil.toProtoTableName(table));
}
}
}
return builder.build();
} catch (IOException e) {
throw new ServiceException(e);
}
}

@Override
public GetTableStateResponse getTableState(RpcController controller, GetTableStateRequest request)
throws ServiceException {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* 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 org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtil;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.TableDescriptor;
import org.apache.hadoop.hbase.client.TableDescriptorBuilder;
import org.apache.hadoop.hbase.testclassification.MasterTests;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category;

@Category({ MasterTests.class, MediumTests.class })
public class TestListTablesByState {
@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestListTablesByState.class);

private static HBaseTestingUtil UTIL;
private static Admin ADMIN;
private final static int SLAVES = 1;

@BeforeClass
public static void setUpBeforeClass() throws Exception {
UTIL = new HBaseTestingUtil();
UTIL.startMiniCluster(SLAVES);
ADMIN = UTIL.getAdmin();
}

@Test
public void testListTableNamesByState() throws Exception {
TableName testTableName = TableName.valueOf("test");
TableDescriptor testTableDesc = TableDescriptorBuilder.newBuilder(testTableName).build();
ADMIN.createTable(testTableDesc);
ADMIN.disableTable(testTableName);
Assert.assertEquals(ADMIN.listTableNamesByState(false).get(0), testTableName);
ADMIN.enableTable(testTableName);
Assert.assertEquals(ADMIN.listTableNamesByState(true).get(0), testTableName);
}

@Test
public void testListTableDescriptorByState() throws Exception {
TableName testTableName = TableName.valueOf("test");
TableDescriptor testTableDesc = TableDescriptorBuilder.newBuilder(testTableName).build();
ADMIN.createTable(testTableDesc);
ADMIN.disableTable(testTableName);
Assert.assertEquals(ADMIN.listTableDescriptorsByState(false).get(0), testTableDesc);
ADMIN.enableTable(testTableName);
Assert.assertEquals(ADMIN.listTableDescriptorsByState(true).get(0), testTableDesc);
}

@AfterClass
public static void tearDownAfterClass() throws Exception {
if (ADMIN != null) {
ADMIN.close();
}
if (UTIL != null) {
UTIL.shutdownMiniCluster();
}
}
}
Loading