forked from pingcap/tiflow
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is an automated cherry-pick of pingcap#11339
Signed-off-by: ti-chi-bot <[email protected]>
- Loading branch information
1 parent
1ecce1d
commit 90ed4d8
Showing
10 changed files
with
173 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
// Copyright 2023 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 kafka | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/IBM/sarama" | ||
"github.com/pingcap/log" | ||
"github.com/pingcap/tiflow/cdc/model" | ||
"github.com/pingcap/tiflow/pkg/errors" | ||
"github.com/pingcap/tiflow/pkg/util" | ||
"github.com/rcrowley/go-metrics" | ||
"go.uber.org/zap" | ||
) | ||
|
||
type saramaFactory struct { | ||
changefeedID model.ChangeFeedID | ||
option *Options | ||
|
||
registry metrics.Registry | ||
} | ||
|
||
// NewSaramaFactory constructs a Factory with sarama implementation. | ||
func NewSaramaFactory( | ||
o *Options, | ||
changefeedID model.ChangeFeedID, | ||
) (Factory, error) { | ||
return &saramaFactory{ | ||
changefeedID: changefeedID, | ||
option: o, | ||
registry: metrics.NewRegistry(), | ||
}, nil | ||
} | ||
|
||
func (f *saramaFactory) AdminClient(ctx context.Context) (ClusterAdminClient, error) { | ||
start := time.Now() | ||
config, err := NewSaramaConfig(ctx, f.option) | ||
duration := time.Since(start).Seconds() | ||
if duration > 2 { | ||
log.Warn("new sarama config cost too much time", zap.Any("duration", duration), zap.Stringer("changefeedID", f.changefeedID)) | ||
} | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
start = time.Now() | ||
client, err := sarama.NewClient(f.option.BrokerEndpoints, config) | ||
duration = time.Since(start).Seconds() | ||
if duration > 2 { | ||
log.Warn("new sarama client cost too much time", zap.Any("duration", duration), zap.Stringer("changefeedID", f.changefeedID)) | ||
} | ||
if err != nil { | ||
return nil, errors.Trace(err) | ||
} | ||
|
||
start = time.Now() | ||
admin, err := sarama.NewClusterAdminFromClient(client) | ||
duration = time.Since(start).Seconds() | ||
if duration > 2 { | ||
log.Warn("new sarama cluster admin cost too much time", zap.Any("duration", duration), zap.Stringer("changefeedID", f.changefeedID)) | ||
} | ||
if err != nil { | ||
return nil, errors.Trace(err) | ||
} | ||
return &saramaAdminClient{ | ||
client: client, | ||
admin: admin, | ||
changefeed: f.changefeedID, | ||
}, nil | ||
} | ||
|
||
// SyncProducer returns a Sync Producer, | ||
// it should be the caller's responsibility to close the producer | ||
func (f *saramaFactory) SyncProducer(ctx context.Context) (SyncProducer, error) { | ||
config, err := NewSaramaConfig(ctx, f.option) | ||
if err != nil { | ||
return nil, err | ||
} | ||
config.MetricRegistry = f.registry | ||
|
||
client, err := sarama.NewClient(f.option.BrokerEndpoints, config) | ||
if err != nil { | ||
return nil, errors.Trace(err) | ||
} | ||
|
||
p, err := sarama.NewSyncProducerFromClient(client) | ||
if err != nil { | ||
return nil, errors.Trace(err) | ||
} | ||
return &saramaSyncProducer{ | ||
id: f.changefeedID, | ||
client: client, | ||
producer: p, | ||
}, nil | ||
} | ||
|
||
// AsyncProducer return an Async Producer, | ||
// it should be the caller's responsibility to close the producer | ||
func (f *saramaFactory) AsyncProducer( | ||
ctx context.Context, | ||
failpointCh chan error, | ||
) (AsyncProducer, error) { | ||
config, err := NewSaramaConfig(ctx, f.option) | ||
if err != nil { | ||
return nil, err | ||
} | ||
config.MetricRegistry = f.registry | ||
|
||
client, err := sarama.NewClient(f.option.BrokerEndpoints, config) | ||
if err != nil { | ||
return nil, errors.Trace(err) | ||
} | ||
p, err := sarama.NewAsyncProducerFromClient(client) | ||
if err != nil { | ||
return nil, errors.Trace(err) | ||
} | ||
return &saramaAsyncProducer{ | ||
client: client, | ||
producer: p, | ||
changefeedID: f.changefeedID, | ||
failpointCh: failpointCh, | ||
}, nil | ||
} | ||
|
||
func (f *saramaFactory) MetricsCollector( | ||
role util.Role, | ||
adminClient ClusterAdminClient, | ||
) MetricsCollector { | ||
return NewSaramaMetricsCollector( | ||
f.changefeedID, role, adminClient, f.registry) | ||
} |
2 changes: 0 additions & 2 deletions
2
tests/integration_tests/hang_sink_suicide/conf/changefeed.toml
This file was deleted.
Oops, something went wrong.
29 changes: 0 additions & 29 deletions
29
tests/integration_tests/hang_sink_suicide/conf/diff_config.toml
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters