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

Fix rule sync2 #32

Closed
wants to merge 20 commits into from
Closed
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
21 changes: 21 additions & 0 deletions pkg/core/basic_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,3 +309,24 @@ func NewKeyRange(startKey, endKey string) KeyRange {
EndKey: []byte(endKey),
}
}

// KeyRanges is a slice of KeyRange.
type KeyRanges struct {
krs []*KeyRange
}

// Append appends a KeyRange.
func (rs *KeyRanges) Append(startKey, endKey []byte) {
rs.krs = append(rs.krs, &KeyRange{
StartKey: startKey,
EndKey: endKey,
})
}

// Ranges returns the slice of KeyRange.
func (rs *KeyRanges) Ranges() []*KeyRange {
if rs == nil {
return nil
}
return rs.krs
}
3 changes: 2 additions & 1 deletion pkg/keyspace/tso_keyspace_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,10 @@ func (m *GroupManager) initTSONodesWatcher(client *clientv3.Client, clusterID ui
client,
"tso-nodes-watcher",
tsoServiceKey,
func([]*clientv3.Event) error { return nil },
putFn,
deleteFn,
func() error { return nil },
func([]*clientv3.Event) error { return nil },
clientv3.WithRange(tsoServiceEndKey),
)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/mcs/scheduling/server/apis/v1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1330,5 +1330,5 @@ func checkRegionsReplicated(c *gin.Context) {
c.String(http.StatusBadRequest, err.Error())
return
}
c.String(http.StatusOK, state)
c.IndentedJSON(http.StatusOK, state)
}
2 changes: 1 addition & 1 deletion pkg/mcs/scheduling/server/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func NewCluster(parentCtx context.Context, persistConfig *config.PersistConfig,
cancel()
return nil, err
}
ruleManager := placement.NewRuleManager(storage, basicCluster, persistConfig)
ruleManager := placement.NewRuleManager(ctx, storage, basicCluster, persistConfig)
c := &Cluster{
ctx: ctx,
cancel: cancel,
Expand Down
36 changes: 18 additions & 18 deletions pkg/mcs/scheduling/server/config/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,22 +139,21 @@ func (cw *Watcher) initializeConfigWatcher() error {
deleteFn := func(kv *mvccpb.KeyValue) error {
return nil
}
postEventFn := func() error {
return nil
}
cw.configWatcher = etcdutil.NewLoopWatcher(
cw.ctx, &cw.wg,
cw.etcdClient,
"scheduling-config-watcher", cw.configPath,
putFn, deleteFn, postEventFn,
func([]*clientv3.Event) error { return nil },
putFn, deleteFn,
func([]*clientv3.Event) error { return nil },
)
cw.configWatcher.StartWatchLoop()
return cw.configWatcher.WaitLoad()
}

func (cw *Watcher) initializeTTLConfigWatcher() error {
putFn := func(kv *mvccpb.KeyValue) error {
key := string(kv.Key)[len(sc.TTLConfigPrefix)+1:]
key := strings.TrimPrefix(string(kv.Key), sc.TTLConfigPrefix+"/")
value := string(kv.Value)
leaseID := kv.Lease
resp, err := cw.etcdClient.TimeToLive(cw.ctx, clientv3.LeaseID(leaseID))
Expand All @@ -166,18 +165,18 @@ func (cw *Watcher) initializeTTLConfigWatcher() error {
return nil
}
deleteFn := func(kv *mvccpb.KeyValue) error {
key := string(kv.Key)[len(sc.TTLConfigPrefix)+1:]
key := strings.TrimPrefix(string(kv.Key), sc.TTLConfigPrefix+"/")
cw.ttl.PutWithTTL(key, nil, 0)
return nil
}
postEventFn := func() error {
return nil
}
cw.ttlConfigWatcher = etcdutil.NewLoopWatcher(
cw.ctx, &cw.wg,
cw.etcdClient,
"scheduling-ttl-config-watcher", cw.ttlConfigPrefix,
putFn, deleteFn, postEventFn, clientv3.WithPrefix(),
func([]*clientv3.Event) error { return nil },
putFn, deleteFn,
func([]*clientv3.Event) error { return nil },
clientv3.WithPrefix(),
)
cw.ttlConfigWatcher.StartWatchLoop()
return cw.ttlConfigWatcher.WaitLoad()
Expand All @@ -186,13 +185,14 @@ func (cw *Watcher) initializeTTLConfigWatcher() error {
func (cw *Watcher) initializeSchedulerConfigWatcher() error {
prefixToTrim := cw.schedulerConfigPathPrefix + "/"
putFn := func(kv *mvccpb.KeyValue) error {
name := strings.TrimPrefix(string(kv.Key), prefixToTrim)
key := string(kv.Key)
name := strings.TrimPrefix(key, prefixToTrim)
log.Info("update scheduler config", zap.String("name", name),
zap.String("value", string(kv.Value)))
err := cw.storage.SaveSchedulerConfig(name, kv.Value)
if err != nil {
log.Warn("failed to save scheduler config",
zap.String("event-kv-key", string(kv.Key)),
zap.String("event-kv-key", key),
zap.String("trimmed-key", name),
zap.Error(err))
return err
Expand All @@ -204,19 +204,19 @@ func (cw *Watcher) initializeSchedulerConfigWatcher() error {
return nil
}
deleteFn := func(kv *mvccpb.KeyValue) error {
log.Info("remove scheduler config", zap.String("key", string(kv.Key)))
key := string(kv.Key)
log.Info("remove scheduler config", zap.String("key", key))
return cw.storage.RemoveSchedulerConfig(
strings.TrimPrefix(string(kv.Key), prefixToTrim),
strings.TrimPrefix(key, prefixToTrim),
)
}
postEventFn := func() error {
return nil
}
cw.schedulerConfigWatcher = etcdutil.NewLoopWatcher(
cw.ctx, &cw.wg,
cw.etcdClient,
"scheduling-scheduler-config-watcher", cw.schedulerConfigPathPrefix,
putFn, deleteFn, postEventFn,
func([]*clientv3.Event) error { return nil },
putFn, deleteFn,
func([]*clientv3.Event) error { return nil },
clientv3.WithPrefix(),
)
cw.schedulerConfigWatcher.StartWatchLoop()
Expand Down
10 changes: 5 additions & 5 deletions pkg/mcs/scheduling/server/meta/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,10 @@ func NewWatcher(
func (w *Watcher) initializeStoreWatcher() error {
putFn := func(kv *mvccpb.KeyValue) error {
store := &metapb.Store{}
key := string(kv.Key)
if err := proto.Unmarshal(kv.Value, store); err != nil {
log.Warn("failed to unmarshal store entry",
zap.String("event-kv-key", string(kv.Key)), zap.Error(err))
zap.String("event-kv-key", key), zap.Error(err))
return err
}
origin := w.basicCluster.GetStore(store.GetId())
Expand Down Expand Up @@ -104,14 +105,13 @@ func (w *Watcher) initializeStoreWatcher() error {
}
return nil
}
postEventFn := func() error {
return nil
}
w.storeWatcher = etcdutil.NewLoopWatcher(
w.ctx, &w.wg,
w.etcdClient,
"scheduling-store-watcher", w.storePathPrefix,
putFn, deleteFn, postEventFn,
func([]*clientv3.Event) error { return nil },
putFn, deleteFn,
func([]*clientv3.Event) error { return nil },
clientv3.WithPrefix(),
)
w.storeWatcher.StartWatchLoop()
Expand Down
Loading
Loading