-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
ccl/changeedccl: Add changefeed options into nemesis tests #137947
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,7 @@ import ( | |
// guarantees in a single table. | ||
type Validator interface { | ||
// NoteRow accepts a changed row entry. | ||
NoteRow(partition string, key, value string, updated hlc.Timestamp) error | ||
NoteRow(partition, key, value string, updated hlc.Timestamp, topic string) error | ||
// NoteResolved accepts a resolved timestamp entry. | ||
NoteResolved(partition string, resolved hlc.Timestamp) error | ||
// Failures returns any violations seen so far. | ||
|
@@ -64,7 +64,7 @@ var _ StreamValidator = &orderValidator{} | |
type noOpValidator struct{} | ||
|
||
// NoteRow accepts a changed row entry. | ||
func (v *noOpValidator) NoteRow(string, string, string, hlc.Timestamp) error { return nil } | ||
func (v *noOpValidator) NoteRow(string, string, string, hlc.Timestamp, string) error { return nil } | ||
|
||
// NoteResolved accepts a resolved timestamp entry. | ||
func (v *noOpValidator) NoteResolved(string, hlc.Timestamp) error { return nil } | ||
|
@@ -125,7 +125,9 @@ func (v *orderValidator) GetValuesForKeyBelowTimestamp( | |
} | ||
|
||
// NoteRow implements the Validator interface. | ||
func (v *orderValidator) NoteRow(partition string, key, value string, updated hlc.Timestamp) error { | ||
func (v *orderValidator) NoteRow( | ||
partition, key, value string, updated hlc.Timestamp, topic string, | ||
) error { | ||
if prev, ok := v.partitionForKey[key]; ok && prev != partition { | ||
v.failures = append(v.failures, fmt.Sprintf( | ||
`key [%s] received on two partitions: %s and %s`, key, prev, partition, | ||
|
@@ -189,14 +191,18 @@ type beforeAfterValidator struct { | |
table string | ||
primaryKeyCols []string | ||
resolved map[string]hlc.Timestamp | ||
fullTableName bool | ||
keyInValue bool | ||
|
||
failures []string | ||
} | ||
|
||
// NewBeforeAfterValidator returns a Validator verifies that the "before" and | ||
// "after" fields in each row agree with the source table when performing AS OF | ||
// SYSTEM TIME lookups before and at the row's timestamp. | ||
func NewBeforeAfterValidator(sqlDB *gosql.DB, table string) (Validator, error) { | ||
func NewBeforeAfterValidator( | ||
sqlDB *gosql.DB, table string, option ChangefeedOption, | ||
) (Validator, error) { | ||
primaryKeyCols, err := fetchPrimaryKeyCols(sqlDB, table) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "fetchPrimaryKeyCols failed") | ||
|
@@ -205,15 +211,30 @@ func NewBeforeAfterValidator(sqlDB *gosql.DB, table string) (Validator, error) { | |
return &beforeAfterValidator{ | ||
sqlDB: sqlDB, | ||
table: table, | ||
fullTableName: option.FullTableName, | ||
keyInValue: option.KeyInValue, | ||
primaryKeyCols: primaryKeyCols, | ||
resolved: make(map[string]hlc.Timestamp), | ||
}, nil | ||
} | ||
|
||
// NoteRow implements the Validator interface. | ||
func (v *beforeAfterValidator) NoteRow( | ||
partition string, key, value string, updated hlc.Timestamp, | ||
partition, key, value string, updated hlc.Timestamp, topic string, | ||
) error { | ||
if v.fullTableName { | ||
if topic != fmt.Sprintf(`d.public.%s`, v.table) { | ||
v.failures = append(v.failures, fmt.Sprintf( | ||
"topic %s does not match expected table d.public.%s", topic, v.table, | ||
)) | ||
} | ||
} else { | ||
if topic != v.table { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. follow up: we can add more test coverage here for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When does that happen? Are there certain settings or options that trigger that? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They are query parameters - https://www.cockroachlabs.com/docs/stable/create-changefeed#query-parameters. |
||
v.failures = append(v.failures, fmt.Sprintf( | ||
"topic %s does not match expected table %s", topic, v.table, | ||
)) | ||
} | ||
} | ||
keyJSON, err := json.ParseJSON(key) | ||
if err != nil { | ||
return err | ||
|
@@ -230,6 +251,26 @@ func (v *beforeAfterValidator) NoteRow( | |
return err | ||
} | ||
|
||
if v.keyInValue { | ||
keyString := keyJSON.String() | ||
keyInValueJSON, err := valueJSON.FetchValKey("key") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if keyInValueJSON == nil { | ||
v.failures = append(v.failures, fmt.Sprintf( | ||
"no key in value, expected key value %s", keyString)) | ||
} else { | ||
keyInValueString := keyInValueJSON.String() | ||
if keyInValueString != keyString { | ||
v.failures = append(v.failures, fmt.Sprintf( | ||
"key in value %s does not match expected key value %s", | ||
keyInValueString, keyString)) | ||
} | ||
} | ||
} | ||
|
||
afterJSON, err := valueJSON.FetchValKey("after") | ||
if err != nil { | ||
return err | ||
|
@@ -451,7 +492,7 @@ func (v *FingerprintValidator) DBFunc( | |
|
||
// NoteRow implements the Validator interface. | ||
func (v *FingerprintValidator) NoteRow( | ||
ignoredPartition string, key, value string, updated hlc.Timestamp, | ||
partition, key, value string, updated hlc.Timestamp, topic string, | ||
) error { | ||
if v.firstRowTimestamp.IsEmpty() || updated.Less(v.firstRowTimestamp) { | ||
v.firstRowTimestamp = updated | ||
|
@@ -663,9 +704,11 @@ func (v *FingerprintValidator) Failures() []string { | |
type Validators []Validator | ||
|
||
// NoteRow implements the Validator interface. | ||
func (vs Validators) NoteRow(partition string, key, value string, updated hlc.Timestamp) error { | ||
func (vs Validators) NoteRow( | ||
partition, key, value string, updated hlc.Timestamp, topic string, | ||
) error { | ||
for _, v := range vs { | ||
if err := v.NoteRow(partition, key, value, updated); err != nil { | ||
if err := v.NoteRow(partition, key, value, updated, topic); err != nil { | ||
return err | ||
} | ||
} | ||
|
@@ -707,10 +750,12 @@ func NewCountValidator(v Validator) *CountValidator { | |
} | ||
|
||
// NoteRow implements the Validator interface. | ||
func (v *CountValidator) NoteRow(partition string, key, value string, updated hlc.Timestamp) error { | ||
func (v *CountValidator) NoteRow( | ||
partition, key, value string, updated hlc.Timestamp, topic string, | ||
) error { | ||
v.NumRows++ | ||
v.rowsSinceResolved++ | ||
return v.v.NoteRow(partition, key, value, updated) | ||
return v.v.NoteRow(partition, key, value, updated, topic) | ||
} | ||
|
||
// NoteResolved implements the Validator interface. | ||
|
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: can we link the limitation github issue you created here in side todo
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.
Adding that now