protected final void storeMetadataAndIndex(final long streamId, final StreamMetadata metadata) { Preconditions.checkNotNull(txnMgr, "Transaction manager must not be null"); txnMgr.runTaskThrowOnConflict((TxTask) tx -> { putMetadataAndHashIndexTask(tx, streamId, metadata); return null; }); }
protected void storeBlockWithNonNullTransaction(@Nullable Transaction tx, final long id, final long blockNumber, final byte[] bytesToStore) { if (tx != null) { storeBlock(tx, id, blockNumber, bytesToStore); } else { Preconditions.checkNotNull(txnMgr, "Transaction manager must not be null"); txnMgr.runTaskThrowOnConflict( (TransactionTask<Void, RuntimeException>) t1 -> { storeBlock(t1, id, blockNumber, bytesToStore); return null; }); } }
@Override public <T, E extends Exception> T runTaskThrowOnConflict(TransactionTask<T, E> task) throws E, TransactionConflictException { return delegate().runTaskThrowOnConflict(wrapTask(task)); }
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 List<RowResult<byte[]>> getRangeInner(ConsecutiveNarrowTable table) { final int rangeRequestSize = 1000; return table.getTransactionManager().runTaskThrowOnConflict(txn -> { RangeRequest request = Iterables.getOnlyElement(table.getRangeRequests(1, rangeRequestSize, false)); List<RowResult<byte[]>> results = BatchingVisitables.copyToList(txn.getRange( table.getTableRef(), request)); Preconditions.checkState(results.size() == rangeRequestSize, "Expected %s rows, found %s rows", rangeRequestSize, results.size()); return results; }); }
protected long storeEmptyMetadata() { Preconditions.checkNotNull(txnMgr, "Transaction manager must not be null"); return txnMgr.runTaskThrowOnConflict(tx -> { putMetadataAndHashIndexTask(tx, tx.getTimestamp(), getEmptyMetadata()); return tx.getTimestamp(); }); }
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; }); }
private static void storeDataInTable(ConsecutiveNarrowTable table, int numOverwrites) { IntStream.range(0, numOverwrites + 1).forEach( $ -> table.getTransactionManager().runTaskThrowOnConflict( txn -> { Map<Cell, byte[]> values = Tables.generateContinuousBatch(table.getRandom(), 0, table.getNumRows()); txn.put(table.getTableRef(), values); return null; })); } }
@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; }); }
protected void populateTable(int numberOfBatches, int batchSize, int numberOfDuplicates) { for (int i = 0; i < numberOfBatches; i++) { Map<Cell, byte[]> batch = Tables.generateRandomBatch(random, batchSize); for (int j = 0; j < numberOfDuplicates; j++) { getTransactionManager().runTaskThrowOnConflict(txn -> { txn.put(getTableRef(), batch); return null; }); } } }
private List<RowResult<byte[]>> getSingleRowWithRangeQueryInner(final ConsecutiveNarrowTable table) { return table.getTransactionManager().runTaskThrowOnConflict(txn -> { RangeRequest request = Iterables.getOnlyElement(table.getRangeRequests(1, 1, false)); List<RowResult<byte[]>> result = BatchingVisitables.copyToList( txn.getRange(table.getTableRef(), request)); byte[] rowName = Iterables.getOnlyElement(result).getRowName(); int rowNumber = ConsecutiveNarrowTable.rowNumber(rowName); int expectedRowNumber = ConsecutiveNarrowTable.rowNumber(request.getStartInclusive()); Preconditions.checkState(rowNumber == expectedRowNumber, "Start Row %s, row number %s", expectedRowNumber, rowNumber); return result; }); }
@Test public void shouldNotRunTaskThrowOnConflictWithClosedTransactionManager() { txMgr.close(); assertThatThrownBy(() -> txMgr.runTaskThrowOnConflict((TransactionTask<Void, RuntimeException>) txn -> { put(txn, "row1", "col1", "v1"); return null; })) .isInstanceOf(IllegalStateException.class) .hasMessage("Operations cannot be performed on closed TransactionManager."); }
@Override public void setupTableData() { getKvs().truncateTable(getTableRef()); Map<Cell, byte[]> batch = Tables.generateRandomBatch(random, BATCH_SIZE); getTransactionManager().runTaskThrowOnConflict(txn -> { txn.put(getTableRef(), batch); return null; }); cells = batch.keySet(); }
@Test public void shouldNotConflictIfImmutableTimestampLockExpiresIfNoReadsOrWrites() { TransactionManager txnManagerWithMocks = setupTransactionManager(); txnManagerWithMocks.runTaskThrowOnConflict(txn -> null); }
@Override public void setupTableData() { getKvs().truncateTable(getTableRef()); Map<Cell, byte[]> batch = Tables.generateRandomBatch(random, 1); getTransactionManager().runTaskThrowOnConflict(txn -> { txn.put(getTableRef(), batch); return null; }); cells = batch.keySet(); }
@Test public void shouldConflictIfImmutableTimestampLockExpiresEvenIfNoWritesOnThoroughSweptTable() { TransactionManager txnManagerWithMocks = setupTransactionManager(); assertThatThrownBy(() -> txnManagerWithMocks.runTaskThrowOnConflict(txn -> { get(txn, TEST_TABLE_THOROUGH, "row1", "col1"); return null; })) .isInstanceOf(TransactionFailedRetriableException.class); }
private Object doDelete(RegeneratingTable<Set<Cell>> table) { return table.getTransactionManager().runTaskThrowOnConflict(txn -> { txn.delete(table.getTableRef(), table.getTableCells()); return table.getTableCells(); }); }
@Test public void shouldNotConflictIfImmutableTimestampLockExpiresEvenIfNoWritesOnNonThoroughSweptTable() { TransactionManager txnManagerWithMocks = setupTransactionManager(); txnManagerWithMocks.runTaskThrowOnConflict(txn -> { get(txn, TEST_TABLE, "row1", "col1"); return null; }); }
@Benchmark @Threads(1) @Warmup(time = 3, timeUnit = TimeUnit.SECONDS) @Measurement(time = 15, timeUnit = TimeUnit.SECONDS) public Object batchRandomPut(EmptyTables tables) { return tables.getTransactionManager().runTaskThrowOnConflict(txn -> { Map<Cell, byte[]> batch = tables.generateBatchToInsert(BATCH_SIZE); txn.put(tables.getFirstTableRef(), batch); return batch; }); }
@Benchmark @Threads(1) @Warmup(time = 2, timeUnit = TimeUnit.SECONDS) @Measurement(time = 10, timeUnit = TimeUnit.SECONDS) public Object singleRandomPut(EmptyTables tables) { return tables.getTransactionManager().runTaskThrowOnConflict(txn -> { Map<Cell, byte[]> batch = tables.generateBatchToInsert(1); txn.put(tables.getFirstTableRef(), batch); return batch; }); }