Skip to content

Conversation

@denis-chudov
Copy link
Contributor

@denis-chudov denis-chudov commented Mar 28, 2024

https://issues.apache.org/jira/browse/IGNITE-21868

Moved the adding/removing the transaction inflights for RO transactions from SqlQueryProcessor to QueryTransactionContext.

…or to QueryTransactionContext and QueryTransactionWrapper

@Override
public CompletableFuture<Void> commitImplicit() {
if (transaction.isReadOnly() && committedImplicit.compareAndSet(false, true)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we really need this CaS? Wouldn't it work correctly without committedImplicit?

Copy link
Contributor Author

@denis-chudov denis-chudov Jun 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getOrStartImplicit and commitImplicit are called inside of SQL code every time when cursor is opened/closed respectively.
getOrStartImplicit may use an existing txn or start a new one.
commitImplicit is always used only to commit the explicit transaction on cursor close. It is no-op for explicit txns, but anyway it's called every time when cursor is closed. Unfortunately commitImplicit is idempotent and SQL code relies on this fact, removeInflight is not - it throws assertion if there are no more inflights. So we would have assertion errors in SQL code without this CAS. Also, commitImplicit is not no-op for explicit txns now: it should remove inflights on cursor close for both explicit and implicit RO txns.

throw new IllegalStateException("Unknown transaction target state: " + txState);
}

if (managedTx.isReadOnly() && completedTx.compareAndSet(false, true)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC removeInflight is idempotent, no need to have a CAS to protect it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not, we have an assertion that there are any inflights to remove. Also check the comment above

transaction = txManager.begin(observableTimeTracker, readOnly);
result = new QueryTransactionWrapperImpl(transaction, true, transactionInflights);
} else {
transaction = tx.unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I didn't find this branch covered with tests.

Copy link
Contributor Author

@denis-chudov denis-chudov Jun 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is the part of QueryTransactionWrapperSelfTest#testQueryTransactionWrapperTxInflightsInteraction regarding explicitRwTxCtx and explicitRoTxCtx. Actually, the only purpose of both these branches is to assign transaction and result to not duplicate the code below adding the inflight.

@korlov42 korlov42 merged commit 5e2f1c2 into apache:main Jun 7, 2024
@korlov42 korlov42 deleted the ignite-21868 branch June 7, 2024 13:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants