-
Notifications
You must be signed in to change notification settings - Fork 310
kafka(ticdc): ddl sink close the underline sink if send ddl or checkpoint failed and refactor the kafka ddl sink (#12112) #12679
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: release-8.1
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -69,9 +69,13 @@ func (k *kafkaDDLProducer) SyncBroadcastMessage(ctx context.Context, topic strin | |
| case <-ctx.Done(): | ||
| return ctx.Err() | ||
| default: | ||
| <<<<<<< HEAD | ||
| err := k.syncProducer.SendMessages(ctx, topic, | ||
| totalPartitionsNum, message.Key, message.Value) | ||
| return cerror.WrapError(cerror.ErrKafkaSendMessage, err) | ||
| ======= | ||
| return k.syncProducer.SendMessages(ctx, topic, totalPartitionsNum, message) | ||
| >>>>>>> 4c631d5951 (kafka(ticdc): ddl sink close the underline sink if send ddl or checkpoint failed and refactor the kafka ddl sink (#12112)) | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -89,9 +93,13 @@ func (k *kafkaDDLProducer) SyncSendMessage(ctx context.Context, topic string, | |
| case <-ctx.Done(): | ||
| return errors.Trace(ctx.Err()) | ||
| default: | ||
| <<<<<<< HEAD | ||
| err := k.syncProducer.SendMessage(ctx, topic, | ||
| partitionNum, message.Key, message.Value) | ||
| return cerror.WrapError(cerror.ErrKafkaSendMessage, err) | ||
| ======= | ||
| return k.syncProducer.SendMessage(ctx, topic, partitionNum, message) | ||
| >>>>>>> 4c631d5951 (kafka(ticdc): ddl sink close the underline sink if send ddl or checkpoint failed and refactor the kafka ddl sink (#12112)) | ||
|
Comment on lines
+96
to
+102
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unresolved merge conflict markers found. Since err := k.syncProducer.SendMessage(ctx, topic,
partitionNum, message.Key, message.Value)
return cerror.WrapError(cerror.ErrKafkaSendMessage, err) |
||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -112,7 +112,11 @@ func NewKafkaDDLSink( | |
| } | ||
|
|
||
| ddlProducer := producerCreator(ctx, changefeedID, syncProducer) | ||
| <<<<<<< HEAD | ||
| s := newDDLSink(ctx, changefeedID, ddlProducer, adminClient, topicManager, eventRouter, encoderBuilder, protocol) | ||
| ======= | ||
| s := newDDLSink(changefeedID, ddlProducer, adminClient, topicManager, eventRouter, encoderBuilder.Build(), protocol) | ||
| >>>>>>> 4c631d5951 (kafka(ticdc): ddl sink close the underline sink if send ddl or checkpoint failed and refactor the kafka ddl sink (#12112)) | ||
|
Comment on lines
+115
to
+119
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unresolved merge conflict markers found. Based on the signature of s := newDDLSink(ctx, changefeedID, ddlProducer, adminClient, topicManager, eventRouter, encoderBuilder.Build(), protocol) |
||
| log.Info("DDL sink producer client created", zap.Duration("duration", time.Since(start))) | ||
| return s, nil | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -100,7 +100,11 @@ func NewPulsarDDLSink( | |
| return nil, errors.Trace(err) | ||
| } | ||
|
|
||
| <<<<<<< HEAD | ||
| s := newDDLSink(ctx, changefeedID, p, nil, topicManager, eventRouter, encoderBuilder, protocol) | ||
| ======= | ||
| s := newDDLSink(changefeedID, p, nil, topicManager, eventRouter, encoderBuilder.Build(), protocol) | ||
| >>>>>>> 4c631d5951 (kafka(ticdc): ddl sink close the underline sink if send ddl or checkpoint failed and refactor the kafka ddl sink (#12112)) | ||
|
Comment on lines
+103
to
+107
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unresolved merge conflict markers found. Based on the signature of s := newDDLSink(ctx, changefeedID, p, nil, topicManager, eventRouter, encoderBuilder.Build(), protocol) |
||
|
|
||
| return s, nil | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -86,7 +86,6 @@ type AsyncProducer interface { | |
|
|
||
| type saramaSyncProducer struct { | ||
| id model.ChangeFeedID | ||
| client sarama.Client | ||
| producer sarama.SyncProducer | ||
| } | ||
|
|
||
|
|
@@ -101,13 +100,17 @@ func (p *saramaSyncProducer) SendMessage( | |
| Value: sarama.ByteEncoder(value), | ||
| Partition: partitionNum, | ||
| }) | ||
| return err | ||
| return cerror.WrapError(cerror.ErrKafkaSendMessage, err) | ||
| } | ||
|
|
||
| <<<<<<< HEAD | ||
| func (p *saramaSyncProducer) SendMessages(ctx context.Context, | ||
| topic string, partitionNum int32, | ||
| key []byte, value []byte, | ||
| ) error { | ||
| ======= | ||
| func (p *saramaSyncProducer) SendMessages(_ context.Context, topic string, partitionNum int32, message *common.Message) error { | ||
| >>>>>>> 4c631d5951 (kafka(ticdc): ddl sink close the underline sink if send ddl or checkpoint failed and refactor the kafka ddl sink (#12112)) | ||
|
Comment on lines
+106
to
+113
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unresolved merge conflict markers found. Since the func (p *saramaSyncProducer) SendMessages(ctx context.Context,
topic string, partitionNum int32,
key []byte, value []byte,
) error { |
||
| msgs := make([]*sarama.ProducerMessage, partitionNum) | ||
| for i := 0; i < int(partitionNum); i++ { | ||
| msgs[i] = &sarama.ProducerMessage{ | ||
|
|
@@ -117,49 +120,25 @@ func (p *saramaSyncProducer) SendMessages(ctx context.Context, | |
| Partition: int32(i), | ||
| } | ||
| } | ||
| return p.producer.SendMessages(msgs) | ||
| err := p.producer.SendMessages(msgs) | ||
| return cerror.WrapError(cerror.ErrKafkaSendMessage, err) | ||
| } | ||
|
|
||
| func (p *saramaSyncProducer) Close() { | ||
| go func() { | ||
| // We need to close it asynchronously. Otherwise, we might get stuck | ||
| // with an unhealthy(i.e. Network jitter, isolation) state of Kafka. | ||
| // Factory has a background thread to fetch and update the metadata. | ||
| // If we close the client synchronously, we might get stuck. | ||
| // Safety: | ||
| // * If the kafka cluster is running well, it will be closed as soon as possible. | ||
| // * If there is a problem with the kafka cluster, | ||
| // no data will be lost because this is a synchronous client. | ||
| // * There is a risk of goroutine leakage, but it is acceptable and our main | ||
| // goal is not to get stuck with the owner tick. | ||
| start := time.Now() | ||
| if err := p.client.Close(); err != nil { | ||
| log.Warn("Close Kafka DDL client with error", | ||
| zap.String("namespace", p.id.Namespace), | ||
| zap.String("changefeed", p.id.ID), | ||
| zap.Duration("duration", time.Since(start)), | ||
| zap.Error(err)) | ||
| } else { | ||
| log.Info("Kafka DDL client closed", | ||
| zap.String("namespace", p.id.Namespace), | ||
| zap.String("changefeed", p.id.ID), | ||
| zap.Duration("duration", time.Since(start))) | ||
| } | ||
| start = time.Now() | ||
| err := p.producer.Close() | ||
| if err != nil { | ||
| log.Error("Close Kafka DDL producer with error", | ||
| zap.String("namespace", p.id.Namespace), | ||
| zap.String("changefeed", p.id.ID), | ||
| zap.Duration("duration", time.Since(start)), | ||
| zap.Error(err)) | ||
| } else { | ||
| log.Info("Kafka DDL producer closed", | ||
| zap.String("namespace", p.id.Namespace), | ||
| zap.String("changefeed", p.id.ID), | ||
| zap.Duration("duration", time.Since(start))) | ||
| } | ||
| }() | ||
| start := time.Now() | ||
| err := p.producer.Close() | ||
| if err != nil { | ||
| log.Error("Close Kafka DDL producer with error", | ||
| zap.String("namespace", p.id.Namespace), | ||
| zap.String("changefeed", p.id.ID), | ||
| zap.Duration("duration", time.Since(start)), | ||
| zap.Error(err)) | ||
| } else { | ||
| log.Info("Kafka DDL producer closed", | ||
| zap.String("namespace", p.id.Namespace), | ||
| zap.String("changefeed", p.id.ID), | ||
| zap.Duration("duration", time.Since(start))) | ||
| } | ||
| } | ||
|
|
||
| type saramaAsyncProducer struct { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -108,19 +108,22 @@ func (f *saramaFactory) SyncProducer(ctx context.Context) (SyncProducer, error) | |
| return nil, err | ||
| } | ||
| config.MetricRegistry = f.registry | ||
| <<<<<<< HEAD | ||
|
|
||
| client, err := newSaramaClientImpl(f.option.BrokerEndpoints, config) | ||
| if err != nil { | ||
| return nil, errors.Trace(err) | ||
| } | ||
| p, err := newSaramaSyncProducerFromClientImpl(client) | ||
| ======= | ||
| p, err := sarama.NewSyncProducer(f.option.BrokerEndpoints, config) | ||
| >>>>>>> 4c631d5951 (kafka(ticdc): ddl sink close the underline sink if send ddl or checkpoint failed and refactor the kafka ddl sink (#12112)) | ||
|
Comment on lines
+111
to
+120
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unresolved merge conflict markers found. To resolve this correctly and avoid leaking the Kafka client, you should choose the incoming branch version ( p, err := sarama.NewSyncProducer(f.option.BrokerEndpoints, config) |
||
| if err != nil { | ||
| closeSaramaClientOnFailure(f.changefeedID, client, "close sarama client after sync producer init failed") | ||
| return nil, errors.Trace(err) | ||
| } | ||
| return &saramaSyncProducer{ | ||
| id: f.changefeedID, | ||
| client: client, | ||
| producer: p, | ||
| }, nil | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -25,6 +25,7 @@ import ( | |||||||||||||||||||||||||||||
| "github.com/pingcap/log" | ||||||||||||||||||||||||||||||
| "github.com/pingcap/tiflow/cdc/model" | ||||||||||||||||||||||||||||||
| "github.com/pingcap/tiflow/pkg/errors" | ||||||||||||||||||||||||||||||
| cerror "github.com/pingcap/tiflow/pkg/errors" | ||||||||||||||||||||||||||||||
|
Comment on lines
27
to
+28
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||||||||||||||||||||||
| "github.com/pingcap/tiflow/pkg/security" | ||||||||||||||||||||||||||||||
| pkafka "github.com/pingcap/tiflow/pkg/sink/kafka" | ||||||||||||||||||||||||||||||
| "github.com/pingcap/tiflow/pkg/util" | ||||||||||||||||||||||||||||||
|
|
@@ -277,12 +278,13 @@ func (s *syncWriter) SendMessage( | |||||||||||||||||||||||||||||
| topic string, partitionNum int32, | ||||||||||||||||||||||||||||||
| key []byte, value []byte, | ||||||||||||||||||||||||||||||
| ) error { | ||||||||||||||||||||||||||||||
| return s.w.WriteMessages(ctx, kafka.Message{ | ||||||||||||||||||||||||||||||
| err := s.w.WriteMessages(ctx, kafka.Message{ | ||||||||||||||||||||||||||||||
| Topic: topic, | ||||||||||||||||||||||||||||||
| Partition: int(partitionNum), | ||||||||||||||||||||||||||||||
| Key: key, | ||||||||||||||||||||||||||||||
| Value: value, | ||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||
| return cerror.WrapError(cerror.ErrKafkaSendMessage, err) | ||||||||||||||||||||||||||||||
|
Comment on lines
+281
to
+287
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use the
Suggested change
|
||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| // SendMessages produces a given set of messages, and returns only when all | ||||||||||||||||||||||||||||||
|
|
@@ -303,19 +305,17 @@ func (s *syncWriter) SendMessages( | |||||||||||||||||||||||||||||
| Partition: i, | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| return s.w.WriteMessages(ctx, msgs...) | ||||||||||||||||||||||||||||||
| err := s.w.WriteMessages(ctx, msgs...) | ||||||||||||||||||||||||||||||
| return cerror.WrapError(cerror.ErrKafkaSendMessage, err) | ||||||||||||||||||||||||||||||
|
Comment on lines
+308
to
+309
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| // Close shuts down the producer; you must call this function before a producer | ||||||||||||||||||||||||||||||
| // object passes out of scope, as it may otherwise leak memory. | ||||||||||||||||||||||||||||||
| // You must call this before calling Close on the underlying client. | ||||||||||||||||||||||||||||||
| func (s *syncWriter) Close() { | ||||||||||||||||||||||||||||||
| log.Info("kafka sync producer start closing", | ||||||||||||||||||||||||||||||
| zap.String("namespace", s.changefeedID.Namespace), | ||||||||||||||||||||||||||||||
| zap.String("changefeed", s.changefeedID.ID)) | ||||||||||||||||||||||||||||||
| start := time.Now() | ||||||||||||||||||||||||||||||
| if err := s.w.Close(); err != nil { | ||||||||||||||||||||||||||||||
| log.Warn("Close kafka sync producer failed", | ||||||||||||||||||||||||||||||
| log.Warn("Close kafka sync producer meet error", | ||||||||||||||||||||||||||||||
| zap.String("namespace", s.changefeedID.Namespace), | ||||||||||||||||||||||||||||||
| zap.String("changefeed", s.changefeedID.ID), | ||||||||||||||||||||||||||||||
| zap.Duration("duration", time.Since(start)), | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unresolved merge conflict markers found. Since the
SyncProducerinterface inpkg/sink/kafka/factory.goexpectskey []byte, value []byteforSendMessages, choosing the incoming branch version (message *common.Message) will break the interface implementation. Please resolve the conflict by keeping the HEAD version.