@Override public void logStatus(int numRangeBoundaries) { txManager.runTaskWithRetry(transaction -> { logStatus(transaction, numRangeBoundaries); return null; }); }
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; }); }
@Override public final void performOneCall() { txnManager.runTaskWithRetry(txn -> { writeValues(txn, allValues); return null; }); }
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); } }
public boolean checkAndSet(Optional<Long> oldValue, Optional<Long> newValue) { return transactionManager.runTaskWithRetry( (transaction) -> new CheckAndSetPersistentValue(transaction).checkAndSet(oldValue, newValue)); } }
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); } }
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)); } }
@Override public void setup() { txnManager.runTaskWithRetry(txn -> { BlobsSerializableTable table = tableFactory.getBlobsSerializableTable(txn); originalValuesByKey.forEach((key, value) -> table.putData(BlobsSerializableRow.of(key), value)); return null; }); }
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); }
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; }
@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); }
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; }); }
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); }); }
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(); }); }
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)); }
@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); }
@Test public void closeShutsDownInitializingExecutorAndClosesTransactionManager() { manager.close(); assertTrue(executorService.isShutdown()); assertThatThrownBy(() -> manager.runTaskWithRetry(ignore -> null)).isInstanceOf(IllegalStateException.class); assertTrue(((SerializableTransactionManager.InitializeCheckingWrapper) manager).isClosedByClose()); }
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(); }); }
@Test public void switchBackToUninitializedImmediatelyWhenPrerequisitesBecomeFalse() { everythingInitialized(); tickInitializingThread(); assertTrue(manager.isInitialized()); nothingInitialized(); assertFalse(manager.isInitialized()); assertThatThrownBy(() -> manager.runTaskWithRetry(ignore -> null)).isInstanceOf(NotInitializedException.class); }
@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; }); }