-
Notifications
You must be signed in to change notification settings - Fork 726
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
*:Rollback config in store when kv.persist failed #1476
Merged
Merged
Changes from 29 commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
b966728
Merge pull request #1 from pingcap/master
bradyjoestar b263e13
Merge pull request #2 from pingcap/master
bradyjoestar 3af8fe3
clear store when persist failed
swbsin 7c02023
log more info
swbsin bc77251
gofmt
swbsin c677fd2
fix error info
swbsin 98f9c4b
Merge branch 'master' into issue-1475
bradyjoestar 5abed59
Merge branch 'master' into issue-1475
bradyjoestar 8e1ec51
Merge branch 'master' into issue-1475
bradyjoestar a77a952
add unit_test
swbsin 3a758c3
try to debug jenkins error
swbsin 237f5a5
try to fix jenkins bug
swbsin 892d1b7
try to fix jenkins error
swbsin 19a566b
fix data race bug
swbsin b5fbb9d
prolong time for region kv to flush
swbsin 5548cdc
Update region_syncer_test.go
bradyjoestar ea2da65
better output log
swbsin 2441a70
Merge branch 'master' into issue-1475
nolouch 800ed08
Merge branch 'master' into issue-1475
bradyjoestar 300ac33
convert 5s to 3s
bradyjoestar 8a090f4
Merge branch 'issue-1475' of github.com:bradyjoestar/pd into issue-1475
bradyjoestar fbb7cc8
Merge branch 'master' into issue-1475
nolouch 54e34c0
Merge branch 'master' into issue-1475
bradyjoestar 28689dc
replace sync.map
bradyjoestar bd2754c
fix ci bug
bradyjoestar 2f777cc
rebuild jenkins
bradyjoestar 6ad3899
Merge branch 'master' into issue-1475
bradyjoestar 51e9451
Merge branch 'master' into issue-1475
bradyjoestar 21c62e4
Merge branch 'master' into issue-1475
nolouch 4b64562
extract function
bradyjoestar 0ec5424
go fmt
bradyjoestar 4db8982
revert system_mon
bradyjoestar 0446e27
Merge branch 'master' into issue-1475
bradyjoestar b710e24
Merge branch 'master' into issue-1475
nolouch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ package server | |
|
||
import ( | ||
"reflect" | ||
"sync" | ||
"sync/atomic" | ||
"time" | ||
|
||
|
@@ -28,7 +29,7 @@ import ( | |
type scheduleOption struct { | ||
v atomic.Value | ||
rep *Replication | ||
ns map[string]*namespaceOption | ||
ns sync.Map // concurrent map[string]*namespaceOption | ||
labelProperty atomic.Value | ||
clusterVersion atomic.Value | ||
pdServerConfig atomic.Value | ||
|
@@ -37,10 +38,10 @@ type scheduleOption struct { | |
func newScheduleOption(cfg *Config) *scheduleOption { | ||
o := &scheduleOption{} | ||
o.store(&cfg.Schedule) | ||
o.ns = make(map[string]*namespaceOption) | ||
o.ns = sync.Map{} | ||
for name, nsCfg := range cfg.Namespace { | ||
nsCfg := nsCfg | ||
o.ns[name] = newNamespaceOption(&nsCfg) | ||
o.ns.Store(name, newNamespaceOption(&nsCfg)) | ||
} | ||
o.rep = newReplication(&cfg.Replication) | ||
o.pdServerConfig.Store(&cfg.PDServerCfg) | ||
|
@@ -61,8 +62,17 @@ func (o *scheduleOption) GetReplication() *Replication { | |
return o.rep | ||
} | ||
|
||
func (o *scheduleOption) getNS(name string) (*namespaceOption, bool) { | ||
if n, ok := o.ns.Load(name); ok { | ||
if n, ok := n.(*namespaceOption); ok { | ||
return n, true | ||
} | ||
} | ||
return nil, false | ||
} | ||
|
||
func (o *scheduleOption) GetMaxReplicas(name string) int { | ||
if n, ok := o.ns[name]; ok { | ||
if n, ok := o.getNS(name); ok { | ||
return n.GetMaxReplicas() | ||
} | ||
return o.rep.GetMaxReplicas() | ||
|
@@ -105,35 +115,35 @@ func (o *scheduleOption) GetMaxStoreDownTime() time.Duration { | |
} | ||
|
||
func (o *scheduleOption) GetLeaderScheduleLimit(name string) uint64 { | ||
if n, ok := o.ns[name]; ok { | ||
if n, ok := o.getNS(name); ok { | ||
return n.GetLeaderScheduleLimit() | ||
} | ||
return o.load().LeaderScheduleLimit | ||
} | ||
|
||
func (o *scheduleOption) GetRegionScheduleLimit(name string) uint64 { | ||
if n, ok := o.ns[name]; ok { | ||
if n, ok := o.getNS(name); ok { | ||
return n.GetRegionScheduleLimit() | ||
} | ||
return o.load().RegionScheduleLimit | ||
} | ||
|
||
func (o *scheduleOption) GetReplicaScheduleLimit(name string) uint64 { | ||
if n, ok := o.ns[name]; ok { | ||
if n, ok := o.getNS(name); ok { | ||
return n.GetReplicaScheduleLimit() | ||
} | ||
return o.load().ReplicaScheduleLimit | ||
} | ||
|
||
func (o *scheduleOption) GetMergeScheduleLimit(name string) uint64 { | ||
if n, ok := o.ns[name]; ok { | ||
if n, ok := o.getNS(name); ok { | ||
return n.GetMergeScheduleLimit() | ||
} | ||
return o.load().MergeScheduleLimit | ||
} | ||
|
||
func (o *scheduleOption) GetHotRegionScheduleLimit(name string) uint64 { | ||
if n, ok := o.ns[name]; ok { | ||
if n, ok := o.getNS(name); ok { | ||
return n.GetHotRegionScheduleLimit() | ||
} | ||
return o.load().HotRegionScheduleLimit | ||
|
@@ -273,9 +283,21 @@ func (o *scheduleOption) loadPDServerConfig() *PDServerConfig { | |
|
||
func (o *scheduleOption) persist(kv *core.KV) error { | ||
namespaces := make(map[string]NamespaceConfig) | ||
for name, ns := range o.ns { | ||
namespaces[name] = *ns.load() | ||
|
||
f := func(k, v interface{}) bool { | ||
var kstr string | ||
var ok bool | ||
if kstr, ok = k.(string); !ok { | ||
return false | ||
} | ||
if ns, ok := v.(*namespaceOption); ok { | ||
namespaces[kstr] = *ns.load() | ||
return true | ||
} | ||
return false | ||
} | ||
o.ns.Range(f) | ||
|
||
cfg := &Config{ | ||
Schedule: *o.load(), | ||
Replication: *o.rep.load(), | ||
|
@@ -290,9 +312,21 @@ func (o *scheduleOption) persist(kv *core.KV) error { | |
|
||
func (o *scheduleOption) reload(kv *core.KV) error { | ||
namespaces := make(map[string]NamespaceConfig) | ||
for name, ns := range o.ns { | ||
namespaces[name] = *ns.load() | ||
|
||
f := func(k, v interface{}) bool { | ||
var kstr string | ||
var ok bool | ||
if kstr, ok = k.(string); !ok { | ||
return false | ||
} | ||
if ns, ok := v.(*namespaceOption); ok { | ||
namespaces[kstr] = *ns.load() | ||
return true | ||
} | ||
return false | ||
} | ||
o.ns.Range(f) | ||
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. em, this part is exactly the same with the code block in 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. Sure!:ok_hand: |
||
|
||
cfg := &Config{ | ||
Schedule: *o.load().clone(), | ||
Replication: *o.rep.load(), | ||
|
@@ -311,7 +345,7 @@ func (o *scheduleOption) reload(kv *core.KV) error { | |
o.rep.store(&cfg.Replication) | ||
for name, nsCfg := range cfg.Namespace { | ||
nsCfg := nsCfg | ||
o.ns[name] = newNamespaceOption(&nsCfg) | ||
o.ns.Store(name, newNamespaceOption(&nsCfg)) | ||
} | ||
o.labelProperty.Store(cfg.LabelProperty) | ||
o.clusterVersion.Store(cfg.ClusterVersion) | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Seems not in good order. We recommend to put it with other 3rd part packages.