use of org.apache.accumulo.core.dataImpl.KeyExtent in project accumulo by apache.
the class LinkingIterator method next.
@Override
public TabletMetadata next() {
long sleepTime = 250;
TabletMetadata currTablet = null;
while (currTablet == null) {
TabletMetadata tmp = source.next();
if (prevTablet == null) {
if (tmp.sawPrevEndRow()) {
Text prevMetaRow = null;
KeyExtent extent = tmp.getExtent();
if (extent.prevEndRow() != null) {
prevMetaRow = TabletsSection.encodeRow(extent.tableId(), extent.prevEndRow());
}
if (prevMetaRow == null || range.beforeStartKey(new Key(prevMetaRow))) {
currTablet = tmp;
} else {
log.debug("First tablet seen provides evidence of earlier tablet in range, retrying {} {} ", prevMetaRow, range);
}
} else {
log.warn("Tablet has no prev end row " + tmp.getTableId() + " " + tmp.getEndRow());
}
} else if (goodTransition(prevTablet, tmp)) {
currTablet = tmp;
}
if (currTablet == null) {
sleepUninterruptibly(sleepTime, MILLISECONDS);
resetSource();
sleepTime = Math.min(2 * sleepTime, 5000);
}
}
prevTablet = currTablet;
return currTablet;
}
use of org.apache.accumulo.core.dataImpl.KeyExtent in project accumulo by apache.
the class TabletMetadata method convertRow.
@VisibleForTesting
public static TabletMetadata convertRow(Iterator<Entry<Key, Value>> rowIter, EnumSet<ColumnType> fetchedColumns, boolean buildKeyValueMap) {
Objects.requireNonNull(rowIter);
TabletMetadata te = new TabletMetadata();
final ImmutableSortedMap.Builder<Key, Value> kvBuilder = buildKeyValueMap ? ImmutableSortedMap.naturalOrder() : null;
final var filesBuilder = ImmutableMap.<StoredTabletFile, DataFileValue>builder();
final var scansBuilder = ImmutableList.<StoredTabletFile>builder();
final var logsBuilder = ImmutableList.<LogEntry>builder();
final var extCompBuilder = ImmutableMap.<ExternalCompactionId, ExternalCompactionMetadata>builder();
final var loadedFilesBuilder = ImmutableMap.<TabletFile, Long>builder();
ByteSequence row = null;
while (rowIter.hasNext()) {
final Entry<Key, Value> kv = rowIter.next();
final Key key = kv.getKey();
final String val = kv.getValue().toString();
final String fam = key.getColumnFamilyData().toString();
final String qual = key.getColumnQualifierData().toString();
if (buildKeyValueMap) {
kvBuilder.put(key, kv.getValue());
}
if (row == null) {
row = key.getRowData();
KeyExtent ke = KeyExtent.fromMetaRow(key.getRow());
te.endRow = ke.endRow();
te.tableId = ke.tableId();
} else if (!row.equals(key.getRowData())) {
throw new IllegalArgumentException("Input contains more than one row : " + row + " " + key.getRowData());
}
switch(fam.toString()) {
case TabletColumnFamily.STR_NAME:
switch(qual) {
case PREV_ROW_QUAL:
te.prevEndRow = TabletColumnFamily.decodePrevEndRow(kv.getValue());
te.sawPrevEndRow = true;
break;
case OLD_PREV_ROW_QUAL:
te.oldPrevEndRow = TabletColumnFamily.decodePrevEndRow(kv.getValue());
te.sawOldPrevEndRow = true;
break;
case SPLIT_RATIO_QUAL:
te.splitRatio = Double.parseDouble(val);
break;
}
break;
case ServerColumnFamily.STR_NAME:
switch(qual) {
case DIRECTORY_QUAL:
Preconditions.checkArgument(ServerColumnFamily.isValidDirCol(val), "Saw invalid dir name {} {}", key, val);
te.dirName = val;
break;
case TIME_QUAL:
te.time = MetadataTime.parse(val);
break;
case FLUSH_QUAL:
te.flush = OptionalLong.of(Long.parseLong(val));
break;
case COMPACT_QUAL:
te.compact = OptionalLong.of(Long.parseLong(val));
break;
}
break;
case DataFileColumnFamily.STR_NAME:
filesBuilder.put(new StoredTabletFile(qual), new DataFileValue(val));
break;
case BulkFileColumnFamily.STR_NAME:
loadedFilesBuilder.put(new StoredTabletFile(qual), BulkFileColumnFamily.getBulkLoadTid(val));
break;
case CurrentLocationColumnFamily.STR_NAME:
te.setLocationOnce(val, qual, LocationType.CURRENT);
break;
case FutureLocationColumnFamily.STR_NAME:
te.setLocationOnce(val, qual, LocationType.FUTURE);
break;
case LastLocationColumnFamily.STR_NAME:
te.last = new Location(val, qual, LocationType.LAST);
break;
case SuspendLocationColumn.STR_NAME:
te.suspend = SuspendingTServer.fromValue(kv.getValue());
break;
case ScanFileColumnFamily.STR_NAME:
scansBuilder.add(new StoredTabletFile(qual));
break;
case ClonedColumnFamily.STR_NAME:
te.cloned = val;
break;
case LogColumnFamily.STR_NAME:
logsBuilder.add(LogEntry.fromMetaWalEntry(kv));
break;
case ExternalCompactionColumnFamily.STR_NAME:
extCompBuilder.put(ExternalCompactionId.of(qual), ExternalCompactionMetadata.fromJson(val));
break;
default:
throw new IllegalStateException("Unexpected family " + fam);
}
}
te.files = filesBuilder.build();
te.loadedFiles = loadedFilesBuilder.build();
te.fetchedCols = fetchedColumns;
te.scans = scansBuilder.build();
te.logs = logsBuilder.build();
te.extCompactions = extCompBuilder.build();
if (buildKeyValueMap) {
te.keyValues = kvBuilder.build();
}
return te;
}
use of org.apache.accumulo.core.dataImpl.KeyExtent in project accumulo by apache.
the class MetadataLocationObtainer method lookupTablets.
@Override
public List<TabletLocation> lookupTablets(ClientContext context, String tserver, Map<KeyExtent, List<Range>> tabletsRanges, TabletLocator parent) throws AccumuloSecurityException, AccumuloException {
final TreeMap<Key, Value> results = new TreeMap<>();
ResultReceiver rr = entries -> {
for (Entry<Key, Value> entry : entries) {
try {
results.putAll(WholeRowIterator.decodeRow(entry.getKey(), entry.getValue()));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
};
ScannerOptions opts = null;
try (SettableScannerOptions unsetOpts = new SettableScannerOptions()) {
opts = unsetOpts.setColumns(locCols);
}
Map<KeyExtent, List<Range>> unscanned = new HashMap<>();
Map<KeyExtent, List<Range>> failures = new HashMap<>();
try {
TabletServerBatchReaderIterator.doLookup(context, tserver, tabletsRanges, failures, unscanned, rr, columns, opts, Authorizations.EMPTY);
if (!failures.isEmpty()) {
// invalidate extents in parents cache
if (log.isTraceEnabled())
log.trace("lookupTablets failed for {} extents", failures.size());
parent.invalidateCache(failures.keySet());
}
} catch (IOException e) {
log.trace("lookupTablets failed server={}", tserver, e);
parent.invalidateCache(context, tserver);
} catch (AccumuloServerException e) {
log.trace("lookupTablets failed server={}", tserver, e);
throw e;
}
return MetadataLocationObtainer.getMetadataLocationEntries(results).getLocations();
}
use of org.apache.accumulo.core.dataImpl.KeyExtent in project accumulo by apache.
the class ReplicationConfigurationUtilTest method rootTableExtentEmptyConf.
@Test
public void rootTableExtentEmptyConf() {
KeyExtent extent = new KeyExtent(RootTable.ID, null, null);
assertFalse(ReplicationConfigurationUtil.isEnabled(extent, new ConfigurationCopy(new HashMap<>())), "The root table should never be replicated");
}
use of org.apache.accumulo.core.dataImpl.KeyExtent in project accumulo by apache.
the class TabletMetadataTest method testFutureAndCurrent.
@Test
public void testFutureAndCurrent() {
KeyExtent extent = new KeyExtent(TableId.of("5"), new Text("df"), new Text("da"));
Mutation mutation = TabletColumnFamily.createPrevRowMutation(extent);
mutation.at().family(CurrentLocationColumnFamily.NAME).qualifier("s001").put("server1:8555");
mutation.at().family(FutureLocationColumnFamily.NAME).qualifier("s001").put("server1:8555");
SortedMap<Key, Value> rowMap = toRowMap(mutation);
assertThrows(IllegalStateException.class, () -> TabletMetadata.convertRow(rowMap.entrySet().iterator(), EnumSet.allOf(ColumnType.class), false));
}
Aggregations