Skip to content

Commit

Permalink
Use better naming for mismatch types
Browse files Browse the repository at this point in the history
  • Loading branch information
driv3r committed Sep 10, 2024
1 parent 53c5c66 commit 535a320
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 25 deletions.
27 changes: 13 additions & 14 deletions inline_verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,8 @@ const (
MismatchColumnMissingOnTarget mismatchType = "column missing on target"
MismatchRowMissingOnSource mismatchType = "row missing on source"
MismatchRowMissingOnTarget mismatchType = "row missing on target"
MismatchContentDifference mismatchType = "content difference"
MismatchChecksumDifference mismatchType = "rows checksum difference"
MismatchColumnValueDifference mismatchType = "column value difference"
MismatchRowChecksumDifference mismatchType = "rows checksum difference"
)

type InlineVerifierMismatches struct {
Expand Down Expand Up @@ -491,7 +491,7 @@ func formatMismatches(mismatches map[string]map[string][]InlineVerifierMismatche
}
}

return messageBuf.String(), incorrectTables
return messageBuf.String(), incorrectTables
}

func (v *InlineVerifier) VerifyDuringCutover() (VerificationResult, error) {
Expand Down Expand Up @@ -613,13 +613,13 @@ func (v *InlineVerifier) compareHashes(source, target map[uint64][]byte) map[uin
sourceHash, exists := source[paginationKey]
if !exists {
mismatchSet[paginationKey] = InlineVerifierMismatches{
Pk: paginationKey,
MismatchType: MismatchRowMissingOnSource,
Pk: paginationKey,
MismatchType: MismatchRowMissingOnSource,
}
} else if !bytes.Equal(sourceHash, targetHash) {
mismatchSet[paginationKey] = InlineVerifierMismatches{
Pk: paginationKey,
MismatchType: MismatchChecksumDifference,
MismatchType: MismatchRowChecksumDifference,
SourceChecksum: string(sourceHash),
TargetChecksum: string(targetHash),
}
Expand All @@ -630,16 +630,15 @@ func (v *InlineVerifier) compareHashes(source, target map[uint64][]byte) map[uin
_, exists := target[paginationKey]
if !exists {
mismatchSet[paginationKey] = InlineVerifierMismatches{
Pk: paginationKey,
MismatchType: MismatchRowMissingOnTarget,
Pk: paginationKey,
MismatchType: MismatchRowMissingOnTarget,
}
}
}

return mismatchSet
}


func compareDecompressedData(source, target map[uint64]map[string][]byte) map[uint64]InlineVerifierMismatches {
mismatchSet := map[uint64]InlineVerifierMismatches{}

Expand All @@ -648,8 +647,8 @@ func compareDecompressedData(source, target map[uint64]map[string][]byte) map[ui
if !exists {
// row missing on source
mismatchSet[paginationKey] = InlineVerifierMismatches{
Pk: paginationKey,
MismatchType: MismatchRowMissingOnSource,
Pk: paginationKey,
MismatchType: MismatchRowMissingOnSource,
}
continue
}
Expand All @@ -669,7 +668,7 @@ func compareDecompressedData(source, target map[uint64]map[string][]byte) map[ui

mismatchSet[paginationKey] = InlineVerifierMismatches{
Pk: paginationKey,
MismatchType: MismatchContentDifference,
MismatchType: MismatchColumnValueDifference,
MismatchColumn: colName,
SourceChecksum: hex.EncodeToString(sourceChecksum[:]),
TargetChecksum: hex.EncodeToString(targetChecksum[:]),
Expand All @@ -684,8 +683,8 @@ func compareDecompressedData(source, target map[uint64]map[string][]byte) map[ui
if !exists {
// row missing on target
mismatchSet[paginationKey] = InlineVerifierMismatches{
Pk: paginationKey,
MismatchType: MismatchRowMissingOnTarget,
Pk: paginationKey,
MismatchType: MismatchRowMissingOnTarget,
}
continue
}
Expand Down
20 changes: 10 additions & 10 deletions inline_verifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ func TestCompareDecompressedDataContentDifference(t *testing.T) {

assert.Equal(t, map[uint64]InlineVerifierMismatches{
1: {
Pk: 1,
MismatchType: MismatchContentDifference,
Pk: 1,
MismatchType: MismatchColumnValueDifference,
MismatchColumn: "name",
SourceChecksum: "e356a972989f87a1531252cfa2152797",
TargetChecksum: "81b8a1b77068d06e1c8190825253066f",
Expand Down Expand Up @@ -67,7 +67,7 @@ func TestFormatMismatch(t *testing.T) {
"default": {
"users": {
InlineVerifierMismatches{
Pk: 1,
Pk: 1,
MismatchType: MismatchRowMissingOnSource,
},
},
Expand All @@ -84,27 +84,27 @@ func TestFormatMismatches(t *testing.T) {
"default": {
"users": {
InlineVerifierMismatches{
Pk: 1,
Pk: 1,
MismatchType: MismatchRowMissingOnSource,
},
InlineVerifierMismatches{
Pk: 5,
Pk: 5,
MismatchType: MismatchRowMissingOnTarget,
},
},
"posts": {
InlineVerifierMismatches{
Pk: 9,
MismatchType: MismatchContentDifference,
Pk: 9,
MismatchType: MismatchColumnValueDifference,
MismatchColumn: string("title"),
SourceChecksum: "boo",
TargetChecksum: "aaa",
},
},
"attachments": {
InlineVerifierMismatches{
Pk: 7,
MismatchType: MismatchContentDifference,
Pk: 7,
MismatchType: MismatchColumnValueDifference,
MismatchColumn: string("name"),
SourceChecksum: "boo",
TargetChecksum: "aaa",
Expand All @@ -114,6 +114,6 @@ func TestFormatMismatches(t *testing.T) {
}
message, tables := formatMismatches(mismatches)

assert.Equal(t, string("cutover verification failed for: default.attachments [PKs: 7 (type: content difference, source: boo, target: aaa, column: name) ] default.posts [PKs: 9 (type: content difference, source: boo, target: aaa, column: title) ] default.users [PKs: 1 (type: row missing on source) 5 (type: row missing on target) ] "), message)
assert.Equal(t, string("cutover verification failed for: default.attachments [PKs: 7 (type: column value difference, source: boo, target: aaa, column: name) ] default.posts [PKs: 9 (type: column value difference, source: boo, target: aaa, column: title) ] default.users [PKs: 1 (type: row missing on source) 5 (type: row missing on target) ] "), message)
assert.Equal(t, []string{string("default.attachments"), string("default.posts"), string("default.users")}, tables)
}
2 changes: 1 addition & 1 deletion test/integration/inline_verifier_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def test_different_compressed_data_is_detected_inline_with_batch_writer
assert_equal ["#{DEFAULT_DB}.#{DEFAULT_TABLE}"], incorrect_tables

expected_message = "cutover verification failed for: gftest.test_table_1 "\
"[PKs: 1 (type: content difference, source: 389101948d1694a3bbfb904f57ae845c, target: 4594bb26f2f93c5c60328df6c86a0846, column: data) ] "
"[PKs: 1 (type: column value difference, source: 389101948d1694a3bbfb904f57ae845c, target: 4594bb26f2f93c5c60328df6c86a0846, column: data) ] "

assert_equal expected_message, ghostferry.error_lines.last["msg"]
end
Expand Down

0 comments on commit 535a320

Please sign in to comment.