-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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: introduce connExecutor, the query execution orchestrator #22277
sql: introduce connExecutor, the query execution orchestrator #22277
Conversation
First commit is #21900 This PR will eventually contain some more things:
But still, I think that getting some review would be very useful. One can start from connExecutor.run() and drill down, or come sit with me at leisure. Thanks! |
4634524
to
b4ec5f2
Compare
Ok so I have reviewed this. This is mostly good, and I have lots of respect for the herculean effort that went into this. Yet I also think the overall structure of the patch does not live up to our usual engineering standards. Before we go further with the review I recommend you merge #21900 and rebase on top of that. I am comfortable with the first commit. Then for the remainder I notice at least 3 unrelated changes:
I recommend you split the change into 3 commits, in that order. In particular I'd like to see the FSM changes isolated from the rest, so I can check what's going on in there. Possibly the first two can be handled in another PR (prefix to the last, largish change) Finally, there are too many "WIPs" and "panics" remaining in the code. If you think the change is too overwhelming to make a single commit/PR for, we can talk it through. Thanks, you're just the best. Reviewed 18 of 18 files at r1, 22 of 22 files at r2. pkg/sql/conn_executor.go, line 187 at r2 (raw file):
Super comment. 👍 🥇 pkg/sql/conn_executor.go, line 224 at r2 (raw file):
We're not merging this into pkg/sql/conn_executor.go, line 246 at r2 (raw file):
So if we merge this now, we can't shut down a node that has active SQL connections any more? pkg/sql/conn_executor.go, line 311 at r2 (raw file):
stray empty line pkg/sql/conn_executor.go, line 398 at r2 (raw file):
wup? pkg/sql/conn_executor.go, line 1519 at r2 (raw file):
s/classical/local pkg/sql/conn_executor.go, line 1712 at r2 (raw file):
I believe so. pkg/sql/conn_executor.go, line 1766 at r2 (raw file):
What's up with this? pkg/sql/results_writer.go, line 319 at r2 (raw file):
?? pkg/sql/session.go, line 134 at r2 (raw file):
What's up with that? It needs to be mentioned+explained in the commit message. pkg/sql/pgwire/v3.go, line 1114 at r2 (raw file):
What's this? Comments from Reviewable |
7bf09ee
to
dc4947d
Compare
2666ded
to
35e91c0
Compare
I've extracted the conn_fsm changes in another PR (all but the last commit are elsewhere). I've explained what's going on with that hidden field in a comment on the source. I've added code for dealing with prepared statements and portals and all that jazz. If you could give that a look, that'd be fantastic (diffing in reviewable since what you've seen last is probably the way to go). Thanks Rafa! Review status: 1 of 34 files reviewed at latest revision, 10 unresolved discussions. pkg/sql/conn_executor.go, line 224 at r2 (raw file): Previously, knz (kena) wrote…
correct pkg/sql/conn_executor.go, line 246 at r2 (raw file): Previously, knz (kena) wrote…
if we merge this now, nobody's creating one of these Servers. In any case, this one had actually been done. pkg/sql/conn_executor.go, line 311 at r2 (raw file): Previously, knz (kena) wrote…
Done. pkg/sql/conn_executor.go, line 398 at r2 (raw file): Previously, knz (kena) wrote…
nobody's using the Server yet pkg/sql/conn_executor.go, line 1519 at r2 (raw file): Previously, knz (kena) wrote…
Done. pkg/sql/conn_executor.go, line 1712 at r2 (raw file): Previously, knz (kena) wrote…
done, thanks pkg/sql/conn_executor.go, line 1766 at r2 (raw file): Previously, knz (kena) wrote…
will come pkg/sql/results_writer.go, line 319 at r2 (raw file): Previously, knz (kena) wrote…
no particular need to call out things with "!!!" and "wip(andrei)". I'm aware of them :) pkg/sql/session.go, line 134 at r2 (raw file): Previously, knz (kena) wrote…
I don't think there's much to be mentioned particularly in the commit message, but I'm happy to explain here. This is a case of something working differently in the new world than the old world. In the new world, the This pkg/sql/pgwire/v3.go, line 1114 at r2 (raw file): Previously, knz (kena) wrote…
removed Comments from Reviewable |
499b681
to
31099de
Compare
fa68ecf
to
65cf485
Compare
42d9f08
to
c74c96a
Compare
All tests pass! I'll address everything in the review over the weekend. Review status: 21 of 56 files reviewed at latest revision, 75 unresolved discussions. Comments from Reviewable |
8f94b96
to
7c9b443
Compare
Review status: 11 of 50 files reviewed at latest revision, 75 unresolved discussions, some commit checks pending. pkg/server/server.go, line 535 at r3 (raw file): Previously, nvanbenschoten (Nathan VanBenschoten) wrote…
Done. pkg/sql/conn_executor.go, line 173 at r4 (raw file): Previously, nvanbenschoten (Nathan VanBenschoten) wrote…
Done. pkg/sql/conn_executor.go, line 221 at r4 (raw file): Previously, nvanbenschoten (Nathan VanBenschoten) wrote…
Done. pkg/sql/conn_executor.go, line 307 at r4 (raw file): Previously, nvanbenschoten (Nathan VanBenschoten) wrote…
I don't think they ever belonged there... pkg/sql/conn_executor.go, line 487 at r4 (raw file): Previously, nvanbenschoten (Nathan VanBenschoten) wrote…
got rid of the type instead pkg/sql/conn_executor.go, line 495 at r4 (raw file): Previously, nvanbenschoten (Nathan VanBenschoten) wrote…
done pkg/sql/conn_executor.go, line 540 at r4 (raw file): Previously, nvanbenschoten (Nathan VanBenschoten) wrote…
I don't think this belongs there; it has nothing to do with a transaction. pkg/sql/conn_executor.go, line 553 at r4 (raw file): Previously, nvanbenschoten (Nathan VanBenschoten) wrote…
I don't think this has anything to do with pkg/sql/conn_executor.go, line 555 at r4 (raw file): Previously, nvanbenschoten (Nathan VanBenschoten) wrote…
removed pkg/sql/conn_executor.go, line 586 at r4 (raw file): Previously, nvanbenschoten (Nathan VanBenschoten) wrote…
I've removed the TODO. pkg/sql/conn_executor.go, line 619 at r4 (raw file): Previously, nvanbenschoten (Nathan VanBenschoten) wrote…
Done. pkg/sql/conn_executor.go, line 653 at r4 (raw file): Previously, nvanbenschoten (Nathan VanBenschoten) wrote…
I think pkg/sql/conn_executor.go, line 670 at r4 (raw file): Previously, nvanbenschoten (Nathan VanBenschoten) wrote…
I think pkg/sql/conn_executor.go, line 735 at r4 (raw file): Previously, nvanbenschoten (Nathan VanBenschoten) wrote…
Done. pkg/sql/conn_executor.go, line 755 at r4 (raw file): Previously, nvanbenschoten (Nathan VanBenschoten) wrote…
Done. pkg/sql/conn_executor.go, line 809 at r4 (raw file): Previously, nvanbenschoten (Nathan VanBenschoten) wrote…
Done. pkg/sql/conn_executor.go, line 814 at r4 (raw file): Previously, nvanbenschoten (Nathan VanBenschoten) wrote…
Done. pkg/sql/conn_executor.go, line 853 at r4 (raw file): Previously, nvanbenschoten (Nathan VanBenschoten) wrote…
moved pkg/sql/conn_executor.go, line 976 at r4 (raw file): Previously, nvanbenschoten (Nathan VanBenschoten) wrote…
removed pkg/sql/conn_executor.go, line 1130 at r4 (raw file): Previously, nvanbenschoten (Nathan VanBenschoten) wrote…
well so some amount of straying is necessary: it used to be that pkg/sql/conn_executor.go, line 1170 at r4 (raw file): Previously, nvanbenschoten (Nathan VanBenschoten) wrote…
same, but let's talk if you're not happy pkg/sql/conn_executor.go, line 1208 at r4 (raw file): Previously, nvanbenschoten (Nathan VanBenschoten) wrote…
Done. pkg/sql/conn_executor.go, line 1368 at r4 (raw file): Previously, nvanbenschoten (Nathan VanBenschoten) wrote…
Done. pkg/sql/conn_executor.go, line 1371 at r4 (raw file): Previously, nvanbenschoten (Nathan VanBenschoten) wrote…
now they all take the pkg/sql/conn_executor.go, line 1384 at r4 (raw file): Previously, nvanbenschoten (Nathan VanBenschoten) wrote…
pkg/sql/conn_executor.go, line 1533 at r4 (raw file): Previously, nvanbenschoten (Nathan VanBenschoten) wrote…
Simplified how? Isn't the logic now as clean as it gets? pkg/sql/conn_executor.go, line 1535 at r4 (raw file): Previously, nvanbenschoten (Nathan VanBenschoten) wrote…
I don't know what to do... I'll leave it :) pkg/sql/conn_executor.go, line 1701 at r4 (raw file): Previously, nvanbenschoten (Nathan VanBenschoten) wrote…
Done. pkg/sql/conn_executor.go, line 1747 at r4 (raw file): Previously, nvanbenschoten (Nathan VanBenschoten) wrote…
Done. pkg/sql/conn_executor.go, line 1822 at r4 (raw file): Previously, nvanbenschoten (Nathan VanBenschoten) wrote…
no, it's only needed when we want to change the tag of the result. If we created the result by passing pkg/sql/conn_executor.go, line 1825 at r4 (raw file): Previously, nvanbenschoten (Nathan VanBenschoten) wrote…
Done. pkg/sql/conn_executor.go, line 1868 at r4 (raw file): Previously, nvanbenschoten (Nathan VanBenschoten) wrote…
Done. pkg/sql/conn_executor.go, line 1909 at r4 (raw file): Previously, nvanbenschoten (Nathan VanBenschoten) wrote…
par stmts use a dedicated planner. It doesn't share this. pkg/sql/conn_executor.go, line 1940 at r4 (raw file): Previously, nvanbenschoten (Nathan VanBenschoten) wrote…
sprinkled some comments here, above, and at the method definition. pkg/sql/conn_executor.go, line 2043 at r4 (raw file): Previously, nvanbenschoten (Nathan VanBenschoten) wrote…
Done. pkg/sql/conn_executor.go, line 2052 at r4 (raw file): Previously, nvanbenschoten (Nathan VanBenschoten) wrote…
Done. pkg/sql/conn_executor.go, line 2093 at r4 (raw file): Previously, nvanbenschoten (Nathan VanBenschoten) wrote…
moved away pkg/sql/conn_executor.go, line 2235 at r4 (raw file): Previously, nvanbenschoten (Nathan VanBenschoten) wrote…
I wouldn't say so. First of all, when talking about a single statement, the word "serially" wouldn't make sense. pkg/sql/conn_executor.go, line 2311 at r4 (raw file): Previously, nvanbenschoten (Nathan VanBenschoten) wrote…
meh pkg/sql/conn_executor.go, line 2367 at r4 (raw file): Previously, nvanbenschoten (Nathan VanBenschoten) wrote…
meh pkg/sql/conn_executor.go, line 2477 at r4 (raw file): Previously, nvanbenschoten (Nathan VanBenschoten) wrote…
meh pkg/sql/conn_executor.go, line 2508 at r4 (raw file): Previously, nvanbenschoten (Nathan VanBenschoten) wrote…
removed pkg/sql/conn_executor.go, line 2560 at r4 (raw file): Previously, nvanbenschoten (Nathan VanBenschoten) wrote…
Done.m pkg/sql/conn_executor.go, line 2588 at r4 (raw file): Previously, nvanbenschoten (Nathan VanBenschoten) wrote…
Done. pkg/sql/conn_executor.go, line 2633 at r4 (raw file): Previously, nvanbenschoten (Nathan VanBenschoten) wrote…
I've created an pkg/sql/conn_executor.go, line 2640 at r4 (raw file): Previously, nvanbenschoten (Nathan VanBenschoten) wrote…
not exported any more pkg/sql/conn_io.go, line 321 at r4 (raw file): Previously, nvanbenschoten (Nathan VanBenschoten) wrote…
Done. pkg/sql/conn_io.go, line 347 at r4 (raw file): Previously, nvanbenschoten (Nathan VanBenschoten) wrote…
removed pkg/sql/conn_io.go, line 389 at r4 (raw file): Previously, nvanbenschoten (Nathan VanBenschoten) wrote…
Done. pkg/sql/conn_io.go, line 520 at r4 (raw file): Previously, nvanbenschoten (Nathan VanBenschoten) wrote…
Done. pkg/sql/conn_io.go, line 570 at r4 (raw file): Previously, nvanbenschoten (Nathan VanBenschoten) wrote…
Done. Shuffled interfaces around, PTAL. pkg/sql/executor.go, line 2250 at r4 (raw file): Previously, nvanbenschoten (Nathan VanBenschoten) wrote…
Done. pkg/sql/results_writer.go, line 259 at r4 (raw file): Previously, nvanbenschoten (Nathan VanBenschoten) wrote…
removed. This was from when I wanted to make this pkg/sql/run_control_test.go, line 91 at r4 (raw file): Previously, nvanbenschoten (Nathan VanBenschoten) wrote…
Did you mean "so this grammar"? pkg/sql/txn_state_test.go, line 775 at r4 (raw file): Previously, nvanbenschoten (Nathan VanBenschoten) wrote…
added spaces if that was what you wanted. Names here follow a couple of patterns. pkg/sql/pgwire/command_result.go, line 53 at r4 (raw file): Previously, nvanbenschoten (Nathan VanBenschoten) wrote…
Hopefully I've improved things in the pkg/sql/pgwire/command_result.go, line 137 at r4 (raw file): Previously, nvanbenschoten (Nathan VanBenschoten) wrote…
see nowenv pkg/sql/pgwire/command_result.go, line 188 at r6 (raw file): Previously, nvanbenschoten (Nathan VanBenschoten) wrote…
meh, I don't think it's worth it pkg/sql/pgwire/conn.go, line 384 at r6 (raw file): Previously, nvanbenschoten (Nathan VanBenschoten) wrote…
Referenced #22630 pkg/sql/pgwire/conn.go, line 660 at r6 (raw file): Previously, nvanbenschoten (Nathan VanBenschoten) wrote…
Not really - this code only decodes what the client sent. The connExecutor than meshes it with the columns that actually exist in the results of the prepared stmt. pkg/sql/pgwire/conn.go, line 743 at r6 (raw file): Previously, nvanbenschoten (Nathan VanBenschoten) wrote…
FastIntMap seems to be about keys being small - which here they generally aren't. CmdPos keeps increasing for the life of a connection. Comments from Reviewable |
7c9b443
to
e0686bc
Compare
Review status: 11 of 50 files reviewed at latest revision, 75 unresolved discussions, all commit checks successful. pkg/sql/pgwire/conn.go, line 384 at r6 (raw file): Previously, andreimatei (Andrei Matei) wrote…
Did something here. Comments from Reviewable |
I left a few more comments that need to be addressed before this can be merged, but besides them the rest Reviewed 17 of 31 files at r7, 25 of 33 files at r8. pkg/sql/conn_executor.go, line 670 at r4 (raw file): Previously, andreimatei (Andrei Matei) wrote…
Whatever order you think is best is fine, but the order we consume pkg/sql/conn_executor.go, line 1533 at r4 (raw file): Previously, andreimatei (Andrei Matei) wrote…
Get rid of pkg/sql/conn_executor.go, line 1701 at r4 (raw file): Previously, andreimatei (Andrei Matei) wrote…
So that you can get rid of the goto! pkg/sql/conn_executor.go, line 1822 at r4 (raw file): Previously, andreimatei (Andrei Matei) wrote…
Please put this in a comment here. pkg/sql/conn_executor.go, line 432 at r8 (raw file):
Is this needed? Isn't it the zero value? pkg/sql/conn_executor.go, line 454 at r8 (raw file):
pkg/sql/conn_executor.go, line 1231 at r8 (raw file):
I still think we should move all methods related to pkg/sql/conn_io.go, line 259 at r8 (raw file):
Also, the order in which each of these pkg/sql/pgwire/command_result.go, line 53 at r4 (raw file): Previously, andreimatei (Andrei Matei) wrote…
This is much better. Thanks! Comments from Reviewable |
Release note: None The connExecutor is the top dog that interfaces with a pgwire connection (through the clientComm and CommandResult interfaces), consumes a stream of queries and produces a stream of results. It encapsulates the connection state machine for which it produces events. It interfaces with the two SQL execution engines for actually running queries. Its main responsibility is to dispatch statements based on the current state (in txn, not in txn, in aborted txn, etc) and to handle execution in all states but Open (in Open it talks to an execution engine). It also handles other commands than executiong queries: preparing, binding, etc and it maintains the session state associated with prepares statements.
e0686bc
to
7e38855
Compare
Review status: 48 of 52 files reviewed at latest revision, 11 unresolved discussions. pkg/sql/conn_executor.go, line 670 at r4 (raw file): Previously, nvanbenschoten (Nathan VanBenschoten) wrote…
Done. pkg/sql/conn_executor.go, line 1533 at r4 (raw file): Previously, nvanbenschoten (Nathan VanBenschoten) wrote…
Done. pkg/sql/conn_executor.go, line 1701 at r4 (raw file): Previously, nvanbenschoten (Nathan VanBenschoten) wrote…
Done. pkg/sql/conn_executor.go, line 1822 at r4 (raw file): Previously, nvanbenschoten (Nathan VanBenschoten) wrote…
Well I don't want to put a comment whenever this method is called. It thing is explained on the method comment, and also the name having "Reset" in it is suggestive enough I think. pkg/sql/conn_executor.go, line 432 at r8 (raw file): Previously, nvanbenschoten (Nathan VanBenschoten) wrote…
Done. pkg/sql/conn_executor.go, line 454 at r8 (raw file): Previously, nvanbenschoten (Nathan VanBenschoten) wrote…
Done. pkg/sql/conn_executor.go, line 1231 at r8 (raw file): Previously, nvanbenschoten (Nathan VanBenschoten) wrote…
Done. pkg/sql/conn_io.go, line 259 at r8 (raw file): Previously, nvanbenschoten (Nathan VanBenschoten) wrote…
Done. Comments from Reviewable |
Reviewed 10 of 56 files at r3, 2 of 12 files at r5, 15 of 31 files at r7, 32 of 33 files at r8, 2 of 4 files at r9. pkg/sql/app_stats.go, line 291 at r8 (raw file):
The locking did not need to change in this PR. pkg/sql/conn_executor.go, line 628 at r8 (raw file):
Define "periodically" here. pkg/sql/conn_executor.go, line 1055 at r8 (raw file):
I'd rather you have this log/report an error and close the connection instead of shutting down the entire node. Otherwise still, log.Fatalf is slightly better than panic. pkg/sql/conn_executor.go, line 1447 at r8 (raw file):
ditto log.Fatalf pkg/sql/conn_executor.go, line 2259 at r8 (raw file):
SetError(commErr) here - the exec logs must show this information. pkg/sql/results_writer.go, line 310 at r8 (raw file):
pkg/sql/txn_restart_test.go, line 362 at r8 (raw file):
return an error + fail the connection, do not panic pkg/sql/pgwire/command_result.go, line 212 at r8 (raw file):
log / report error but avoid shutting down node Comments from Reviewable |
In general I think we have a general Review status: 50 of 52 files reviewed at latest revision, 18 unresolved discussions, some commit checks pending. Comments from Reviewable |
I thought in SQL we like panics over Fatalf because of that panic handler that anonymizes the query and sends a crash report, no? Review status: 50 of 52 files reviewed at latest revision, 18 unresolved discussions, some commit checks pending. Comments from Reviewable |
I do not have a clean answer to the question of panic vs fatalf. I do believe however that both/either should be avoided and replaced by an error log + reported event + conn close, without crashing the node. This PR does not move us in that direction, and actually moves us a bit further because the code path needed to make this happen now becomes more complex. I suggest we work on this in the coming two months. Review status: 50 of 52 files reviewed at latest revision, 18 unresolved discussions, some commit checks pending. Comments from Reviewable |
Review status: 50 of 52 files reviewed at latest revision, 18 unresolved discussions, all commit checks successful. pkg/sql/app_stats.go, line 291 at r8 (raw file): Previously, knz (kena) wrote…
how do you mean? It didn't really change... pkg/sql/conn_executor.go, line 2259 at r8 (raw file): Previously, knz (kena) wrote…
this is done at a higher layer, in pkg/sql/txn_restart_test.go, line 362 at r8 (raw file): Previously, knz (kena) wrote…
testing code, doesn't really matter Comments from Reviewable |
Not sure what you're referring to :). A lot of panics have been transformed to errors, like you say. I think it most definitely takes us in the direction you want. Review status: 50 of 52 files reviewed at latest revision, 18 unresolved discussions, all commit checks successful. Comments from Reviewable |
I fail to agree as long as the connection is closed immediately and any currently open kv txn is not given a chance to commit. Reviewed 1 of 4 files at r9. pkg/sql/app_stats.go, line 291 at r8 (raw file): Previously, andreimatei (Andrei Matei) wrote…
The party line is to avoid defers if there's a single control path out of the critical section. There was no need to change that here. pkg/sql/conn_executor.go, line 2259 at r8 (raw file): Previously, andreimatei (Andrei Matei) wrote…
Thanks. pkg/sql/txn_restart_test.go, line 362 at r8 (raw file): Previously, andreimatei (Andrei Matei) wrote…
'doh. Carry on. Comments from Reviewable |
@andreimatei, @knz See #16479 for a reason to prefer log.Fatal over panic. If only panics include anonymized queries, we could investigate ways to alleviate that. This comment is not intended to motivate changing anything in this PR. Review status: 51 of 52 files reviewed at latest revision, 15 unresolved discussions, all commit checks successful. Comments from Reviewable |
Merging this and the cherry-pick. Will address the remaining comments here in another PR. Review status: 51 of 52 files reviewed at latest revision, 15 unresolved discussions, all commit checks successful. Comments from Reviewable |
Release note: None
The connExecutor is the top dog that interfaces with a pgwire connection
(through the clientComm and CommandResult interfaces), consumes a stream
of queries and produces a stream of results. It encapsulates the
connection state machine for which it produces events. It interfaces
with the two SQL execution engines for actually running queries. Its
main responsibility is to dispatch statements based on the current state
(in txn, not in txn, in aborted txn, etc) and to handle execution in all
states but Open (in Open it talks to an execution engine). It also
handles other commands than executiong queries: preparing, binding, etc
and it maintains the session state associated with prepares statements.