diff --git a/cdc/processor/sinkmanager/manager.go b/cdc/processor/sinkmanager/manager.go index 49528e7fc3b..694b248a7ce 100644 --- a/cdc/processor/sinkmanager/manager.go +++ b/cdc/processor/sinkmanager/manager.go @@ -164,15 +164,13 @@ func New( m.redoTaskChan = make(chan *redoTask) m.redoWorkerAvailable = make(chan struct{}, 1) - if changefeedInfo.Config.Consistent.EnableEventCache { - // 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 - m.redoMemQuota = memquota.NewMemQuota(changefeedID, redoQuota, "redo") - m.eventCache = newRedoEventCache(changefeedID, redoQuota/2*1) - } else { - m.sinkMemQuota = memquota.NewMemQuota(changefeedID, changefeedInfo.Config.MemoryQuota/2, "sink") - m.redoMemQuota = memquota.NewMemQuota(changefeedID, changefeedInfo.Config.MemoryQuota/2, "redo") + redoQuota := uint64(float64(changefeedInfo.Config.MemoryQuota*changefeedInfo.Config.Consistent.MemoryQuotaPercentage) / 100) + sinkQuota := changefeedInfo.Config.MemoryQuota - redoQuota + m.sinkMemQuota = memquota.NewMemQuota(changefeedID, sinkQuota, "sink") + m.redoMemQuota = memquota.NewMemQuota(changefeedID, redoQuota, "redo") + eventCache := uint64(float64(redoQuota*changefeedInfo.Config.Consistent.EventCachePercentage) / 100) + if eventCache > 0 { + m.eventCache = newRedoEventCache(changefeedID, eventCache) } } else { m.sinkMemQuota = memquota.NewMemQuota(changefeedID, changefeedInfo.Config.MemoryQuota, "sink") diff --git a/pkg/config/config_test_data.go b/pkg/config/config_test_data.go index b713adbf628..d2c15920865 100644 --- a/pkg/config/config_test_data.go +++ b/pkg/config/config_test_data.go @@ -76,7 +76,8 @@ const ( "flush-worker-num": 8, "storage": "", "use-file-backend": false, - "enable-event-cache": false + "memory-quota-percentage": 50, + "event-cache-percentage": 0 }, "scheduler": { "enable-table-across-nodes": false, @@ -315,7 +316,8 @@ const ( "flush-worker-num": 8, "storage": "", "use-file-backend": false, - "enable-event-cache": false + "memory-quota-percentage": 50, + "event-cache-percentage": 0 }, "scheduler": { "enable-table-across-nodes": true, @@ -468,7 +470,8 @@ const ( "flush-worker-num": 8, "storage": "", "use-file-backend": false, - "enable-event-cache": false + "memory-quota-percentage": 50, + "event-cache-percentage": 0 }, "scheduler": { "enable-table-across-nodes": true, diff --git a/pkg/config/consistent.go b/pkg/config/consistent.go index 1b99e9c5bcc..bf90ff5dcf9 100644 --- a/pkg/config/consistent.go +++ b/pkg/config/consistent.go @@ -32,7 +32,11 @@ type ConsistentConfig struct { FlushWorkerNum int `toml:"flush-worker-num" json:"flush-worker-num"` Storage string `toml:"storage" json:"storage"` UseFileBackend bool `toml:"use-file-backend" json:"use-file-backend"` - EnableEventCache bool `toml:"enable-event-cache" json:"enable-event-cache"` + // 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. diff --git a/pkg/config/replica_config.go b/pkg/config/replica_config.go index 869a4458e92..1a347b4fba6 100644 --- a/pkg/config/replica_config.go +++ b/pkg/config/replica_config.go @@ -88,6 +88,8 @@ var defaultReplicaConfig = &ReplicaConfig{ FlushWorkerNum: redo.DefaultFlushWorkerNum, Storage: "", UseFileBackend: false, + MemoryQuotaPercentage: 50, + EventCachePercentage: 0, }, Scheduler: &ChangefeedSchedulerConfig{ EnableTableAcrossNodes: false,