@Override public State<TXN, CONTEXT> deserialize(DataInputView source) throws IOException { TXN pendingTxnHandle = transactionSerializer.deserialize(source); final long pendingTxnStartTime = source.readLong(); final TransactionHolder<TXN> pendingTxn = new TransactionHolder<>( pendingTxnHandle, pendingTxnStartTime); int numPendingCommitTxns = source.readInt(); List<TransactionHolder<TXN>> pendingCommitTxns = new ArrayList<>(numPendingCommitTxns); for (int i = 0; i < numPendingCommitTxns; i++) { final TXN pendingCommitTxnHandle = transactionSerializer.deserialize(source); final long pendingCommitTxnStartTime = source.readLong(); pendingCommitTxns.add(new TransactionHolder<>( pendingCommitTxnHandle, pendingCommitTxnStartTime)); } Optional<CONTEXT> context = Optional.empty(); boolean hasContext = source.readBoolean(); if (hasContext) { context = Optional.of(contextSerializer.deserialize(source)); } return new State<>(pendingTxn, pendingCommitTxns, context); }
private void logWarningIfTimeoutAlmostReached(TransactionHolder<TXN> transactionHolder) { final long elapsedTime = transactionHolder.elapsedTime(clock); if (transactionTimeoutWarningRatio >= 0 && elapsedTime > transactionTimeout * transactionTimeoutWarningRatio) { LOG.warn("Transaction {} has been open for {} ms. " + "This is close to or even exceeding the transaction timeout of {} ms.", transactionHolder.handle, elapsedTime, transactionTimeout); } }
@Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } State<?, ?> state = (State<?, ?>) o; if (pendingTransaction != null ? !pendingTransaction.equals(state.pendingTransaction) : state.pendingTransaction != null) { return false; } if (pendingCommitTransactions != null ? !pendingCommitTransactions.equals(state.pendingCommitTransactions) : state.pendingCommitTransactions != null) { return false; } return context != null ? context.equals(state.context) : state.context == null; }
@Override public State<TXN, CONTEXT> deserialize(DataInputView source) throws IOException { TXN pendingTxnHandle = transactionSerializer.deserialize(source); final long pendingTxnStartTime = source.readLong(); final TransactionHolder<TXN> pendingTxn = new TransactionHolder<>( pendingTxnHandle, pendingTxnStartTime); int numPendingCommitTxns = source.readInt(); List<TransactionHolder<TXN>> pendingCommitTxns = new ArrayList<>(numPendingCommitTxns); for (int i = 0; i < numPendingCommitTxns; i++) { final TXN pendingCommitTxnHandle = transactionSerializer.deserialize(source); final long pendingCommitTxnStartTime = source.readLong(); pendingCommitTxns.add(new TransactionHolder<>( pendingCommitTxnHandle, pendingCommitTxnStartTime)); } Optional<CONTEXT> context = Optional.empty(); boolean hasContext = source.readBoolean(); if (hasContext) { context = Optional.of(contextSerializer.deserialize(source)); } return new State<>(pendingTxn, pendingCommitTxns, context); }
@Override public State<TXN, CONTEXT> deserialize(DataInputView source) throws IOException { TXN pendingTxnHandle = transactionSerializer.deserialize(source); final long pendingTxnStartTime = source.readLong(); final TransactionHolder<TXN> pendingTxn = new TransactionHolder<>( pendingTxnHandle, pendingTxnStartTime); int numPendingCommitTxns = source.readInt(); List<TransactionHolder<TXN>> pendingCommitTxns = new ArrayList<>(numPendingCommitTxns); for (int i = 0; i < numPendingCommitTxns; i++) { final TXN pendingCommitTxnHandle = transactionSerializer.deserialize(source); final long pendingCommitTxnStartTime = source.readLong(); pendingCommitTxns.add(new TransactionHolder<>( pendingCommitTxnHandle, pendingCommitTxnStartTime)); } Optional<CONTEXT> context = Optional.empty(); boolean hasContext = source.readBoolean(); if (hasContext) { context = Optional.of(contextSerializer.deserialize(source)); } return new State<>(pendingTxn, pendingCommitTxns, context); }
@Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } State<?, ?> state = (State<?, ?>) o; if (pendingTransaction != null ? !pendingTransaction.equals(state.pendingTransaction) : state.pendingTransaction != null) { return false; } if (pendingCommitTransactions != null ? !pendingCommitTransactions.equals(state.pendingCommitTransactions) : state.pendingCommitTransactions != null) { return false; } return context != null ? context.equals(state.context) : state.context == null; }
@Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } State<?, ?> state = (State<?, ?>) o; if (pendingTransaction != null ? !pendingTransaction.equals(state.pendingTransaction) : state.pendingTransaction != null) { return false; } if (pendingCommitTransactions != null ? !pendingCommitTransactions.equals(state.pendingCommitTransactions) : state.pendingCommitTransactions != null) { return false; } return context != null ? context.equals(state.context) : state.context == null; }
@Override public State<TXN, CONTEXT> copy(State<TXN, CONTEXT> from) { final TransactionHolder<TXN> pendingTransaction = from.getPendingTransaction(); final TransactionHolder<TXN> copiedPendingTransaction = new TransactionHolder<>( transactionSerializer.copy(pendingTransaction.handle), pendingTransaction.transactionStartTime); final List<TransactionHolder<TXN>> copiedPendingCommitTransactions = new ArrayList<>(); for (TransactionHolder<TXN> txn : from.getPendingCommitTransactions()) { final TXN txnHandleCopy = transactionSerializer.copy(txn.handle); copiedPendingCommitTransactions.add(new TransactionHolder<>( txnHandleCopy, txn.transactionStartTime)); } final Optional<CONTEXT> copiedContext = from.getContext().map(contextSerializer::copy); return new State<>(copiedPendingTransaction, copiedPendingCommitTransactions, copiedContext); }
@Override public State<TXN, CONTEXT> copy(State<TXN, CONTEXT> from) { final TransactionHolder<TXN> pendingTransaction = from.getPendingTransaction(); final TransactionHolder<TXN> copiedPendingTransaction = new TransactionHolder<>( transactionSerializer.copy(pendingTransaction.handle), pendingTransaction.transactionStartTime); final List<TransactionHolder<TXN>> copiedPendingCommitTransactions = new ArrayList<>(); for (TransactionHolder<TXN> txn : from.getPendingCommitTransactions()) { final TXN txnHandleCopy = transactionSerializer.copy(txn.handle); copiedPendingCommitTransactions.add(new TransactionHolder<>( txnHandleCopy, txn.transactionStartTime)); } final Optional<CONTEXT> copiedContext = from.getContext().map(contextSerializer::copy); return new State<>(copiedPendingTransaction, copiedPendingCommitTransactions, copiedContext); }
@Override public int hashCode() { int result = pendingTransaction != null ? pendingTransaction.hashCode() : 0; result = 31 * result + (pendingCommitTransactions != null ? pendingCommitTransactions.hashCode() : 0); result = 31 * result + (context != null ? context.hashCode() : 0); return result; } }
/** * This method must be the only place to call {@link #beginTransaction()} to ensure that the * {@link TransactionHolder} is created at the same time. */ private TransactionHolder<TXN> beginTransactionInternal() throws Exception { return new TransactionHolder<>(beginTransaction(), clock.millis()); }
@Override public int hashCode() { int result = pendingTransaction != null ? pendingTransaction.hashCode() : 0; result = 31 * result + (pendingCommitTransactions != null ? pendingCommitTransactions.hashCode() : 0); result = 31 * result + (context != null ? context.hashCode() : 0); return result; } }
private void logWarningIfTimeoutAlmostReached(TransactionHolder<TXN> transactionHolder) { final long elapsedTime = transactionHolder.elapsedTime(clock); if (transactionTimeoutWarningRatio >= 0 && elapsedTime > transactionTimeout * transactionTimeoutWarningRatio) { LOG.warn("Transaction {} has been open for {} ms. " + "This is close to or even exceeding the transaction timeout of {} ms.", transactionHolder.handle, elapsedTime, transactionTimeout); } }
private void logWarningIfTimeoutAlmostReached(TransactionHolder<TXN> transactionHolder) { final long elapsedTime = transactionHolder.elapsedTime(clock); if (transactionTimeoutWarningRatio >= 0 && elapsedTime > transactionTimeout * transactionTimeoutWarningRatio) { LOG.warn("Transaction {} has been open for {} ms. " + "This is close to or even exceeding the transaction timeout of {} ms.", transactionHolder.handle, elapsedTime, transactionTimeout); } }
/** * This method must be the only place to call {@link #beginTransaction()} to ensure that the * {@link TransactionHolder} is created at the same time. */ private TransactionHolder<TXN> beginTransactionInternal() throws Exception { return new TransactionHolder<>(beginTransaction(), clock.millis()); }
@Override public State<TXN, CONTEXT> copy(State<TXN, CONTEXT> from) { final TransactionHolder<TXN> pendingTransaction = from.getPendingTransaction(); final TransactionHolder<TXN> copiedPendingTransaction = new TransactionHolder<>( transactionSerializer.copy(pendingTransaction.handle), pendingTransaction.transactionStartTime); final List<TransactionHolder<TXN>> copiedPendingCommitTransactions = new ArrayList<>(); for (TransactionHolder<TXN> txn : from.getPendingCommitTransactions()) { final TXN txnHandleCopy = transactionSerializer.copy(txn.handle); copiedPendingCommitTransactions.add(new TransactionHolder<>( txnHandleCopy, txn.transactionStartTime)); } final Optional<CONTEXT> copiedContext = from.getContext().map(contextSerializer::copy); return new State<>(copiedPendingTransaction, copiedPendingCommitTransactions, copiedContext); }
@Override public int hashCode() { int result = pendingTransaction != null ? pendingTransaction.hashCode() : 0; result = 31 * result + (pendingCommitTransactions != null ? pendingCommitTransactions.hashCode() : 0); result = 31 * result + (context != null ? context.hashCode() : 0); return result; } }
/** * This method must be the only place to call {@link #beginTransaction()} to ensure that the * {@link TransactionHolder} is created at the same time. */ private TransactionHolder<TXN> beginTransactionInternal() throws Exception { return new TransactionHolder<>(beginTransaction(), clock.millis()); }
@Test public void testElapsedTime() { final long elapsedTime = new TransactionHolder<>(new Object(), 0) .elapsedTime(Clock.fixed(Instant.ofEpochMilli(1000), ZoneOffset.UTC)); assertThat(elapsedTime, equalTo(1000L)); }