Skip to content

opt: fix panic due to concurrent map writes when copying metadata#66792

Merged
craig[bot] merged 1 commit intocockroachdb:masterfrom
rytaft:concurrent-map-update
Jun 24, 2021
Merged

opt: fix panic due to concurrent map writes when copying metadata#66792
craig[bot] merged 1 commit intocockroachdb:masterfrom
rytaft:concurrent-map-update

Conversation

@rytaft
Copy link
Copy Markdown
Collaborator

@rytaft rytaft commented Jun 23, 2021

This commit fixes a bug that caused a panic due to concurrent map writes
when copying table metadata. The fix is to make a deep copy of the map
before updating it.

Fixes #66717

Release note (bug fix): Fixed a panic that could occur in the optimizer
when executing a prepared plan with placeholders. This could happen when
one of the tables used by the query had computed columns or a partial
index.

@rytaft rytaft requested review from a team, RaduBerinde and nvb June 23, 2021 20:30
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

Copy link
Copy Markdown
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.

:lgtm:

Reviewed 1 of 1 files at r1.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @nvanbenschoten and @RaduBerinde)

Copy link
Copy Markdown
Member

@RaduBerinde RaduBerinde left a comment

Choose a reason for hiding this comment

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

Oof, LGTM

Maybe we should tighten our policy for how soon non-critical backports can be merged. In this case we would have needed ~3 days.

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

@rytaft
Copy link
Copy Markdown
Collaborator Author

rytaft commented Jun 23, 2021

TFTRs!

Maybe we should tighten our policy for how soon non-critical backports can be merged. In this case we would have needed ~3 days.

Yea, good call

bors r+

@rytaft
Copy link
Copy Markdown
Collaborator Author

rytaft commented Jun 23, 2021

Looks like I need to update a test

bors r-

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Jun 23, 2021

Canceled.

@rytaft rytaft force-pushed the concurrent-map-update branch from 94fbb9d to 75569a9 Compare June 23, 2021 22:01
@rytaft
Copy link
Copy Markdown
Collaborator Author

rytaft commented Jun 23, 2021

Fixed -- PTAL

Copy link
Copy Markdown
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.

:lgtm:

Reviewed 1 of 1 files at r2.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @nvanbenschoten)

Copy link
Copy Markdown
Member

@RaduBerinde RaduBerinde 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! 1 of 0 LGTMs obtained (waiting on @nvanbenschoten and @rytaft)


pkg/sql/opt/table_meta.go, line 190 at r2 (raw file):

	}

	if len(tm.ComputedCols) > 0 {

I think this should be if tm.ComputedCols == nil. We don't want to share the map if it happens to be empty. (I realize an empty map probably never happens in practice but still)

This commit fixes a bug that caused a panic due to concurrent map writes
when copying table metadata. The fix is to make a deep copy of the map
before updating it.

Fixes cockroachdb#66717

Release note (bug fix): Fixed a panic that could occur in the optimizer
when executing a prepared plan with placeholders. This could happen when
one of the tables used by the query had computed columns or a partial
index.
@rytaft rytaft force-pushed the concurrent-map-update branch from 75569a9 to 990807e Compare June 24, 2021 02:45
Copy link
Copy Markdown
Collaborator Author

@rytaft rytaft left a comment

Choose a reason for hiding this comment

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

TFTRs!

bors r+

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


pkg/sql/opt/table_meta.go, line 190 at r2 (raw file):

Previously, RaduBerinde wrote…

I think this should be if tm.ComputedCols == nil. We don't want to share the map if it happens to be empty. (I realize an empty map probably never happens in practice but still)

Done.

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Jun 24, 2021

Build failed (retrying...):

@tbg
Copy link
Copy Markdown
Member

tbg commented Jun 24, 2021

Becca, this PR fixes #66747 but it doesn't fix #66717, only the backport will do that.

@rytaft
Copy link
Copy Markdown
Collaborator Author

rytaft commented Jun 24, 2021

Oh ok thanks, @tbg. I don't want to stop bors at this point, but I will close/reopen the issues after.

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Jun 24, 2021

Build succeeded:

@craig craig bot merged commit a1f969c into cockroachdb:master Jun 24, 2021
@mgartner
Copy link
Copy Markdown
Contributor

😬 Thanks for fixing this!

mgartner added a commit to mgartner/cockroach that referenced this pull request Jun 30, 2021
…ata maps

This commit adds assertions to `TestMetadata` that ensure that
`Metadata.CopyFrom` makes copies of computed column expression maps and
parital index predicate maps in table metadata, rather than sharing the
same underlying map. These tests would have caught the bug that was
fixed in cockroachdb#66792.

Release note: None
craig bot pushed a commit that referenced this pull request Jun 30, 2021
66595: ui: add an Overload dashboard r=RaduBerinde a=RaduBerinde

This commit adds an Overload dashboard in the metrics view. This is
intended to be a convenient way to monitor admission control.

The dashboard contains:
 - SQL Queries
 - Service latency
 - CPU Percent
 - Runnable Goroutines per CPU
 - L0 Sublevels and Files

Release note (ui change): a new Overload dashboard groups metrics that
are useful for admission control.

66786: sql: incorporate lookupExpr cpu cost into cost model r=rytaft a=cucaroach

Informs #51576

This is a prep-the-patient change required for enabling the lookup join inequality conditions.   It enables for instance partial indexes to be selected when there's a costing tie between a lookup join with a partial index vs a full index with the partial index qualifier as a lookup join condition.

Release note (sql): improve cost model to include cpu cost of lookupExprs used by lookup joins.


67078: opt: add test to ensure Metadata.CopyFrom makes copies of table metadata maps r=mgartner a=mgartner

This commit adds assertions to `TestMetadata` that ensure that
`Metadata.CopyFrom` makes copies of computed column expression maps and
parital index predicate maps in table metadata, rather than sharing the
same underlying map. These tests would have caught the bug that was
fixed in #66792.

Release note: None

Co-authored-by: Radu Berinde <radu@cockroachlabs.com>
Co-authored-by: Tommy Reilly <treilly@cockroachlabs.com>
Co-authored-by: Marcus Gartner <marcus@cockroachlabs.com>
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.

roachtest: tpce/c=5000/nodes=3 failed

6 participants