@Override public void get(long firstBlock, long numBlocks, OutputStream destination) { if (parent.isUncommitted()) { loadNBlocksToOutputStream(parent, id, firstBlock, numBlocks, destination); } else { txnMgr.runTaskReadOnly(txn -> { loadNBlocksToOutputStream(txn, id, firstBlock, numBlocks, destination); return null; }); } }
static TransactionAndImmutableTsLock of(Transaction transaction, LockToken immutableTsLock) { return ImmutableTransactionAndImmutableTsLock.builder() .transaction(transaction) .immutableTsLock(immutableTsLock) .build(); } }
private SimpleCoordinationResource( TransactionManager transactionManager, TransactionSchemaManager transactionSchemaManager) { this.transactionManager = transactionManager; this.transactionSchemaManager = transactionSchemaManager; this.timestampService = transactionManager.getTimestampService(); }
@Override public boolean doTransactionAndReportOutcome() { try { return transactionManager.runTaskThrowOnConflict(tx -> { KeyValueService kvs = transactionManager.getKeyValueService(); kvs.createTable(TEST_TABLE, AtlasDbConstants.GENERIC_TABLE_METADATA); tx.put(TEST_TABLE, ImmutableMap.of(TEST_CELL, new byte[1])); return true; }); } catch (Exception e) { return false; } }
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); } }
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 Object doDelete(RegeneratingTable<Set<Cell>> table) { return table.getTransactionManager().runTaskThrowOnConflict(txn -> { txn.delete(table.getTableRef(), table.getTableCells()); return table.getTableCells(); }); }
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); }); }
protected long storeEmptyMetadata() { Preconditions.checkNotNull(txnMgr, "Transaction manager must not be null"); return txnMgr.runTaskThrowOnConflict(tx -> { putMetadataAndHashIndexTask(tx, tx.getTimestamp(), getEmptyMetadata()); return tx.getTimestamp(); }); }
Optional<String> selectTableToCompact() { return transactionManager.runTaskReadOnly(this::selectTableToCompactInternal); }
@Override public void throwIfConditionInvalid(long timestamp) { throw new TransactionFailedRetriableException("Condition failed"); }
public T execute(Transaction transaction) throws E { try { return delegate.execute(transaction); } catch (Exception ex) { if (shouldRethrowWithoutLockValidation(ex) || immutableTsLockIsValid()) { throw ex; } throw new TransactionLockTimeoutException( "The following immutable timestamp lock is no longer valid: " + immutableTsLock); } }
@Override public T execute(Transaction tx, Iterable<HeldLocksToken> heldLocks) throws E { return task.execute(tx); }
@Override public void abort(TransactionToken token) { TransactionAndImmutableTsLock txAndLock = transactions.getIfPresent(token); if (txAndLock != null) { txManager.finishRunTaskWithLockThrowOnConflict(txAndLock, (TxTask) transaction -> { transaction.abort(); return null; }); transactions.invalidate(token); } }
public static <T, E extends Exception> TransactionTask<T, E> asLockUnaware( final LockAwareTransactionTask<T, E> task, final Iterable<HeldLocksToken> locks) { return tx -> task.execute(tx, locks); } }
@Override public <T, C extends PreCommitCondition, E extends Exception> T runTaskWithConditionThrowOnConflict( C condition, ConditionAwareTransactionTask<T, C, E> task) throws E, TransactionFailedRetriableException { checkOpen(); try { TransactionAndImmutableTsLock txAndLock = runTimed(() -> setupRunTaskWithConditionThrowOnConflict(condition), "setupTask"); return finishRunTaskWithLockThrowOnConflict(txAndLock, transaction -> task.execute(transaction, condition)); } finally { condition.cleanup(); } }
public static Map<String, Object> execute(TransactionManager txnManager, int numClients, int requestsPerClient) { return new LockAndUnlockUncontendedBenchmark(txnManager.getTimelockService(), numClients, requestsPerClient).execute(); }
@Override public void throwIfConditionInvalid(long timestamp) { throw new TransactionFailedNonRetriableException("Condition failed"); }
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); } }
@Override public void throwIfConditionInvalid(long timestamp) { throw new TransactionFailedRetriableException("Condition failed"); }