Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
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
3 changes: 2 additions & 1 deletion pkg/config/sink.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ type SinkConfig struct {
DispatchRules []*DispatchRule `toml:"dispatchers" json:"dispatchers,omitempty"`

ColumnSelectors []*ColumnSelector `toml:"column-selectors" json:"column-selectors,omitempty"`
// SchemaRegistry is only available when the downstream is MQ using avro protocol.
// SchemaRegistry is only available when the downstream is MQ using avro protocol
// or debezium protocol with Confluent Avro encoding.
SchemaRegistry *string `toml:"schema-registry" json:"schema-registry,omitempty"`
// EncoderConcurrency is only available when the downstream is MQ.
EncoderConcurrency *int `toml:"encoder-concurrency" json:"encoder-concurrency,omitempty"`
Expand Down
3 changes: 3 additions & 0 deletions pkg/sink/codec/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ func NewEventEncoder(ctx context.Context, cfg *common.Config) (common.EventEncod
case config.ProtocolCanalJSON:
return canal.NewJSONRowEventEncoder(ctx, cfg)
case config.ProtocolDebezium:
if cfg.AvroConfluentSchemaRegistry != "" {
return debezium.NewAvroBatchEncoder(ctx, cfg, config.GetGlobalServerConfig().ClusterID)
}
return debezium.NewBatchEncoder(cfg, config.GetGlobalServerConfig().ClusterID), nil
case config.ProtocolSimple:
return simple.NewEncoder(ctx, cfg)
Expand Down
10 changes: 9 additions & 1 deletion pkg/sink/codec/common/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ type Config struct {

OutputRowKey bool

// avro only
// avro only, except AvroConfluentSchemaRegistry is also used by debezium
// protocol when Confluent Avro encoding is enabled.
AvroConfluentSchemaRegistry string
AvroDecimalHandlingMode string
AvroBigintUnsignedHandlingMode string
Expand Down Expand Up @@ -410,6 +411,13 @@ func (c *Config) Validate() error {
}
}

if c.Protocol == config.ProtocolDebezium && c.AvroGlueSchemaRegistry != nil {
return errors.ErrCodecInvalidConfig.GenWithStack(
`Debezium protocol only supports "%s" for Confluent Avro Schema Registry`,
codecOPTAvroSchemaRegistry,
)
}

if c.MaxMessageBytes <= 0 {
return errors.ErrCodecInvalidConfig.Wrap(
errors.Errorf("invalid max-message-bytes %d", c.MaxMessageBytes),
Expand Down
33 changes: 33 additions & 0 deletions pkg/sink/codec/common/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright 2026 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.

package common

import (
"testing"

"github.com/pingcap/ticdc/pkg/config"
"github.com/stretchr/testify/require"
)

func TestDebeziumSchemaRegistryConfig(t *testing.T) {
t.Parallel()

cfg := NewConfig(config.ProtocolDebezium)
cfg.AvroConfluentSchemaRegistry = "http://127.0.0.1:8081"
require.NoError(t, cfg.Validate())

cfg = NewConfig(config.ProtocolDebezium)
cfg.AvroGlueSchemaRegistry = &config.GlueSchemaRegistryConfig{}
require.ErrorContains(t, cfg.Validate(), `Debezium protocol only supports "schema-registry"`)
}
Loading
Loading