Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions api/v2/changefeed.go
Original file line number Diff line number Diff line change
Expand Up @@ -1838,7 +1838,11 @@ func verifyTablesForSink(
}

isAvroLike := protocol == config.ProtocolAvro || protocol == config.ProtocolDebeziumAvro
<<<<<<< HEAD
eventRouter, err := eventrouter.NewEventRouter(replicaConfig.Sink, util.GetOrZero(replicaConfig.CaseSensitive), topic, config.IsPulsarScheme(scheme), isAvroLike)
=======
eventRouter, err := eventrouter.NewEventRouter(replicaConfig.Sink, topic, config.IsPulsarScheme(scheme), isAvroLike)
>>>>>>> d220ee9b8 (sink: add debezium-avro protocol (#5475))
if err != nil {
return err
}
Expand Down
4 changes: 4 additions & 0 deletions cmd/kafka-consumer/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,13 @@ func getPartitionNum(o *option) (int32, error) {
}
return 0, errors.Trace(err)
}
<<<<<<< HEAD

topicDetail, ok := resp.Topics[topic]
if ok && topicDetail.Error.Code() == kafka.ErrNoError {
=======
if topicDetail, ok := resp.Topics[topic]; ok {
>>>>>>> d220ee9b8 (sink: add debezium-avro protocol (#5475))
numPartitions := int32(len(topicDetail.Partitions))
log.Info("get partition number of topic",
zap.String("topic", topic),
Expand Down
55 changes: 55 additions & 0 deletions cmd/kafka-consumer/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,11 @@ func newWriter(ctx context.Context, o *option) *writer {
}

isAvroLike := o.protocol == config.ProtocolAvro || o.protocol == config.ProtocolDebeziumAvro
<<<<<<< HEAD
eventRouter, err := eventrouter.NewEventRouter(o.sinkConfig, o.caseSensitive, o.topic, false, isAvroLike)
=======
eventRouter, err := eventrouter.NewEventRouter(o.sinkConfig, o.topic, false, isAvroLike)
>>>>>>> d220ee9b8 (sink: add debezium-avro protocol (#5475))
if err != nil {
log.Panic("initialize the event router failed",
zap.Any("protocol", o.protocol), zap.Any("topic", o.topic),
Expand Down Expand Up @@ -649,13 +653,64 @@ func (w *writer) appendMessage2Group(message *common.DMLMessage, progress *parti
zap.Stringer("eventType", message.RowType))
return
}
<<<<<<< HEAD
log.Warn("DML event commit ts fallback, append it and sort before flush",
zap.Int32("partition", progress.partition), zap.Any("offset", offset),
zap.Uint64("commitTs", commitTs), zap.Uint64("highWatermark", group.HighWatermark),
zap.Any("partitionWatermark", progress.watermark), zap.Any("watermarkOffset", progress.watermarkOffset),
zap.String("schema", schema), zap.String("table", table), zap.Int64("tableID", tableID),
zap.Stringer("eventType", message.RowType),
zap.Any("protocol", w.protocol), zap.Bool("enableTableAcrossNodes", w.enableTableAcrossNodes))
=======
if w.enableTableAcrossNodes {
log.Warn("DML events fallback, but enableTableAcrossNodes is true, still append it",
zap.Int32("partition", group.Partition), zap.Any("offset", offset),
zap.Uint64("commitTs", commitTs), zap.Uint64("HighWatermark", group.HighWatermark),
zap.String("schema", schema), zap.String("table", table), zap.Int64("tableID", tableID),
zap.Stringer("eventType", dml.RowTypes[0]))
group.Append(dml, true)
return
}
switch w.protocol {
case config.ProtocolSimple:
// simple protocol set the table id for all row message, it can be known which table the row message belongs to,
// also consider the table partition.
// open protocol set the partition table id if the table is partitioned.
// for normal table, the table id is generated by the fake table id generator by using schema and table name.
// so one event group for one normal table or one table partition, replayed messages can be ignored.
log.Warn("DML event fallback row, since less than the group high watermark, ignore it",
zap.Int32("partition", progress.partition), zap.Any("offset", offset),
zap.Uint64("commitTs", commitTs), zap.Uint64("highWatermark", group.HighWatermark),
zap.Any("partitionWatermark", progress.watermark), zap.Any("watermarkOffset", progress.watermarkOffset),
zap.String("schema", schema), zap.String("table", table), zap.Int64("tableID", tableID),
zap.Stringer("eventType", dml.RowTypes[0]),
// zap.Any("columns", row.Columns), zap.Any("preColumns", row.PreColumns),
zap.Any("protocol", w.protocol), zap.Bool("IsPartition", dml.TableInfo.TableName.IsPartition))
case config.ProtocolCanalJSON, config.ProtocolOpen, config.ProtocolAvro,
config.ProtocolDebezium, config.ProtocolDebeziumAvro:
// for partition table, these protocols cannot assign physical table id to each dml message,
// we cannot distinguish whether it's a real fallback event or not, still append it.
if w.partitionTableAccessor.IsPartitionTable(schema, table) {
log.Warn("DML events fallback, but the table is a partition table, still append it",
zap.Int32("partition", group.Partition), zap.Any("offset", offset),
zap.Uint64("commitTs", commitTs), zap.Uint64("highWatermark", group.HighWatermark),
zap.String("schema", schema), zap.String("table", table), zap.Int64("tableID", tableID),
zap.Stringer("eventType", dml.RowTypes[0]), zap.Any("protocol", w.protocol))
group.Append(dml, true)
return
}
log.Warn("DML event fallback row, since less than the group high watermark, ignore it",
zap.Int32("partition", progress.partition), zap.Any("offset", offset),
zap.Uint64("commitTs", commitTs), zap.Uint64("HighWatermark", group.HighWatermark),
zap.Any("partitionWatermark", progress.watermark), zap.Any("watermarkOffset", progress.watermarkOffset),
zap.String("schema", schema), zap.String("table", table), zap.Int64("tableID", tableID),
zap.Stringer("eventType", dml.RowTypes[0]),
// zap.Any("columns", row.Columns), zap.Any("preColumns", row.PreColumns),
zap.Any("protocol", w.protocol), zap.Bool("IsPartition", dml.TableInfo.TableName.IsPartition))
default:
log.Panic("unknown protocol", zap.Any("protocol", w.protocol))
}
>>>>>>> d220ee9b8 (sink: add debezium-avro protocol (#5475))
}

func openDB(ctx context.Context, dsn string) (*sql.DB, error) {
Expand Down
15 changes: 15 additions & 0 deletions cmd/kafka-consumer/writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,11 @@ func TestAppendRow2GroupKeepsDebeziumPartitionTableFallback(t *testing.T) {
} {
t.Run(protocol.String(), func(t *testing.T) {
replicaCfg := config.GetDefaultReplicaConfig()
<<<<<<< HEAD
eventRouter, err := eventrouter.NewEventRouter(replicaCfg.Sink, false, "test-topic", false, false)
=======
eventRouter, err := eventrouter.NewEventRouter(replicaCfg.Sink, "test-topic", false, false)
>>>>>>> d220ee9b8 (sink: add debezium-avro protocol (#5475))
require.NoError(t, err)

w := &writer{
Expand Down Expand Up @@ -449,6 +453,7 @@ func TestAppendRow2GroupKeepsDebeziumPartitionTableFallback(t *testing.T) {
}

progress := w.progresses[0]
<<<<<<< HEAD
w.appendMessage2Group(codeccommon.NewDMLMessageFromEvent(newDMLEvent(200)), progress, kafka.Offset(10))
w.appendMessage2Group(codeccommon.NewDMLMessageFromEvent(newDMLEvent(100)), progress, kafka.Offset(11))

Expand Down Expand Up @@ -507,4 +512,14 @@ func TestMessageWithPartitionCheckRejectsNilEvent(t *testing.T) {
require.PanicsWithValue(t, "DML message decoded to nil event", func() {
checked.ToDMLEvent()
})
=======
w.appendRow2Group(newDMLEvent(200), progress, kafka.Offset(10))
w.appendRow2Group(newDMLEvent(100), progress, kafka.Offset(11))

resolved := progress.eventsGroup[1].ResolveInto(150, nil)
require.Len(t, resolved, 1)
require.Equal(t, uint64(100), resolved[0].CommitTs)
})
}
>>>>>>> d220ee9b8 (sink: add debezium-avro protocol (#5475))
}
66 changes: 66 additions & 0 deletions downstreamadapter/sink/kafka/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,72 @@ func (c components) close() {
if c.factory != nil {
c.factory.Close()
}
<<<<<<< HEAD
=======

options := kafka.NewOptions()
if err = options.Apply(changefeedID, sinkURI, sinkConfig); err != nil {
return kafkaComponent, protocol, errors.WrapError(errors.ErrKafkaInvalidConfig, err)
}
options.Topic = topic

kafkaComponent.factory, err = factoryCreator(ctx, options, changefeedID)
if err != nil {
return kafkaComponent, protocol, errors.WrapError(errors.ErrKafkaNewProducer, err)
}

isAvroLike := protocol == config.ProtocolAvro || protocol == config.ProtocolDebeziumAvro
kafkaComponent.eventRouter, err = eventrouter.NewEventRouter(
sinkConfig, topic, false, isAvroLike)
if err != nil {
return kafkaComponent, protocol, errors.Trace(err)
}

kafkaComponent.columnSelector, err = columnselector.New(sinkConfig)
if err != nil {
return kafkaComponent, protocol, errors.Trace(err)
}

encoderConfig, err := helper.GetEncoderConfig(changefeedID, sinkURI, protocol, sinkConfig, options.MaxMessageBytes)
if err != nil {
return kafkaComponent, protocol, errors.Trace(err)
}

kafkaComponent.encoderGroup, err = codec.NewEncoderGroup(ctx, sinkConfig, encoderConfig, changefeedID)
if err != nil {
return kafkaComponent, protocol, errors.Trace(err)
}

kafkaComponent.encoder, err = codec.NewEventEncoder(ctx, encoderConfig)
if err != nil {
return kafkaComponent, protocol, errors.Trace(err)
}

kafkaComponent.adminClient, err = kafkaComponent.factory.AdminClient(ctx)
if err != nil {
return kafkaComponent, protocol, errors.WrapError(errors.ErrKafkaNewProducer, err)
}

// We must close adminClient when this func return cause by an error
// otherwise the adminClient will never be closed and lead to a goroutine leak.
defer func() {
if err != nil && kafkaComponent.adminClient != nil {
kafkaComponent.adminClient.Close()
}
}()

kafkaComponent.topicManager, err = topicmanager.GetTopicManagerAndTryCreateTopic(
ctx,
changefeedID,
topic,
options.DeriveTopicConfig(),
kafkaComponent.adminClient,
)
if err != nil {
return kafkaComponent, protocol, errors.Trace(err)
}
return kafkaComponent, protocol, nil
>>>>>>> d220ee9b8 (sink: add debezium-avro protocol (#5475))
}

func newKafkaSinkComponent(
Expand Down
3 changes: 3 additions & 0 deletions pkg/config/changefeed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ func TestChangeFeedInfoRmUnusedFieldsKeepsSchemaRegistryForAvroProtocols(t *test
})
}
}
<<<<<<< HEAD

func TestMaskChangefeedInfoRedactsErrorMessages(t *testing.T) {
originalMode := errors.RedactLogEnabled.Load()
Expand Down Expand Up @@ -409,3 +410,5 @@ func TestChangeFeedInfoToChangefeedConfigIntegrity(t *testing.T) {
replicaConfig.Sink = nil
require.Nil(t, info.ToChangefeedConfig().SinkConfig)
}
=======
>>>>>>> d220ee9b8 (sink: add debezium-avro protocol (#5475))
4 changes: 4 additions & 0 deletions pkg/sink/codec/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ func NewEventEncoder(
case config.ProtocolDebezium:
return debezium.NewBatchEncoder(cfg, config.GetGlobalServerConfig().ClusterID), nil
case config.ProtocolDebeziumAvro:
<<<<<<< HEAD
return debezium.NewAvroBatchEncoder(cfg, config.GetGlobalServerConfig().ClusterID, schemaM)
=======
return debezium.NewAvroBatchEncoder(ctx, cfg, config.GetGlobalServerConfig().ClusterID)
>>>>>>> d220ee9b8 (sink: add debezium-avro protocol (#5475))
case config.ProtocolSimple:
return simple.NewEncoder(cfg, claimCheck)
default:
Expand Down
13 changes: 13 additions & 0 deletions pkg/sink/codec/common/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -472,19 +472,23 @@ func (c *Config) Validate() error {
zap.String("protocol", c.Protocol.String()))
}

<<<<<<< HEAD
if c.DebeziumIncludeStartTs && c.Protocol != config.ProtocolDebezium {
return errors.ErrCodecInvalidConfig.GenWithStack(
`debezium-include-start-ts only takes effect with protocol "debezium"`,
)
}

=======
>>>>>>> d220ee9b8 (sink: add debezium-avro protocol (#5475))
if c.Protocol == config.ProtocolDebezium &&
(c.AvroConfluentSchemaRegistry != "" || c.AvroGlueSchemaRegistry != nil) {
return errors.ErrCodecInvalidConfig.GenWithStack(
`Debezium protocol does not support schema registry; use protocol "debezium-avro"`,
)
}

<<<<<<< HEAD
if c.SimpleIncludeStartTs {
if c.Protocol != config.ProtocolSimple {
return errors.ErrCodecInvalidConfig.GenWithStack(
Expand Down Expand Up @@ -534,6 +538,15 @@ func (c *Config) Validate() error {
protocol = "Debezium Avro"
}
return errors.ErrCodecInvalidConfig.GenWithStack(
=======
if c.Protocol == config.ProtocolAvro || c.Protocol == config.ProtocolDebeziumAvro {
if c.AvroConfluentSchemaRegistry != "" && c.AvroGlueSchemaRegistry != nil {
protocol := "Avro"
if c.Protocol == config.ProtocolDebeziumAvro {
protocol = "Debezium Avro"
}
return errors.ErrCodecInvalidConfig.GenWithStack(
>>>>>>> d220ee9b8 (sink: add debezium-avro protocol (#5475))
`%s protocol requires only one of "%s" or "%s" to specify the schema registry`,
protocol,
codecOPTAvroSchemaRegistry,
Expand Down
7 changes: 7 additions & 0 deletions pkg/sink/codec/common/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@
"net/url"
"testing"

<<<<<<< HEAD

Check failure on line 20 in pkg/sink/codec/common/config_test.go

View workflow job for this annotation

GitHub Actions / Build Classic CDC

missing import path

Check failure on line 20 in pkg/sink/codec/common/config_test.go

View workflow job for this annotation

GitHub Actions / Classic Unit Tests

missing import path
"github.com/BurntSushi/toml"
"github.com/pingcap/ticdc/pkg/config"
"github.com/pingcap/ticdc/pkg/errors"
=======
"github.com/pingcap/ticdc/pkg/config"
>>>>>>> d220ee9b8 (sink: add debezium-avro protocol (#5475))
"github.com/pingcap/ticdc/pkg/util"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -97,6 +101,7 @@
require.True(t, cfg.AvroEnableWatermark)
require.Equal(t, "http://127.0.0.1:8081", cfg.AvroConfluentSchemaRegistry)
}
<<<<<<< HEAD

func TestApplyReturnsSinkInvalidConfigForQueryBindingError(t *testing.T) {
cfg := NewConfig(config.ProtocolOpen)
Expand Down Expand Up @@ -384,3 +389,5 @@
})
}
}
=======
>>>>>>> d220ee9b8 (sink: add debezium-avro protocol (#5475))
10 changes: 10 additions & 0 deletions pkg/sink/codec/debezium/avro.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,16 @@ func (d *BatchEncoder) encodeAvroPayload(
}

subject := debeziumAvroSubject(topic, subjectSuffix, message.Schema.Name)
<<<<<<< HEAD
avroCodec, header, err := d.codecCache.GetOrRegister(
ctx,
subject,
message.Schema.Name,
=======
avroCodec, header, err := d.schemaM.GetCachedOrRegister(
ctx,
subject,
>>>>>>> d220ee9b8 (sink: add debezium-avro protocol (#5475))
schemaVersion,
func() (string, error) {
converter := newDebeziumAvroSchemaConverter()
Expand Down Expand Up @@ -455,7 +461,11 @@ func (c *dbzCodec) buildDebeziumConnectSourceSchema(
) (*debeziumConnectSchema, error) {
buf := &bytes.Buffer{}
writer := util.BorrowJSONWriter(buf)
<<<<<<< HEAD
c.writeSourceSchema(writer, schemaName, false)
=======
c.writeSourceSchema(writer, schemaName)
>>>>>>> d220ee9b8 (sink: add debezium-avro protocol (#5475))
util.ReturnJSONWriter(writer)

return decodeDebeziumConnectSchema(buf.Bytes())
Expand Down
Loading
Loading