-
-
Notifications
You must be signed in to change notification settings - Fork 514
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
Implement traditional
auto-increment lock mode hold the lock for the duration of the insert iter.
#7704
Conversation
@nicktobey DOLT
|
99db5af
to
e0d8534
Compare
@nicktobey DOLT
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, a few small comments. I skipped over the changes included from #7699 since those have already been reviewed and you're working on some follow ups there.
Looks like a few CI checks are also failing. Some looked transient, but it doesn't look like the new BATS tests are running well in the Lambda executor and probably still need some work.
My biggest comment is that I think the test code would be easier to understand and easier to extend if they used the sql-server golang multi session test framework we have in Dolt already. Testing this in BATS feels more complicated to me.
We have a few tests that use the sql-server multi session test framework in Dolt already (e.g. for testing multi-session behavior with branch deletion). There are definitely some gaps in that part of our testing framework, but it would be really valuable to improve it so we could use it more easily for more functionality like this in the future.
run dolt sql -q "INSERT INTO test1 (c0) select v from sequence5bit; SELECT * from timestamps; COMMIT;" & | ||
run dolt sql -q "INSERT INTO test2 (c0) select v from sequence5bit; SELECT * from timestamps; COMMIT;" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(minor) Doesn't seem like the COMMIT
s are needed here, right? Since @@autocommit
is enabled? Not a big deal, but might be nice remove them just to simplify and not confuse future code readers into thinking there's manual tx management going on.
Is it interesting to test behavior for concurrent transactions? If so, that's another good reason to use the sql server multi session tests in the Go code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Autocommit is actually disabled when the server is started with the start_sql_server_with_config
helper function, so these commits are necessary.
#!/usr/bin/env bats | ||
load $BATS_TEST_DIRNAME/helper/common.bash |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you get a chance to check out the sql server multi session tests in Dolt's Go code? Those tests are somewhat easier to debug, although since they start up a separate sql server process, it's still not as direct as a non-server test. They also have the advantage of having multiple concurrent sessions running and being able to interleave commands from different sessions. They are a little hacky, but improving them so we could use them more would be pretty valuable.
In regards to your comments about the server multi session tests: I took a look at them, but (if I understood them correctly) their limitation is that while they allow multiple sessions, the test harness is still only executing one statement at a time. For these tests, I need to test multiple sessions that are attempting to execute a statement concurrently. I'm sure we could improve them to allow for this kind of concurrency, but in the meantime it was easier to just implement the tests this way. |
…t asserted it can't.
fc77d06
to
e311f89
Compare
@nicktobey DOLT
|
@coffeegoddd DOLT
|
@nicktobey DOLT
|
I don't think the BATS test gives you any better guarantee about the concurrency of the two sessions here – you're spinning up two processes through the shell, so there's no guarantee that the sessions will even be concurrent depending on how the OS ends up scheduling those processes. If you really need two cores to run the same statement at the same time to test this logic, I don't think this BATS test is the way to get that. |
@nicktobey DOLT
|
var row1 sql.Row | ||
require.NoError(t, err1) | ||
row1, err1 = iter1.Next(ctx) | ||
_ = row1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(minor) Could you get rid of the var row1
completely by saying: _, err1 = iter1.Next(ctx)
like you're doing for iter2
?
err = iter2.Close(ctx) | ||
require.NoError(t, err) | ||
|
||
dsess.DSessFromSess(ctx.Session).CommitTransaction(ctx, ctx.GetTransaction()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want these to be executed in the same session?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In a real environment they wouldn't be, but I don't think it matters here. The engine tests have a single session baked in, and figuring out how to disentangle that didn't seem worth it for a single test.
@nicktobey DOLT
|
@coffeegoddd DOLT
|
…gine: the test manages the engine itself.
@nicktobey DOLT
|
@coffeegoddd DOLT
|
@coffeegoddd DOLT
|
Fixes #7634
This is the dolt half of dolthub/go-mysql-server#2439
This adds support for
innodb_autoinc_lock_mode=0
("traditional"). When this system variable is set, the engine will guarantee that every insert statement generates consecutive IDs forAUTO INCREMENT
columns.This PR also allows the user to set
innodb_autoinc_lock_mode=1
("consecutive"), although the behavior is currently identical to "traditional". This is acceptable because both modes make the same guarantees (that each statement gets consecutive IDs), and the observed behavior is the same in almost all cases.(The "consecutive" contains an additional optimization: if there is a known upper bound on the number of IDs that must be generated for an insert, under "consecutive" mode the engine will just increment the counter by that upper bound and immediately release the lock. In places where not all of those IDs are actually used, the excess are wasted. This PR does not include that optimization. Thus, with this PR,
traditional
andconsecutive
behave the same.)