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(cdc): custom redo event cache and disable it by default (#10139) #10315

Merged
Merged
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
21 changes: 21 additions & 0 deletions cdc/api/v2/model.go
Original file line number Diff line number Diff line change
@@ -274,6 +274,12 @@ func (c *ReplicaConfig) toInternalReplicaConfigWithOriginConfig(
Compression: c.Consistent.Compression,
FlushConcurrency: c.Consistent.FlushConcurrency,
}
if c.Consistent.MemoryUsage != nil {
res.Consistent.MemoryUsage = &config.ConsistentMemoryUsage{
MemoryQuotaPercentage: c.Consistent.MemoryUsage.MemoryQuotaPercentage,
EventCachePercentage: c.Consistent.MemoryUsage.EventCachePercentage,
}
}
}
if c.Sink != nil {
var dispatchRules []*config.DispatchRule
@@ -505,7 +511,14 @@ func ToAPIReplicaConfig(c *config.ReplicaConfig) *ReplicaConfig {
Compression: cloned.Consistent.Compression,
FlushConcurrency: cloned.Consistent.FlushConcurrency,
}
if cloned.Consistent.MemoryUsage != nil {
res.Consistent.MemoryUsage = &ConsistentMemoryUsage{
MemoryQuotaPercentage: cloned.Consistent.MemoryUsage.MemoryQuotaPercentage,
EventCachePercentage: cloned.Consistent.MemoryUsage.EventCachePercentage,
}
}
}

if cloned.Mounter != nil {
res.Mounter = &MounterConfig{
WorkerNum: cloned.Mounter.WorkerNum,
@@ -693,6 +706,14 @@ type ConsistentConfig struct {
UseFileBackend bool `json:"use_file_backend"`
Compression string `json:"compression,omitempty"`
FlushConcurrency int `json:"flush_concurrency,omitempty"`

MemoryUsage *ConsistentMemoryUsage `json:"memory_usage"`
}

// ConsistentMemoryUsage represents memory usage of Consistent module.
type ConsistentMemoryUsage struct {
MemoryQuotaPercentage uint64 `json:"memory_quota_percentage"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

redo_memory_quota_percentage

EventCachePercentage uint64 `json:"event_cache_percentage"`
}

// ChangefeedSchedulerConfig is per changefeed scheduler settings.
4 changes: 4 additions & 0 deletions cdc/api/v2/model_test.go
Original file line number Diff line number Diff line change
@@ -64,6 +64,10 @@ var defaultAPIConfig = &ReplicaConfig{
FlushWorkerNum: redo.DefaultFlushWorkerNum,
Storage: "",
UseFileBackend: false,
MemoryUsage: &ConsistentMemoryUsage{
MemoryQuotaPercentage: 50,
EventCachePercentage: 0,
},
},
ChangefeedErrorStuckDuration: &JSONDuration{config.
GetDefaultReplicaConfig().ChangefeedErrorStuckDuration},
20 changes: 15 additions & 5 deletions cdc/processor/sinkmanager/manager.go
Original file line number Diff line number Diff line change
@@ -160,20 +160,30 @@ func New(
metricsTableSinkTotalRows: metricsTableSinkTotalRows,
}

totalQuota := changefeedInfo.Config.MemoryQuota
if redoDMLMgr != nil && redoDMLMgr.Enabled() {
m.redoDMLMgr = redoDMLMgr
m.redoProgressHeap = newTableProgresses()
m.redoWorkers = make([]*redoWorker, 0, redoWorkerNum)
m.redoTaskChan = make(chan *redoTask)
m.redoWorkerAvailable = make(chan struct{}, 1)

// Use 3/4 memory quota as redo quota, and 1/2 again for redo cache.
m.sinkMemQuota = memquota.NewMemQuota(changefeedID, changefeedInfo.Config.MemoryQuota/4*1, "sink")
redoQuota := changefeedInfo.Config.MemoryQuota / 4 * 3
consistentMemoryUsage := changefeedInfo.Config.Consistent.MemoryUsage
if consistentMemoryUsage == nil {
consistentMemoryUsage = config.GetDefaultReplicaConfig().Consistent.MemoryUsage
}

redoQuota := totalQuota * consistentMemoryUsage.MemoryQuotaPercentage / 100
sinkQuota := totalQuota - redoQuota
m.sinkMemQuota = memquota.NewMemQuota(changefeedID, sinkQuota, "sink")
m.redoMemQuota = memquota.NewMemQuota(changefeedID, redoQuota, "redo")
m.eventCache = newRedoEventCache(changefeedID, redoQuota/2*1)

eventCache := redoQuota * consistentMemoryUsage.EventCachePercentage / 100
if eventCache > 0 {
m.eventCache = newRedoEventCache(changefeedID, eventCache)
}
} else {
m.sinkMemQuota = memquota.NewMemQuota(changefeedID, changefeedInfo.Config.MemoryQuota, "sink")
m.sinkMemQuota = memquota.NewMemQuota(changefeedID, totalQuota, "sink")
m.redoMemQuota = memquota.NewMemQuota(changefeedID, 0, "redo")
}

5 changes: 4 additions & 1 deletion cdc/processor/sinkmanager/manager_test.go
Original file line number Diff line number Diff line change
@@ -68,10 +68,13 @@ func createManagerWithMemEngine(
}

func getChangefeedInfo() *model.ChangeFeedInfo {
replicaConfig := config.GetDefaultReplicaConfig()
replicaConfig.Consistent.MemoryUsage.MemoryQuotaPercentage = 75
replicaConfig.Consistent.MemoryUsage.EventCachePercentage = 50
return &model.ChangeFeedInfo{
Error: nil,
SinkURI: "blackhole://",
Config: config.GetDefaultReplicaConfig(),
Config: replicaConfig,
}
}

18 changes: 15 additions & 3 deletions pkg/config/config_test_data.go
Original file line number Diff line number Diff line change
@@ -65,7 +65,11 @@ const (
"encoding-worker-num": 16,
"flush-worker-num": 8,
"storage": "",
"use-file-backend": false
"use-file-backend": false,
"memory-usage": {
"memory-quota-percentage": 50,
"event-cache-percentage": 0
}
},
"changefeed-error-stuck-duration": 1800000000000,
"sql-mode":"ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
@@ -227,7 +231,11 @@ const (
"encoding-worker-num": 16,
"flush-worker-num": 8,
"storage": "",
"use-file-backend": false
"use-file-backend": false,
"memory-usage": {
"memory-quota-percentage": 50,
"event-cache-percentage": 0
}
},
"changefeed-error-stuck-duration": 1800000000000,
"sql-mode":"ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
@@ -293,7 +301,11 @@ const (
"encoding-worker-num": 16,
"flush-worker-num": 8,
"storage": "",
"use-file-backend": false
"use-file-backend": false,
"memory-usage": {
"memory-quota-percentage": 50,
"event-cache-percentage": 0
}
},
"changefeed-error-stuck-duration": 1800000000000,
"sql-mode":"ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
11 changes: 11 additions & 0 deletions pkg/config/consistent.go
Original file line number Diff line number Diff line change
@@ -35,6 +35,17 @@ type ConsistentConfig struct {
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"`

MemoryUsage *ConsistentMemoryUsage `toml:"memory-usage" json:"memory-usage"`
}

// ConsistentMemoryUsage represents memory usage of Consistent module.
type ConsistentMemoryUsage struct {
// ReplicaConfig.MemoryQuota * MemoryQuotaPercentage / 100 will be used for redo events.
MemoryQuotaPercentage uint64 `toml:"memory-quota-percentage" json:"memory-quota-percentage"`
// ReplicaConfig.MemoryQuota * MemoryQuotaPercentage / 100 * EventCachePercentage / 100
// will be used for redo cache.
EventCachePercentage uint64 `toml:"event-cache-percentage" json:"event-cache-percentage"`
}

// ValidateAndAdjust validates the consistency config and adjusts it if necessary.
4 changes: 4 additions & 0 deletions pkg/config/replica_config.go
Original file line number Diff line number Diff line change
@@ -82,6 +82,10 @@ var defaultReplicaConfig = &ReplicaConfig{
Storage: "",
UseFileBackend: false,
Compression: "",
MemoryUsage: &ConsistentMemoryUsage{
MemoryQuotaPercentage: 50,
EventCachePercentage: 0,
},
},
ChangefeedErrorStuckDuration: time.Minute * 30,
SQLMode: defaultSQLMode,
Loading