From 5b739f6166c5f111f67d5272cd3621a2da7626c0 Mon Sep 17 00:00:00 2001 From: rick Date: Sat, 30 Nov 2013 10:05:48 -0700 Subject: [PATCH] track CompareAndDelete stats --- store/stats.go | 14 +++++++++++++- store/store.go | 10 +++++----- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/store/stats.go b/store/stats.go index 2eb271d73..5f3cd62a3 100644 --- a/store/stats.go +++ b/store/stats.go @@ -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) } diff --git a/store/store.go b/store/store.go index 39ee3b136..08a9e1702 100644 --- a/store/store.go +++ b/store/store.go @@ -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) }