Skip to content

Commit

Permalink
source-postgres: Detect tuple/relation mismatch
Browse files Browse the repository at this point in the history
This should never happen but we observed it once. I still have no
idea how it could possibly happen so we need more information in
case it happens again someday.
  • Loading branch information
willdonnelly committed Feb 26, 2025
1 parent 49f5235 commit a641841
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions source-postgres/replication.go
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,30 @@ func (s *replicationStream) decodeTuple(
return nil, nil
}

// Check if tuple columns match relation columns. They should never differ, so if
// they do something is very wrong and we need to log a bunch of debug info.
if len(tuple.Columns) > len(rel.Columns) {
var relColumnNames []string
var relColumnTypes []uint32
for _, col := range rel.Columns {
relColumnNames = append(relColumnNames, col.Name)
relColumnTypes = append(relColumnTypes, col.DataType)
}
var tupleColumnTypes []uint8
var tupleColumnData []string
for _, col := range tuple.Columns {
tupleColumnTypes = append(tupleColumnTypes, col.DataType)
tupleColumnData = append(tupleColumnData, string(col.Data))
}
logrus.WithFields(logrus.Fields{
"relNames": relColumnNames,
"relTypeOIDs": relColumnTypes,
"tupleTypes": tupleColumnTypes,
"tupleData": tupleColumnData,
}).Warn("tuple has more columns than relation")
return nil, fmt.Errorf("tuple has %d columns but relation only has %d columns", len(tuple.Columns), len(rel.Columns))
}

var fields = make(map[string]interface{})
for idx, col := range tuple.Columns {
if keyOnly && (rel.Columns[idx].Flags&1) == 0 {
Expand Down

0 comments on commit a641841

Please sign in to comment.