Search in sources :

Example 1 with TabletId

use of org.apache.accumulo.core.data.TabletId in project accumulo by apache.

the class TestIngest method ingest.

public static void ingest(Connector connector, FileSystem fs, Opts opts, BatchWriterOpts bwOpts) throws IOException, AccumuloException, AccumuloSecurityException, TableNotFoundException, MutationsRejectedException, TableExistsException {
    long stopTime;
    byte[][] bytevals = generateValues(opts.dataSize);
    byte[] randomValue = new byte[opts.dataSize];
    Random random = new Random();
    long bytesWritten = 0;
    createTable(connector, opts);
    BatchWriter bw = null;
    FileSKVWriter writer = null;
    if (opts.outputFile != null) {
        Configuration conf = CachedConfiguration.getInstance();
        writer = FileOperations.getInstance().newWriterBuilder().forFile(opts.outputFile + "." + RFile.EXTENSION, fs, conf).withTableConfiguration(DefaultConfiguration.getInstance()).build();
        writer.startDefaultLocalityGroup();
    } else {
        bw = connector.createBatchWriter(opts.getTableName(), bwOpts.getBatchWriterConfig());
        connector.securityOperations().changeUserAuthorizations(opts.getPrincipal(), AUTHS);
    }
    Text labBA = new Text(opts.columnVisibility.getExpression());
    long startTime = System.currentTimeMillis();
    for (int i = 0; i < opts.rows; i++) {
        int rowid;
        if (opts.stride > 0) {
            rowid = ((i % opts.stride) * (opts.rows / opts.stride)) + (i / opts.stride);
        } else {
            rowid = i;
        }
        Text row = generateRow(rowid, opts.startRow);
        Mutation m = new Mutation(row);
        for (int j = 0; j < opts.cols; j++) {
            Text colf = new Text(opts.columnFamily);
            Text colq = new Text(FastFormat.toZeroPaddedString(j, 7, 10, COL_PREFIX));
            if (writer != null) {
                Key key = new Key(row, colf, colq, labBA);
                if (opts.timestamp >= 0) {
                    key.setTimestamp(opts.timestamp);
                } else {
                    key.setTimestamp(startTime);
                }
                if (opts.delete) {
                    key.setDeleted(true);
                } else {
                    key.setDeleted(false);
                }
                bytesWritten += key.getSize();
                if (opts.delete) {
                    writer.append(key, new Value(new byte[0]));
                } else {
                    byte[] value;
                    if (opts.random != null) {
                        value = genRandomValue(random, randomValue, opts.random, rowid + opts.startRow, j);
                    } else {
                        value = bytevals[j % bytevals.length];
                    }
                    Value v = new Value(value);
                    writer.append(key, v);
                    bytesWritten += v.getSize();
                }
            } else {
                Key key = new Key(row, colf, colq, labBA);
                bytesWritten += key.getSize();
                if (opts.delete) {
                    if (opts.timestamp >= 0)
                        m.putDelete(colf, colq, opts.columnVisibility, opts.timestamp);
                    else
                        m.putDelete(colf, colq, opts.columnVisibility);
                } else {
                    byte[] value;
                    if (opts.random != null) {
                        value = genRandomValue(random, randomValue, opts.random, rowid + opts.startRow, j);
                    } else {
                        value = bytevals[j % bytevals.length];
                    }
                    bytesWritten += value.length;
                    if (opts.timestamp >= 0) {
                        m.put(colf, colq, opts.columnVisibility, opts.timestamp, new Value(value, true));
                    } else {
                        m.put(colf, colq, opts.columnVisibility, new Value(value, true));
                    }
                }
            }
        }
        if (bw != null)
            bw.addMutation(m);
    }
    if (writer != null) {
        writer.close();
    } else if (bw != null) {
        try {
            bw.close();
        } catch (MutationsRejectedException e) {
            if (e.getSecurityErrorCodes().size() > 0) {
                for (Entry<TabletId, Set<SecurityErrorCode>> entry : e.getSecurityErrorCodes().entrySet()) {
                    System.err.println("ERROR : Not authorized to write to : " + entry.getKey() + " due to " + entry.getValue());
                }
            }
            if (e.getConstraintViolationSummaries().size() > 0) {
                for (ConstraintViolationSummary cvs : e.getConstraintViolationSummaries()) {
                    System.err.println("ERROR : Constraint violates : " + cvs);
                }
            }
            throw e;
        }
    }
    stopTime = System.currentTimeMillis();
    int totalValues = opts.rows * opts.cols;
    double elapsed = (stopTime - startTime) / 1000.0;
    System.out.printf("%,12d records written | %,8d records/sec | %,12d bytes written | %,8d bytes/sec | %6.3f secs   %n", totalValues, (int) (totalValues / elapsed), bytesWritten, (int) (bytesWritten / elapsed), elapsed);
}
Also used : TreeSet(java.util.TreeSet) Set(java.util.Set) Configuration(org.apache.hadoop.conf.Configuration) DefaultConfiguration(org.apache.accumulo.core.conf.DefaultConfiguration) CachedConfiguration(org.apache.accumulo.core.util.CachedConfiguration) FileSKVWriter(org.apache.accumulo.core.file.FileSKVWriter) Text(org.apache.hadoop.io.Text) Random(java.util.Random) Value(org.apache.accumulo.core.data.Value) TabletId(org.apache.accumulo.core.data.TabletId) ConstraintViolationSummary(org.apache.accumulo.core.data.ConstraintViolationSummary) TabletServerBatchWriter(org.apache.accumulo.core.client.impl.TabletServerBatchWriter) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Mutation(org.apache.accumulo.core.data.Mutation) Key(org.apache.accumulo.core.data.Key) MutationsRejectedException(org.apache.accumulo.core.client.MutationsRejectedException)

Example 2 with TabletId

use of org.apache.accumulo.core.data.TabletId in project accumulo by apache.

the class LocatorIT method assertContains.

private void assertContains(Locations locations, HashSet<String> tservers, Map<Range, ImmutableSet<TabletId>> expected1, Map<TabletId, ImmutableSet<Range>> expected2) {
    Map<Range, Set<TabletId>> gbr = new HashMap<>();
    for (Entry<Range, List<TabletId>> entry : locations.groupByRange().entrySet()) {
        gbr.put(entry.getKey(), new HashSet<>(entry.getValue()));
    }
    Assert.assertEquals(expected1, gbr);
    Map<TabletId, Set<Range>> gbt = new HashMap<>();
    for (Entry<TabletId, List<Range>> entry : locations.groupByTablet().entrySet()) {
        gbt.put(entry.getKey(), new HashSet<>(entry.getValue()));
        TabletId tid = entry.getKey();
        String location = locations.getTabletLocation(tid);
        Assert.assertNotNull("Location for " + tid + " was null", location);
        Assert.assertTrue("Unknown location " + location, tservers.contains(location));
        Assert.assertTrue("Expected <host>:<port> " + location, location.split(":").length == 2);
    }
    Assert.assertEquals(expected2, gbt);
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) TabletId(org.apache.accumulo.core.data.TabletId) Range(org.apache.accumulo.core.data.Range)

Example 3 with TabletId

use of org.apache.accumulo.core.data.TabletId in project accumulo by apache.

the class ProxyServer method getActiveCompactions.

@Override
public List<org.apache.accumulo.proxy.thrift.ActiveCompaction> getActiveCompactions(ByteBuffer login, String tserver) throws org.apache.accumulo.proxy.thrift.AccumuloException, org.apache.accumulo.proxy.thrift.AccumuloSecurityException, TException {
    try {
        List<org.apache.accumulo.proxy.thrift.ActiveCompaction> result = new ArrayList<>();
        List<ActiveCompaction> active = getConnector(login).instanceOperations().getActiveCompactions(tserver);
        for (ActiveCompaction comp : active) {
            org.apache.accumulo.proxy.thrift.ActiveCompaction pcomp = new org.apache.accumulo.proxy.thrift.ActiveCompaction();
            pcomp.age = comp.getAge();
            pcomp.entriesRead = comp.getEntriesRead();
            pcomp.entriesWritten = comp.getEntriesWritten();
            TabletId e = comp.getTablet();
            pcomp.extent = new org.apache.accumulo.proxy.thrift.KeyExtent(e.getTableId().toString(), TextUtil.getByteBuffer(e.getEndRow()), TextUtil.getByteBuffer(e.getPrevEndRow()));
            pcomp.inputFiles = new ArrayList<>();
            if (comp.getInputFiles() != null) {
                pcomp.inputFiles.addAll(comp.getInputFiles());
            }
            pcomp.localityGroup = comp.getLocalityGroup();
            pcomp.outputFile = comp.getOutputFile();
            pcomp.reason = CompactionReason.valueOf(comp.getReason().toString());
            pcomp.type = CompactionType.valueOf(comp.getType().toString());
            pcomp.iterators = new ArrayList<>();
            if (comp.getIterators() != null) {
                for (IteratorSetting setting : comp.getIterators()) {
                    org.apache.accumulo.proxy.thrift.IteratorSetting psetting = new org.apache.accumulo.proxy.thrift.IteratorSetting(setting.getPriority(), setting.getName(), setting.getIteratorClass(), setting.getOptions());
                    pcomp.iterators.add(psetting);
                }
            }
            result.add(pcomp);
        }
        return result;
    } catch (Exception e) {
        handleException(e);
        return null;
    }
}
Also used : ActiveCompaction(org.apache.accumulo.core.client.admin.ActiveCompaction) ArrayList(java.util.ArrayList) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) NamespaceNotFoundException(org.apache.accumulo.core.client.NamespaceNotFoundException) MutationsRejectedException(org.apache.accumulo.core.client.MutationsRejectedException) TableExistsException(org.apache.accumulo.core.client.TableExistsException) TException(org.apache.thrift.TException) NoMoreEntriesException(org.apache.accumulo.proxy.thrift.NoMoreEntriesException) ThriftTableOperationException(org.apache.accumulo.core.client.impl.thrift.ThriftTableOperationException) NamespaceExistsException(org.apache.accumulo.core.client.NamespaceExistsException) NamespaceNotEmptyException(org.apache.accumulo.core.client.NamespaceNotEmptyException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) AccumuloException(org.apache.accumulo.core.client.AccumuloException) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) TabletId(org.apache.accumulo.core.data.TabletId)

Example 4 with TabletId

use of org.apache.accumulo.core.data.TabletId in project accumulo by apache.

the class MutationsRejectedException method format.

private static String format(Map<TabletId, Set<SecurityErrorCode>> hashMap, Instance instance) {
    Map<String, Set<SecurityErrorCode>> result = new HashMap<>();
    for (Entry<TabletId, Set<SecurityErrorCode>> entry : hashMap.entrySet()) {
        TabletId tabletId = entry.getKey();
        String tableInfo = Tables.getPrintableTableInfoFromId(instance, Table.ID.of(tabletId.getTableId().toString()));
        if (!result.containsKey(tableInfo)) {
            result.put(tableInfo, new HashSet<>());
        }
        result.get(tableInfo).addAll(hashMap.get(tabletId));
    }
    return result.toString();
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) TabletId(org.apache.accumulo.core.data.TabletId)

Example 5 with TabletId

use of org.apache.accumulo.core.data.TabletId in project accumulo by apache.

the class ProxyServer method getActiveScans.

@Override
public List<org.apache.accumulo.proxy.thrift.ActiveScan> getActiveScans(ByteBuffer login, String tserver) throws org.apache.accumulo.proxy.thrift.AccumuloException, org.apache.accumulo.proxy.thrift.AccumuloSecurityException, TException {
    List<org.apache.accumulo.proxy.thrift.ActiveScan> result = new ArrayList<>();
    try {
        List<ActiveScan> activeScans = getConnector(login).instanceOperations().getActiveScans(tserver);
        for (ActiveScan scan : activeScans) {
            org.apache.accumulo.proxy.thrift.ActiveScan pscan = new org.apache.accumulo.proxy.thrift.ActiveScan();
            pscan.client = scan.getClient();
            pscan.user = scan.getUser();
            pscan.table = scan.getTable();
            pscan.age = scan.getAge();
            pscan.idleTime = scan.getIdleTime();
            pscan.type = ScanType.valueOf(scan.getType().toString());
            pscan.state = ScanState.valueOf(scan.getState().toString());
            TabletId e = scan.getTablet();
            pscan.extent = new org.apache.accumulo.proxy.thrift.KeyExtent(e.getTableId().toString(), TextUtil.getByteBuffer(e.getEndRow()), TextUtil.getByteBuffer(e.getPrevEndRow()));
            pscan.columns = new ArrayList<>();
            if (scan.getColumns() != null) {
                for (Column c : scan.getColumns()) {
                    org.apache.accumulo.proxy.thrift.Column column = new org.apache.accumulo.proxy.thrift.Column();
                    column.setColFamily(c.getColumnFamily());
                    column.setColQualifier(c.getColumnQualifier());
                    column.setColVisibility(c.getColumnVisibility());
                    pscan.columns.add(column);
                }
            }
            pscan.iterators = new ArrayList<>();
            for (String iteratorString : scan.getSsiList()) {
                String[] parts = iteratorString.split("[=,]");
                if (parts.length == 3) {
                    String name = parts[0];
                    int priority = Integer.parseInt(parts[1]);
                    String classname = parts[2];
                    org.apache.accumulo.proxy.thrift.IteratorSetting settings = new org.apache.accumulo.proxy.thrift.IteratorSetting(priority, name, classname, scan.getSsio().get(name));
                    pscan.iterators.add(settings);
                }
            }
            pscan.authorizations = new ArrayList<>();
            if (scan.getAuthorizations() != null) {
                for (byte[] a : scan.getAuthorizations()) {
                    pscan.authorizations.add(ByteBuffer.wrap(a));
                }
            }
            result.add(pscan);
        }
        return result;
    } catch (Exception e) {
        handleException(e);
        return null;
    }
}
Also used : ActiveScan(org.apache.accumulo.core.client.admin.ActiveScan) ArrayList(java.util.ArrayList) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) NamespaceNotFoundException(org.apache.accumulo.core.client.NamespaceNotFoundException) MutationsRejectedException(org.apache.accumulo.core.client.MutationsRejectedException) TableExistsException(org.apache.accumulo.core.client.TableExistsException) TException(org.apache.thrift.TException) NoMoreEntriesException(org.apache.accumulo.proxy.thrift.NoMoreEntriesException) ThriftTableOperationException(org.apache.accumulo.core.client.impl.thrift.ThriftTableOperationException) NamespaceExistsException(org.apache.accumulo.core.client.NamespaceExistsException) NamespaceNotEmptyException(org.apache.accumulo.core.client.NamespaceNotEmptyException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) AccumuloException(org.apache.accumulo.core.client.AccumuloException) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) Column(org.apache.accumulo.core.data.Column) ScanColumn(org.apache.accumulo.proxy.thrift.ScanColumn) TabletId(org.apache.accumulo.core.data.TabletId)

Aggregations

TabletId (org.apache.accumulo.core.data.TabletId)7 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)4 Set (java.util.Set)4 TreeSet (java.util.TreeSet)4 MutationsRejectedException (org.apache.accumulo.core.client.MutationsRejectedException)4 HashMap (java.util.HashMap)3 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)3 AccumuloException (org.apache.accumulo.core.client.AccumuloException)2 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)2 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)2 NamespaceExistsException (org.apache.accumulo.core.client.NamespaceExistsException)2 NamespaceNotEmptyException (org.apache.accumulo.core.client.NamespaceNotEmptyException)2 NamespaceNotFoundException (org.apache.accumulo.core.client.NamespaceNotFoundException)2 TableExistsException (org.apache.accumulo.core.client.TableExistsException)2 ThriftTableOperationException (org.apache.accumulo.core.client.impl.thrift.ThriftTableOperationException)2 ConstraintViolationSummary (org.apache.accumulo.core.data.ConstraintViolationSummary)2 Range (org.apache.accumulo.core.data.Range)2 NoMoreEntriesException (org.apache.accumulo.proxy.thrift.NoMoreEntriesException)2 Text (org.apache.hadoop.io.Text)2