-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
gh-ost does not define a transaction isolation level #1155
Comments
This is a tricky one! I would be cautious about making the transaction isolation level user-configurable when we don't have a good way to reliably test that gh-ost behaves as expected with I'd be in favour of:
@timvaillancourt what do you think of that approach? |
@dm-2 that's a great point 👍. I've added a
I think that's a reasonable approach for now 👍 Assuming |
I've ended up here to see if we can alleviate the pain from gh-ost 1.1.5 starting, and whilst I have the information to hand thought it might be worth documenting some real world experience. Despite a default isolation of
when gh-ost opts to do SELECT keyId FROM SomeTable ORDER BY keyId ASC LIMIT 1;
SELECT keyId FROM SomeTable ORDER BY keyId DESC LIMIT 1;
this took over 6 hours and caused significant impact to history length and purging That makes me think that the default isolation The same queries could be rewritten as follows, completely avoiding the impact altogether SELECT MIN(keyId), MAX(keyId) FROM SomeTable; I had assumed that gh-ost wasn't doing that in order to get accurate rows examined statistic, but the first Copy log line proceeds to start at
which uses the estimated row count anyway. So in terms of feedback, we'd most definitely support being able to set isolation to |
@EagleEyeJohn a new |
Thank you, I will try to find some time to test that out. We solved our history length issue (#1155 (comment)) when
It would be helpful if |
@EagleEyeJohn that's pretty interesting. Ordering the index makes a lot of sense. By default this is If we want this to apply to just 1-2 queries I suggest a I believe this can be achieved by: |
gh-ost does not define a transaction isolation level when it sets up new connections in
go/mysql/connection.go
. This means thatgh-ost
"trusts" the safety of the default isolation level of the MySQL serverIn most situations this is probably a safe assumption, but I believe this could bite us if the server default is
READ_UNCOMMITTED
. This isolation could cause the min/max queries for row copying to return un-comitted rows. These rows may never actually be committed (due toROLLBACK
) or committed later than when they're read 😱Luckily, the transaction isolation can be defined at a per-connection level. Setting a transaction isolation at a per-connection level allows us to be certain we're using the right isolation while allowing users to default to more-relaxed isolations. I would like to take that approach
There are 2 x isolations I can see fitting for
gh-ost
:REPEATABLE_READ
- this is the default for MySQL and is probably the most commonly used. It's snapshot-level isolation and gap-locking may be more strict thangh-ost
really needs, however. This isolation can cause more redo/undo logging as well, although it may be negligible in this use-caseREAD_COMMITTED
- this always returns what has beenCOMMIT
-ed to disk (not a snapshot in time) and disables gap-locking. Asgh-ost
usesautocommit=true
our transactions are a single operation only (BEGIN
=> a single-operation =>COMMIT
), so I believe there would be no major difference to "visibility" of rows returned in this use case. If we did several queries per transaction (we don't) there would be a major difference, however. So in practice I think this isolation would just cause less overhead to the server, not a change to what rows are visible. Please correct me if I'm wrong here!REPEATABLE_READ
is the safest bet, but I am curious if the community has feedback on the feasibility ofREAD_COMMITTED
becoming the default isolation forgh-ost
, and if there are any gotchas/benefits I missed above 🤔More on the differences between these two isolations in this great Percona Blog 👍
cc @dm-2 / @rashiq / @shlomi-noach / @ajm188 for thoughts/validation here 🙇
The text was updated successfully, but these errors were encountered: