Skip to content

Commit 4da60e3

Browse files
authored
Minor TableOperations changes (#5510)
* Minor TableOperations changes: - Added early `return true` for all system tables for `TableOperations.exists()` - system table check for `TableOperations.setTabletAvailability()` would only occur client side. Now occurs server side as well. The client side check now results in a `AccumuloException` instead of the previous `IllegalArgumentException`. All the other `TableOperations` that can't be called on a system table result in an `AccumuloException` if they are called on a system table, so this change keeps consistency with the other `TableOperations` * ensure table is not system table for offline, online client-side
1 parent 770cba8 commit 4da60e3

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

core/src/main/java/org/apache/accumulo/core/clientImpl/TableOperationsImpl.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
import static org.apache.accumulo.core.util.LazySingletons.RANDOM;
4242
import static org.apache.accumulo.core.util.Validators.EXISTING_TABLE_NAME;
4343
import static org.apache.accumulo.core.util.Validators.NEW_TABLE_NAME;
44-
import static org.apache.accumulo.core.util.Validators.NOT_BUILTIN_TABLE;
4544
import static org.apache.accumulo.core.util.threads.ThreadPoolNames.SPLIT_START_POOL;
4645
import static org.apache.accumulo.core.util.threads.ThreadPoolNames.SPLIT_WAIT_POOL;
4746

@@ -223,8 +222,7 @@ public SortedSet<String> list() {
223222
public boolean exists(String tableName) {
224223
EXISTING_TABLE_NAME.validate(tableName);
225224

226-
if (tableName.equals(SystemTables.METADATA.tableName())
227-
|| tableName.equals(SystemTables.ROOT.tableName())) {
225+
if (SystemTables.containsTableName(tableName)) {
228226
return true;
229227
}
230228

@@ -1517,15 +1515,13 @@ private void changeTableState(String tableName, boolean wait, TableState newStat
15171515
switch (newState) {
15181516
case OFFLINE:
15191517
op = TFateOperation.TABLE_OFFLINE;
1520-
if (tableName.equals(SystemTables.METADATA.tableName())
1521-
|| tableName.equals(SystemTables.ROOT.tableName())) {
1518+
if (SystemTables.containsTableName(tableName)) {
15221519
throw new AccumuloException("Cannot set table to offline state");
15231520
}
15241521
break;
15251522
case ONLINE:
15261523
op = TFateOperation.TABLE_ONLINE;
1527-
if (tableName.equals(SystemTables.METADATA.tableName())
1528-
|| tableName.equals(SystemTables.ROOT.tableName())) {
1524+
if (SystemTables.containsTableName(tableName)) {
15291525
// Don't submit a Fate operation for this, these tables can only be online.
15301526
return;
15311527
}
@@ -2249,7 +2245,10 @@ private void validatePropertiesToSet(Map<String,String> opts, Map<String,String>
22492245
public void setTabletAvailability(String tableName, Range range, TabletAvailability availability)
22502246
throws AccumuloSecurityException, AccumuloException {
22512247
EXISTING_TABLE_NAME.validate(tableName);
2252-
NOT_BUILTIN_TABLE.validate(tableName);
2248+
if (SystemTables.containsTableName(tableName)) {
2249+
throw new AccumuloException("Cannot set set tablet availability for table " + tableName);
2250+
}
2251+
22532252
checkArgument(range != null, "range is null");
22542253
checkArgument(availability != null, "tabletAvailability is null");
22552254

server/manager/src/main/java/org/apache/accumulo/manager/FateServiceHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import static org.apache.accumulo.core.util.Validators.NOT_BUILTIN_NAMESPACE;
2828
import static org.apache.accumulo.core.util.Validators.NOT_BUILTIN_TABLE;
2929
import static org.apache.accumulo.core.util.Validators.NOT_BUILTIN_TABLE_ID;
30-
import static org.apache.accumulo.core.util.Validators.NOT_METADATA_TABLE;
3130
import static org.apache.accumulo.core.util.Validators.NOT_ROOT_TABLE_ID;
3231
import static org.apache.accumulo.core.util.Validators.VALID_TABLE_ID;
3332
import static org.apache.accumulo.core.util.Validators.sameNamespaceAs;
@@ -671,7 +670,8 @@ public void executeFateOperation(TInfo tinfo, TCredentials c, TFateId opid, TFat
671670
case TABLE_TABLET_AVAILABILITY: {
672671
TableOperation tableOp = TableOperation.SET_TABLET_AVAILABILITY;
673672
validateArgumentCount(arguments, tableOp, 3);
674-
String tableName = validateName(arguments.get(0), tableOp, NOT_METADATA_TABLE);
673+
String tableName =
674+
validateName(arguments.get(0), tableOp, NOT_BUILTIN_TABLE.and(EXISTING_TABLE_NAME));
675675
TableId tableId = null;
676676
try {
677677
tableId = manager.getContext().getTableId(tableName);

0 commit comments

Comments
 (0)