Merge pull request #1326 from coolljt0725/fix_update_endpoint_cnt
Fix update endpoint count to store
This commit is contained in:
commit
7b470ea14d
1 changed files with 10 additions and 1 deletions
|
@ -113,6 +113,9 @@ func (ec *endpointCnt) updateStore() error {
|
||||||
if store == nil {
|
if store == nil {
|
||||||
return fmt.Errorf("store not found for scope %s on endpoint count update", ec.DataScope())
|
return fmt.Errorf("store not found for scope %s on endpoint count update", ec.DataScope())
|
||||||
}
|
}
|
||||||
|
// make a copy of count and n to avoid being overwritten by store.GetObject
|
||||||
|
count := ec.EndpointCnt()
|
||||||
|
n := ec.n
|
||||||
for {
|
for {
|
||||||
if err := ec.n.getController().updateToStore(ec); err == nil || err != datastore.ErrKeyModified {
|
if err := ec.n.getController().updateToStore(ec); err == nil || err != datastore.ErrKeyModified {
|
||||||
return err
|
return err
|
||||||
|
@ -120,6 +123,10 @@ func (ec *endpointCnt) updateStore() error {
|
||||||
if err := store.GetObject(datastore.Key(ec.Key()...), ec); err != nil {
|
if err := store.GetObject(datastore.Key(ec.Key()...), ec); err != nil {
|
||||||
return fmt.Errorf("could not update the kvobject to latest on endpoint count update: %v", err)
|
return fmt.Errorf("could not update the kvobject to latest on endpoint count update: %v", err)
|
||||||
}
|
}
|
||||||
|
ec.Lock()
|
||||||
|
ec.Count = count
|
||||||
|
ec.n = n
|
||||||
|
ec.Unlock()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,8 +143,10 @@ retry:
|
||||||
if inc {
|
if inc {
|
||||||
ec.Count++
|
ec.Count++
|
||||||
} else {
|
} else {
|
||||||
|
if ec.Count > 0 {
|
||||||
ec.Count--
|
ec.Count--
|
||||||
}
|
}
|
||||||
|
}
|
||||||
ec.Unlock()
|
ec.Unlock()
|
||||||
|
|
||||||
store := ec.n.getController().getStore(ec.DataScope())
|
store := ec.n.getController().getStore(ec.DataScope())
|
||||||
|
|
Loading…
Add table
Reference in a new issue