mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
track CompareAndDelete stats
This commit is contained in:
parent
702cf1cc36
commit
5b739f6166
@ -35,6 +35,8 @@ const (
|
||||
GetSuccess
|
||||
GetFail
|
||||
ExpireCount
|
||||
CompareAndDeleteSuccess
|
||||
CompareAndDeleteFail
|
||||
)
|
||||
|
||||
type Stats struct {
|
||||
@ -63,6 +65,10 @@ type Stats struct {
|
||||
CompareAndSwapSuccess uint64 `json:"compareAndSwapSuccess"`
|
||||
CompareAndSwapFail uint64 `json:"compareAndSwapFail"`
|
||||
|
||||
// Number of compareAndDelete requests
|
||||
CompareAndDeleteSuccess uint64 `json:"compareAndDeleteSuccess"`
|
||||
CompareAndDeleteFail uint64 `json:"compareAndDeleteFail"`
|
||||
|
||||
ExpireCount uint64 `json:"expireCount"`
|
||||
|
||||
Watchers uint64 `json:"watchers"`
|
||||
@ -76,7 +82,8 @@ func newStats() *Stats {
|
||||
func (s *Stats) clone() *Stats {
|
||||
return &Stats{s.GetSuccess, s.GetFail, s.SetSuccess, s.SetFail,
|
||||
s.DeleteSuccess, s.DeleteFail, s.UpdateSuccess, s.UpdateFail, s.CreateSuccess,
|
||||
s.CreateFail, s.CompareAndSwapSuccess, s.CompareAndSwapFail, s.Watchers, s.ExpireCount}
|
||||
s.CreateFail, s.CompareAndSwapSuccess, s.CompareAndSwapFail,
|
||||
s.CompareAndDeleteSuccess, s.CompareAndDeleteFail, s.Watchers, s.ExpireCount}
|
||||
}
|
||||
|
||||
// Status() return the statistics info of etcd storage its recent start
|
||||
@ -93,6 +100,7 @@ func (s *Stats) TotalTranscations() uint64 {
|
||||
return s.SetSuccess + s.SetFail +
|
||||
s.DeleteSuccess + s.DeleteFail +
|
||||
s.CompareAndSwapSuccess + s.CompareAndSwapFail +
|
||||
s.CompareAndDeleteSuccess + s.CompareAndDeleteFail +
|
||||
s.UpdateSuccess + s.UpdateFail
|
||||
}
|
||||
|
||||
@ -122,6 +130,10 @@ func (s *Stats) Inc(field int) {
|
||||
atomic.AddUint64(&s.CompareAndSwapSuccess, 1)
|
||||
case CompareAndSwapFail:
|
||||
atomic.AddUint64(&s.CompareAndSwapFail, 1)
|
||||
case CompareAndDeleteSuccess:
|
||||
atomic.AddUint64(&s.CompareAndDeleteSuccess, 1)
|
||||
case CompareAndDeleteFail:
|
||||
atomic.AddUint64(&s.CompareAndDeleteFail, 1)
|
||||
case ExpireCount:
|
||||
atomic.AddUint64(&s.ExpireCount, 1)
|
||||
}
|
||||
|
@ -291,12 +291,12 @@ func (s *store) CompareAndDelete(nodePath string, prevValue string, prevIndex ui
|
||||
n, err := s.internalGet(nodePath)
|
||||
|
||||
if err != nil { // if the node does not exist, return error
|
||||
s.Stats.Inc(DeleteFail)
|
||||
s.Stats.Inc(CompareAndDeleteFail)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if n.IsDir() { // can only test and set file
|
||||
s.Stats.Inc(DeleteFail)
|
||||
s.Stats.Inc(CompareAndDeleteFail)
|
||||
return nil, etcdErr.NewError(etcdErr.EcodeNotFile, nodePath, s.CurrentIndex)
|
||||
}
|
||||
|
||||
@ -315,7 +315,7 @@ func (s *store) CompareAndDelete(nodePath string, prevValue string, prevIndex ui
|
||||
err = n.Remove(false, callback)
|
||||
|
||||
if err != nil {
|
||||
s.Stats.Inc(DeleteFail)
|
||||
s.Stats.Inc(CompareAndDeleteFail)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@ -323,12 +323,12 @@ func (s *store) CompareAndDelete(nodePath string, prevValue string, prevIndex ui
|
||||
s.CurrentIndex++
|
||||
|
||||
s.WatcherHub.notify(e)
|
||||
s.Stats.Inc(DeleteSuccess)
|
||||
s.Stats.Inc(CompareAndDeleteSuccess)
|
||||
return e, nil
|
||||
}
|
||||
|
||||
cause := fmt.Sprintf("[%v != %v] [%v != %v]", prevValue, n.Value, prevIndex, n.ModifiedIndex)
|
||||
s.Stats.Inc(DeleteFail)
|
||||
s.Stats.Inc(CompareAndDeleteFail)
|
||||
return nil, etcdErr.NewError(etcdErr.EcodeTestFailed, cause, s.CurrentIndex)
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user