github.com/pingcap/ticdc@v0.0.0-20220526033649-485a10ef2652/pkg/config/cyclic.go (about) 1 // Copyright 2020 PingCAP, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package config 15 16 import ( 17 "encoding/json" 18 19 "github.com/pingcap/errors" 20 ) 21 22 // CyclicConfig represents config used for cyclic replication 23 type CyclicConfig struct { 24 Enable bool `toml:"enable" json:"enable"` 25 ReplicaID uint64 `toml:"replica-id" json:"replica-id"` 26 FilterReplicaID []uint64 `toml:"filter-replica-ids" json:"filter-replica-ids"` 27 IDBuckets int `toml:"id-buckets" json:"id-buckets"` 28 SyncDDL bool `toml:"sync-ddl" json:"sync-ddl"` 29 } 30 31 // IsEnabled returns whether cyclic replication is enabled or not. 32 func (c *CyclicConfig) IsEnabled() bool { 33 return c != nil && c.Enable 34 } 35 36 // Marshal returns the json marshal format of a ReplicationConfig 37 func (c *CyclicConfig) Marshal() (string, error) { 38 cfg, err := json.Marshal(c) 39 if err != nil { 40 return "", errors.Annotatef(err, "Unmarshal data: %v", c) 41 } 42 return string(cfg), nil 43 } 44 45 // Unmarshal unmarshals into *ReplicationConfig from json marshal byte slice 46 func (c *CyclicConfig) Unmarshal(data []byte) error { 47 return json.Unmarshal(data, c) 48 }