Skip to content
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

redo(ticdc): use multi part s3 uploader in redo (#10227) #10233

Merged
Merged
Show file tree
Hide file tree
Changes from all 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: 3 additions & 0 deletions cdc/api/v2/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ func (c *ReplicaConfig) toInternalReplicaConfigWithOriginConfig(
Storage: c.Consistent.Storage,
UseFileBackend: c.Consistent.UseFileBackend,
Compression: c.Consistent.Compression,
FlushConcurrency: c.Consistent.FlushConcurrency,
}
}
if c.Sink != nil {
Expand Down Expand Up @@ -502,6 +503,7 @@ func ToAPIReplicaConfig(c *config.ReplicaConfig) *ReplicaConfig {
Storage: cloned.Consistent.Storage,
UseFileBackend: cloned.Consistent.UseFileBackend,
Compression: cloned.Consistent.Compression,
FlushConcurrency: cloned.Consistent.FlushConcurrency,
}
}
if cloned.Mounter != nil {
Expand Down Expand Up @@ -690,6 +692,7 @@ type ConsistentConfig struct {
Storage string `json:"storage,omitempty"`
UseFileBackend bool `json:"use_file_backend"`
Compression string `json:"compression,omitempty"`
FlushConcurrency int `json:"flush_concurrency,omitempty"`
}

// ChangefeedSchedulerConfig is per changefeed scheduler settings.
Expand Down
20 changes: 19 additions & 1 deletion cdc/redo/writer/memory/file_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,12 @@ func (f *fileWorkerGroup) bgFlushFileCache(egCtx context.Context) error {
if err := file.writer.Close(); err != nil {
return errors.Trace(err)
}
err := f.extStorage.WriteFile(egCtx, file.filename, file.writer.buf.Bytes())
var err error
if f.cfg.FlushConcurrency <= 1 {
err = f.extStorage.WriteFile(egCtx, file.filename, file.writer.buf.Bytes())
} else {
err = f.multiPartUpload(egCtx, file)
}
f.metricFlushAllDuration.Observe(time.Since(start).Seconds())
if err != nil {
return errors.Trace(err)
Expand All @@ -204,6 +209,19 @@ func (f *fileWorkerGroup) bgFlushFileCache(egCtx context.Context) error {
}
}

func (f *fileWorkerGroup) multiPartUpload(ctx context.Context, file *fileCache) error {
multipartWrite, err := f.extStorage.Create(ctx, file.filename, &storage.WriterOption{
Concurrency: f.cfg.FlushConcurrency,
})
if err != nil {
return errors.Trace(err)
}
if _, err = multipartWrite.Write(ctx, file.writer.buf.Bytes()); err != nil {
return errors.Trace(err)
}
return errors.Trace(multipartWrite.Close(ctx))
}

func (f *fileWorkerGroup) bgWriteLogs(
egCtx context.Context, inputCh <-chan *polymorphicRedoEvent,
) (err error) {
Expand Down
1 change: 1 addition & 0 deletions pkg/config/consistent.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type ConsistentConfig struct {
Storage string `toml:"storage" json:"storage"`
UseFileBackend bool `toml:"use-file-backend" json:"use-file-backend"`
Compression string `toml:"compression" json:"compression"`
FlushConcurrency int `toml:"flush-concurrency" json:"flush-concurrency,omitempty"`
}

// ValidateAndAdjust validates the consistency config and adjusts it if necessary.
Expand Down
8 changes: 6 additions & 2 deletions pkg/util/external_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,12 @@ func (s *extStorageWithTimeout) WalkDir(
func (s *extStorageWithTimeout) Create(
ctx context.Context, path string, option *storage.WriterOption,
) (storage.ExternalFileWriter, error) {
ctx, cancel := context.WithTimeout(ctx, s.timeout)
defer cancel()
if option.Concurrency <= 1 {
var cancel context.CancelFunc
ctx, cancel = context.WithTimeout(ctx, s.timeout)
defer cancel()
}
// multipart uploading spawns a background goroutine, can't set timeout
return s.ExternalStorage.Create(ctx, path, option)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[consistent]
level = "eventual"
storage = "s3://logbucket/test-changefeed?endpoint=http://127.0.0.1:24927/"
flush-concurrency = 2
Loading