Search in sources :

Example 1 with TRange

use of org.apache.accumulo.core.dataImpl.thrift.TRange in project accumulo by apache.

the class TabletServerBatchReaderIterator method doLookup.

static void doLookup(ClientContext context, String server, Map<KeyExtent, List<Range>> requested, Map<KeyExtent, List<Range>> failures, Map<KeyExtent, List<Range>> unscanned, ResultReceiver receiver, List<Column> columns, ScannerOptions options, Authorizations authorizations, TimeoutTracker timeoutTracker) throws IOException, AccumuloSecurityException, AccumuloServerException {
    if (requested.isEmpty()) {
        return;
    }
    // copy requested to unscanned map. we will remove ranges as they are scanned in trackScanning()
    for (Entry<KeyExtent, List<Range>> entry : requested.entrySet()) {
        ArrayList<Range> ranges = new ArrayList<>();
        for (Range range : entry.getValue()) {
            ranges.add(new Range(range));
        }
        unscanned.put(KeyExtent.copyOf(entry.getKey()), ranges);
    }
    timeoutTracker.startingScan();
    try {
        final HostAndPort parsedServer = HostAndPort.fromString(server);
        final TabletClientService.Client client;
        if (timeoutTracker.getTimeOut() < context.getClientTimeoutInMillis())
            client = ThriftUtil.getTServerClient(parsedServer, context, timeoutTracker.getTimeOut());
        else
            client = ThriftUtil.getTServerClient(parsedServer, context);
        try {
            OpTimer timer = null;
            if (log.isTraceEnabled()) {
                log.trace("tid={} Starting multi scan, tserver={}  #tablets={}  #ranges={} ssil={} ssio={}", Thread.currentThread().getId(), server, requested.size(), sumSizes(requested.values()), options.serverSideIteratorList, options.serverSideIteratorOptions);
                timer = new OpTimer().start();
            }
            TabletType ttype = TabletType.type(requested.keySet());
            boolean waitForWrites = !ThriftScanner.serversWaitedForWrites.get(ttype).contains(server);
            // @formatter:off
            Map<TKeyExtent, List<TRange>> thriftTabletRanges = requested.entrySet().stream().collect(Collectors.toMap((entry) -> entry.getKey().toThrift(), (entry) -> entry.getValue().stream().map(Range::toThrift).collect(Collectors.toList())));
            // @formatter:on
            Map<String, String> execHints = options.executionHints.isEmpty() ? null : options.executionHints;
            InitialMultiScan imsr = client.startMultiScan(TraceUtil.traceInfo(), context.rpcCreds(), thriftTabletRanges, columns.stream().map(Column::toThrift).collect(Collectors.toList()), options.serverSideIteratorList, options.serverSideIteratorOptions, ByteBufferUtil.toByteBuffers(authorizations.getAuthorizations()), waitForWrites, SamplerConfigurationImpl.toThrift(options.getSamplerConfiguration()), options.batchTimeOut, options.classLoaderContext, execHints);
            if (waitForWrites)
                ThriftScanner.serversWaitedForWrites.get(ttype).add(server.toString());
            MultiScanResult scanResult = imsr.result;
            if (timer != null) {
                timer.stop();
                log.trace("tid={} Got 1st multi scan results, #results={} {} in {}", Thread.currentThread().getId(), scanResult.results.size(), (scanResult.more ? "scanID=" + imsr.scanID : ""), String.format("%.3f secs", timer.scale(SECONDS)));
            }
            ArrayList<Entry<Key, Value>> entries = new ArrayList<>(scanResult.results.size());
            for (TKeyValue kv : scanResult.results) {
                entries.add(new SimpleImmutableEntry<>(new Key(kv.key), new Value(kv.value)));
            }
            if (!entries.isEmpty())
                receiver.receive(entries);
            if (!entries.isEmpty() || !scanResult.fullScans.isEmpty())
                timeoutTracker.madeProgress();
            trackScanning(failures, unscanned, scanResult);
            AtomicLong nextOpid = new AtomicLong();
            while (scanResult.more) {
                timeoutTracker.check();
                if (timer != null) {
                    log.trace("tid={} oid={} Continuing multi scan, scanid={}", Thread.currentThread().getId(), nextOpid.get(), imsr.scanID);
                    timer.reset().start();
                }
                scanResult = client.continueMultiScan(TraceUtil.traceInfo(), imsr.scanID);
                if (timer != null) {
                    timer.stop();
                    log.trace("tid={} oid={} Got more multi scan results, #results={} {} in {}", Thread.currentThread().getId(), nextOpid.getAndIncrement(), scanResult.results.size(), (scanResult.more ? " scanID=" + imsr.scanID : ""), String.format("%.3f secs", timer.scale(SECONDS)));
                }
                entries = new ArrayList<>(scanResult.results.size());
                for (TKeyValue kv : scanResult.results) {
                    entries.add(new SimpleImmutableEntry<>(new Key(kv.key), new Value(kv.value)));
                }
                if (!entries.isEmpty())
                    receiver.receive(entries);
                if (!entries.isEmpty() || !scanResult.fullScans.isEmpty())
                    timeoutTracker.madeProgress();
                trackScanning(failures, unscanned, scanResult);
            }
            client.closeMultiScan(TraceUtil.traceInfo(), imsr.scanID);
        } finally {
            ThriftUtil.returnClient(client, context);
        }
    } catch (TTransportException e) {
        log.debug("Server : {} msg : {}", server, e.getMessage());
        timeoutTracker.errorOccured();
        throw new IOException(e);
    } catch (ThriftSecurityException e) {
        log.debug("Server : {} msg : {}", server, e.getMessage(), e);
        throw new AccumuloSecurityException(e.user, e.code, e);
    } catch (TApplicationException e) {
        log.debug("Server : {} msg : {}", server, e.getMessage(), e);
        throw new AccumuloServerException(server, e);
    } catch (NoSuchScanIDException e) {
        log.debug("Server : {} msg : {}", server, e.getMessage(), e);
        throw new IOException(e);
    } catch (TSampleNotPresentException e) {
        log.debug("Server : " + server + " msg : " + e.getMessage(), e);
        String tableInfo = "?";
        if (e.getExtent() != null) {
            TableId tableId = KeyExtent.fromThrift(e.getExtent()).tableId();
            tableInfo = context.getPrintableTableInfoFromId(tableId);
        }
        String message = "Table " + tableInfo + " does not have sampling configured or built";
        throw new SampleNotPresentException(message, e);
    } catch (TException e) {
        log.debug("Server : {} msg : {}", server, e.getMessage(), e);
        timeoutTracker.errorOccured();
        throw new IOException(e);
    }
}
Also used : TableId(org.apache.accumulo.core.data.TableId) ThriftUtil(org.apache.accumulo.core.rpc.ThriftUtil) ListIterator(java.util.ListIterator) TTransportException(org.apache.thrift.transport.TTransportException) MultiScanResult(org.apache.accumulo.core.dataImpl.thrift.MultiScanResult) LoggerFactory(org.slf4j.LoggerFactory) TKeyValue(org.apache.accumulo.core.dataImpl.thrift.TKeyValue) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) Map(java.util.Map) TabletClientService(org.apache.accumulo.core.tabletserver.thrift.TabletClientService) Value(org.apache.accumulo.core.data.Value) NoSuchScanIDException(org.apache.accumulo.core.tabletserver.thrift.NoSuchScanIDException) Column(org.apache.accumulo.core.data.Column) Collection(java.util.Collection) Set(java.util.Set) ThriftSecurityException(org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException) Collectors(java.util.stream.Collectors) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) List(java.util.List) Entry(java.util.Map.Entry) TRange(org.apache.accumulo.core.dataImpl.thrift.TRange) TraceUtil(org.apache.accumulo.core.trace.TraceUtil) ByteBufferUtil(org.apache.accumulo.core.util.ByteBufferUtil) TimedOutException(org.apache.accumulo.core.client.TimedOutException) SamplerConfigurationImpl(org.apache.accumulo.core.sample.impl.SamplerConfigurationImpl) HostAndPort(org.apache.accumulo.core.util.HostAndPort) HashMap(java.util.HashMap) SimpleImmutableEntry(java.util.AbstractMap.SimpleImmutableEntry) TableDeletedException(org.apache.accumulo.core.client.TableDeletedException) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) TSampleNotPresentException(org.apache.accumulo.core.tabletserver.thrift.TSampleNotPresentException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) Key(org.apache.accumulo.core.data.Key) InitialMultiScan(org.apache.accumulo.core.dataImpl.thrift.InitialMultiScan) NoSuchElementException(java.util.NoSuchElementException) TApplicationException(org.apache.thrift.TApplicationException) ExecutorService(java.util.concurrent.ExecutorService) TKeyExtent(org.apache.accumulo.core.dataImpl.thrift.TKeyExtent) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) Semaphore(java.util.concurrent.Semaphore) KeyExtent(org.apache.accumulo.core.dataImpl.KeyExtent) TException(org.apache.thrift.TException) IOException(java.io.IOException) SampleNotPresentException(org.apache.accumulo.core.client.SampleNotPresentException) Authorizations(org.apache.accumulo.core.security.Authorizations) AccumuloException(org.apache.accumulo.core.client.AccumuloException) Range(org.apache.accumulo.core.data.Range) AtomicLong(java.util.concurrent.atomic.AtomicLong) OpTimer(org.apache.accumulo.core.util.OpTimer) Collections(java.util.Collections) SECONDS(java.util.concurrent.TimeUnit.SECONDS) TableId(org.apache.accumulo.core.data.TableId) TException(org.apache.thrift.TException) ArrayList(java.util.ArrayList) TTransportException(org.apache.thrift.transport.TTransportException) TKeyExtent(org.apache.accumulo.core.dataImpl.thrift.TKeyExtent) KeyExtent(org.apache.accumulo.core.dataImpl.KeyExtent) HostAndPort(org.apache.accumulo.core.util.HostAndPort) Entry(java.util.Map.Entry) SimpleImmutableEntry(java.util.AbstractMap.SimpleImmutableEntry) MultiScanResult(org.apache.accumulo.core.dataImpl.thrift.MultiScanResult) Column(org.apache.accumulo.core.data.Column) List(java.util.List) ArrayList(java.util.ArrayList) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) TKeyValue(org.apache.accumulo.core.dataImpl.thrift.TKeyValue) InitialMultiScan(org.apache.accumulo.core.dataImpl.thrift.InitialMultiScan) TKeyExtent(org.apache.accumulo.core.dataImpl.thrift.TKeyExtent) IOException(java.io.IOException) TRange(org.apache.accumulo.core.dataImpl.thrift.TRange) Range(org.apache.accumulo.core.data.Range) ThriftSecurityException(org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException) NoSuchScanIDException(org.apache.accumulo.core.tabletserver.thrift.NoSuchScanIDException) TApplicationException(org.apache.thrift.TApplicationException) AtomicLong(java.util.concurrent.atomic.AtomicLong) TSampleNotPresentException(org.apache.accumulo.core.tabletserver.thrift.TSampleNotPresentException) SampleNotPresentException(org.apache.accumulo.core.client.SampleNotPresentException) TSampleNotPresentException(org.apache.accumulo.core.tabletserver.thrift.TSampleNotPresentException) OpTimer(org.apache.accumulo.core.util.OpTimer) TKeyValue(org.apache.accumulo.core.dataImpl.thrift.TKeyValue) Value(org.apache.accumulo.core.data.Value) TabletClientService(org.apache.accumulo.core.tabletserver.thrift.TabletClientService) Key(org.apache.accumulo.core.data.Key)

Example 2 with TRange

use of org.apache.accumulo.core.dataImpl.thrift.TRange in project accumulo by apache.

the class RangeTest method testThrift.

@Test
public void testThrift() {
    Range r = newRange("nuts", "soup");
    TRange tr = r.toThrift();
    Range r2 = new Range(tr);
    assertEquals(r, r2);
}
Also used : TRange(org.apache.accumulo.core.dataImpl.thrift.TRange) TRange(org.apache.accumulo.core.dataImpl.thrift.TRange) Test(org.junit.jupiter.api.Test)

Example 3 with TRange

use of org.apache.accumulo.core.dataImpl.thrift.TRange in project accumulo by apache.

the class AuditedSecurityOperation method canScan.

@Override
public boolean canScan(TCredentials credentials, TableId tableId, NamespaceId namespaceId, TRange range, List<TColumn> columns, List<IterInfo> ssiList, Map<String, Map<String, String>> ssio, List<ByteBuffer> authorizations) throws ThriftSecurityException {
    if (shouldAudit(credentials, tableId)) {
        Range convertedRange = new Range(range);
        List<String> convertedColumns = truncate(columns.stream().map(Column::new).collect(Collectors.toList()));
        String tableName = getTableName(tableId);
        try {
            boolean canScan = super.canScan(credentials, tableId, namespaceId);
            audit(credentials, canScan, CAN_SCAN_AUDIT_TEMPLATE, tableName, getAuthString(authorizations), convertedRange, convertedColumns, ssiList, ssio);
            return canScan;
        } catch (ThriftSecurityException ex) {
            audit(credentials, ex, CAN_SCAN_AUDIT_TEMPLATE, getAuthString(authorizations), tableId, convertedRange, convertedColumns, ssiList, ssio);
            throw ex;
        }
    } else {
        return super.canScan(credentials, tableId, namespaceId);
    }
}
Also used : Column(org.apache.accumulo.core.data.Column) TColumn(org.apache.accumulo.core.dataImpl.thrift.TColumn) Range(org.apache.accumulo.core.data.Range) TRange(org.apache.accumulo.core.dataImpl.thrift.TRange) ThriftSecurityException(org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException)

Example 4 with TRange

use of org.apache.accumulo.core.dataImpl.thrift.TRange in project accumulo by apache.

the class RangeTest method testThrift_Check.

@Test
public void testThrift_Check() {
    Range r = new Range(new Key(new Text("soup")), true, false, new Key(new Text("nuts")), true, false);
    TRange tr = r.toThrift();
    assertThrows(IllegalArgumentException.class, () -> new Range(tr), "Thrift constructor allowed invalid range");
}
Also used : TRange(org.apache.accumulo.core.dataImpl.thrift.TRange) Text(org.apache.hadoop.io.Text) TRange(org.apache.accumulo.core.dataImpl.thrift.TRange) Test(org.junit.jupiter.api.Test)

Example 5 with TRange

use of org.apache.accumulo.core.dataImpl.thrift.TRange in project accumulo by apache.

the class VerifyTabletAssignments method checkTabletServer.

private static void checkTabletServer(ClientContext context, Entry<HostAndPort, List<KeyExtent>> entry, HashSet<KeyExtent> failures) throws ThriftSecurityException, TException, NoSuchScanIDException {
    TabletClientService.Iface client = ThriftUtil.getTServerClient(entry.getKey(), context);
    Map<TKeyExtent, List<TRange>> batch = new TreeMap<>();
    for (KeyExtent keyExtent : entry.getValue()) {
        Text row = keyExtent.endRow();
        Text row2 = null;
        if (row == null) {
            row = keyExtent.prevEndRow();
            if (row != null) {
                row = new Text(row);
                row.append(new byte[] { 'a' }, 0, 1);
            } else {
                row = new Text("1234567890");
            }
            row2 = new Text(row);
            row2.append(new byte[] { '!' }, 0, 1);
        } else {
            row = new Text(row);
            row2 = new Text(row);
            row.getBytes()[row.getLength() - 1] = (byte) (row.getBytes()[row.getLength() - 1] - 1);
        }
        Range r = new Range(row, true, row2, false);
        batch.put(keyExtent.toThrift(), Collections.singletonList(r.toThrift()));
    }
    TInfo tinfo = TraceUtil.traceInfo();
    Map<String, Map<String, String>> emptyMapSMapSS = Collections.emptyMap();
    List<IterInfo> emptyListIterInfo = Collections.emptyList();
    List<TColumn> emptyListColumn = Collections.emptyList();
    InitialMultiScan is = client.startMultiScan(tinfo, context.rpcCreds(), batch, emptyListColumn, emptyListIterInfo, emptyMapSMapSS, Authorizations.EMPTY.getAuthorizationsBB(), false, null, 0L, null, null);
    if (is.result.more) {
        MultiScanResult result = client.continueMultiScan(tinfo, is.scanID);
        checkFailures(entry.getKey(), failures, result);
        while (result.more) {
            result = client.continueMultiScan(tinfo, is.scanID);
            checkFailures(entry.getKey(), failures, result);
        }
    }
    client.closeMultiScan(tinfo, is.scanID);
    ThriftUtil.returnClient((TServiceClient) client, context);
}
Also used : TInfo(org.apache.accumulo.core.trace.thrift.TInfo) TColumn(org.apache.accumulo.core.dataImpl.thrift.TColumn) InitialMultiScan(org.apache.accumulo.core.dataImpl.thrift.InitialMultiScan) Text(org.apache.hadoop.io.Text) TKeyExtent(org.apache.accumulo.core.dataImpl.thrift.TKeyExtent) TreeMap(java.util.TreeMap) Range(org.apache.accumulo.core.data.Range) TRange(org.apache.accumulo.core.dataImpl.thrift.TRange) TKeyExtent(org.apache.accumulo.core.dataImpl.thrift.TKeyExtent) KeyExtent(org.apache.accumulo.core.dataImpl.KeyExtent) IterInfo(org.apache.accumulo.core.dataImpl.thrift.IterInfo) MultiScanResult(org.apache.accumulo.core.dataImpl.thrift.MultiScanResult) ArrayList(java.util.ArrayList) List(java.util.List) TabletClientService(org.apache.accumulo.core.tabletserver.thrift.TabletClientService) Map(java.util.Map) TreeMap(java.util.TreeMap)

Aggregations

TRange (org.apache.accumulo.core.dataImpl.thrift.TRange)9 Range (org.apache.accumulo.core.data.Range)6 MultiScanResult (org.apache.accumulo.core.dataImpl.thrift.MultiScanResult)6 ArrayList (java.util.ArrayList)5 List (java.util.List)5 Map (java.util.Map)5 ThriftSecurityException (org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException)5 KeyExtent (org.apache.accumulo.core.dataImpl.KeyExtent)5 TKeyExtent (org.apache.accumulo.core.dataImpl.thrift.TKeyExtent)5 IOException (java.io.IOException)4 HashMap (java.util.HashMap)4 SampleNotPresentException (org.apache.accumulo.core.client.SampleNotPresentException)4 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)4 Column (org.apache.accumulo.core.data.Column)4 TColumn (org.apache.accumulo.core.dataImpl.thrift.TColumn)4 HashSet (java.util.HashSet)3 Iterator (java.util.Iterator)3 Entry (java.util.Map.Entry)3 Collectors (java.util.stream.Collectors)3 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)3