本文整理了Java中com.palantir.atlasdb.transaction.api.TransactionManager.runTaskThrowOnConflict()
方法的一些代码示例,展示了TransactionManager.runTaskThrowOnConflict()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TransactionManager.runTaskThrowOnConflict()
方法的具体详情如下:
包路径:com.palantir.atlasdb.transaction.api.TransactionManager
类名称:TransactionManager
方法名:runTaskThrowOnConflict
[英]#runTaskWithRetry(TransactionTask) should be preferred over #runTaskThrowOnConflict(TransactionTask). This method should be used unless #runTaskWithRetry(TransactionTask) cannot be used because the arguments passed are not immutable and will be modified by the transaction so doing automatic retry is unsafe. Runs the given TransactionTask. If the task completes successfully and does not call Transaction#commit() or Transaction#abort(), Transaction#commit() is called automatically.
If runTaskThrowOnConflict()
completes successfully (no exception is thrown) and the task did not explicitly abort the transaction, then the transaction was successfully committed. If an exception is thrown by the TransactionTask
and the task did not call Transaction#commit(), then the transaction will be rolled back.
NOTE: If an exception is thrown by Transaction#commit(), the transaction might have been committed.
[中]#runTaskWithRetry(TransactionTask)应优先于#runTaskThrowOnConflict(TransactionTask)。除非无法使用#runTaskWithRetry(TransactionTask),否则应使用此方法,因为传递的参数不是不变的,将由事务修改,因此执行自动重试是不安全的。运行给定的TransactionTask。如果任务成功完成且未调用事务#提交()或事务#中止(),则会自动调用事务#提交()。
如果runTaskThrowOnConflict()
成功完成(未引发异常),且任务未显式中止事务,则事务已成功提交。如果TransactionTask
引发异常,且任务未调用事务#commit(),则事务将回滚。
注意:如果事务#commit()引发异常,则该事务可能已提交。
代码示例来源:origin: palantir/atlasdb
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;
});
}
代码示例来源:origin: palantir/atlasdb
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;
});
}
}
代码示例来源:origin: palantir/atlasdb
@Override
public <T, E extends Exception> T runTaskThrowOnConflict(TransactionTask<T, E> task) throws E,
TransactionConflictException {
return delegate().runTaskThrowOnConflict(wrapTask(task));
}
代码示例来源:origin: palantir/atlasdb
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;
});
}
代码示例来源:origin: palantir/atlasdb
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;
});
}
代码示例来源:origin: palantir/atlasdb
protected long storeEmptyMetadata() {
Preconditions.checkNotNull(txnMgr, "Transaction manager must not be null");
return txnMgr.runTaskThrowOnConflict(tx -> {
putMetadataAndHashIndexTask(tx, tx.getTimestamp(), getEmptyMetadata());
return tx.getTimestamp();
});
}
代码示例来源:origin: palantir/atlasdb
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;
});
}
代码示例来源:origin: palantir/atlasdb
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;
}));
}
}
代码示例来源:origin: palantir/atlasdb
@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;
});
}
代码示例来源:origin: palantir/atlasdb
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;
});
}
}
}
代码示例来源:origin: palantir/atlasdb
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;
});
}
代码示例来源:origin: palantir/atlasdb
@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.");
}
代码示例来源:origin: palantir/atlasdb
@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();
}
代码示例来源:origin: palantir/atlasdb
@Test
public void shouldNotConflictIfImmutableTimestampLockExpiresIfNoReadsOrWrites() {
TransactionManager txnManagerWithMocks = setupTransactionManager();
txnManagerWithMocks.runTaskThrowOnConflict(txn -> null);
}
代码示例来源:origin: palantir/atlasdb
@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();
}
代码示例来源:origin: palantir/atlasdb
@Test
public void shouldConflictIfImmutableTimestampLockExpiresEvenIfNoWritesOnThoroughSweptTable() {
TransactionManager txnManagerWithMocks = setupTransactionManager();
assertThatThrownBy(() -> txnManagerWithMocks.runTaskThrowOnConflict(txn -> {
get(txn, TEST_TABLE_THOROUGH, "row1", "col1");
return null;
}))
.isInstanceOf(TransactionFailedRetriableException.class);
}
代码示例来源:origin: palantir/atlasdb
private Object doDelete(RegeneratingTable<Set<Cell>> table) {
return table.getTransactionManager().runTaskThrowOnConflict(txn -> {
txn.delete(table.getTableRef(), table.getTableCells());
return table.getTableCells();
});
}
代码示例来源:origin: palantir/atlasdb
@Test
public void shouldNotConflictIfImmutableTimestampLockExpiresEvenIfNoWritesOnNonThoroughSweptTable() {
TransactionManager txnManagerWithMocks = setupTransactionManager();
txnManagerWithMocks.runTaskThrowOnConflict(txn -> {
get(txn, TEST_TABLE, "row1", "col1");
return null;
});
}
代码示例来源:origin: palantir/atlasdb
@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;
});
}
代码示例来源:origin: palantir/atlasdb
@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;
});
}
内容来源于网络,如有侵权,请联系作者删除!