Browse Source

track CompareAndDelete stats

rick 12 years ago
parent
commit
5b739f6166
2 changed files with 18 additions and 6 deletions
  1. 13 1
      store/stats.go
  2. 5 5
      store/store.go

+ 13 - 1
store/stats.go

@@ -35,6 +35,8 @@ const (
 	GetSuccess
 	GetSuccess
 	GetFail
 	GetFail
 	ExpireCount
 	ExpireCount
+	CompareAndDeleteSuccess
+	CompareAndDeleteFail
 )
 )
 
 
 type Stats struct {
 type Stats struct {
@@ -63,6 +65,10 @@ type Stats struct {
 	CompareAndSwapSuccess uint64 `json:"compareAndSwapSuccess"`
 	CompareAndSwapSuccess uint64 `json:"compareAndSwapSuccess"`
 	CompareAndSwapFail    uint64 `json:"compareAndSwapFail"`
 	CompareAndSwapFail    uint64 `json:"compareAndSwapFail"`
 
 
+	// Number of compareAndDelete requests
+	CompareAndDeleteSuccess uint64 `json:"compareAndDeleteSuccess"`
+	CompareAndDeleteFail    uint64 `json:"compareAndDeleteFail"`
+
 	ExpireCount uint64 `json:"expireCount"`
 	ExpireCount uint64 `json:"expireCount"`
 
 
 	Watchers uint64 `json:"watchers"`
 	Watchers uint64 `json:"watchers"`
@@ -76,7 +82,8 @@ func newStats() *Stats {
 func (s *Stats) clone() *Stats {
 func (s *Stats) clone() *Stats {
 	return &Stats{s.GetSuccess, s.GetFail, s.SetSuccess, s.SetFail,
 	return &Stats{s.GetSuccess, s.GetFail, s.SetSuccess, s.SetFail,
 		s.DeleteSuccess, s.DeleteFail, s.UpdateSuccess, s.UpdateFail, s.CreateSuccess,
 		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
 // 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 +
 	return s.SetSuccess + s.SetFail +
 		s.DeleteSuccess + s.DeleteFail +
 		s.DeleteSuccess + s.DeleteFail +
 		s.CompareAndSwapSuccess + s.CompareAndSwapFail +
 		s.CompareAndSwapSuccess + s.CompareAndSwapFail +
+		s.CompareAndDeleteSuccess + s.CompareAndDeleteFail +
 		s.UpdateSuccess + s.UpdateFail
 		s.UpdateSuccess + s.UpdateFail
 }
 }
 
 
@@ -122,6 +130,10 @@ func (s *Stats) Inc(field int) {
 		atomic.AddUint64(&s.CompareAndSwapSuccess, 1)
 		atomic.AddUint64(&s.CompareAndSwapSuccess, 1)
 	case CompareAndSwapFail:
 	case CompareAndSwapFail:
 		atomic.AddUint64(&s.CompareAndSwapFail, 1)
 		atomic.AddUint64(&s.CompareAndSwapFail, 1)
+	case CompareAndDeleteSuccess:
+		atomic.AddUint64(&s.CompareAndDeleteSuccess, 1)
+	case CompareAndDeleteFail:
+		atomic.AddUint64(&s.CompareAndDeleteFail, 1)
 	case ExpireCount:
 	case ExpireCount:
 		atomic.AddUint64(&s.ExpireCount, 1)
 		atomic.AddUint64(&s.ExpireCount, 1)
 	}
 	}

+ 5 - 5
store/store.go

@@ -291,12 +291,12 @@ func (s *store) CompareAndDelete(nodePath string, prevValue string, prevIndex ui
 	n, err := s.internalGet(nodePath)
 	n, err := s.internalGet(nodePath)
 
 
 	if err != nil { // if the node does not exist, return error
 	if err != nil { // if the node does not exist, return error
-		s.Stats.Inc(DeleteFail)
+		s.Stats.Inc(CompareAndDeleteFail)
 		return nil, err
 		return nil, err
 	}
 	}
 
 
 	if n.IsDir() { // can only test and set file
 	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)
 		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)
 		err = n.Remove(false, callback)
 
 
 		if err != nil {
 		if err != nil {
-			s.Stats.Inc(DeleteFail)
+			s.Stats.Inc(CompareAndDeleteFail)
 			return nil, err
 			return nil, err
 		}
 		}
 
 
@@ -323,12 +323,12 @@ func (s *store) CompareAndDelete(nodePath string, prevValue string, prevIndex ui
 		s.CurrentIndex++
 		s.CurrentIndex++
 
 
 		s.WatcherHub.notify(e)
 		s.WatcherHub.notify(e)
-		s.Stats.Inc(DeleteSuccess)
+		s.Stats.Inc(CompareAndDeleteSuccess)
 		return e, nil
 		return e, nil
 	}
 	}
 
 
 	cause := fmt.Sprintf("[%v != %v] [%v != %v]", prevValue, n.Value, prevIndex, n.ModifiedIndex)
 	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)
 	return nil, etcdErr.NewError(etcdErr.EcodeTestFailed, cause, s.CurrentIndex)
 }
 }