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);
}
}
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);
}
}
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);
}
}
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
}
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
}
Aggregations