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

testutils: add fingerprint utility package #104089

Merged
merged 2 commits into from
Jun 14, 2023

Conversation

msbutler
Copy link
Collaborator

This patch adds a couple helper methods that make it easier to: fingerprint a table, database or cluster, compare fingerprints, and identify a mismatch on the table level. All fingerprinting methods call crdb_internal.fingerprint() on the table span level with the user provided options.

This patch also integrates the new methods in the backupccl and streamingccl codebases.

A future patch could add a helper method that identifies mismatched keys within a mismatched table.

Informs #103072

Release note: None

@msbutler msbutler self-assigned this May 30, 2023
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@msbutler msbutler force-pushed the butler-c2c-fingerprint-hook branch from 710eb87 to 8f98372 Compare May 30, 2023 16:29
@msbutler msbutler force-pushed the butler-c2c-fingerprint-hook branch from 8f98372 to 5d33486 Compare May 30, 2023 17:39
@msbutler msbutler marked this pull request as ready for review May 30, 2023 17:39
@msbutler msbutler requested review from a team as code owners May 30, 2023 17:39
@msbutler msbutler requested review from rharding6373, herkolategan, srosenberg, rhu713 and stevendanna and removed request for a team and rharding6373 May 30, 2023 17:39
@msbutler
Copy link
Collaborator Author

msbutler commented Jun 5, 2023

putting this on hold until #104219 merges

This patch adds a couple helper methods that make it easier to: fingerprint a
table, database or cluster, compare fingerprints, and identify a mismatch on
the table level. All fingerprinting methods call crdb_internal.fingerprint() on
the table span level with the user provided options.

This patch also integrates the new methods in the backupccl and streamingccl
codebases.

A future patch could add a helper method that identifies mismatched keys within
a mismatched table.

Informs cockroachdb#103072

Release note: None
@msbutler msbutler force-pushed the butler-c2c-fingerprint-hook branch from 148b0e2 to bad4864 Compare June 13, 2023 17:23
@msbutler
Copy link
Collaborator Author

unrelated flake in extended CI. @rhu713 @stevendanna Please take a look!

Copy link
Collaborator

@stevendanna stevendanna left a comment

Choose a reason for hiding this comment

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

Left some minor comments, but this seems like a nice tool to help us use the fingerprinting a bit more.

pkg/testutils/fingerprintutils/fingerprint.go Outdated Show resolved Hide resolved
pkg/testutils/fingerprintutils/fingerprint.go Outdated Show resolved Hide resolved
pkg/testutils/fingerprintutils/fingerprint.go Outdated Show resolved Hide resolved
Comment on lines 197 to 230
func CompareDatabaseFingerprints(db1, db2 map[string]int64) error {
for tableName, tableFingerprint := range db1 {
table2Fingerprint, ok := db2[tableName]
if !ok {
return errors.Newf("%s table not in second database", tableName)
}
if tableFingerprint != table2Fingerprint {
return errors.Newf("fingerprint mismatch on %s table: %d != %d", tableName,
tableFingerprint, table2Fingerprint)
}
delete(db2, tableName)
}
if len(db2) > 0 {
return errors.Newf("second database has more tables %s", db2)
}
return nil
}

func CompareClusterFingerprints(c1, c2 map[string]map[string]int64) error {
for dbName, dbFingerprints := range c1 {
db2Fingerprints, ok := c2[dbName]
if !ok {
return errors.Newf("%s table not in second database", dbName)
}
if err := CompareDatabaseFingerprints(dbFingerprints, db2Fingerprints); err != nil {
return fmt.Errorf("failed comparing fingerprints for database %s: %w", dbName, err)
}
delete(c2, dbName)
}
if len(c2) > 0 {
return errors.Newf("second cluster has more databases %s", c2)
}
return nil
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Fine to keep but I wonder how much clearer this output is than require.Equal on the two input maps.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I kept away from the require package in this pr because I think the caller should decide how to handle any error this package bubbles up. require tends to fatal anything it doesn't like.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sure, I more meant whether we need this custom comparison function at all.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah i see. I like this func because it will point you to exactly what's wrong with your fingerprint comparison. require over the maps implies that the test debugger has to squint at printed maps :D.

I could also see a future where we scan over the mismatched table to find the wrong key.

pkg/testutils/fingerprintutils/fingerprint.go Outdated Show resolved Hide resolved
Copy link
Collaborator Author

@msbutler msbutler left a comment

Choose a reason for hiding this comment

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

@stevendanna thanks for the review. Ready for another look!

pkg/testutils/fingerprintutils/fingerprint.go Outdated Show resolved Hide resolved
pkg/testutils/fingerprintutils/fingerprint.go Outdated Show resolved Hide resolved
Comment on lines 197 to 230
func CompareDatabaseFingerprints(db1, db2 map[string]int64) error {
for tableName, tableFingerprint := range db1 {
table2Fingerprint, ok := db2[tableName]
if !ok {
return errors.Newf("%s table not in second database", tableName)
}
if tableFingerprint != table2Fingerprint {
return errors.Newf("fingerprint mismatch on %s table: %d != %d", tableName,
tableFingerprint, table2Fingerprint)
}
delete(db2, tableName)
}
if len(db2) > 0 {
return errors.Newf("second database has more tables %s", db2)
}
return nil
}

func CompareClusterFingerprints(c1, c2 map[string]map[string]int64) error {
for dbName, dbFingerprints := range c1 {
db2Fingerprints, ok := c2[dbName]
if !ok {
return errors.Newf("%s table not in second database", dbName)
}
if err := CompareDatabaseFingerprints(dbFingerprints, db2Fingerprints); err != nil {
return fmt.Errorf("failed comparing fingerprints for database %s: %w", dbName, err)
}
delete(c2, dbName)
}
if len(c2) > 0 {
return errors.Newf("second cluster has more databases %s", c2)
}
return nil
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I kept away from the require package in this pr because I think the caller should decide how to handle any error this package bubbles up. require tends to fatal anything it doesn't like.

pkg/testutils/fingerprintutils/fingerprint.go Outdated Show resolved Hide resolved
pkg/testutils/fingerprintutils/fingerprint.go Outdated Show resolved Hide resolved
@msbutler
Copy link
Collaborator Author

unrelated extended CI flake.

@msbutler
Copy link
Collaborator Author

TFTR!

bors r=stevendanna

@craig
Copy link
Contributor

craig bot commented Jun 14, 2023

Build failed (retrying...):

@msbutler msbutler added the backport-23.1.x Flags PRs that need to be backported to 23.1 label Jun 14, 2023
@craig
Copy link
Contributor

craig bot commented Jun 14, 2023

Build succeeded:

@craig craig bot merged commit ae25f4d into cockroachdb:master Jun 14, 2023
@blathers-crl
Copy link

blathers-crl bot commented Jun 14, 2023

Encountered an error creating backports. Some common things that can go wrong:

  1. The backport branch might have already existed.
  2. There was a merge conflict.
  3. The backport branch contained merge commits.

You might need to create your backport manually using the backport tool.


error setting reviewers, but backport branch blathers/backport-release-23.1-104089 is ready: POST https://api.github.com/repos/cockroachdb/cockroach/pulls/104918/requested_reviewers: 422 Reviews may only be requested from collaborators. One or more of the teams you specified is not a collaborator of the cockroachdb/cockroach repository. []

Backport to branch 23.1.x failed. See errors above.


🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-23.1.x Flags PRs that need to be backported to 23.1 T-disaster-recovery
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants