Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sql: rationalize some output events from the connection state machine #45515

Merged

Conversation

andreimatei
Copy link
Contributor

@andreimatei andreimatei commented Feb 27, 2020

See individual commits.

Release note: None

@andreimatei
Copy link
Contributor Author

cc @knz

@cockroach-teamcity
Copy link
Member

This change is Reviewable

@andreimatei andreimatei changed the title sql: rationalize the txnRestart event sql: rationalize some output events from the connection state machine Feb 28, 2020
Copy link
Member

@nvanbenschoten nvanbenschoten left a comment

Choose a reason for hiding this comment

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

Reviewed 4 of 4 files at r1, 2 of 2 files at r2, 5 of 5 files at r3.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @andreimatei)


pkg/sql/conn_fsm.go, line 506 at r3 (raw file):

})

// cleanupAndFinish rolls back the KV txn and finishes the SQL txn.

Four suggestions to make this easier to read:

  1. could you move this down right below finishTxn because these are the two code paths that can produce this txnRollback event?
  2. could you rename this to cleanupAndFinishOnError?
  3. could you make this a method on *txnState to parallel noTxnToOpen and finishTxn?
  4. could you pull out the actions that do the same thing except they don't ts.finishSQLTxn() into a similar helper method?

pkg/sql/txn_state.go, line 381 at r1 (raw file):

	// txnRestart means that the transaction is expecting a retry. The iteration
	// of the txn just finished will not commit.
	// This event is produced both when entering the RetryWait state and sometimes

We seem to like these comments around here, so consider updating it instead of deleting it.


pkg/sql/txn_state.go, line 373 at r3 (raw file):

	// when leaving it.
	txnCommit
	// txnRollback means that the transaction has rolled back.

Could you include a bit more here? How far has the transaction rolled back? To a savepoint? All the way? Either?

Do you want to include something about when the event is produced?

The connection state machine returns events to the connExecutor
distilling what happened to the SQL txn (these events are different from
the input events of the state machine). One of these events is
txnRestart. The connExecutor reacts to it by clearing some state that it
was maintaining for the transaction (e.g. schema change stuff).
Before this patch, txnRestart used to be returned both when entering and
when exiting the restartWait state. This was redundant and confusing.
More over, it's in my way for some savepoints work. This patch makes the
event only be generated when the transaction is actually restarted (i.e.
when exiting the restartWait state).

Release note: None
This patch makes the connection state machine return a txnRestart when
transitioning from the Aborted to the Open transition through a
ROLLBACK TO SAVEPOINT cockroach_restart.
This seems like the right thing to do because we want the state reset
that comes with that event. I think we were getting away without it
because we were generating the txnAborted event, with similar effects,
when we were entering the Aborted state. But I'm preparing to get rid of
that.

Release note: None
The connection state machine returns an event to the connExecutor -
txnAborted - telling it to clean up some state. This event was
confusingly returned both when entering the Aborted state and sometimes
when leaving it.
This patch replaces txnAborted with a txnRollback event which is
returned strictly on rollback. Entering the Aborted state no longer
triggers this event; it triggers no event. This is in preparation for
broader support for savepoints, which want to enter the Aborted state
without much fuss.

Release note: None
@andreimatei andreimatei force-pushed the savepoint.rationalize-txnRestart branch from 483c170 to d75f7c9 Compare February 28, 2020 18:48
Copy link
Contributor Author

@andreimatei andreimatei left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @nvanbenschoten)


pkg/sql/conn_fsm.go, line 506 at r3 (raw file):

Previously, nvanbenschoten (Nathan VanBenschoten) wrote…

Four suggestions to make this easier to read:

  1. could you move this down right below finishTxn because these are the two code paths that can produce this txnRollback event?
  2. could you rename this to cleanupAndFinishOnError?
  3. could you make this a method on *txnState to parallel noTxnToOpen and finishTxn?
  4. could you pull out the actions that do the same thing except they don't ts.finishSQLTxn() into a similar helper method?
  1. done
  2. done
  3. I went the other way and made noTxnToOpen a free-standing function. And see 4)
  4. done - also as a free-standing function that can be referenced directly in the state machine transitions, without having to write an inline function.

pkg/sql/txn_state.go, line 381 at r1 (raw file):

Previously, nvanbenschoten (Nathan VanBenschoten) wrote…

We seem to like these comments around here, so consider updating it instead of deleting it.

done


pkg/sql/txn_state.go, line 373 at r3 (raw file):

Previously, nvanbenschoten (Nathan VanBenschoten) wrote…

Could you include a bit more here? How far has the transaction rolled back? To a savepoint? All the way? Either?

Do you want to include something about when the event is produced?

done

Copy link
Member

@nvanbenschoten nvanbenschoten left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 5 of 5 files at r4, 2 of 2 files at r5, 5 of 5 files at r6.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained

Copy link
Contributor Author

@andreimatei andreimatei left a comment

Choose a reason for hiding this comment

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

bors r+

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained

@craig
Copy link
Contributor

craig bot commented Mar 2, 2020

Build succeeded

@craig craig bot merged commit e314075 into cockroachdb:master Mar 2, 2020
@andreimatei andreimatei deleted the savepoint.rationalize-txnRestart branch March 10, 2020 18:32
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