@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); }
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; }
public Map<BlobsRow, byte[]> getDatas(Collection<BlobsRow> rows) { Map<Cell, BlobsRow> cells = Maps.newHashMapWithExpectedSize(rows.size()); for (BlobsRow row : rows) { cells.put(Cell.create(row.persistToBytes(), PtBytes.toCachedBytes("d")), row); } Map<Cell, byte[]> results = t.get(tableRef, cells.keySet()); Map<BlobsRow, byte[]> ret = Maps.newHashMapWithExpectedSize(results.size()); for (Entry<Cell, byte[]> e : results.entrySet()) { byte[] val = Data.BYTES_HYDRATOR.hydrateFromBytes(e.getValue()).getValue(); ret.put(cells.get(e.getKey()), val); } return ret; }
@Override public Map<Cell, byte[]> get(TableReference tableRef, Set<Cell> cells) { checkTableName(tableRef); return delegate().get(tableRef, cells); }
private Map<Cell, byte[]> getCellsInner(ConsecutiveNarrowTable table) { final int getCellsSize = 1000; return table.getTransactionManager().runTaskThrowOnConflict(txn -> { Set<Cell> request = table.getCellsRequest(getCellsSize); Map<Cell, byte[]> result = txn.get(table.getTableRef(), request); Preconditions.checkState(result.size() == getCellsSize, "expected %s cells, found %s cells", getCellsSize, result.size()); return result; }); }
private Map<Cell, byte[]> getSingleCellInner(ConsecutiveNarrowTable table) { return table.getTransactionManager().runTaskThrowOnConflict(txn -> { Set<Cell> request = table.getCellsRequest(1); Map<Cell, byte[]> result = txn.get(table.getTableRef(), request); byte[] rowName = Iterables.getOnlyElement(result.entrySet()).getKey().getRowName(); int rowNumber = Ints.fromByteArray(rowName); int expectRowNumber = ConsecutiveNarrowTable.rowNumber(Iterables.getOnlyElement(request).getRowName()); Preconditions.checkState(rowNumber == expectRowNumber, "Start Row %s, row number %s", expectRowNumber, rowNumber); return result; }); }
@Benchmark @Threads(1) @Warmup(time = 25, timeUnit = TimeUnit.SECONDS) @Measurement(time = 180, timeUnit = TimeUnit.SECONDS) public Object getAllColumnsExplicitly(ModeratelyWideRowTable table) { return table.getTransactionManager().runTaskThrowOnConflict(txn -> { Map<Cell, byte[]> result = txn.get(table.getTableRef(), table.getAllCells()); Preconditions.checkState(result.values().size() == table.getNumCols(), "Should be %s columns, but were: %s", table.getNumCols(), result.values().size()); return result; }); }
@Override public TableCellVal getCells(TransactionToken token, final TableCell cells) { return runReadOnly(token, transaction -> { Map<Cell, byte[]> values = transaction.get(getTableRef(cells.getTableName()), ImmutableSet.copyOf(cells.getCells())); return new TableCellVal(cells.getTableName(), values); }); }
public Map<TestHashComponentsStreamValueRow, byte[]> getValues(Collection<TestHashComponentsStreamValueRow> rows) { Map<Cell, TestHashComponentsStreamValueRow> cells = Maps.newHashMapWithExpectedSize(rows.size()); for (TestHashComponentsStreamValueRow row : rows) { cells.put(Cell.create(row.persistToBytes(), PtBytes.toCachedBytes("v")), row); } Map<Cell, byte[]> results = t.get(tableRef, cells.keySet()); Map<TestHashComponentsStreamValueRow, byte[]> ret = Maps.newHashMapWithExpectedSize(results.size()); for (Entry<Cell, byte[]> e : results.entrySet()) { byte[] val = Value.BYTES_HYDRATOR.hydrateFromBytes(e.getValue()).getValue(); ret.put(cells.get(e.getKey()), val); } return ret; }
public Map<TestHashComponentsStreamMetadataRow, com.palantir.atlasdb.protos.generated.StreamPersistence.StreamMetadata> getMetadatas(Collection<TestHashComponentsStreamMetadataRow> rows) { Map<Cell, TestHashComponentsStreamMetadataRow> cells = Maps.newHashMapWithExpectedSize(rows.size()); for (TestHashComponentsStreamMetadataRow row : rows) { cells.put(Cell.create(row.persistToBytes(), PtBytes.toCachedBytes("md")), row); } Map<Cell, byte[]> results = t.get(tableRef, cells.keySet()); Map<TestHashComponentsStreamMetadataRow, com.palantir.atlasdb.protos.generated.StreamPersistence.StreamMetadata> ret = Maps.newHashMapWithExpectedSize(results.size()); for (Entry<Cell, byte[]> e : results.entrySet()) { com.palantir.atlasdb.protos.generated.StreamPersistence.StreamMetadata val = Metadata.BYTES_HYDRATOR.hydrateFromBytes(e.getValue()).getValue(); ret.put(cells.get(e.getKey()), val); } return ret; }
public Map<TwoColumnsRow, Long> getFoos(Collection<TwoColumnsRow> rows) { Map<Cell, TwoColumnsRow> cells = Maps.newHashMapWithExpectedSize(rows.size()); for (TwoColumnsRow row : rows) { cells.put(Cell.create(row.persistToBytes(), PtBytes.toCachedBytes("f")), row); } Map<Cell, byte[]> results = t.get(tableRef, cells.keySet()); Map<TwoColumnsRow, Long> ret = Maps.newHashMapWithExpectedSize(results.size()); for (Entry<Cell, byte[]> e : results.entrySet()) { Long val = Foo.BYTES_HYDRATOR.hydrateFromBytes(e.getValue()).getValue(); ret.put(cells.get(e.getKey()), val); } return ret; }
public Map<StreamTestStreamMetadataRow, com.palantir.atlasdb.protos.generated.StreamPersistence.StreamMetadata> getMetadatas(Collection<StreamTestStreamMetadataRow> rows) { Map<Cell, StreamTestStreamMetadataRow> cells = Maps.newHashMapWithExpectedSize(rows.size()); for (StreamTestStreamMetadataRow row : rows) { cells.put(Cell.create(row.persistToBytes(), PtBytes.toCachedBytes("md")), row); } Map<Cell, byte[]> results = t.get(tableRef, cells.keySet()); Map<StreamTestStreamMetadataRow, com.palantir.atlasdb.protos.generated.StreamPersistence.StreamMetadata> ret = Maps.newHashMapWithExpectedSize(results.size()); for (Entry<Cell, byte[]> e : results.entrySet()) { com.palantir.atlasdb.protos.generated.StreamPersistence.StreamMetadata val = Metadata.BYTES_HYDRATOR.hydrateFromBytes(e.getValue()).getValue(); ret.put(cells.get(e.getKey()), val); } return ret; }
public void deleteJson(Iterable<UserProfileRow> rows) { byte[] col = PtBytes.toCachedBytes("j"); Set<Cell> cells = Cells.cellsWithConstantColumn(Persistables.persistAll(rows), col); Map<Cell, byte[]> results = t.get(tableRef, cells); deleteCookiesIdxRaw(results); t.delete(tableRef, cells); }
public void deleteCreate(Iterable<UserProfileRow> rows) { byte[] col = PtBytes.toCachedBytes("c"); Set<Cell> cells = Cells.cellsWithConstantColumn(Persistables.persistAll(rows), col); Map<Cell, byte[]> results = t.get(tableRef, cells); deleteCreatedIdxRaw(results); t.delete(tableRef, cells); }
public void deleteMetadata(Iterable<UserProfileRow> rows) { byte[] col = PtBytes.toCachedBytes("m"); Set<Cell> cells = Cells.cellsWithConstantColumn(Persistables.persistAll(rows), col); Map<Cell, byte[]> results = t.get(tableRef, cells); deleteUserBirthdaysIdxRaw(results); t.delete(tableRef, cells); }
@Test public void readTransactionSucceedsIfConditionSucceeds() { serializableTxManager.runTaskWithConditionReadOnly(PreCommitConditions.NO_OP, (tx, condition) -> tx.get(TABLE, ImmutableSet.of(TEST_CELL))); TransactionOutcomeMetricsAssert.assertThat(transactionOutcomeMetrics) .hasSuccessfulCommits(1); }
@Test public void testIgnoresOrphanedSweepSentinel() { Cell cell = Cell.create(PtBytes.toBytes("row1"), PtBytes.toBytes("column1")); keyValueService.addGarbageCollectionSentinelValues(TABLE, ImmutableSet.of(cell)); Transaction txn = txManager.createNewTransaction(); assertThat(txn.get(TABLE, ImmutableSet.of(cell)), is(ImmutableMap.of())); }
@Test public void readTransactionFailsIfConditionFails() { try { serializableTxManager.runTaskWithConditionReadOnly(ALWAYS_FAILS_CONDITION, (tx, condition) -> tx.get(TABLE, ImmutableSet.of(TEST_CELL))); fail(); } catch (TransactionFailedRetriableException e) { assertThat(e.getMessage(), containsString("Condition failed")); } TransactionOutcomeMetricsAssert.assertThat(transactionOutcomeMetrics) .hasFailedCommits(1); }
public void deleteFoo(Iterable<TwoColumnsRow> rows) { byte[] col = PtBytes.toCachedBytes("f"); Set<Cell> cells = Cells.cellsWithConstantColumn(Persistables.persistAll(rows), col); Map<Cell, byte[]> results = t.get(tableRef, cells); deleteFooToIdCondIdxRaw(results); deleteFooToIdIdxRaw(results); t.delete(tableRef, cells); }
public void deleteValue(Iterable<DataRow> rows) { byte[] col = PtBytes.toCachedBytes("v"); Set<Cell> cells = Cells.cellsWithConstantColumn(Persistables.persistAll(rows), col); Map<Cell, byte[]> results = t.get(tableRef, cells); deleteIndex1IdxRaw(results); deleteIndex2IdxRaw(results); deleteIndex3IdxRaw(results); deleteIndex4IdxRaw(results); t.delete(tableRef, cells); }