-
Notifications
You must be signed in to change notification settings - Fork 720
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
*: prevent store config updating periodically #7163
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,10 +19,12 @@ import ( | |
"strings" | ||
"sync" | ||
|
||
"github.com/pingcap/log" | ||
"github.com/tikv/pd/pkg/storage/endpoint" | ||
"github.com/tikv/pd/pkg/utils/etcdutil" | ||
"go.etcd.io/etcd/clientv3" | ||
"go.etcd.io/etcd/mvcc/mvccpb" | ||
"go.uber.org/zap" | ||
) | ||
|
||
// ruleStorage is an in-memory storage for Placement Rules, | ||
|
@@ -163,12 +165,14 @@ func (rw *Watcher) initializeRuleWatcher() error { | |
putFn := func(kv *mvccpb.KeyValue) error { | ||
// Since the PD API server will validate the rule before saving it to etcd, | ||
// so we could directly save the string rule in JSON to the storage here. | ||
log.Info("update placement rule", zap.String("key", string(kv.Key)), zap.String("value", string(kv.Value))) | ||
return rw.ruleStore.SaveRule( | ||
strings.TrimPrefix(string(kv.Key), prefixToTrim), | ||
string(kv.Value), | ||
) | ||
} | ||
deleteFn := func(kv *mvccpb.KeyValue) error { | ||
log.Info("delete placement rule", zap.String("key", string(kv.Key))) | ||
Comment on lines
167
to
+175
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will it print a lot of logs? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we frequently add/remove the rule, it will, like the current status of the audit log. However, we cannot change the log level for microservices. Once it is supported, I can change it to the debug level if it's too noisy. Right now, it is more convenient for us to test. |
||
return rw.ruleStore.DeleteRule(strings.TrimPrefix(string(kv.Key), prefixToTrim)) | ||
} | ||
postEventFn := func() error { | ||
|
@@ -188,12 +192,14 @@ func (rw *Watcher) initializeRuleWatcher() error { | |
func (rw *Watcher) initializeGroupWatcher() error { | ||
prefixToTrim := rw.ruleGroupPathPrefix + "/" | ||
putFn := func(kv *mvccpb.KeyValue) error { | ||
log.Info("update placement rule group", zap.String("key", string(kv.Key)), zap.String("value", string(kv.Value))) | ||
return rw.ruleStore.SaveRuleGroup( | ||
strings.TrimPrefix(string(kv.Key), prefixToTrim), | ||
string(kv.Value), | ||
) | ||
} | ||
deleteFn := func(kv *mvccpb.KeyValue) error { | ||
log.Info("delete placement rule group", zap.String("key", string(kv.Key))) | ||
return rw.ruleStore.DeleteRuleGroup(strings.TrimPrefix(string(kv.Key), prefixToTrim)) | ||
} | ||
postEventFn := func() error { | ||
|
@@ -213,12 +219,14 @@ func (rw *Watcher) initializeGroupWatcher() error { | |
func (rw *Watcher) initializeRegionLabelWatcher() error { | ||
prefixToTrim := rw.regionLabelPathPrefix + "/" | ||
putFn := func(kv *mvccpb.KeyValue) error { | ||
log.Info("update region label rule", zap.String("key", string(kv.Key)), zap.String("value", string(kv.Value))) | ||
return rw.ruleStore.SaveRegionRule( | ||
strings.TrimPrefix(string(kv.Key), prefixToTrim), | ||
string(kv.Value), | ||
) | ||
} | ||
deleteFn := func(kv *mvccpb.KeyValue) error { | ||
log.Info("delete region label rule", zap.String("key", string(kv.Key))) | ||
return rw.ruleStore.DeleteRegionRule(strings.TrimPrefix(string(kv.Key), prefixToTrim)) | ||
} | ||
postEventFn := func() error { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -427,8 +427,8 @@ | |
defer c.wg.Done() | ||
|
||
var ( | ||
synced, switchRaftV2Config bool | ||
stores = c.GetStores() | ||
synced, switchRaftV2Config, isLastSynced bool | ||
stores = c.GetStores() | ||
) | ||
// Start the ticker with a second-level timer to accelerate | ||
// the bootstrap stage. | ||
|
@@ -441,11 +441,14 @@ | |
log.Warn("store config persisted failed", zap.Error(err)) | ||
} | ||
} | ||
isLastSynced = synced | ||
// Update the stores if the synchronization is not completed. | ||
if !synced { | ||
stores = c.GetStores() | ||
} else if err := c.opt.Persist(c.storage); err != nil { | ||
log.Warn("store config persisted failed", zap.Error(err)) | ||
} else if !isLastSynced && synced { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems to cause the config only to be saved once forever. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, nice catch, let me think about how to fix it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated. PTAL |
||
if err := c.opt.Persist(c.storage); err != nil { | ||
log.Warn("store config persisted failed", zap.Error(err)) | ||
} | ||
} | ||
select { | ||
case <-c.ctx.Done(): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not use zap.String?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated