本文整理了Java中com.palantir.atlasdb.transaction.api.TransactionManager.runTaskWithRetry()
方法的一些代码示例,展示了TransactionManager.runTaskWithRetry()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TransactionManager.runTaskWithRetry()
方法的具体详情如下:
包路径:com.palantir.atlasdb.transaction.api.TransactionManager
类名称:TransactionManager
方法名:runTaskWithRetry
[英]Runs the given TransactionTask. If the task completes successfully and does not call Transaction#commit() or Transaction#abort(), Transaction#commit() is called automatically.
The task is re-run if a conflict is detected (if a TransactionConflictException is thrown)
If runTaskWithRetry
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.
It is important that the TransactionTask does not modify any of its input state in any non-idempotent way. If this task gets retried, and if you modified your input, then the second try might not do the right thing. For example: if you are passed a list of objects and at the end of the TransactionTask, you clear the list. If your task gets retried it will have no work to do, because the list was cleared.
[中]运行给定的TransactionTask。如果任务成功完成且未调用事务#提交()或事务#中止(),则会自动调用事务#提交()。
如果检测到冲突(如果引发TransactionConflictException),任务将重新运行
如果runTaskWithRetry
成功完成(未引发异常),且任务未显式中止事务,则事务已成功提交。如果TransactionTask
引发异常,且任务未调用事务#commit(),则事务将回滚。
注意:如果事务#commit()引发异常,则该事务可能已提交。
TransactionTask不以任何非幂等方式修改其任何输入状态,这一点很重要。如果重试此任务,并且您修改了输入,那么第二次尝试可能不会做正确的事情。例如:如果您收到一个对象列表,并在TransactionTask结束时清除该列表。如果您的任务被重试,它将没有工作要做,因为列表已被清除。
代码示例来源:origin: palantir/atlasdb
@Override
public void logStatus(int numRangeBoundaries) {
txManager.runTaskWithRetry(transaction -> {
logStatus(transaction, numRangeBoundaries);
return null;
});
}
代码示例来源:origin: palantir/atlasdb
private void validateTable(final TableReference table, final int limit, final Transaction t1) {
// read only, but need to use a write tx in case the source table has SweepStrategy.THOROUGH
validationToTransactionManager.runTaskWithRetry(
(TransactionTask<Map<Cell, byte[]>, RuntimeException>) t2 -> {
validateTable(table, limit, t1, t2);
return null;
});
}
代码示例来源:origin: palantir/atlasdb
@Override
public final void performOneCall() {
txnManager.runTaskWithRetry(txn -> {
writeValues(txn, allValues);
return null;
});
}
代码示例来源:origin: palantir/atlasdb
private <T> T runReadOnly(TransactionToken token, RuntimeTransactionTask<T> task) {
if (token.shouldAutoCommit()) {
return txManager.runTaskWithRetry(task);
} else {
Transaction tx = transactions.getIfPresent(token).transaction();
Preconditions.checkNotNull(tx, "The given transaction does not exist.");
return task.execute(tx);
}
}
代码示例来源:origin: palantir/atlasdb
public boolean checkAndSet(Optional<Long> oldValue, Optional<Long> newValue) {
return transactionManager.runTaskWithRetry(
(transaction) -> new CheckAndSetPersistentValue(transaction).checkAndSet(oldValue, newValue));
}
}
代码示例来源:origin: palantir/atlasdb
private <T> T runWithRetry(TransactionToken token, RuntimeTransactionTask<T> task) {
if (token.shouldAutoCommit()) {
return txManager.runTaskWithRetry(task);
} else {
Transaction tx = transactions.getIfPresent(token).transaction();
Preconditions.checkNotNull(tx, "The given transaction does not exist.");
return task.execute(tx);
}
}
代码示例来源:origin: palantir/atlasdb
private byte[] copyOneTransactionFromReadTxManager(final RangeRequest range,
final long rangeId,
final Transaction writeT) {
if (readTxManager == txManager) {
// don't wrap
return copyOneTransactionInternal(range, rangeId, writeT, writeT);
} else {
// read only, but need to use a write tx in case the source table has SweepStrategy.THOROUGH
return readTxManager.runTaskWithRetry(readT -> copyOneTransactionInternal(range, rangeId, readT, writeT));
}
}
代码示例来源:origin: palantir/atlasdb
@Override
public void setup() {
txnManager.runTaskWithRetry(txn -> {
BlobsSerializableTable table = tableFactory.getBlobsSerializableTable(txn);
originalValuesByKey.forEach((key, value) -> table.putData(BlobsSerializableRow.of(key), value));
return null;
});
}
代码示例来源:origin: palantir/atlasdb
private void validateTable(final TableReference table) {
final int limit = getBatchSize(table);
// read only, but need to use a write tx in case the source table has SweepStrategy.THOROUGH
validationFromTransactionManager.runTaskWithRetry(
(TransactionTask<Map<Cell, byte[]>, RuntimeException>) t1 -> {
validateTable(table, limit, t1);
return null;
});
KeyValueServiceMigratorUtils
.processMessage(messageProcessor, "Validated " + table, KvsMigrationMessageLevel.INFO);
}
代码示例来源:origin: palantir/atlasdb
public static TransactionManager mockTxManager() {
TransactionManager txManager = mock(TransactionManager.class);
Answer runTaskAnswer = inv -> {
Object[] args = inv.getArguments();
TransactionTask<?, ?> task = (TransactionTask<?, ?>) args[0];
return task.execute(mock(Transaction.class));
};
doAnswer(runTaskAnswer).when(txManager).runTaskReadOnly(any());
doAnswer(runTaskAnswer).when(txManager).runTaskWithRetry(any());
return txManager;
}
代码示例来源:origin: palantir/atlasdb
@Test
public void canReturnRegistrationFailure() throws InterruptedException {
doThrow(new RuntimeException()).when(txManager).runTaskWithRetry(any());
BackgroundCompactor.CompactionOutcome outcome = compactor.grabLockAndRunOnce(lockService);
assertThat(outcome).isEqualTo(BackgroundCompactor.CompactionOutcome.COMPACTED_BUT_NOT_REGISTERED);
}
代码示例来源:origin: palantir/atlasdb
private void runContendedTransaction(byte[] key, byte[] originalValue) {
txnManager.runTaskWithRetry(txn -> {
BlobsSerializableTable table = tableFactory.getBlobsSerializableTable(txn);
byte[] currentValue = table.getRow(BlobsSerializableRow.of(key))
.get().getData();
if (Arrays.equals(currentValue, originalValue)) {
byte[] newValue = RandomBytes.ofLength(16);
table.putData(BlobsSerializableRow.of(key), newValue);
}
return null;
});
}
代码示例来源:origin: palantir/atlasdb
private <T> T runWithRetry(Transaction.TransactionType type, Function<ProfileStore, T> task) {
return txnMgr.runTaskWithRetry(txn -> {
txn.setTransactionType(type);
ProfileStore store = new ProfileStore(txnMgr, txn);
return task.apply(store);
});
}
代码示例来源:origin: palantir/atlasdb
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();
});
}
代码示例来源:origin: palantir/atlasdb
private void performTransaction(TransactionManager manager) {
RangeScanTestTable.RangeScanTestRow testRow = RangeScanTestTable.RangeScanTestRow.of("foo");
manager.runTaskWithRetry(tx -> {
GenericTestSchemaTableFactory.of().getRangeScanTestTable(tx).putColumn1(testRow, 12345L);
return null;
});
Map<RangeScanTestTable.RangeScanTestRow, Long> result = manager.runTaskWithRetry(tx ->
GenericTestSchemaTableFactory.of().getRangeScanTestTable(tx).getColumn1s(ImmutableSet.of(testRow)));
assertThat(Iterables.getOnlyElement(result.entrySet()).getValue(), is(12345L));
}
代码示例来源:origin: palantir/atlasdb
@Test
public void exceptionInCleanupClosesTransactionManager() {
RuntimeException cause = new RuntimeException("VALID REASON");
doThrow(cause).when(mockCallback).runWithRetry(any(SerializableTransactionManager.class));
everythingInitialized();
tickInitializingThread();
assertTrue(((SerializableTransactionManager.InitializeCheckingWrapper) manager).isClosedByCallbackFailure());
assertThatThrownBy(() -> manager.runTaskWithRetry($ -> null))
.isInstanceOf(IllegalStateException.class)
.hasCause(cause);
}
代码示例来源:origin: palantir/atlasdb
@Test
public void closeShutsDownInitializingExecutorAndClosesTransactionManager() {
manager.close();
assertTrue(executorService.isShutdown());
assertThatThrownBy(() -> manager.runTaskWithRetry(ignore -> null)).isInstanceOf(IllegalStateException.class);
assertTrue(((SerializableTransactionManager.InitializeCheckingWrapper) manager).isClosedByClose());
}
代码示例来源:origin: palantir/atlasdb
public long addNamespacedTodoWithIdAndReturnTimestamp(long id, String namespace, Todo todo) {
return transactionManager.runTaskWithRetry(tx -> {
TodoSchemaTableFactory.of().getNamespacedTodoTable(tx).put(
NamespacedTodoTable.NamespacedTodoRow.of(namespace),
NamespacedTodoTable.NamespacedTodoColumnValue.of(
NamespacedTodoTable.NamespacedTodoColumn.of(id),
todo.text()));
return tx.getTimestamp();
});
}
代码示例来源:origin: palantir/atlasdb
@Test
public void switchBackToUninitializedImmediatelyWhenPrerequisitesBecomeFalse() {
everythingInitialized();
tickInitializingThread();
assertTrue(manager.isInitialized());
nothingInitialized();
assertFalse(manager.isInitialized());
assertThatThrownBy(() -> manager.runTaskWithRetry(ignore -> null)).isInstanceOf(NotInitializedException.class);
}
代码示例来源:origin: palantir/atlasdb
@Test
public void timelockServiceCanStartTransactionsEvenWithoutStartTransactionEndpoint() {
availableServer.stubFor(TIMELOCK_START_TRANSACTION_MAPPING.willReturn(
aResponse().withStatus(Response.Status.NOT_FOUND.getStatusCode())));
TransactionManager tm = TransactionManagers.createInMemory(GenericTestSchema.getSchema());
tm.runTaskWithRetry(tx -> {
RangeScanTestTable testTable = GenericTestSchemaTableFactory.of().getRangeScanTestTable(tx);
testTable.putColumn1(RangeScanTestTable.RangeScanTestRow.of("foo"), 12345L);
return null;
});
}
内容来源于网络,如有侵权,请联系作者删除!