public Optional<LatestSnapshotRowResult> getRow(LatestSnapshotRow row, ColumnSelection columns) { byte[] bytes = row.persistToBytes(); RowResult<byte[]> rowResult = t.getRows(tableRef, ImmutableSet.of(bytes), columns).get(bytes); if (rowResult == null) { return Optional.empty(); } else { return Optional.of(LatestSnapshotRowResult.of(rowResult)); } }
private void verifyAllGetRangesImplsNumRanges(Transaction t, Iterable<RangeRequest> rangeRequests, List<String> expectedValues) { Iterable<BatchingVisitable<RowResult<byte[]>>> getRangesWithPrefetchingImpl = t.getRanges(TEST_TABLE, rangeRequests); Iterable<BatchingVisitable<RowResult<byte[]>>> getRangesInParallelImpl = t.getRanges(TEST_TABLE, rangeRequests, 2, (rangeRequest, visitable) -> visitable).collect(Collectors.toList()); Iterable<BatchingVisitable<RowResult<byte[]>>> getRangesLazyImpl = t.getRangesLazy(TEST_TABLE, rangeRequests).collect(Collectors.toList()); assertEquals(expectedValues, extractStringsFromVisitables(getRangesWithPrefetchingImpl)); assertEquals(expectedValues, extractStringsFromVisitables(getRangesInParallelImpl)); assertEquals(expectedValues, extractStringsFromVisitables(getRangesLazyImpl)); }
public BatchingVisitableView<KeyValueRowResult> getRange(RangeRequest range) { if (range.getColumnNames().isEmpty()) { range = range.getBuilder().retainColumns(allColumns).build(); } return BatchingVisitables.transform(t.getRange(tableRef, range), new Function<RowResult<byte[]>, KeyValueRowResult>() { @Override public KeyValueRowResult apply(RowResult<byte[]> input) { return KeyValueRowResult.of(input); } }); }
private String getCell(Transaction txn, TableReference tableRef, String rowName, String columnName) { Cell cell = createCell(rowName, columnName); Map<Cell, byte[]> map = txn.get(tableRef, ImmutableSet.of(cell)); byte[] valueBytes = map.get(cell); return valueBytes != null ? PtBytes.toString(valueBytes) : null; }
@Override public void delete(Iterable<ValueStreamMetadataRow> rows) { List<byte[]> rowBytes = Persistables.persistAll(rows); Set<Cell> cells = Sets.newHashSetWithExpectedSize(rowBytes.size()); cells.addAll(Cells.cellsWithConstantColumn(rowBytes, PtBytes.toCachedBytes("md"))); t.delete(tableRef, cells); }
@Override public Iterator<Map.Entry<Cell, byte[]>> getRowsColumnRange(TableReference tableRef, Iterable<byte[]> rows, ColumnRangeSelection columnRangeSelection, int batchHint) { checkTableName(tableRef); return delegate().getRowsColumnRange(tableRef, rows, columnRangeSelection, batchHint); }
private long put(SerializableTransactionManager txm, TableReference table, String row, String val) { Cell cell = Cell.create(row.getBytes(StandardCharsets.UTF_8), COL.getBytes(StandardCharsets.UTF_8)); return txm.runTaskWithRetry(t -> { t.put(table, ImmutableMap.of(cell, val.getBytes(StandardCharsets.UTF_8))); return t.getTimestamp(); }); }
public <T> Stream<T> getRanges(Iterable<RangeRequest> ranges, int concurrencyLevel, BiFunction<RangeRequest, BatchingVisitable<KeyValueRowResult>, T> visitableProcessor) { return t.getRanges(tableRef, ranges, concurrencyLevel, (rangeRequest, visitable) -> visitableProcessor.apply(rangeRequest, BatchingVisitables.transform(visitable, KeyValueRowResult::of))); }
protected long storeEmptyMetadata() { Preconditions.checkNotNull(txnMgr, "Transaction manager must not be null"); return txnMgr.runTaskThrowOnConflict(tx -> { putMetadataAndHashIndexTask(tx, tx.getTimestamp(), getEmptyMetadata()); return tx.getTimestamp(); }); }
@Test public void writesNotAddedToSweepQueueOrKvsOnWriteWriteConflict() { Transaction t1 = txManager.createNewTransaction(); Transaction t2 = txManager.createNewTransaction(); put(t1, SINGLE_WRITE); put(t2, SINGLE_WRITE); t1.commit(); assertThatThrownBy(t2::commit).isInstanceOf(TransactionConflictException.class); verify(sweepQueue, times(1)).enqueue(anyList()); assertLatestEntryForCellInKvsAtTimestamp(TABLE_CONS, TEST_CELL, t1.getTimestamp()); }
@Override public Stream<BatchingVisitable<RowResult<byte[]>>> getRangesLazy( final TableReference tableRef, Iterable<RangeRequest> rangeRequests) { return delegate().getRangesLazy(tableRef, rangeRequests); }
public BatchingVisitableView<CreatedIdxRowResult> getRange(RangeRequest range) { if (range.getColumnNames().isEmpty()) { range = range.getBuilder().retainColumns(allColumns).build(); } return BatchingVisitables.transform(t.getRange(tableRef, range), new Function<RowResult<byte[]>, CreatedIdxRowResult>() { @Override public CreatedIdxRowResult apply(RowResult<byte[]> input) { return CreatedIdxRowResult.of(input); } }); }
@Override public byte[] getCheckpoint(String extraId, long rangeId, Transaction tx) { Cell cell = getCell(extraId, rangeId); byte[] value = tx.get(checkpointTable, ImmutableSet.of(cell)).get(cell); return fromDb(value); }
@Override public void delete(Iterable<TodoRow> rows) { List<byte[]> rowBytes = Persistables.persistAll(rows); Set<Cell> cells = Sets.newHashSetWithExpectedSize(rowBytes.size()); cells.addAll(Cells.cellsWithConstantColumn(rowBytes, PtBytes.toCachedBytes("t"))); t.delete(tableRef, cells); }
@Override public Iterator<Map.Entry<SweepNameToIdRow, SweepNameToIdNamedColumnValue<?>>> getRowsColumnRange(Iterable<SweepNameToIdRow> rows, ColumnRangeSelection columnRangeSelection, int batchHint) { Iterator<Map.Entry<Cell, byte[]>> results = t.getRowsColumnRange(getTableRef(), Persistables.persistAll(rows), columnRangeSelection, batchHint); return Iterators.transform(results, e -> { SweepNameToIdRow row = SweepNameToIdRow.BYTES_HYDRATOR.hydrateFromBytes(e.getKey().getRowName()); SweepNameToIdNamedColumnValue<?> colValue = shortNameToHydrator.get(PtBytes.toString(e.getKey().getColumnName())).hydrateFromBytes(e.getValue()); return Maps.immutableEntry(row, colValue); }); }
public long addTodoWithIdAndReturnTimestamp(long id, Todo todo) { return transactionManager.runTaskWithRetry((transaction) -> { Cell thisCell = Cell.create(ValueType.FIXED_LONG.convertFromJava(id), TodoSchema.todoTextColumn()); Map<Cell, byte[]> write = ImmutableMap.of(thisCell, ValueType.STRING.convertFromJava(todo.text())); transaction.put(TodoSchema.todoTable(), write); return transaction.getTimestamp(); }); }
public <T> Stream<T> getRanges(Iterable<RangeRequest> ranges, BiFunction<RangeRequest, BatchingVisitable<SweepPriorityRowResult>, T> visitableProcessor) { return t.getRanges(tableRef, ranges, (rangeRequest, visitable) -> visitableProcessor.apply(rangeRequest, BatchingVisitables.transform(visitable, SweepPriorityRowResult::of))); }
@Override public void abort() { if (isTraceEnabled()) { trace(String.format("ABORT: timestamp=%d", delegate.getTimestamp())); } super.abort(); }