-
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
backfill: Fixed a bug where we ignore indexes to backfill #103476
Conversation
It looks like your PR touches production code but doesn't add or edit any test code. Did you consider adding tests to your PR? 🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf. |
7a7e701
to
a5cf86e
Compare
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.
just nits, lgtm overall
pkg/sql/backfill/backfill.go
Outdated
// If `whitelist` is non-nil, we only allow those in this white list. | ||
func (ib *IndexBackfiller) initIndexes(desc catalog.TableDescriptor, whitelist []catid.IndexID) { | ||
var whitelistAsSet catid.IndexSet | ||
if whitelist != nil { |
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.
I think we should do len(whitelist) > 0
instead.
@@ -1161,6 +1161,11 @@ func (node *UniqueConstraintTableDef) Format(ctx *FmtCtx) { | |||
ctx.WriteString(" VISIBILITY " + fmt.Sprintf("%.2f", 1-invisibility)) | |||
} | |||
} | |||
if node.StorageParams != nil { |
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.
I think this worth some parser tests
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.
agreed
pkg/sql/backfill/backfill.go
Outdated
mon *mon.BytesMonitor, | ||
) error { | ||
|
||
// Initialize ib.added. | ||
ib.initIndexes(desc) | ||
ib.initIndexes(desc, indexesToBackfill) |
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.
Is there a way to test this? I think probably a unit test for the initIndexes
method is sufficient, that logic here should trivial, but nice to make sure the method actually set thing right.
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.
LGTM modulo some straightforward changes
pkg/sql/backfill/backfill.go
Outdated
@@ -505,7 +506,7 @@ func (ib *IndexBackfiller) InitForLocalUse( | |||
) error { | |||
|
|||
// Initialize ib.added. | |||
ib.initIndexes(desc) | |||
ib.initIndexes(desc, nil /* whitelist */) |
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.
s/whitelist/allowlist, applies elsewhere also
pkg/sql/backfill/backfill.go
Outdated
@@ -640,11 +641,12 @@ func (ib *IndexBackfiller) InitForDistributedUse( | |||
ctx context.Context, | |||
flowCtx *execinfra.FlowCtx, | |||
desc catalog.TableDescriptor, | |||
indexesToBackfill []catid.IndexID, |
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.
s/indexesToBackfill/allowlist for consistency, also you might as well make this a catid.IndexSet
here. This value comes from a protobuf which IIRC makes zero-length slices nil by default.
pkg/sql/backfill/backfill.go
Outdated
// If `whitelist` is non-nil, we only allow those in this white list. | ||
func (ib *IndexBackfiller) initIndexes(desc catalog.TableDescriptor, whitelist []catid.IndexID) { | ||
var whitelistAsSet catid.IndexSet | ||
if whitelist != nil { |
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.
nit: this nil-check is superfluous
@@ -1161,6 +1161,11 @@ func (node *UniqueConstraintTableDef) Format(ctx *FmtCtx) { | |||
ctx.WriteString(" VISIBILITY " + fmt.Sprintf("%.2f", 1-invisibility)) | |||
} | |||
} | |||
if node.StorageParams != nil { |
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.
agreed
@@ -392,6 +392,22 @@ func isColumnFilter(_ scpb.Status, _ scpb.TargetStatus, e scpb.Element) bool { | |||
return isColumn | |||
} | |||
|
|||
func orFilter( | |||
f1, f2 func(_ scpb.Status, _ scpb.TargetStatus, _ scpb.Element) bool, |
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.
nit: you could make orFilter
variadic
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.
Reviewed 3 of 3 files at r1, 2 of 2 files at r2, 4 of 4 files at r3, all commit messages.
Reviewable status: complete! 1 of 0 LGTMs obtained (waiting on @chengxiong-ruan, @rharding6373, and @Xiang-Gu)
pkg/sql/backfill/backfill.go
line 644 at r1 (raw file):
flowCtx *execinfra.FlowCtx, desc catalog.TableDescriptor, indexesToBackfill []catid.IndexID,
Probably that nil has a special meaning above to indicate that everything is whitelisted.
pkg/sql/sem/tree/create.go
line 1164 at r2 (raw file):
Previously, postamar (Marius Posta) wrote…
agreed
+1
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.
Reviewable status: complete! 2 of 0 LGTMs obtained (waiting on @chengxiong-ruan and @Xiang-Gu)
a5cf86e
to
3feb5f9
Compare
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.
Reviewable status: complete! 2 of 0 LGTMs obtained (waiting on @chengxiong-ruan, @fqazi, and @postamar)
pkg/sql/backfill/backfill.go
line 509 at r1 (raw file):
Previously, postamar (Marius Posta) wrote…
s/whitelist/allowlist, applies elsewhere also
Done.
pkg/sql/backfill/backfill.go
line 644 at r1 (raw file):
Previously, postamar (Marius Posta) wrote…
s/indexesToBackfill/allowlist for consistency, also you might as well make this a
catid.IndexSet
here. This value comes from a protobuf which IIRC makes zero-length slices nil by default.
changed the name to allowList but I don't think I can use a catid.IndexSet
bc, like Faizan pointed out, a nil allowList
means everything is allowed (the old behavior before my change), so we need something whose zero value is nil.
pkg/sql/backfill/backfill.go
line 644 at r1 (raw file):
Previously, fqazi (Faizan Qazi) wrote…
Probably that nil has a special meaning above to indicate that everything is whitelisted.
Done.
pkg/sql/backfill/backfill.go
line 649 at r1 (raw file):
Previously, chengxiong-ruan (Chengxiong Ruan) wrote…
Is there a way to test this? I think probably a unit test for the
initIndexes
method is sufficient, that logic here should trivial, but nice to make sure the method actually set thing right.
done
pkg/sql/backfill/backfill.go
line 737 at r1 (raw file):
Previously, postamar (Marius Posta) wrote…
nit: this nil-check is superfluous
nil means "everything is allowed" rather than "nothing is allowed". I made this decision so that nil
input gives the old behavior before this change.
pkg/sql/backfill/backfill.go
line 737 at r1 (raw file):
Previously, chengxiong-ruan (Chengxiong Ruan) wrote…
I think we should do
len(whitelist) > 0
instead.
whitelist can be nil
pkg/sql/schemachanger/scbuild/internal/scbuildstmt/helpers.go
line 396 at r3 (raw file):
Previously, postamar (Marius Posta) wrote…
nit: you could make
orFilter
variadic
done
pkg/sql/sem/tree/create.go
line 1164 at r2 (raw file):
Previously, fqazi (Faizan Qazi) wrote…
+1
It's implicitly tested because all statements ever appeared in a logic test will be invoked on VerifyStatementPrettyRoundtrip
which utilize this code path in order to round-trip.
3feb5f9
to
83e07fc
Compare
bors r+ |
Previously, Xiang-Gu (Xiang Gu) wrote…
|
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.
Reviewable status: complete! 0 of 0 LGTMs obtained (and 2 stale) (waiting on @chengxiong-ruan, @fqazi, and @postamar)
pkg/sql/backfill/backfill.go
line 737 at r1 (raw file):
Previously, chengxiong-ruan (Chengxiong Ruan) wrote…
len(nil)
also returns 0
good point!
bors r- |
Canceled. |
Previously, when declarative schema changer emit BackfillIndex operation with a target index ID, the backfill logic ignores this and would backfill all existing adding indexes. This will cause problem as we are transitioning into a paradigm where we will have to construct multiple primary indexes to complete an schema change statement.
Previously, when we round-trip an ADD PRIMARY KEY statement with storage parameter, the storage parameter will be dropped. This PR fixes it.
This commit cleaned our element results set filters to be more principled.
83e07fc
to
fef97d9
Compare
bors r+ |
Build succeeded: |
This PR contains three misc bug fixes/refactorings:
They were discovered while working on #99526 but they are tangent enough to be of its own separate PR.
Epic: None