Skip to content
Open
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 @@ -3733,6 +3733,12 @@ public List<TableName> listTableNamesByNamespace(String name) throws IOException
return listTableNames(name, null, true);
}

@Override
public List<TableName> listTableNames() throws IOException {
checkInitialized();
return listTableNames(null, null, false);
}

@Override
public List<TableDescriptor> listTableDescriptorsByNamespace(String name) throws IOException {
checkInitialized();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,11 @@ long splitRegion(final RegionInfo regionInfo, final byte[] splitRow, final long
/** Returns Return table descriptors implementation. */
TableDescriptors getTableDescriptors();

/** Return the list of table names, should be used at local HMaster end only */
default List<TableName> listTableNames() throws IOException {
return null;
}

/**
* Registers a new protocol buffer {@link Service} subclass as a master coprocessor endpoint.
* <p/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package org.apache.hadoop.hbase.quotas;

import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
Expand Down Expand Up @@ -67,20 +66,21 @@ public class SnapshotQuotaObserverChore extends ScheduledChore {
private final Configuration conf;
private final MetricsMaster metrics;
private final FileSystem fs;
private final HMaster master;

public SnapshotQuotaObserverChore(HMaster master, MetricsMaster metrics) {
this(master.getConnection(), master.getConfiguration(), master.getFileSystem(), master,
metrics);
this(master.getConfiguration(), master, master, metrics);
}

SnapshotQuotaObserverChore(Connection conn, Configuration conf, FileSystem fs, Stoppable stopper,
SnapshotQuotaObserverChore(Configuration conf, HMaster master, Stoppable stopper,
MetricsMaster metrics) {
super(QuotaObserverChore.class.getSimpleName(), stopper, getPeriod(conf), getInitialDelay(conf),
getTimeUnit(conf));
this.conn = conn;
this.conn = master.getConnection();
this.conf = conf;
this.metrics = metrics;
this.fs = fs;
this.fs = master.getFileSystem();
this.master = master;
}

@Override
Expand Down Expand Up @@ -178,7 +178,7 @@ Multimap<TableName, String> getSnapshotsToComputeSize() throws IOException {
}
// Collect either the table name itself, or all of the tables in the namespace
if (null != ns) {
tablesToFetchSnapshotsFrom.addAll(Arrays.asList(admin.listTableNamesByNamespace(ns)));
tablesToFetchSnapshotsFrom.addAll(master.listTableNamesByNamespace(ns));
} else {
tablesToFetchSnapshotsFrom.add(tn);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2123,15 +2123,18 @@ public void preGetTableDescriptors(ObserverContext<MasterCoprocessorEnvironment>
if (regex == null && tableNamesList != null && !tableNamesList.isEmpty()) {
// Otherwise, if the requestor has ADMIN or CREATE privs for all listed tables, the
// request can be granted.
try (Admin admin = ctx.getEnvironment().getConnection().getAdmin()) {
for (TableName tableName : tableNamesList) {
// Skip checks for a table that does not exist
if (!admin.tableExists(tableName)) {
continue;
}
requirePermission(ctx, "getTableDescriptors", tableName, null, null, Action.ADMIN,
Action.CREATE);
List<TableName> sns = null;
if (ctx.getEnvironment() instanceof HasMasterServices) {
sns = (((HasMasterServices) ctx.getEnvironment()).getMasterServices().listTableNames());
}
if (sns == null) return;
for (TableName tableName : tableNamesList) {
// Skip checks for a table that does not exist
if (!sns.contains(tableName)) {
continue;
}
requirePermission(ctx, "getTableDescriptors", tableName, null, null, Action.ADMIN,
Action.CREATE);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -423,10 +423,8 @@
</div>

<% if (rsGroupTables != null && rsGroupTables.size() > 0) {
List<TableDescriptor> tables;
try (Admin admin = master.getConnection().getAdmin()) {
tables = master.isInitialized() ? admin.listTableDescriptors(true) : null;
}
List<TableDescriptor> tables = master.isInitialized() ?
master.listTableDescriptorsByNamespace(null) : null;
Map<TableName, TableDescriptor> tableDescriptors = tables.stream().collect(
Collectors.toMap(TableDescriptor::getTableName, Function.identity()));
%>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ public void setup(TestInfo testInfo) throws Exception {
helper = new SpaceQuotaHelperForTests(TEST_UTIL, () -> testName, COUNTER);
master = TEST_UTIL.getHBaseCluster().getMaster();
helper.removeAllQuotas(conn);
testChore = new SnapshotQuotaObserverChore(TEST_UTIL.getConnection(),
TEST_UTIL.getConfiguration(), master.getFileSystem(), master, null);
testChore = new SnapshotQuotaObserverChore(master, null);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2270,7 +2270,10 @@ public Object run() throws Exception {
public Object run() throws Exception {
try (Connection conn = ConnectionFactory.createConnection(TEST_UTIL.getConfiguration());
Admin admin = conn.getAdmin()) {
return admin.getDescriptor(TEST_TABLE);
ACCESS_CONTROLLER.requirePermission(ObserverContextImpl.createAndPrepare(CP_ENV),
"getTableDescriptors", admin.getDescriptor(TEST_TABLE).getTableName(), null, null,
Action.ADMIN, Action.CREATE);
return null;
}
}
};
Expand Down
Loading