Search in sources :

Example 26 with KeyExtent

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;
}
Also used : Text(org.apache.hadoop.io.Text) KeyExtent(org.apache.accumulo.core.dataImpl.KeyExtent) Key(org.apache.accumulo.core.data.Key) PartialKey(org.apache.accumulo.core.data.PartialKey)

Example 27 with KeyExtent

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;
}
Also used : ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) KeyExtent(org.apache.accumulo.core.dataImpl.KeyExtent) Value(org.apache.accumulo.core.data.Value) OptionalLong(java.util.OptionalLong) StoredTabletFile(org.apache.accumulo.core.metadata.StoredTabletFile) StoredTabletFile(org.apache.accumulo.core.metadata.StoredTabletFile) TabletFile(org.apache.accumulo.core.metadata.TabletFile) Key(org.apache.accumulo.core.data.Key) LogEntry(org.apache.accumulo.core.tabletserver.log.LogEntry) ByteSequence(org.apache.accumulo.core.data.ByteSequence) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 28 with KeyExtent

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();
}
Also used : TabletServerBatchReaderIterator(org.apache.accumulo.core.clientImpl.TabletServerBatchReaderIterator) SortedSet(java.util.SortedSet) TabletLocation(org.apache.accumulo.core.clientImpl.TabletLocator.TabletLocation) LoggerFactory(org.slf4j.LoggerFactory) Text(org.apache.hadoop.io.Text) HashMap(java.util.HashMap) ResultReceiver(org.apache.accumulo.core.clientImpl.TabletServerBatchReaderIterator.ResultReceiver) IterInfo(org.apache.accumulo.core.dataImpl.thrift.IterInfo) FutureLocationColumnFamily(org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.FutureLocationColumnFamily) TextUtil(org.apache.accumulo.core.util.TextUtil) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) TabletLocator(org.apache.accumulo.core.clientImpl.TabletLocator) CurrentLocationColumnFamily(org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.CurrentLocationColumnFamily) Map(java.util.Map) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) Key(org.apache.accumulo.core.data.Key) Value(org.apache.accumulo.core.data.Value) ScannerOptions(org.apache.accumulo.core.clientImpl.ScannerOptions) ThriftScanner(org.apache.accumulo.core.clientImpl.ThriftScanner) Logger(org.slf4j.Logger) ClientContext(org.apache.accumulo.core.clientImpl.ClientContext) Column(org.apache.accumulo.core.data.Column) KeyExtent(org.apache.accumulo.core.dataImpl.KeyExtent) IOException(java.io.IOException) Constants(org.apache.accumulo.core.Constants) Authorizations(org.apache.accumulo.core.security.Authorizations) AccumuloException(org.apache.accumulo.core.client.AccumuloException) Range(org.apache.accumulo.core.data.Range) AccumuloServerException(org.apache.accumulo.core.clientImpl.AccumuloServerException) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) List(java.util.List) TabletLocationObtainer(org.apache.accumulo.core.clientImpl.TabletLocatorImpl.TabletLocationObtainer) OpTimer(org.apache.accumulo.core.util.OpTimer) TreeMap(java.util.TreeMap) Entry(java.util.Map.Entry) TabletLocations(org.apache.accumulo.core.clientImpl.TabletLocator.TabletLocations) TabletColumnFamily(org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.TabletColumnFamily) PartialKey(org.apache.accumulo.core.data.PartialKey) Collections(java.util.Collections) SECONDS(java.util.concurrent.TimeUnit.SECONDS) SortedMap(java.util.SortedMap) WholeRowIterator(org.apache.accumulo.core.iterators.user.WholeRowIterator) HashMap(java.util.HashMap) IOException(java.io.IOException) TreeMap(java.util.TreeMap) KeyExtent(org.apache.accumulo.core.dataImpl.KeyExtent) AccumuloServerException(org.apache.accumulo.core.clientImpl.AccumuloServerException) Entry(java.util.Map.Entry) Value(org.apache.accumulo.core.data.Value) ArrayList(java.util.ArrayList) List(java.util.List) ScannerOptions(org.apache.accumulo.core.clientImpl.ScannerOptions) Key(org.apache.accumulo.core.data.Key) PartialKey(org.apache.accumulo.core.data.PartialKey) ResultReceiver(org.apache.accumulo.core.clientImpl.TabletServerBatchReaderIterator.ResultReceiver)

Example 29 with KeyExtent

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");
}
Also used : ConfigurationCopy(org.apache.accumulo.core.conf.ConfigurationCopy) KeyExtent(org.apache.accumulo.core.dataImpl.KeyExtent) Test(org.junit.jupiter.api.Test)

Example 30 with KeyExtent

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));
}
Also used : Value(org.apache.accumulo.core.data.Value) Text(org.apache.hadoop.io.Text) Mutation(org.apache.accumulo.core.data.Mutation) KeyExtent(org.apache.accumulo.core.dataImpl.KeyExtent) Key(org.apache.accumulo.core.data.Key) Test(org.junit.jupiter.api.Test)

Aggregations

KeyExtent (org.apache.accumulo.core.dataImpl.KeyExtent)239 Text (org.apache.hadoop.io.Text)98 ArrayList (java.util.ArrayList)72 HashMap (java.util.HashMap)60 Value (org.apache.accumulo.core.data.Value)57 Key (org.apache.accumulo.core.data.Key)56 TableId (org.apache.accumulo.core.data.TableId)53 Test (org.junit.Test)52 Mutation (org.apache.accumulo.core.data.Mutation)47 IOException (java.io.IOException)40 List (java.util.List)40 TKeyExtent (org.apache.accumulo.core.dataImpl.thrift.TKeyExtent)39 HashSet (java.util.HashSet)38 TreeMap (java.util.TreeMap)38 Range (org.apache.accumulo.core.data.Range)38 Map (java.util.Map)33 Scanner (org.apache.accumulo.core.client.Scanner)31 Entry (java.util.Map.Entry)30 AccumuloClient (org.apache.accumulo.core.client.AccumuloClient)30 Test (org.junit.jupiter.api.Test)30