Search in sources :

Example 6 with RowIterator

use of org.apache.accumulo.core.client.RowIterator in project accumulo by apache.

the class TabletGroupWatcher method deleteTablets.

private void deleteTablets(MergeInfo info, Range scanRange, BatchWriter bw, Connector conn) throws TableNotFoundException, MutationsRejectedException {
    Scanner scanner;
    Mutation m;
    // Delete everything in the other tablets
    // group all deletes into tablet into one mutation, this makes tablets
    // either disappear entirely or not all.. this is important for the case
    // where the process terminates in the loop below...
    scanner = conn.createScanner(info.getExtent().isMeta() ? RootTable.NAME : MetadataTable.NAME, Authorizations.EMPTY);
    Master.log.debug("Deleting range {}", scanRange);
    scanner.setRange(scanRange);
    RowIterator rowIter = new RowIterator(scanner);
    while (rowIter.hasNext()) {
        Iterator<Entry<Key, Value>> row = rowIter.next();
        m = null;
        while (row.hasNext()) {
            Entry<Key, Value> entry = row.next();
            Key key = entry.getKey();
            if (m == null)
                m = new Mutation(key.getRow());
            m.putDelete(key.getColumnFamily(), key.getColumnQualifier());
            Master.log.debug("deleting entry {}", key);
        }
        bw.addMutation(m);
    }
    bw.flush();
}
Also used : Scanner(org.apache.accumulo.core.client.Scanner) Entry(java.util.Map.Entry) RowIterator(org.apache.accumulo.core.client.RowIterator) Value(org.apache.accumulo.core.data.Value) Mutation(org.apache.accumulo.core.data.Mutation) Key(org.apache.accumulo.core.data.Key) PartialKey(org.apache.accumulo.core.data.PartialKey)

Example 7 with RowIterator

use of org.apache.accumulo.core.client.RowIterator in project accumulo by apache.

the class InputConfigurator method binOffline.

public static Map<String, Map<KeyExtent, List<Range>>> binOffline(Table.ID tableId, List<Range> ranges, Instance instance, Connector conn) throws AccumuloException, TableNotFoundException {
    Map<String, Map<KeyExtent, List<Range>>> binnedRanges = new HashMap<>();
    if (Tables.getTableState(instance, tableId) != TableState.OFFLINE) {
        Tables.clearCache(instance);
        if (Tables.getTableState(instance, tableId) != TableState.OFFLINE) {
            throw new AccumuloException("Table is online tableId:" + tableId + " cannot scan table in offline mode ");
        }
    }
    for (Range range : ranges) {
        Text startRow;
        if (range.getStartKey() != null)
            startRow = range.getStartKey().getRow();
        else
            startRow = new Text();
        Range metadataRange = new Range(new KeyExtent(tableId, startRow, null).getMetadataEntry(), true, null, false);
        Scanner scanner = conn.createScanner(MetadataTable.NAME, Authorizations.EMPTY);
        MetadataSchema.TabletsSection.TabletColumnFamily.PREV_ROW_COLUMN.fetch(scanner);
        scanner.fetchColumnFamily(MetadataSchema.TabletsSection.LastLocationColumnFamily.NAME);
        scanner.fetchColumnFamily(MetadataSchema.TabletsSection.CurrentLocationColumnFamily.NAME);
        scanner.fetchColumnFamily(MetadataSchema.TabletsSection.FutureLocationColumnFamily.NAME);
        scanner.setRange(metadataRange);
        RowIterator rowIter = new RowIterator(scanner);
        KeyExtent lastExtent = null;
        while (rowIter.hasNext()) {
            Iterator<Map.Entry<Key, Value>> row = rowIter.next();
            String last = "";
            KeyExtent extent = null;
            String location = null;
            while (row.hasNext()) {
                Map.Entry<Key, Value> entry = row.next();
                Key key = entry.getKey();
                if (key.getColumnFamily().equals(MetadataSchema.TabletsSection.LastLocationColumnFamily.NAME)) {
                    last = entry.getValue().toString();
                }
                if (key.getColumnFamily().equals(MetadataSchema.TabletsSection.CurrentLocationColumnFamily.NAME) || key.getColumnFamily().equals(MetadataSchema.TabletsSection.FutureLocationColumnFamily.NAME)) {
                    location = entry.getValue().toString();
                }
                if (MetadataSchema.TabletsSection.TabletColumnFamily.PREV_ROW_COLUMN.hasColumns(key)) {
                    extent = new KeyExtent(key.getRow(), entry.getValue());
                }
            }
            if (location != null)
                return null;
            if (!extent.getTableId().equals(tableId)) {
                throw new AccumuloException("Saw unexpected table Id " + tableId + " " + extent);
            }
            if (lastExtent != null && !extent.isPreviousExtent(lastExtent)) {
                throw new AccumuloException(" " + lastExtent + " is not previous extent " + extent);
            }
            Map<KeyExtent, List<Range>> tabletRanges = binnedRanges.get(last);
            if (tabletRanges == null) {
                tabletRanges = new HashMap<>();
                binnedRanges.put(last, tabletRanges);
            }
            List<Range> rangeList = tabletRanges.get(extent);
            if (rangeList == null) {
                rangeList = new ArrayList<>();
                tabletRanges.put(extent, rangeList);
            }
            rangeList.add(range);
            if (extent.getEndRow() == null || range.afterEndKey(new Key(extent.getEndRow()).followingKey(PartialKey.ROW))) {
                break;
            }
            lastExtent = extent;
        }
    }
    return binnedRanges;
}
Also used : AccumuloException(org.apache.accumulo.core.client.AccumuloException) BatchScanner(org.apache.accumulo.core.client.BatchScanner) ClientSideIteratorScanner(org.apache.accumulo.core.client.ClientSideIteratorScanner) IsolatedScanner(org.apache.accumulo.core.client.IsolatedScanner) Scanner(org.apache.accumulo.core.client.Scanner) HashMap(java.util.HashMap) Text(org.apache.hadoop.io.Text) Range(org.apache.accumulo.core.data.Range) KeyExtent(org.apache.accumulo.core.data.impl.KeyExtent) RowIterator(org.apache.accumulo.core.client.RowIterator) Value(org.apache.accumulo.core.data.Value) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) Key(org.apache.accumulo.core.data.Key) PartialKey(org.apache.accumulo.core.data.PartialKey)

Example 8 with RowIterator

use of org.apache.accumulo.core.client.RowIterator in project accumulo by apache.

the class CompactionDriver method isReady.

@Override
public long isReady(long tid, Master master) throws Exception {
    String zCancelID = Constants.ZROOT + "/" + master.getInstance().getInstanceID() + Constants.ZTABLES + "/" + tableId + Constants.ZTABLE_COMPACT_CANCEL_ID;
    IZooReaderWriter zoo = ZooReaderWriter.getInstance();
    if (Long.parseLong(new String(zoo.getData(zCancelID, null))) >= compactId) {
        // compaction was canceled
        throw new AcceptableThriftTableOperationException(tableId.canonicalID(), null, TableOperation.COMPACT, TableOperationExceptionType.OTHER, "Compaction canceled");
    }
    MapCounter<TServerInstance> serversToFlush = new MapCounter<>();
    Connector conn = master.getConnector();
    Scanner scanner;
    if (tableId.equals(MetadataTable.ID)) {
        scanner = new IsolatedScanner(conn.createScanner(RootTable.NAME, Authorizations.EMPTY));
        scanner.setRange(MetadataSchema.TabletsSection.getRange());
    } else {
        scanner = new IsolatedScanner(conn.createScanner(MetadataTable.NAME, Authorizations.EMPTY));
        Range range = new KeyExtent(tableId, null, startRow == null ? null : new Text(startRow)).toMetadataRange();
        scanner.setRange(range);
    }
    TabletsSection.ServerColumnFamily.COMPACT_COLUMN.fetch(scanner);
    TabletsSection.ServerColumnFamily.DIRECTORY_COLUMN.fetch(scanner);
    scanner.fetchColumnFamily(TabletsSection.CurrentLocationColumnFamily.NAME);
    long t1 = System.currentTimeMillis();
    RowIterator ri = new RowIterator(scanner);
    int tabletsToWaitFor = 0;
    int tabletCount = 0;
    while (ri.hasNext()) {
        Iterator<Entry<Key, Value>> row = ri.next();
        long tabletCompactID = -1;
        TServerInstance server = null;
        Entry<Key, Value> entry = null;
        while (row.hasNext()) {
            entry = row.next();
            Key key = entry.getKey();
            if (TabletsSection.ServerColumnFamily.COMPACT_COLUMN.equals(key.getColumnFamily(), key.getColumnQualifier()))
                tabletCompactID = Long.parseLong(entry.getValue().toString());
            if (TabletsSection.CurrentLocationColumnFamily.NAME.equals(key.getColumnFamily()))
                server = new TServerInstance(entry.getValue(), key.getColumnQualifier());
        }
        if (tabletCompactID < compactId) {
            tabletsToWaitFor++;
            if (server != null)
                serversToFlush.increment(server, 1);
        }
        tabletCount++;
        Text tabletEndRow = new KeyExtent(entry.getKey().getRow(), (Text) null).getEndRow();
        if (tabletEndRow == null || (endRow != null && tabletEndRow.compareTo(new Text(endRow)) >= 0))
            break;
    }
    long scanTime = System.currentTimeMillis() - t1;
    Instance instance = master.getInstance();
    Tables.clearCache(instance);
    if (tabletCount == 0 && !Tables.exists(instance, tableId))
        throw new AcceptableThriftTableOperationException(tableId.canonicalID(), null, TableOperation.COMPACT, TableOperationExceptionType.NOTFOUND, null);
    if (serversToFlush.size() == 0 && Tables.getTableState(instance, tableId) == TableState.OFFLINE)
        throw new AcceptableThriftTableOperationException(tableId.canonicalID(), null, TableOperation.COMPACT, TableOperationExceptionType.OFFLINE, null);
    if (tabletsToWaitFor == 0)
        return 0;
    for (TServerInstance tsi : serversToFlush.keySet()) {
        try {
            final TServerConnection server = master.getConnection(tsi);
            if (server != null)
                server.compact(master.getMasterLock(), tableId.canonicalID(), startRow, endRow);
        } catch (TException ex) {
            LoggerFactory.getLogger(CompactionDriver.class).error(ex.toString());
        }
    }
    long sleepTime = 500;
    if (serversToFlush.size() > 0)
        // make wait time depend on the server with the most to
        sleepTime = Collections.max(serversToFlush.values()) * sleepTime;
    // compact
    sleepTime = Math.max(2 * scanTime, sleepTime);
    sleepTime = Math.min(sleepTime, 30000);
    return sleepTime;
}
Also used : TException(org.apache.thrift.TException) Connector(org.apache.accumulo.core.client.Connector) IsolatedScanner(org.apache.accumulo.core.client.IsolatedScanner) Scanner(org.apache.accumulo.core.client.Scanner) Instance(org.apache.accumulo.core.client.Instance) TServerInstance(org.apache.accumulo.server.master.state.TServerInstance) Text(org.apache.hadoop.io.Text) Range(org.apache.accumulo.core.data.Range) KeyExtent(org.apache.accumulo.core.data.impl.KeyExtent) TServerInstance(org.apache.accumulo.server.master.state.TServerInstance) AcceptableThriftTableOperationException(org.apache.accumulo.core.client.impl.AcceptableThriftTableOperationException) TServerConnection(org.apache.accumulo.server.master.LiveTServerSet.TServerConnection) Entry(java.util.Map.Entry) IZooReaderWriter(org.apache.accumulo.fate.zookeeper.IZooReaderWriter) RowIterator(org.apache.accumulo.core.client.RowIterator) MapCounter(org.apache.accumulo.core.util.MapCounter) Value(org.apache.accumulo.core.data.Value) IsolatedScanner(org.apache.accumulo.core.client.IsolatedScanner) Key(org.apache.accumulo.core.data.Key)

Example 9 with RowIterator

use of org.apache.accumulo.core.client.RowIterator in project accumulo by apache.

the class OfflineIterator method getTabletFiles.

private Pair<KeyExtent, String> getTabletFiles(Range nextRange, List<String> relFiles) throws TableNotFoundException {
    Scanner scanner = conn.createScanner(MetadataTable.NAME, Authorizations.EMPTY);
    scanner.setBatchSize(100);
    scanner.setRange(nextRange);
    RowIterator rowIter = new RowIterator(scanner);
    Iterator<Entry<Key, Value>> row = rowIter.next();
    KeyExtent extent = null;
    String location = null;
    while (row.hasNext()) {
        Entry<Key, Value> entry = row.next();
        Key key = entry.getKey();
        if (key.getColumnFamily().equals(DataFileColumnFamily.NAME)) {
            relFiles.add(key.getColumnQualifier().toString());
        }
        if (key.getColumnFamily().equals(TabletsSection.CurrentLocationColumnFamily.NAME) || key.getColumnFamily().equals(TabletsSection.FutureLocationColumnFamily.NAME)) {
            location = entry.getValue().toString();
        }
        if (TabletsSection.TabletColumnFamily.PREV_ROW_COLUMN.hasColumns(key)) {
            extent = new KeyExtent(key.getRow(), entry.getValue());
        }
    }
    return new Pair<>(extent, location);
}
Also used : Scanner(org.apache.accumulo.core.client.Scanner) Entry(java.util.Map.Entry) RowIterator(org.apache.accumulo.core.client.RowIterator) KeyValue(org.apache.accumulo.core.data.KeyValue) Value(org.apache.accumulo.core.data.Value) KeyExtent(org.apache.accumulo.core.data.impl.KeyExtent) Key(org.apache.accumulo.core.data.Key) PartialKey(org.apache.accumulo.core.data.PartialKey) Pair(org.apache.accumulo.core.util.Pair)

Example 10 with RowIterator

use of org.apache.accumulo.core.client.RowIterator in project gora by apache.

the class AccumuloStore method deleteByQuery.

@Override
public long deleteByQuery(Query<K, T> query) throws GoraException {
    try {
        Scanner scanner = createScanner(query);
        // add iterator that drops values on the server side
        scanner.addScanIterator(new IteratorSetting(Integer.MAX_VALUE, SortedKeyIterator.class));
        RowIterator iterator = new RowIterator(scanner.iterator());
        long count = 0;
        while (iterator.hasNext()) {
            Iterator<Entry<Key, Value>> row = iterator.next();
            Mutation m = null;
            while (row.hasNext()) {
                Entry<Key, Value> entry = row.next();
                Key key = entry.getKey();
                if (m == null)
                    m = new Mutation(key.getRow());
                // TODO optimize to avoid continually creating column vis? prob does not matter for empty
                m.putDelete(key.getColumnFamily(), key.getColumnQualifier(), new ColumnVisibility(key.getColumnVisibility()), key.getTimestamp());
            }
            getBatchWriter().addMutation(m);
            count++;
        }
        return count;
    } catch (Exception e) {
        throw new GoraException(e);
    }
}
Also used : IsolatedScanner(org.apache.accumulo.core.client.IsolatedScanner) Scanner(org.apache.accumulo.core.client.Scanner) TableOfflineException(org.apache.accumulo.core.client.TableOfflineException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) GoraException(org.apache.gora.util.GoraException) MutationsRejectedException(org.apache.accumulo.core.client.MutationsRejectedException) InvocationTargetException(java.lang.reflect.InvocationTargetException) TableExistsException(org.apache.accumulo.core.client.TableExistsException) TableDeletedException(org.apache.accumulo.core.client.TableDeletedException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) IOException(java.io.IOException) AccumuloException(org.apache.accumulo.core.client.AccumuloException) Entry(java.util.Map.Entry) GoraException(org.apache.gora.util.GoraException) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) SortedKeyIterator(org.apache.accumulo.core.iterators.SortedKeyIterator) RowIterator(org.apache.accumulo.core.client.RowIterator) Value(org.apache.accumulo.core.data.Value) Mutation(org.apache.accumulo.core.data.Mutation) ColumnVisibility(org.apache.accumulo.core.security.ColumnVisibility) Key(org.apache.accumulo.core.data.Key)

Aggregations

RowIterator (org.apache.accumulo.core.client.RowIterator)16 Key (org.apache.accumulo.core.data.Key)13 Value (org.apache.accumulo.core.data.Value)13 Scanner (org.apache.accumulo.core.client.Scanner)12 Entry (java.util.Map.Entry)11 Text (org.apache.hadoop.io.Text)10 IsolatedScanner (org.apache.accumulo.core.client.IsolatedScanner)9 AccumuloException (org.apache.accumulo.core.client.AccumuloException)6 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)6 PartialKey (org.apache.accumulo.core.data.PartialKey)6 Range (org.apache.accumulo.core.data.Range)6 ArrayList (java.util.ArrayList)5 KeyExtent (org.apache.accumulo.core.data.impl.KeyExtent)5 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)4 BatchScanner (org.apache.accumulo.core.client.BatchScanner)4 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 List (java.util.List)3 Map (java.util.Map)3