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

release-24.1: colexecerror: avoid debug.Stack in CatchVectorizedRuntimeError #123499

Merged
merged 4 commits into from May 3, 2024

Conversation

blathers-crl[bot]
Copy link

@blathers-crl blathers-crl bot commented May 2, 2024

Backport 4/4 commits from #123277 on behalf of @michae2.

/cc @cockroachdb/release


See individual commits for details.

Benchmarks before and after the change:

                                                                    │ /tmp/tmp.PrzUglo6GH/bench.catch~3 │    /tmp/tmp.PrzUglo6GH/bench.catch     │
                                                                    │              sec/op               │    sec/op      vs base                 │
CatchVectorizedRuntimeError/noError-12                                                    0.4033n ± ∞ ¹   0.4224n ± ∞ ¹        ~ (p=1.000 n=1) ²
CatchVectorizedRuntimeError/expected-12                                                 40831.00n ± ∞ ¹    98.55n ± ∞ ¹        ~ (p=1.000 n=1) ²
CatchVectorizedRuntimeError/storage-12                                                  41302.00n ± ∞ ¹    99.54n ± ∞ ¹        ~ (p=1.000 n=1) ²
CatchVectorizedRuntimeError/contextCanceled-12                                          40947.00n ± ∞ ¹    99.78n ± ∞ ¹        ~ (p=1.000 n=1) ²
CatchVectorizedRuntimeError/internalWithCode-12                                          41088.0n ± ∞ ¹    474.6n ± ∞ ¹        ~ (p=1.000 n=1) ²
CatchVectorizedRuntimeError/internal-12                                                  41032.0n ± ∞ ¹    943.0n ± ∞ ¹        ~ (p=1.000 n=1) ²
CatchVectorizedRuntimeError/runtime-12                                                    37.094µ ± ∞ ¹    1.091µ ± ∞ ¹        ~ (p=1.000 n=1) ²
SQLCatchVectorizedRuntimeError/conns=12/noError-12                                         43.83µ ± ∞ ¹    43.63µ ± ∞ ¹        ~ (p=1.000 n=1) ²
SQLCatchVectorizedRuntimeError/conns=12/expectedWithCode-12                              1234.24µ ± ∞ ¹    48.27µ ± ∞ ¹        ~ (p=1.000 n=1) ²
SQLCatchVectorizedRuntimeError/conns=12/expectedAssertion-12                             1182.11µ ± ∞ ¹    88.12µ ± ∞ ¹        ~ (p=1.000 n=1) ²
SQLCatchVectorizedRuntimeError/conns=12/internalAssertion-12                             1211.83µ ± ∞ ¹    77.58µ ± ∞ ¹        ~ (p=1.000 n=1) ²
SQLCatchVectorizedRuntimeError/conns=12/internalIndexOutOfRange-12                       1227.76µ ± ∞ ¹    82.40µ ± ∞ ¹        ~ (p=1.000 n=1) ²
SQLCatchVectorizedRuntimeError/conns=12/internalDivideByZero-12                          1224.45µ ± ∞ ¹    81.01µ ± ∞ ¹        ~ (p=1.000 n=1) ²
SQLCatchVectorizedRuntimeError/conns=12/contextCanceled-12                               1265.30µ ± ∞ ¹    44.83µ ± ∞ ¹        ~ (p=1.000 n=1) ²
SQLCatchVectorizedRuntimeError/conns=240/noError-12                                        43.78µ ± ∞ ¹    42.83µ ± ∞ ¹        ~ (p=1.000 n=1) ²
SQLCatchVectorizedRuntimeError/conns=240/expectedWithCode-12                             1210.98µ ± ∞ ¹    48.41µ ± ∞ ¹        ~ (p=1.000 n=1) ²
SQLCatchVectorizedRuntimeError/conns=240/expectedAssertion-12                            1187.21µ ± ∞ ¹    84.70µ ± ∞ ¹        ~ (p=1.000 n=1) ²
SQLCatchVectorizedRuntimeError/conns=240/internalAssertion-12                            1224.62µ ± ∞ ¹    73.85µ ± ∞ ¹        ~ (p=1.000 n=1) ²
SQLCatchVectorizedRuntimeError/conns=240/internalIndexOutOfRange-12                      1224.56µ ± ∞ ¹    81.39µ ± ∞ ¹        ~ (p=1.000 n=1) ²
SQLCatchVectorizedRuntimeError/conns=240/internalDivideByZero-12                         1259.05µ ± ∞ ¹    80.63µ ± ∞ ¹        ~ (p=1.000 n=1) ²
SQLCatchVectorizedRuntimeError/conns=240/contextCanceled-12                              1262.44µ ± ∞ ¹    47.13µ ± ∞ ¹        ~ (p=1.000 n=1) ²
SQLCatchVectorizedRuntimeError/conns=600/noError-12                                        44.98µ ± ∞ ¹    43.53µ ± ∞ ¹        ~ (p=1.000 n=1) ²
SQLCatchVectorizedRuntimeError/conns=600/expectedWithCode-12                             1231.37µ ± ∞ ¹    48.65µ ± ∞ ¹        ~ (p=1.000 n=1) ²
SQLCatchVectorizedRuntimeError/conns=600/expectedAssertion-12                            1201.74µ ± ∞ ¹    97.23µ ± ∞ ¹        ~ (p=1.000 n=1) ²
SQLCatchVectorizedRuntimeError/conns=600/internalAssertion-12                            1249.63µ ± ∞ ¹    80.46µ ± ∞ ¹        ~ (p=1.000 n=1) ²
SQLCatchVectorizedRuntimeError/conns=600/internalIndexOutOfRange-12                      1257.86µ ± ∞ ¹    77.83µ ± ∞ ¹        ~ (p=1.000 n=1) ²
SQLCatchVectorizedRuntimeError/conns=600/internalDivideByZero-12                         1251.79µ ± ∞ ¹    82.22µ ± ∞ ¹        ~ (p=1.000 n=1) ²
SQLCatchVectorizedRuntimeError/conns=600/contextCanceled-12                              1271.82µ ± ∞ ¹    51.19µ ± ∞ ¹        ~ (p=1.000 n=1) ²
geomean                                                                                    243.2µ          13.09µ        -94.62%
¹ need >= 6 samples for confidence interval at level 0.95
² need >= 4 samples to detect a difference at alpha level 0.05

                                                                    │ /tmp/tmp.PrzUglo6GH/bench.catch~3 │    /tmp/tmp.PrzUglo6GH/bench.catch     │
                                                                    │               B/op                │     B/op       vs base                 │
CatchVectorizedRuntimeError/noError-12                                                      0.000 ± ∞ ¹     0.000 ± ∞ ¹        ~ (p=1.000 n=1) ²
CatchVectorizedRuntimeError/expected-12                                                   9834.00 ± ∞ ¹     32.00 ± ∞ ¹        ~ (p=1.000 n=1) ³
CatchVectorizedRuntimeError/storage-12                                                    8880.00 ± ∞ ¹     32.00 ± ∞ ¹        ~ (p=1.000 n=1) ³
CatchVectorizedRuntimeError/contextCanceled-12                                            8840.00 ± ∞ ¹     40.00 ± ∞ ¹        ~ (p=1.000 n=1) ³
CatchVectorizedRuntimeError/internalWithCode-12                                           9.586Ki ± ∞ ¹   1.511Ki ± ∞ ¹        ~ (p=1.000 n=1) ³
CatchVectorizedRuntimeError/internal-12                                                  10.479Ki ± ∞ ¹   2.961Ki ± ∞ ¹        ~ (p=1.000 n=1) ³
CatchVectorizedRuntimeError/runtime-12                                                   10.964Ki ± ∞ ¹   2.656Ki ± ∞ ¹        ~ (p=1.000 n=1) ³
SQLCatchVectorizedRuntimeError/conns=12/noError-12                                        81.75Ki ± ∞ ¹   81.71Ki ± ∞ ¹        ~ (p=1.000 n=1) ³
SQLCatchVectorizedRuntimeError/conns=12/expectedWithCode-12                              143.04Ki ± ∞ ¹   85.28Ki ± ∞ ¹        ~ (p=1.000 n=1) ³
SQLCatchVectorizedRuntimeError/conns=12/expectedAssertion-12                              362.7Ki ± ∞ ¹   304.5Ki ± ∞ ¹        ~ (p=1.000 n=1) ³
SQLCatchVectorizedRuntimeError/conns=12/internalAssertion-12                              304.2Ki ± ∞ ¹   245.3Ki ± ∞ ¹        ~ (p=1.000 n=1) ³
SQLCatchVectorizedRuntimeError/conns=12/internalIndexOutOfRange-12                        313.0Ki ± ∞ ¹   267.2Ki ± ∞ ¹        ~ (p=1.000 n=1) ³
SQLCatchVectorizedRuntimeError/conns=12/internalDivideByZero-12                           308.3Ki ± ∞ ¹   260.7Ki ± ∞ ¹        ~ (p=1.000 n=1) ³
SQLCatchVectorizedRuntimeError/conns=12/contextCanceled-12                               128.96Ki ± ∞ ¹   80.60Ki ± ∞ ¹        ~ (p=1.000 n=1) ³
SQLCatchVectorizedRuntimeError/conns=240/noError-12                                       81.21Ki ± ∞ ¹   81.25Ki ± ∞ ¹        ~ (p=1.000 n=1) ³
SQLCatchVectorizedRuntimeError/conns=240/expectedWithCode-12                             136.02Ki ± ∞ ¹   84.99Ki ± ∞ ¹        ~ (p=1.000 n=1) ³
SQLCatchVectorizedRuntimeError/conns=240/expectedAssertion-12                             362.0Ki ± ∞ ¹   302.9Ki ± ∞ ¹        ~ (p=1.000 n=1) ³
SQLCatchVectorizedRuntimeError/conns=240/internalAssertion-12                             291.4Ki ± ∞ ¹   244.5Ki ± ∞ ¹        ~ (p=1.000 n=1) ³
SQLCatchVectorizedRuntimeError/conns=240/internalIndexOutOfRange-12                       317.1Ki ± ∞ ¹   267.0Ki ± ∞ ¹        ~ (p=1.000 n=1) ³
SQLCatchVectorizedRuntimeError/conns=240/internalDivideByZero-12                          308.4Ki ± ∞ ¹   260.4Ki ± ∞ ¹        ~ (p=1.000 n=1) ³
SQLCatchVectorizedRuntimeError/conns=240/contextCanceled-12                              145.34Ki ± ∞ ¹   81.73Ki ± ∞ ¹        ~ (p=1.000 n=1) ³
SQLCatchVectorizedRuntimeError/conns=600/noError-12                                       81.33Ki ± ∞ ¹   81.24Ki ± ∞ ¹        ~ (p=1.000 n=1) ³
SQLCatchVectorizedRuntimeError/conns=600/expectedWithCode-12                             137.49Ki ± ∞ ¹   85.05Ki ± ∞ ¹        ~ (p=1.000 n=1) ³
SQLCatchVectorizedRuntimeError/conns=600/expectedAssertion-12                             364.7Ki ± ∞ ¹   305.8Ki ± ∞ ¹        ~ (p=1.000 n=1) ³
SQLCatchVectorizedRuntimeError/conns=600/internalAssertion-12                             318.4Ki ± ∞ ¹   244.5Ki ± ∞ ¹        ~ (p=1.000 n=1) ³
SQLCatchVectorizedRuntimeError/conns=600/internalIndexOutOfRange-12                       315.8Ki ± ∞ ¹   265.4Ki ± ∞ ¹        ~ (p=1.000 n=1) ³
SQLCatchVectorizedRuntimeError/conns=600/internalDivideByZero-12                          310.9Ki ± ∞ ¹   260.2Ki ± ∞ ¹        ~ (p=1.000 n=1) ³
SQLCatchVectorizedRuntimeError/conns=600/contextCanceled-12                              133.20Ki ± ∞ ¹   80.53Ki ± ∞ ¹        ~ (p=1.000 n=1) ³
geomean                                                                                               ⁴                  -61.19%               ⁴
¹ need >= 6 samples for confidence interval at level 0.95
² all samples are equal
³ need >= 4 samples to detect a difference at alpha level 0.05
⁴ summaries must be >0 to compute geomean

                                                                    │ /tmp/tmp.PrzUglo6GH/bench.catch~3 │    /tmp/tmp.PrzUglo6GH/bench.catch    │
                                                                    │             allocs/op             │  allocs/op    vs base                 │
CatchVectorizedRuntimeError/noError-12                                                      0.000 ± ∞ ¹    0.000 ± ∞ ¹        ~ (p=1.000 n=1) ²
CatchVectorizedRuntimeError/expected-12                                                    36.000 ± ∞ ¹    3.000 ± ∞ ¹        ~ (p=1.000 n=1) ³
CatchVectorizedRuntimeError/storage-12                                                     11.000 ± ∞ ¹    3.000 ± ∞ ¹        ~ (p=1.000 n=1) ³
CatchVectorizedRuntimeError/contextCanceled-12                                             11.000 ± ∞ ¹    4.000 ± ∞ ¹        ~ (p=1.000 n=1) ³
CatchVectorizedRuntimeError/internalWithCode-12                                             35.00 ± ∞ ¹    37.00 ± ∞ ¹        ~ (p=1.000 n=1) ³
CatchVectorizedRuntimeError/internal-12                                                     46.00 ± ∞ ¹    59.00 ± ∞ ¹        ~ (p=1.000 n=1) ³
CatchVectorizedRuntimeError/runtime-12                                                      58.00 ± ∞ ¹    51.00 ± ∞ ¹        ~ (p=1.000 n=1) ³
SQLCatchVectorizedRuntimeError/conns=12/noError-12                                          838.0 ± ∞ ¹    838.0 ± ∞ ¹        ~ (p=1.000 n=1) ²
SQLCatchVectorizedRuntimeError/conns=12/expectedWithCode-12                                1110.0 ± ∞ ¹    950.0 ± ∞ ¹        ~ (p=1.000 n=1) ³
SQLCatchVectorizedRuntimeError/conns=12/expectedAssertion-12                               1.736k ± ∞ ¹   1.581k ± ∞ ¹        ~ (p=1.000 n=1) ³
SQLCatchVectorizedRuntimeError/conns=12/internalAssertion-12                               1.285k ± ∞ ¹   1.228k ± ∞ ¹        ~ (p=1.000 n=1) ³
SQLCatchVectorizedRuntimeError/conns=12/internalIndexOutOfRange-12                         1.418k ± ∞ ¹   1.425k ± ∞ ¹        ~ (p=1.000 n=1) ³
SQLCatchVectorizedRuntimeError/conns=12/internalDivideByZero-12                            1.413k ± ∞ ¹   1.411k ± ∞ ¹        ~ (p=1.000 n=1) ³
SQLCatchVectorizedRuntimeError/conns=12/contextCanceled-12                                  880.0 ± ∞ ¹    865.0 ± ∞ ¹        ~ (p=1.000 n=1) ³
SQLCatchVectorizedRuntimeError/conns=240/noError-12                                         836.0 ± ∞ ¹    836.0 ± ∞ ¹        ~ (p=1.000 n=1) ²
SQLCatchVectorizedRuntimeError/conns=240/expectedWithCode-12                               1012.0 ± ∞ ¹    949.0 ± ∞ ¹        ~ (p=1.000 n=1) ³
SQLCatchVectorizedRuntimeError/conns=240/expectedAssertion-12                              1.744k ± ∞ ¹   1.572k ± ∞ ¹        ~ (p=1.000 n=1) ³
SQLCatchVectorizedRuntimeError/conns=240/internalAssertion-12                              1.201k ± ∞ ¹   1.228k ± ∞ ¹        ~ (p=1.000 n=1) ³
SQLCatchVectorizedRuntimeError/conns=240/internalIndexOutOfRange-12                        1.518k ± ∞ ¹   1.424k ± ∞ ¹        ~ (p=1.000 n=1) ³
SQLCatchVectorizedRuntimeError/conns=240/internalDivideByZero-12                           1.429k ± ∞ ¹   1.411k ± ∞ ¹        ~ (p=1.000 n=1) ³
SQLCatchVectorizedRuntimeError/conns=240/contextCanceled-12                                 993.0 ± ∞ ¹    865.0 ± ∞ ¹        ~ (p=1.000 n=1) ³
SQLCatchVectorizedRuntimeError/conns=600/noError-12                                         838.0 ± ∞ ¹    837.0 ± ∞ ¹        ~ (p=1.000 n=1) ³
SQLCatchVectorizedRuntimeError/conns=600/expectedWithCode-12                               1038.0 ± ∞ ¹    951.0 ± ∞ ¹        ~ (p=1.000 n=1) ³
SQLCatchVectorizedRuntimeError/conns=600/expectedAssertion-12                              1.782k ± ∞ ¹   1.594k ± ∞ ¹        ~ (p=1.000 n=1) ³
SQLCatchVectorizedRuntimeError/conns=600/internalAssertion-12                              1.471k ± ∞ ¹   1.231k ± ∞ ¹        ~ (p=1.000 n=1) ³
SQLCatchVectorizedRuntimeError/conns=600/internalIndexOutOfRange-12                        1.476k ± ∞ ¹   1.417k ± ∞ ¹        ~ (p=1.000 n=1) ³
SQLCatchVectorizedRuntimeError/conns=600/internalDivideByZero-12                           1.471k ± ∞ ¹   1.411k ± ∞ ¹        ~ (p=1.000 n=1) ³
SQLCatchVectorizedRuntimeError/conns=600/contextCanceled-12                                 960.0 ± ∞ ¹    867.0 ± ∞ ¹        ~ (p=1.000 n=1) ³
geomean                                                                                               ⁴                 -18.86%               ⁴
¹ need >= 6 samples for confidence interval at level 0.95
² all samples are equal
³ need >= 4 samples to detect a difference at alpha level 0.05
⁴ summaries must be >0 to compute geomean

Fixes: #123235

Release note (performance improvement): Make error handling in the vectorized execution engine much cheaper. This should help avoid bad metastable regimes perpetuated by statement timeout handling consuming all CPU time, leading to more statement timeouts.

Co-authored-by: Drew Kimball drewk@cockroachlabs.com


Release justification: fix for serious performance issue.

Fixes: #123235

Release note (performance improvement): Make error handling in the
vectorized execution engine much cheaper. This should help avoid bad
metastable regimes perpetuated by statement timeout handling consuming
all CPU time, leading to more statement timeouts.
@blathers-crl blathers-crl bot requested review from a team as code owners May 2, 2024 18:21
@blathers-crl blathers-crl bot force-pushed the blathers/backport-release-24.1-123277 branch from fbde5c2 to fab0529 Compare May 2, 2024 18:21
@blathers-crl blathers-crl bot requested review from DrewKimball and removed request for a team May 2, 2024 18:21
@blathers-crl blathers-crl bot added blathers-backport This is a backport that Blathers created automatically. O-robot Originated from a bot. labels May 2, 2024
Copy link
Author

blathers-crl bot commented May 2, 2024

Thanks for opening a backport.

Please check the backport criteria before merging:

  • Backports should only be created for serious
    issues
    or test-only changes.
  • Backports should not break backwards-compatibility.
  • Backports should change as little code as possible.
  • Backports should not change on-disk formats or node communication protocols.
  • Backports should not add new functionality (except as defined
    here).
  • Backports must not add, edit, or otherwise modify cluster versions; or add version gates.
  • All backports must be reviewed by the owning areas TL and one additional
    TL. For more information as to how that review should be conducted, please consult the backport
    policy
    .
If your backport adds new functionality, please ensure that the following additional criteria are satisfied:
  • There is a high priority need for the functionality that cannot wait until the next release and is difficult to address in another way.
  • The new functionality is additive-only and only runs for clusters which have specifically “opted in” to it (e.g. by a cluster setting).
  • New code is protected by a conditional check that is trivial to verify and ensures that it only runs for opt-in clusters. State changes must be further protected such that nodes running old binaries will not be negatively impacted by the new state (with a mixed version test added).
  • The PM and TL on the team that owns the changed code have signed off that the change obeys the above rules.
  • Your backport must be accompanied by a post to the appropriate Slack
    channel (#db-backports-point-releases or #db-backports-XX-X-release) for awareness and discussion.

Also, please add a brief release justification to the body of your PR to justify this
backport.

@blathers-crl blathers-crl bot added the backport Label PR's that are backports to older release branches label May 2, 2024
@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Collaborator

@DrewKimball DrewKimball 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 7 of 7 files at r1, 1 of 1 files at r2, 1 of 1 files at r3, 1 of 1 files at r4, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @mgartner, @michae2, and @rafiss)

Copy link
Collaborator

@rafiss rafiss left a comment

Choose a reason for hiding this comment

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

Reviewed 6 of 7 files at r1, 1 of 1 files at r4, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @mgartner and @michae2)

Copy link
Collaborator

@mgartner mgartner 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 7 of 7 files at r1, 1 of 1 files at r2, 1 of 1 files at r3, 1 of 1 files at r4, all commit messages.
Reviewable status: :shipit: complete! 2 of 0 LGTMs obtained (waiting on @blathers-crl[bot] and @michae2)


pkg/sql/colexecerror/error.go line 87 at r4 (raw file):

		var panicEmittedFrom string
		// We should be able to find it within 3 program counters, starting with the
		// caller of this deferred function (2 above the runtime.Callers frame).

IIRC this was discussed in Slack, but can't find the thread. What is the reasoning for only checking 3 pcs (or 5) PCs deep?


pkg/sql/colexecerror/error.go line 88 at r4 (raw file):

		// We should be able to find it within 3 program counters, starting with the
		// caller of this deferred function (2 above the runtime.Callers frame).
		pc := make([]uintptr, 3)

nit: this could be an array [3]uintptr to avoid an allocation.

Copy link
Collaborator

@michae2 michae2 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! 2 of 0 LGTMs obtained (waiting on @mgartner)


pkg/sql/colexecerror/error.go line 87 at r4 (raw file):

Previously, mgartner (Marcus Gartner) wrote…

IIRC this was discussed in Slack, but can't find the thread. What is the reasoning for only checking 3 pcs (or 5) PCs deep?

We expect the stack to look something like this when we catch the panic:

github.com/cockroachdb/cockroach/pkg/sql/colexecerror.CatchVectorizedRuntimeError.func1()
	github.com/cockroachdb/cockroach/pkg/sql/colexecerror/error.go:90 +0x110
panic({0x1069ad940?, 0x10ab3a8c0?})
	GOROOT/src/runtime/panic.go:770 +0x124
github.com/cockroachdb/cockroach/pkg/sql/sem/builtins.init.func625({0x107466690?, 0x140058f4db0?}, 0x140058f4db0?, {0x140060d43a0, 0x2, 0x107466690?})
	github.com/cockroachdb/cockroach/pkg/sql/sem/builtins/builtins.go:5724 +0x410
github.com/cockroachdb/cockroach/pkg/sql/sem/eval.(*evaluator).EvalFuncExpr(0x14003970008, {0x107466690, 0x140058f4db0}, 0x14003a22480)
	github.com/cockroachdb/cockroach/pkg/sql/sem/eval/expr.go:483 +0xe4
github.com/cockroachdb/cockroach/pkg/sql/sem/tree.(*FuncExpr).Eval(0x14005861900?, {0x107466690?, 0x140058f4db0?}, {0x107503080?, 0x14003970008?})
	github.com/cockroachdb/cockroach/bazel-out/darwin_arm64-fastbuild/bin/pkg/sql/sem/tree/eval_expr_generated.go:282 +0x38
github.com/cockroachdb/cockroach/pkg/sql/sem/eval.Expr(...)
	github.com/cockroachdb/cockroach/pkg/sql/sem/eval/expr.go:26
github.com/cockroachdb/cockroach/pkg/sql.(*valuesNode).startExec(0x14003281080, {{0x107466690, 0x140058f4db0}, 0x14003970008, 0x140043e9988})
	github.com/cockroachdb/cockroach/pkg/sql/values.go:89 +0x228
github.com/cockroachdb/cockroach/pkg/sql.startExec.func2({0x11414bae0?, 0x140058f4de0?}, {0x107469250, 0x14003281080})
	github.com/cockroachdb/cockroach/pkg/sql/plan.go:520 +0xfc
github.com/cockroachdb/cockroach/pkg/sql.(*planVisitor).visitInternal.func1()
	github.com/cockroachdb/cockroach/pkg/sql/walk.go:112 +0x44
github.com/cockroachdb/cockroach/pkg/sql.(*planVisitor).visitInternal(0x14003c52b58, {0x107469250?, 0x14003281080}, {0x104c473d9?, 0x6?})
	github.com/cockroachdb/cockroach/pkg/sql/walk.go:299 +0x1594
github.com/cockroachdb/cockroach/pkg/sql.(*planVisitor).visit(0x14003c52b58, {0x107469250, 0x14003281080})
	github.com/cockroachdb/cockroach/pkg/sql/walk.go:79 +0xe8
github.com/cockroachdb/cockroach/pkg/sql.walkPlan(...)
	github.com/cockroachdb/cockroach/pkg/sql/walk.go:43
github.com/cockroachdb/cockroach/pkg/sql.startExec({{0x107466690?, 0x140058f4db0?}, 0x14003970008?, 0x140043e9988?}, {0x107469250, 0x14003281080})
	github.com/cockroachdb/cockroach/pkg/sql/plan.go:523 +0xdc
github.com/cockroachdb/cockroach/pkg/sql.(*planNodeToRowSource).Start(0x140077d1c08, {0x107466690, 0x140058f4d80})
	github.com/cockroachdb/cockroach/pkg/sql/plan_node_to_row_source.go:175 +0xf0
github.com/cockroachdb/cockroach/pkg/sql/colexec.(*Columnarizer).Init(0x14003927808, {0x107466690, 0x140058f4d50})
	github.com/cockroachdb/cockroach/pkg/sql/colexec/columnarizer.go:183 +0xd0
github.com/cockroachdb/cockroach/pkg/sql/colflow.(*batchInfoCollector).init(...)
	github.com/cockroachdb/cockroach/pkg/sql/colflow/stats.go:94
...

The panic() should always be the frame before the deferred function doing the recover, and we want to look at the frame before the panic frame.

So:

  • runtime.Callers(0, [1]uintptr) would be the call to runtime.Callers
  • runtime.Callers(1, [1]uintptr) would be the call to colexecerror.CatchVectorizedRuntimeError.func1
  • runtime.Callers(2, [1]uintptr) would be the call to panic
  • runtime.Callers(2, [2]uintptr) would be the call to panic + frame before
  • runtime.Callers(2, [3]uintptr) would be the call to panic + two frames before, just for safety

pkg/sql/colexecerror/error.go line 88 at r4 (raw file):

Previously, mgartner (Marcus Gartner) wrote…

nit: this could be an array [3]uintptr to avoid an allocation.

Ah, drat, good point.

Copy link
Collaborator

@mgartner mgartner 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! 2 of 0 LGTMs obtained (waiting on @michae2)


pkg/sql/colexecerror/error.go line 87 at r4 (raw file):

Previously, michae2 (Michael Erickson) wrote…

We expect the stack to look something like this when we catch the panic:

github.com/cockroachdb/cockroach/pkg/sql/colexecerror.CatchVectorizedRuntimeError.func1()
	github.com/cockroachdb/cockroach/pkg/sql/colexecerror/error.go:90 +0x110
panic({0x1069ad940?, 0x10ab3a8c0?})
	GOROOT/src/runtime/panic.go:770 +0x124
github.com/cockroachdb/cockroach/pkg/sql/sem/builtins.init.func625({0x107466690?, 0x140058f4db0?}, 0x140058f4db0?, {0x140060d43a0, 0x2, 0x107466690?})
	github.com/cockroachdb/cockroach/pkg/sql/sem/builtins/builtins.go:5724 +0x410
github.com/cockroachdb/cockroach/pkg/sql/sem/eval.(*evaluator).EvalFuncExpr(0x14003970008, {0x107466690, 0x140058f4db0}, 0x14003a22480)
	github.com/cockroachdb/cockroach/pkg/sql/sem/eval/expr.go:483 +0xe4
github.com/cockroachdb/cockroach/pkg/sql/sem/tree.(*FuncExpr).Eval(0x14005861900?, {0x107466690?, 0x140058f4db0?}, {0x107503080?, 0x14003970008?})
	github.com/cockroachdb/cockroach/bazel-out/darwin_arm64-fastbuild/bin/pkg/sql/sem/tree/eval_expr_generated.go:282 +0x38
github.com/cockroachdb/cockroach/pkg/sql/sem/eval.Expr(...)
	github.com/cockroachdb/cockroach/pkg/sql/sem/eval/expr.go:26
github.com/cockroachdb/cockroach/pkg/sql.(*valuesNode).startExec(0x14003281080, {{0x107466690, 0x140058f4db0}, 0x14003970008, 0x140043e9988})
	github.com/cockroachdb/cockroach/pkg/sql/values.go:89 +0x228
github.com/cockroachdb/cockroach/pkg/sql.startExec.func2({0x11414bae0?, 0x140058f4de0?}, {0x107469250, 0x14003281080})
	github.com/cockroachdb/cockroach/pkg/sql/plan.go:520 +0xfc
github.com/cockroachdb/cockroach/pkg/sql.(*planVisitor).visitInternal.func1()
	github.com/cockroachdb/cockroach/pkg/sql/walk.go:112 +0x44
github.com/cockroachdb/cockroach/pkg/sql.(*planVisitor).visitInternal(0x14003c52b58, {0x107469250?, 0x14003281080}, {0x104c473d9?, 0x6?})
	github.com/cockroachdb/cockroach/pkg/sql/walk.go:299 +0x1594
github.com/cockroachdb/cockroach/pkg/sql.(*planVisitor).visit(0x14003c52b58, {0x107469250, 0x14003281080})
	github.com/cockroachdb/cockroach/pkg/sql/walk.go:79 +0xe8
github.com/cockroachdb/cockroach/pkg/sql.walkPlan(...)
	github.com/cockroachdb/cockroach/pkg/sql/walk.go:43
github.com/cockroachdb/cockroach/pkg/sql.startExec({{0x107466690?, 0x140058f4db0?}, 0x14003970008?, 0x140043e9988?}, {0x107469250, 0x14003281080})
	github.com/cockroachdb/cockroach/pkg/sql/plan.go:523 +0xdc
github.com/cockroachdb/cockroach/pkg/sql.(*planNodeToRowSource).Start(0x140077d1c08, {0x107466690, 0x140058f4d80})
	github.com/cockroachdb/cockroach/pkg/sql/plan_node_to_row_source.go:175 +0xf0
github.com/cockroachdb/cockroach/pkg/sql/colexec.(*Columnarizer).Init(0x14003927808, {0x107466690, 0x140058f4d50})
	github.com/cockroachdb/cockroach/pkg/sql/colexec/columnarizer.go:183 +0xd0
github.com/cockroachdb/cockroach/pkg/sql/colflow.(*batchInfoCollector).init(...)
	github.com/cockroachdb/cockroach/pkg/sql/colflow/stats.go:94
...

The panic() should always be the frame before the deferred function doing the recover, and we want to look at the frame before the panic frame.

So:

  • runtime.Callers(0, [1]uintptr) would be the call to runtime.Callers
  • runtime.Callers(1, [1]uintptr) would be the call to colexecerror.CatchVectorizedRuntimeError.func1
  • runtime.Callers(2, [1]uintptr) would be the call to panic
  • runtime.Callers(2, [2]uintptr) would be the call to panic + frame before
  • runtime.Callers(2, [3]uintptr) would be the call to panic + two frames before, just for safety

Thanks for spelling it out for me! This was helpful.

I suppose this is robust because Go does not allow import cycles, so we would never see a stack like:

colexecerror.CatchVectorizedRuntimeError.func1
panic
pkg/sql/colexec
...
pkg/sql/sem/builtins
...
pkg/sql/colexec

Although maybe that is possible in some cases where we avoid cycles by setting global variables in a package. 🤷


pkg/sql/colexecerror/error.go line 88 at r4 (raw file):

Previously, michae2 (Michael Erickson) wrote…

Ah, drat, good point.

Doubt it matters all that much, but you can make the change on master if you're up to it.

@mgartner
Copy link
Collaborator

mgartner commented May 3, 2024

pkg/sql/colexecerror/error.go line 87 at r4 (raw file):

Although maybe that is possible in some cases where we avoid cycles by setting global variables in a package.

Oh and passing closures to packages would also make that possible.

Though I guess the previous version of this code would have the same problem, so probably not something to worry about right now.

Copy link
Collaborator

@michae2 michae2 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! 2 of 0 LGTMs obtained (waiting on @mgartner)


pkg/sql/colexecerror/error.go line 87 at r4 (raw file):

Previously, mgartner (Marcus Gartner) wrote…

Although maybe that is possible in some cases where we avoid cycles by setting global variables in a package.

Oh and passing closures to packages would also make that possible.

Though I guess the previous version of this code would have the same problem, so probably not something to worry about right now.

It's a good point, there might be some edge cases where we let the panic escape when we don't need to.

@michae2 michae2 merged commit f876d25 into release-24.1 May 3, 2024
19 of 20 checks passed
@michae2 michae2 deleted the blathers/backport-release-24.1-123277 branch May 3, 2024 18:57
Copy link
Member

@yuzefovich yuzefovich 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! 2 of 0 LGTMs obtained


pkg/sql/colexecerror/error.go line 88 at r4 (raw file):

Previously, mgartner (Marcus Gartner) wrote…

Doubt it matters all that much, but you can make the change on master if you're up to it.

I too had the same thought, but I think this allocation will still escape to the heap (because we pass it into another function) - IIRC I did a quick check with gcflags=-m=2 when I was reviewing the original PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport Label PR's that are backports to older release branches blathers-backport This is a backport that Blathers created automatically. O-robot Originated from a bot.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants