Java源码示例:org.apache.accumulo.core.data.TabletId
示例1
@Override
public void close(TaskAttemptContext attempt) throws IOException, InterruptedException {
log.debug("mutations written: " + mutCount + ", values written: " + valCount);
if (simulate) {
return;
}
try {
mtbw.close();
} catch (MutationsRejectedException e) {
if (e.getSecurityErrorCodes().size() >= 0) {
HashSet<String> tables = new HashSet<>();
for (TabletId tabletId : e.getSecurityErrorCodes().keySet()) {
tables.add(tabletId.getTableId().toString());
}
log.error("Not authorized to write to tables : " + tables);
}
if (!e.getConstraintViolationSummaries().isEmpty()) {
log.error("Constraint violations : " + e.getConstraintViolationSummaries());
}
} finally {
returnConnector();
}
}
示例2
public static String toDebugOutput(TabletId tid) {
StringJoiner joiner = new StringJoiner(", ", "[", "]");
Text endRow = tid.getEndRow();
if (null != endRow) {
Optional<String> prefix = decodeRowPrefix(endRow);
OptionalLong offset = decodeRowOffset(endRow);
prefix.ifPresent(s -> joiner.add("prefix: " + s));
if (offset.isPresent()) {
LocalDateTime date = Instant.ofEpochMilli(offset.getAsLong()).atZone(ZoneId.of("UTC"))
.toLocalDateTime();
joiner.add("date: " + date.toString());
joiner.add("millis: " + offset.getAsLong());
}
}
return joiner.toString();
}
示例3
/**
* Continually scans the metdata table attempting to get the split locations for the shard table.
*
* @param log
* logger for reporting errors
* @param accumuloHelper
* Accumulo helper to query shard locations
* @param shardedTableName
* name of the shard table--the table whose locations we are querying
* @return a map of split (endRow) to the location of those tablets in accumulo
*/
public static Map<Text,String> getLocations(Logger log, AccumuloHelper accumuloHelper, String shardedTableName) {
// split (endRow) -> String location mapping
Map<Text,String> splitToLocation = new TreeMap<>();
boolean keepRetrying = true;
int attempts = 0;
while (keepRetrying && attempts < MAX_RETRY_ATTEMPTS) {
try {
TableOperations tableOps = accumuloHelper.getConnector().tableOperations();
attempts++;
// if table does not exist don't want to catch the errors and end up in infinite loop
if (!tableOps.exists(shardedTableName)) {
log.error("Table " + shardedTableName + " not found, skipping split locations for missing table");
} else {
Range range = new Range();
Locations locations = tableOps.locate(shardedTableName, Collections.singletonList(range));
List<TabletId> tabletIds = locations.groupByRange().get(range);
tabletIds.stream().filter(tId -> tId.getEndRow() != null)
.forEach(tId -> splitToLocation.put(tId.getEndRow(), locations.getTabletLocation(tId)));
}
// made it here, no errors so break out
keepRetrying = false;
} catch (Exception e) {
log.warn(e.getClass().getName() + ":" + e.getMessage() + " ... retrying ...", e);
UtilWaitThread.sleep(3000);
splitToLocation.clear();
}
}
return splitToLocation;
}
示例4
protected void redistributeQueries(Multimap<String,QueryPlan> serverPlan, QueryPlan currentPlan) throws AccumuloException, AccumuloSecurityException,
TableNotFoundException {
List<Range> ranges = Lists.newArrayList(currentPlan.getRanges());
if (!ranges.isEmpty()) {
Map<String,Map<TabletId,List<Range>>> binnedRanges = binRanges(ranges);
for (String server : binnedRanges.keySet()) {
Map<TabletId,List<Range>> hostedExtentMap = binnedRanges.get(server);
Iterable<Range> rangeIter = Lists.newArrayList();
for (Entry<TabletId,List<Range>> rangeEntry : hostedExtentMap.entrySet()) {
if (log.isTraceEnabled())
log.trace("Adding range from " + rangeEntry.getValue());
rangeIter = Iterables.concat(rangeIter, rangeEntry.getValue());
}
if (log.isTraceEnabled())
log.trace("Adding query tree " + JexlStringBuildingVisitor.buildQuery(currentPlan.getQueryTree()) + " " + currentPlan.getSettings().size()
+ " for " + server);
serverPlan.put(server, new QueryPlan(currentPlan.getQueryTree(), rangeIter, currentPlan.getSettings(), currentPlan.getColumnFamilies()));
}
}
}
示例5
protected Map<String,Map<TabletId,List<Range>>> binRanges(List<Range> ranges) throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
Map<String,Map<TabletId,List<Range>>> binnedRanges = new HashMap<>();
Locations locations = config.getConnector().tableOperations().locate(tableName, ranges);
Map<TabletId,List<Range>> tabletToRange = locations.groupByTablet();
for (TabletId tid : tabletToRange.keySet()) {
binnedRanges.put(locations.getTabletLocation(tid), tabletToRange);
}
// truncate the ranges to within the tablets... this makes it easier
// to know what work
// needs to be redone when failures occurs and tablets have merged
// or split
Map<String,Map<TabletId,List<Range>>> binnedRanges2 = new HashMap<>();
for (Entry<String,Map<TabletId,List<Range>>> entry : binnedRanges.entrySet()) {
Map<TabletId,List<Range>> tabletMap = new HashMap<>();
binnedRanges2.put(entry.getKey(), tabletMap);
for (Entry<TabletId,List<Range>> tabletRanges : entry.getValue().entrySet()) {
Range tabletRange = tabletRanges.getKey().toRange();
List<Range> clippedRanges = new ArrayList<>();
tabletMap.put(tabletRanges.getKey(), clippedRanges);
for (Range range : tabletRanges.getValue())
clippedRanges.add(tabletRange.clip(range));
}
}
binnedRanges.clear();
binnedRanges.putAll(binnedRanges2);
return binnedRanges;
}
示例6
public MajorCompactionRequest build() {
String tableName = "1";
KeyExtent ke = new KeyExtent();
ke.setTableId(tableName);
if (null != endKeyMetric) {
ke.setEndRow(endKeyMetric.getRow());
}
if (null != prevKeyMetric) {
ke.setPrevEndRow(prevKeyMetric.getRow());
}
TabletId tid = new TabletIdImpl(ke);
// @formatter:off
MajorCompactionRequest req = EasyMock.partialMockBuilder(MajorCompactionRequest.class)
.withConstructor(KeyExtent.class, MajorCompactionReason.class, VolumeManager.class,
AccumuloConfiguration.class)
.withArgs(ke, MajorCompactionReason.NORMAL, null, AccumuloConfiguration.getDefaultConfiguration())
.addMockedMethod("getTabletId")
.addMockedMethod("getTableProperties")
.createMock();
// @formatter:on
req.setFiles(refs);
EasyMock.expect(req.getTabletId()).andStubReturn(tid);
EasyMock.expect(req.getTableProperties()).andStubReturn(tableProperties);
EasyMock.replay(req);
return req;
}
示例7
@Test
public void debugOutputTest() {
long offset = 1554962382848L;
ComparablePair<String, Long> p = new ComparablePair<>("sys.disk.disk_octets", offset);
byte[] bytes = pairCoder.encode(p);
TabletId tid = EasyMock.createMock(TabletId.class);
EasyMock.expect(tid.getEndRow()).andReturn(new Text(bytes));
EasyMock.replay(tid);
String debug = TabletRowAdapter.toDebugOutput(tid);
assertThat(debug, CoreMatchers.containsString("prefix: sys.disk.disk_octets"));
assertThat(debug, CoreMatchers.containsString("date: 2019-04-11T05:59:42.848"));
assertThat(debug, CoreMatchers.containsString("millis: 1554962382848"));
}
示例8
@Override
public Map<TabletId, List<Range>> getLocationsGroupedByTablet() {
return locations.groupByTablet();
}
示例9
@Override
public String getTabletLocation(TabletId tabletId) {
return locations.getTabletLocation(tabletId);
}
示例10
@Override
public Range toRange(TabletId tabletId) {
return tabletId.toRange();
}
示例11
public Map<TabletId, List<Range>> getLocationsGroupedByTablet();
示例12
public String getTabletLocation(TabletId tabletId);
示例13
public Range toRange(TabletId tabletId);