Search in sources :

Example 71 with NavigableMap

use of java.util.NavigableMap in project cdap by caskdata.

the class MetricsTableOnTable method increment.

@Override
public void increment(NavigableMap<byte[], NavigableMap<byte[], Long>> updates) {
    for (Map.Entry<byte[], NavigableMap<byte[], Long>> rowUpdate : updates.entrySet()) {
        Increment increment = new Increment(rowUpdate.getKey());
        for (Map.Entry<byte[], Long> columnUpdate : rowUpdate.getValue().entrySet()) {
            increment.add(columnUpdate.getKey(), columnUpdate.getValue());
        }
        table.increment(increment);
    }
}
Also used : NavigableMap(java.util.NavigableMap) Increment(co.cask.cdap.api.dataset.table.Increment) Map(java.util.Map) NavigableMap(java.util.NavigableMap) SortedMap(java.util.SortedMap)

Example 72 with NavigableMap

use of java.util.NavigableMap in project cdap by caskdata.

the class BufferingTable method get.

@ReadOnly
@Override
public List<Row> get(List<Get> gets) {
    ensureTransactionIsStarted();
    try {
        // get persisted, then overwrite with whats buffered
        List<Map<byte[], byte[]>> persistedRows = getPersisted(gets);
        // gets and rows lists are always of the same size
        Preconditions.checkArgument(gets.size() == persistedRows.size(), "Invalid number of rows fetched when performing multi-get. There must be one row for each get.");
        List<Row> result = Lists.newArrayListWithCapacity(persistedRows.size());
        Iterator<Map<byte[], byte[]>> persistedRowsIter = persistedRows.iterator();
        Iterator<Get> getIter = gets.iterator();
        while (persistedRowsIter.hasNext() && getIter.hasNext()) {
            Get get = getIter.next();
            Map<byte[], byte[]> persistedRow = persistedRowsIter.next();
            // navigable copy of the persisted data. Implementation may return immutable or unmodifiable maps,
            // so we make a copy here.
            NavigableMap<byte[], byte[]> rowColumns = Maps.newTreeMap(Bytes.BYTES_COMPARATOR);
            rowColumns.putAll(persistedRow);
            byte[] row = get.getRow();
            NavigableMap<byte[], Update> buffCols = buff.get(row);
            // merge what was in the buffer and what was persisted
            if (buffCols != null) {
                List<byte[]> getColumns = get.getColumns();
                byte[][] columns = getColumns == null ? null : getColumns.toArray(new byte[getColumns.size()][]);
                mergeToPersisted(rowColumns, buffCols, columns);
            }
            result.add(new Result(row, unwrapDeletes(rowColumns)));
        }
        return result;
    } catch (Exception e) {
        LOG.debug("multi-get failed for table: " + getTransactionAwareName(), e);
        throw new DataSetException("multi-get failed", e);
    }
}
Also used : IOException(java.io.IOException) DataSetException(co.cask.cdap.api.dataset.DataSetException) Result(co.cask.cdap.api.dataset.table.Result) DataSetException(co.cask.cdap.api.dataset.DataSetException) Get(co.cask.cdap.api.dataset.table.Get) Row(co.cask.cdap.api.dataset.table.Row) Map(java.util.Map) NavigableMap(java.util.NavigableMap) ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) ReadOnly(co.cask.cdap.api.annotation.ReadOnly)

Example 73 with NavigableMap

use of java.util.NavigableMap in project cdap by caskdata.

the class BufferingTable method scan.

@ReadOnly
@Override
public Scanner scan(Scan scan) {
    ensureTransactionIsStarted();
    NavigableMap<byte[], NavigableMap<byte[], Update>> bufferMap = scanBuffer(scan);
    try {
        return new BufferingScanner(bufferMap, scanPersisted(scan));
    } catch (Exception e) {
        LOG.debug("scan failed for table: " + getTransactionAwareName() + ", scan: " + scan.toString(), e);
        throw new DataSetException("scan failed", e);
    }
}
Also used : NavigableMap(java.util.NavigableMap) DataSetException(co.cask.cdap.api.dataset.DataSetException) IOException(java.io.IOException) DataSetException(co.cask.cdap.api.dataset.DataSetException) ReadOnly(co.cask.cdap.api.annotation.ReadOnly)

Example 74 with NavigableMap

use of java.util.NavigableMap in project cdap by caskdata.

the class IncrementHandler method prePut.

@Override
public void prePut(ObserverContext<RegionCoprocessorEnvironment> ctx, Put put, WALEdit edit, Durability durability) throws IOException {
    // we assume that if any of the column families written to are transactional, the entire write is transactional
    boolean transactional = state.containsTransactionalFamily(put.getFamilyCellMap().keySet());
    boolean isIncrement = put.getAttribute(HBaseTable.DELTA_WRITE) != null;
    if (isIncrement || !transactional) {
        // incremental write
        NavigableMap<byte[], List<Cell>> newFamilyMap = new TreeMap<>(Bytes.BYTES_COMPARATOR);
        long tsToAssign = 0;
        if (!transactional) {
            tsToAssign = state.getUniqueTimestamp();
        }
        for (Map.Entry<byte[], List<Cell>> entry : put.getFamilyCellMap().entrySet()) {
            List<Cell> newCells = new ArrayList<>(entry.getValue().size());
            for (Cell cell : entry.getValue()) {
                // rewrite the cell value with a special prefix to identify it as a delta
                // for 0.98 we can update this to use cell tags
                byte[] newValue = isIncrement ? Bytes.add(IncrementHandlerState.DELTA_MAGIC_PREFIX, CellUtil.cloneValue(cell)) : CellUtil.cloneValue(cell);
                newCells.add(CellUtil.createCell(CellUtil.cloneRow(cell), CellUtil.cloneFamily(cell), CellUtil.cloneQualifier(cell), transactional ? cell.getTimestamp() : tsToAssign, cell.getTypeByte(), newValue));
            }
            newFamilyMap.put(entry.getKey(), newCells);
        }
        put.setFamilyCellMap(newFamilyMap);
    }
// put completes normally with value prefix marker
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) TreeMap(java.util.TreeMap) Map(java.util.Map) NavigableMap(java.util.NavigableMap) TreeMap(java.util.TreeMap) Cell(org.apache.hadoop.hbase.Cell)

Example 75 with NavigableMap

use of java.util.NavigableMap in project cdap by caskdata.

the class IncrementHandler method prePut.

@Override
public void prePut(ObserverContext<RegionCoprocessorEnvironment> ctx, Put put, WALEdit edit, Durability durability) throws IOException {
    // we assume that if any of the column families written to are transactional, the entire write is transactional
    boolean transactional = state.containsTransactionalFamily(put.getFamilyCellMap().keySet());
    boolean isIncrement = put.getAttribute(HBaseTable.DELTA_WRITE) != null;
    if (isIncrement || !transactional) {
        // incremental write
        NavigableMap<byte[], List<Cell>> newFamilyMap = new TreeMap<>(Bytes.BYTES_COMPARATOR);
        long tsToAssign = 0;
        if (!transactional) {
            tsToAssign = state.getUniqueTimestamp();
        }
        for (Map.Entry<byte[], List<Cell>> entry : put.getFamilyCellMap().entrySet()) {
            List<Cell> newCells = new ArrayList<>(entry.getValue().size());
            for (Cell cell : entry.getValue()) {
                // rewrite the cell value with a special prefix to identify it as a delta
                // for 0.98 we can update this to use cell tags
                byte[] newValue = isIncrement ? Bytes.add(IncrementHandlerState.DELTA_MAGIC_PREFIX, CellUtil.cloneValue(cell)) : CellUtil.cloneValue(cell);
                newCells.add(CellUtil.createCell(CellUtil.cloneRow(cell), CellUtil.cloneFamily(cell), CellUtil.cloneQualifier(cell), transactional ? cell.getTimestamp() : tsToAssign, cell.getTypeByte(), newValue));
            }
            newFamilyMap.put(entry.getKey(), newCells);
        }
        put.setFamilyCellMap(newFamilyMap);
    }
// put completes normally with value prefix marker
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) TreeMap(java.util.TreeMap) Map(java.util.Map) NavigableMap(java.util.NavigableMap) TreeMap(java.util.TreeMap) Cell(org.apache.hadoop.hbase.Cell)

Aggregations

NavigableMap (java.util.NavigableMap)173 Map (java.util.Map)85 TreeMap (java.util.TreeMap)62 SortedMap (java.util.SortedMap)35 ArrayList (java.util.ArrayList)34 List (java.util.List)27 HashMap (java.util.HashMap)21 Iterator (java.util.Iterator)21 Cell (org.apache.hadoop.hbase.Cell)20 Result (org.apache.hadoop.hbase.client.Result)19 Set (java.util.Set)14 Get (org.apache.hadoop.hbase.client.Get)14 IOException (java.io.IOException)12 KeyValue (org.apache.hadoop.hbase.KeyValue)11 Test (org.junit.Test)11 Put (org.apache.hadoop.hbase.client.Put)10 Entry (java.util.Map.Entry)9 Update (co.cask.cdap.data2.dataset2.lib.table.Update)7 ImmutableMap (com.google.common.collect.ImmutableMap)7 TestSuite (junit.framework.TestSuite)7