Skip to content

Commit 65763d9

Browse files
authored
Merge pull request #3062 from redpanda-data/pgcdc
pgcdc: consolidate mode into operation
2 parents a03a02a + 181ad11 commit 65763d9

File tree

7 files changed

+19
-20
lines changed

7 files changed

+19
-20
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file.
88
### Changed
99

1010
- The `pg_stream` input has been renamed to `postgres_cdc`. The old name will continue to function as an alias. (@rockwotj)
11+
- The `postgres_cdc` input no longer emits `mode` metadata and instead snapshot reads set `operation` metadata to be `read` instead of `insert`. (@rockwotj)
1112

1213
### Fixed
1314

docs/modules/components/pages/inputs/pg_stream.adoc

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@ Additionally, if `stream_snapshot` is set to true, then the existing data in the
106106
== Metadata
107107
108108
This input adds the following metadata fields to each message:
109-
- mode (Either "streaming" or "snapshot" indicating whether the message is part of a streaming operation or snapshot processing)
110109
- table (Name of the table that the message originated from)
111-
- operation (Type of operation that generated the message: "insert", "update", or "delete". This will also be "begin" and "commit" if `include_transaction_markers` is enabled)
110+
- operation (Type of operation that generated the message: "read", "insert", "update", or "delete". "read" is from messages that are read in the initial snapshot phase. This will also be "begin" and "commit" if `include_transaction_markers` is enabled)
111+
- lsn (the log sequence number in postgres)
112112
113113
114114
== Fields

docs/modules/components/pages/inputs/postgres_cdc.adoc

+2-2
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ Additionally, if `stream_snapshot` is set to true, then the existing data in the
101101
== Metadata
102102
103103
This input adds the following metadata fields to each message:
104-
- mode (Either "streaming" or "snapshot" indicating whether the message is part of a streaming operation or snapshot processing)
105104
- table (Name of the table that the message originated from)
106-
- operation (Type of operation that generated the message: "insert", "update", or "delete". This will also be "begin" and "commit" if `include_transaction_markers` is enabled)
105+
- operation (Type of operation that generated the message: "read", "insert", "update", or "delete". "read" is from messages that are read in the initial snapshot phase. This will also be "begin" and "commit" if `include_transaction_markers` is enabled)
106+
- lsn (the log sequence number in postgres)
107107
108108
109109
== Fields

internal/impl/postgresql/input_pg_stream.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ Additionally, if ` + "`" + fieldStreamSnapshot + "`" + ` is set to true, then th
6161
== Metadata
6262
6363
This input adds the following metadata fields to each message:
64-
- mode (Either "streaming" or "snapshot" indicating whether the message is part of a streaming operation or snapshot processing)
6564
- table (Name of the table that the message originated from)
66-
- operation (Type of operation that generated the message: "insert", "update", or "delete". This will also be "begin" and "commit" if ` + "`" + fieldIncludeTxnMarkers + "`" + ` is enabled)
65+
- operation (Type of operation that generated the message: "read", "insert", "update", or "delete". "read" is from messages that are read in the initial snapshot phase. This will also be "begin" and "commit" if ` + "`" + fieldIncludeTxnMarkers + "`" + ` is enabled)
66+
- lsn (the log sequence number in postgres)
6767
`).
6868
Field(service.NewStringField(fieldDSN).
6969
Description("The Data Source Name for the PostgreSQL database in the form of `postgres://[user[:password]@][netloc][:port][/dbname][?param1=value1&...]`. Please note that Postgres enforces SSL by default, you can override this with the parameter `sslmode=disable` if required.").
@@ -259,7 +259,7 @@ func newPgStreamInput(conf *service.ParsedConfig, mgr *service.Resources) (s ser
259259
return nil, err
260260
}
261261

262-
return conf.WrapBatchInputExtractTracingSpanMapping("pg_stream", r)
262+
return conf.WrapBatchInputExtractTracingSpanMapping("postgres_cdc", r)
263263
}
264264

265265
// validateSimpleString ensures we aren't vuln to SQL injection
@@ -367,7 +367,6 @@ func (p *pgStreamInput) processStream(pgStream *pglogicalstream.Stream, batcher
367367
break
368368
}
369369
batchMsg := service.NewMessage(mb)
370-
batchMsg.MetaSet("mode", string(message.Mode))
371370
batchMsg.MetaSet("table", message.Table)
372371
batchMsg.MetaSet("operation", string(message.Operation))
373372
if message.LSN != nil {

internal/impl/postgresql/pglogicalstream/logical_stream.go

+4-6
Original file line numberDiff line numberDiff line change
@@ -580,12 +580,10 @@ func (s *Stream) processSnapshot() error {
580580

581581
snapshotChangePacket := StreamMessage{
582582
LSN: nil,
583-
Mode: StreamModeSnapshot,
584-
Operation: InsertOpType,
585-
586-
Table: tableWithoutSchema,
587-
Schema: s.schema,
588-
Data: data,
583+
Operation: ReadOpType,
584+
Table: tableWithoutSchema,
585+
Schema: s.schema,
586+
Data: data,
589587
}
590588

591589
if rowsCount%100 == 0 {

internal/impl/postgresql/pglogicalstream/replication_message_decoders.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func isCommitMessage(WALData []byte) (bool, *CommitMessage, error) {
4747
// before the change message.
4848
func decodePgOutput(WALData []byte, relations map[uint32]*RelationMessage, typeMap *pgtype.Map) (*StreamMessage, error) {
4949
logicalMsg, err := Parse(WALData)
50-
message := &StreamMessage{Mode: StreamModeStreaming}
50+
message := &StreamMessage{}
5151

5252
if err != nil {
5353
return nil, err

internal/impl/postgresql/pglogicalstream/stream_message.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ const (
2222
type OpType string
2323

2424
const (
25+
// ReadOpType is a snapshot read
26+
ReadOpType OpType = "read"
2527
// InsertOpType is a database insert
2628
InsertOpType OpType = "insert"
2729
// UpdateOpType is a database update
@@ -36,11 +38,10 @@ const (
3638

3739
// StreamMessage represents a single change from the database
3840
type StreamMessage struct {
39-
LSN *string `json:"lsn"`
40-
Operation OpType `json:"operation"`
41-
Schema string `json:"schema"`
42-
Table string `json:"table"`
43-
Mode StreamMode `json:"mode"`
41+
LSN *string `json:"lsn"`
42+
Operation OpType `json:"operation"`
43+
Schema string `json:"schema"`
44+
Table string `json:"table"`
4445
// For deleted messages - there will be old changes if replica identity set to full or empty changes
4546
Data any `json:"data"`
4647
}

0 commit comments

Comments
 (0)