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 @@ -1063,16 +1063,15 @@ default TimeType getTimeType(String tableName) throws TableNotFoundException {

/**
* Sets the tablet availability for a range of Tablets in the specified table, but does not wait
* for the tablets to reach this availability state. For the Range parameter, note that the Row
* portion of the start and end Keys and the inclusivity parameters are used when determining the
* range of affected tablets. The other portions of the start and end Keys are not used.
* for the tablets to reach this availability state. The supplied row range is compared against
* the tablets' start/end rows using its lower/upper bounds and inclusivity flags.
*
* @param tableName table name
* @param range tablet range
* @param rowRange tablet row range
* @param tabletAvailability tablet availability
* @since 4.0.0
*/
default void setTabletAvailability(String tableName, Range range,
default void setTabletAvailability(String tableName, RowRange rowRange,
TabletAvailability tabletAvailability)
throws AccumuloSecurityException, AccumuloException, TableNotFoundException {
throw new UnsupportedOperationException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
*/
package org.apache.accumulo.core.client.admin;

import org.apache.accumulo.core.data.RowRange;

/**
* @see TableOperations#setTabletAvailability(String, org.apache.accumulo.core.data.Range,
* TabletAvailability)
* @see TableOperations#setTabletAvailability(String, RowRange, TabletAvailability)
* @since 4.0.0
*/
public enum TabletAvailability {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2210,16 +2210,18 @@ private void validatePropertiesToSet(Map<String,String> opts, Map<String,String>
}

@Override
public void setTabletAvailability(String tableName, Range range, TabletAvailability availability)
throws AccumuloSecurityException, AccumuloException {
public void setTabletAvailability(String tableName, RowRange rowRange,
TabletAvailability availability) throws AccumuloSecurityException, AccumuloException {
EXISTING_TABLE_NAME.validate(tableName);
if (SystemTables.containsTableName(tableName)) {
throw new AccumuloException("Cannot set set tablet availability for table " + tableName);
}

checkArgument(range != null, "range is null");
checkArgument(rowRange != null, "rowRange is null");
checkArgument(availability != null, "tabletAvailability is null");

Range range = rowRange.asRange();

byte[] bRange;
try {
bRange = new TSerializer().serialize(range.toThrift());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public void offline(String tableName, boolean wait) {}
public void online(String tableName, boolean wait) {}

@Override
public void setTabletAvailability(String tableName, Range range,
public void setTabletAvailability(String tableName, RowRange rowRange,
TabletAvailability tabletAvailability)
throws AccumuloSecurityException, AccumuloException, TableNotFoundException {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.apache.accumulo.core.client.AccumuloSecurityException;
import org.apache.accumulo.core.client.TableNotFoundException;
import org.apache.accumulo.core.client.admin.TabletAvailability;
import org.apache.accumulo.core.data.Range;
import org.apache.accumulo.core.data.RowRange;
import org.apache.accumulo.shell.Shell;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.Option;
Expand All @@ -38,7 +38,7 @@ public class SetAvailabilityCommand extends TableOperation {
private Option optEndRowExclusive;
private Option availabilityOpt;

private Range range;
private RowRange rowRange;
private TabletAvailability tabletAvailability;

@Override
Expand All @@ -54,10 +54,10 @@ public String description() {
@Override
protected void doTableOp(final Shell shellState, final String tableName)
throws AccumuloException, AccumuloSecurityException, TableNotFoundException, IOException {
shellState.getAccumuloClient().tableOperations().setTabletAvailability(tableName, range,
shellState.getAccumuloClient().tableOperations().setTabletAvailability(tableName, rowRange,
tabletAvailability);
Shell.log.debug("Set tablet availability: {} on table: {}, range: {}", tabletAvailability,
tableName, range);
tableName, rowRange);
}

@Override
Expand All @@ -73,13 +73,14 @@ public int execute(final String fullCommand, final CommandLine cl, final Shell s
}

if (cl.hasOption(optRow.getOpt())) {
this.range = new Range(new Text(cl.getOptionValue(optRow.getOpt()).getBytes(Shell.CHARSET)));
this.rowRange =
RowRange.closed(new Text(cl.getOptionValue(optRow.getOpt()).getBytes(Shell.CHARSET)));
} else {
Text startRow = OptUtil.getStartRow(cl);
Text endRow = OptUtil.getEndRow(cl);
final boolean startInclusive = !cl.hasOption(optStartRowExclusive.getOpt());
final boolean endInclusive = !cl.hasOption(optEndRowExclusive.getOpt());
this.range = new Range(startRow, startInclusive, endRow, endInclusive);
this.rowRange = RowRange.range(startRow, startInclusive, endRow, endInclusive);
}

this.tabletAvailability =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,7 @@ public void testCreateTableWithManyOptions() throws Exception {
// set last tablet in table to always be HOSTED, setting a tablet availability here will test
// export and cloning tables with tablet availabilities
client.tableOperations().setTabletAvailability(everythingTable,
new Range(everythingSplits.last(), false, null, true), TabletAvailability.HOSTED);
RowRange.greaterThan(everythingSplits.last()), TabletAvailability.HOSTED);

write(client, everythingTable, generateMutations(0, 100, tr -> true));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,7 @@ public void test_setTabletAvailability_getTabletInformation() throws Exception {
for (var sysTable : SystemTables.tableNames()) {
// should not be able to unhost any system table
assertThrows(AccumuloException.class,
() -> ops.setTabletAvailability(sysTable, new Range(), TabletAvailability.UNHOSTED));
() -> ops.setTabletAvailability(sysTable, RowRange.all(), TabletAvailability.UNHOSTED));
assertTrue(ops.getTabletInformation(sysTable, List.of(RowRange.all())).findAny().isPresent());
ops.getTabletInformation(sysTable, List.of(RowRange.all()))
.forEach(ti -> assertEquals(TabletAvailability.HOSTED, ti.getTabletAvailability()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,9 @@ public void testImportedTableIsOnDemand() throws Exception {
// add split 'h' and 'q'. Leave first as ONDEMAND, set second to UNHOSTED, and third to HOSTED
SortedSet<Text> splits = Sets.newTreeSet(Arrays.asList(new Text("h"), new Text("q")));
client.tableOperations().addSplits(srcTable, splits);
Range range = new Range(new Text("h"), false, new Text("q"), true);
RowRange range = RowRange.openClosed(new Text("h"), new Text("q"));
client.tableOperations().setTabletAvailability(srcTable, range, TabletAvailability.UNHOSTED);
range = new Range(new Text("q"), false, null, true);
range = RowRange.greaterThan(new Text("q"));
client.tableOperations().setTabletAvailability(srcTable, range, TabletAvailability.HOSTED);

// verify
Expand Down
3 changes: 2 additions & 1 deletion test/src/main/java/org/apache/accumulo/test/LocatorIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.apache.accumulo.core.client.admin.TabletAvailability;
import org.apache.accumulo.core.client.admin.servers.ServerId;
import org.apache.accumulo.core.data.Range;
import org.apache.accumulo.core.data.RowRange;
import org.apache.accumulo.core.data.TableId;
import org.apache.accumulo.core.data.TabletId;
import org.apache.accumulo.core.dataImpl.KeyExtent;
Expand Down Expand Up @@ -129,7 +130,7 @@ public void testBasic() throws Exception {

ranges.clear();

tableOps.setTabletAvailability(tableName, new Range(), TabletAvailability.HOSTED);
tableOps.setTabletAvailability(tableName, RowRange.all(), TabletAvailability.HOSTED);
Wait.waitFor(() -> hostedAndCurrentNotNull
.test(ManagerAssignmentIT.getTabletMetadata(client, tableId, null)), 60000, 250);

Expand Down
13 changes: 7 additions & 6 deletions test/src/main/java/org/apache/accumulo/test/ScanServerIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import org.apache.accumulo.core.conf.ClientProperty;
import org.apache.accumulo.core.conf.Property;
import org.apache.accumulo.core.data.Range;
import org.apache.accumulo.core.data.RowRange;
import org.apache.accumulo.core.data.TableId;
import org.apache.accumulo.core.fate.FateId;
import org.apache.accumulo.core.fate.FateInstanceType;
Expand Down Expand Up @@ -254,7 +255,7 @@ public void testScanTabletsWithOperationIds() throws Exception {

// Unload all tablets
TableId tid = TableId.of(client.tableOperations().tableIdMap().get(tableName));
client.tableOperations().setTabletAvailability(tableName, new Range((Text) null, (Text) null),
client.tableOperations().setTabletAvailability(tableName, RowRange.all(),
TabletAvailability.ONDEMAND);

// Wait for the tablets to be unloaded
Expand Down Expand Up @@ -373,14 +374,14 @@ protected static int setupTableWithTabletAvailabilityMix(AccumuloClient client,
String tableId = client.tableOperations().tableIdMap().get(tableName);

// row 1 -> 3 are HOSTED
client.tableOperations().setTabletAvailability(tableName,
new Range(null, true, "row_0000000003", true), TabletAvailability.HOSTED);
client.tableOperations().setTabletAvailability(tableName, RowRange.atMost("row_0000000003"),
TabletAvailability.HOSTED);
// row 4 -> 7 are UNHOSTED
client.tableOperations().setTabletAvailability(tableName,
new Range("row_0000000004", true, "row_0000000007", true), TabletAvailability.UNHOSTED);
RowRange.closed("row_0000000004", "row_0000000007"), TabletAvailability.UNHOSTED);
// row 8 and 9 are ondemand
client.tableOperations().setTabletAvailability(tableName,
new Range("row_0000000008", true, null, true), TabletAvailability.ONDEMAND);
client.tableOperations().setTabletAvailability(tableName, RowRange.atLeast("row_0000000008"),
TabletAvailability.ONDEMAND);

// Wait for the UNHOSTED and ONDEMAND tablets to be unloaded due to inactivity
Wait.waitFor(() -> ScanServerIT.getNumHostedTablets(client, tableId) == 3, 30_000, 1_000);
Expand Down
60 changes: 30 additions & 30 deletions test/src/main/java/org/apache/accumulo/test/TableOperationsIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
import org.apache.accumulo.core.data.Key;
import org.apache.accumulo.core.data.Mutation;
import org.apache.accumulo.core.data.PartialKey;
import org.apache.accumulo.core.data.Range;
import org.apache.accumulo.core.data.RowRange;
import org.apache.accumulo.core.data.TableId;
import org.apache.accumulo.core.data.TabletId;
Expand Down Expand Up @@ -614,14 +613,14 @@ public void testGetTabletAvailability_MixedAvailabilities() throws AccumuloExcep
accumuloClient.tableOperations().create(tableName, ntc);

// set each tablet with a different availability and query to see if they are set accordingly
Range range = new Range(null, false, new Text("d"), true);
accumuloClient.tableOperations().setTabletAvailability(tableName, range,
RowRange rowRange = RowRange.atMost(new Text("d"));
accumuloClient.tableOperations().setTabletAvailability(tableName, rowRange,
TabletAvailability.UNHOSTED);
range = new Range(new Text("m"), false, new Text("s"), true);
accumuloClient.tableOperations().setTabletAvailability(tableName, range,
rowRange = RowRange.openClosed(new Text("m"), new Text("s"));
accumuloClient.tableOperations().setTabletAvailability(tableName, rowRange,
TabletAvailability.HOSTED);
range = new Range(new Text("s"), false, null, true);
accumuloClient.tableOperations().setTabletAvailability(tableName, range,
rowRange = RowRange.greaterThan(new Text("s"));
accumuloClient.tableOperations().setTabletAvailability(tableName, rowRange,
TabletAvailability.UNHOSTED);

Map<String,String> idMap = accumuloClient.tableOperations().tableIdMap();
Expand Down Expand Up @@ -663,12 +662,12 @@ public void testGetTabletAvailability_NonSplitBoundaries() throws AccumuloExcept

// set each different availability for each tablet and query to see if they are set
// accordingly
accumuloClient.tableOperations().setTabletAvailability(tableName, new Range(new Text("d")),
TabletAvailability.HOSTED);
accumuloClient.tableOperations().setTabletAvailability(tableName, new Range(new Text("m")),
TabletAvailability.UNHOSTED);
accumuloClient.tableOperations().setTabletAvailability(tableName, new Range(new Text("s")),
TabletAvailability.HOSTED);
accumuloClient.tableOperations().setTabletAvailability(tableName,
RowRange.closed(new Text("d")), TabletAvailability.HOSTED);
accumuloClient.tableOperations().setTabletAvailability(tableName,
RowRange.closed(new Text("m")), TabletAvailability.UNHOSTED);
accumuloClient.tableOperations().setTabletAvailability(tableName,
RowRange.closed(new Text("s")), TabletAvailability.HOSTED);

idMap = accumuloClient.tableOperations().tableIdMap();
tableId = idMap.get(tableName);
Expand All @@ -679,17 +678,17 @@ public void testGetTabletAvailability_NonSplitBoundaries() throws AccumuloExcept
verifyTabletAvailabilities(tableName, RowRange.closed("a"), expectedTabletAvailability);

// test using startRowInclusive set to true
RowRange range = RowRange.closed(new Text("c"));
verifyTabletAvailabilities(tableName, range, expectedTabletAvailability);
RowRange rowRange = RowRange.closed(new Text("c"));
verifyTabletAvailabilities(tableName, rowRange, expectedTabletAvailability);

expectedTabletAvailability.clear();
setExpectedTabletAvailability(expectedTabletAvailability, tableId, "m", "d",
TabletAvailability.UNHOSTED);
setExpectedTabletAvailability(expectedTabletAvailability, tableId, "s", "m",
TabletAvailability.HOSTED);

range = RowRange.closed(new Text("m"), new Text("p"));
verifyTabletAvailabilities(tableName, range, expectedTabletAvailability);
rowRange = RowRange.closed(new Text("m"), new Text("p"));
verifyTabletAvailabilities(tableName, rowRange, expectedTabletAvailability);

expectedTabletAvailability.clear();
setExpectedTabletAvailability(expectedTabletAvailability, tableId, "d", null,
Expand All @@ -701,8 +700,8 @@ public void testGetTabletAvailability_NonSplitBoundaries() throws AccumuloExcept
setExpectedTabletAvailability(expectedTabletAvailability, tableId, null, "s",
TabletAvailability.ONDEMAND);

range = RowRange.openClosed("b", "t");
verifyTabletAvailabilities(tableName, range, expectedTabletAvailability);
rowRange = RowRange.openClosed("b", "t");
verifyTabletAvailabilities(tableName, rowRange, expectedTabletAvailability);

} finally {
accumuloClient.tableOperations().delete(tableName);
Expand All @@ -722,7 +721,7 @@ public void testGetTabletAvailability_DelayedSplits() throws AccumuloException,
Map<String,String> idMap = accumuloClient.tableOperations().tableIdMap();

// set goals to HOSTED
accumuloClient.tableOperations().setTabletAvailability(tableName, new Range(),
accumuloClient.tableOperations().setTabletAvailability(tableName, RowRange.all(),
TabletAvailability.HOSTED);

Map<TabletId,TabletAvailability> expectedTabletAvailability = new HashMap<>();
Expand Down Expand Up @@ -773,11 +772,11 @@ public void testGetTabletAvailability_StaggeredSplits() throws AccumuloException
// add split 'h' and 'q'. Leave first as ONDEMAND, set second to UNHOSTED, and third to HOSTED
SortedSet<Text> splits = Sets.newTreeSet(Arrays.asList(new Text("h"), new Text("q")));
accumuloClient.tableOperations().addSplits(tableName, splits);
Range range = new Range(new Text("h"), false, new Text("q"), true);
accumuloClient.tableOperations().setTabletAvailability(tableName, range,
RowRange rowRange = RowRange.openClosed(new Text("h"), new Text("q"));
accumuloClient.tableOperations().setTabletAvailability(tableName, rowRange,
TabletAvailability.UNHOSTED);
range = new Range(new Text("q"), false, null, true);
accumuloClient.tableOperations().setTabletAvailability(tableName, range,
rowRange = RowRange.greaterThan(new Text("q"));
accumuloClient.tableOperations().setTabletAvailability(tableName, rowRange,
TabletAvailability.HOSTED);

// verify
Expand Down Expand Up @@ -869,17 +868,18 @@ private void verifyTablesWithSplits(String tableName, Map<String,String> idMap,
expectedTabletAvailability);
}

public static void verifyTabletAvailabilities(String tableName, RowRange range,
public static void verifyTabletAvailabilities(String tableName, RowRange rowRange,
Map<TabletId,TabletAvailability> expectedAvailability) throws TableNotFoundException {
verifyTabletAvailabilities(accumuloClient, tableName, range, expectedAvailability);
verifyTabletAvailabilities(accumuloClient, tableName, rowRange, expectedAvailability);
}

public static void verifyTabletAvailabilities(AccumuloClient client, String tableName,
RowRange range, Map<TabletId,TabletAvailability> expectedAvailability)
RowRange rowRange, Map<TabletId,TabletAvailability> expectedAvailability)
throws TableNotFoundException {
Map<TabletId,TabletAvailability> seenAvailability =
client.tableOperations().getTabletInformation(tableName, List.of(range)).collect(Collectors
.toMap(TabletInformation::getTabletId, TabletInformation::getTabletAvailability));
Map<TabletId,
TabletAvailability> seenAvailability = client.tableOperations()
.getTabletInformation(tableName, List.of(rowRange)).collect(Collectors
.toMap(TabletInformation::getTabletId, TabletInformation::getTabletAvailability));
assertEquals(expectedAvailability, seenAvailability);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import org.apache.accumulo.core.client.admin.NewTableConfiguration;
import org.apache.accumulo.core.client.admin.TabletAvailability;
import org.apache.accumulo.core.conf.Property;
import org.apache.accumulo.core.data.Range;
import org.apache.accumulo.core.data.RowRange;
import org.apache.accumulo.core.dataImpl.KeyExtent;
import org.apache.accumulo.core.metadata.schema.TabletMetadata;
import org.apache.accumulo.miniclusterImpl.MiniAccumuloConfigImpl;
Expand Down Expand Up @@ -83,7 +83,7 @@ public void test() throws Exception {

// This operation will fail when there are two locations set on a tablet
assertThrows(AccumuloException.class, () -> c.tableOperations().setTabletAvailability(table,
new Range(), TabletAvailability.HOSTED));
RowRange.all(), TabletAvailability.HOSTED));

try (var scanner = c.createScanner(table)) {
// should not be able to scan the table when a tablet has multiple locations
Expand Down Expand Up @@ -116,7 +116,7 @@ public void test() throws Exception {
}

// this should no longer fail
c.tableOperations().setTabletAvailability(table, new Range(), TabletAvailability.HOSTED);
c.tableOperations().setTabletAvailability(table, RowRange.all(), TabletAvailability.HOSTED);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1130,11 +1130,11 @@ public void testAvailability() throws Exception {

addSplits(c, tableName, "0100 0200 0300 0400 0500");

c.tableOperations().setTabletAvailability(tableName, new Range("0100", false, "0200", true),
c.tableOperations().setTabletAvailability(tableName, RowRange.openClosed("0100", "0200"),
TabletAvailability.HOSTED);
c.tableOperations().setTabletAvailability(tableName, new Range("0300", false, "0400", true),
c.tableOperations().setTabletAvailability(tableName, RowRange.openClosed("0300", "0400"),
TabletAvailability.HOSTED);
c.tableOperations().setTabletAvailability(tableName, new Range("0400", false, null, true),
c.tableOperations().setTabletAvailability(tableName, RowRange.greaterThan("0400"),
TabletAvailability.UNHOSTED);

// verify tablet availabilities are as expected
Expand Down
Loading