Browse Source

refactor(node_extern.go) remove unused prevValue field

Xiang Li 12 years ago
parent
commit
189b98c03f
4 changed files with 2 additions and 18 deletions
  1. 2 2
      store/event.go
  2. 0 1
      store/node_extern.go
  3. 0 6
      store/store.go
  4. 0 9
      store/store_test.go

+ 2 - 2
store/event.go

@@ -35,7 +35,7 @@ func (e *Event) IsCreated() bool {
 		return true
 		return true
 	}
 	}
 
 
-	if e.Action == Set && e.Node.PrevValue == "" {
+	if e.Action == Set && e.PrevNode == nil {
 		return true
 		return true
 	}
 	}
 
 
@@ -53,7 +53,7 @@ func (event *Event) Response(currentIndex uint64) interface{} {
 			Action:     event.Action,
 			Action:     event.Action,
 			Key:        event.Node.Key,
 			Key:        event.Node.Key,
 			Value:      event.Node.Value,
 			Value:      event.Node.Value,
-			PrevValue:  event.Node.PrevValue,
+			PrevValue:  event.PrevNode.Value,
 			Index:      event.Node.ModifiedIndex,
 			Index:      event.Node.ModifiedIndex,
 			TTL:        event.Node.TTL,
 			TTL:        event.Node.TTL,
 			Expiration: event.Node.Expiration,
 			Expiration: event.Node.Expiration,

+ 0 - 1
store/node_extern.go

@@ -10,7 +10,6 @@ import (
 // TTL is time to live in second
 // TTL is time to live in second
 type NodeExtern struct {
 type NodeExtern struct {
 	Key           string      `json:"key, omitempty"`
 	Key           string      `json:"key, omitempty"`
-	PrevValue     string      `json:"-"`
 	Value         string      `json:"value,omitempty"`
 	Value         string      `json:"value,omitempty"`
 	Dir           bool        `json:"dir,omitempty"`
 	Dir           bool        `json:"dir,omitempty"`
 	Expiration    *time.Time  `json:"expiration,omitempty"`
 	Expiration    *time.Time  `json:"expiration,omitempty"`

+ 0 - 6
store/store.go

@@ -228,8 +228,6 @@ func (s *store) CompareAndSwap(nodePath string, prevValue string, prevIndex uint
 	e.PrevNode = n.Repr(false, false)
 	e.PrevNode = n.Repr(false, false)
 	eNode := e.Node
 	eNode := e.Node
 
 
-	eNode.PrevValue = n.Value
-
 	// if test succeed, write the value
 	// if test succeed, write the value
 	n.Write(value, s.CurrentIndex)
 	n.Write(value, s.CurrentIndex)
 	n.UpdateTTL(expireTime)
 	n.UpdateTTL(expireTime)
@@ -273,8 +271,6 @@ func (s *store) Delete(nodePath string, dir, recursive bool) (*Event, error) {
 
 
 	if n.IsDir() {
 	if n.IsDir() {
 		eNode.Dir = true
 		eNode.Dir = true
-	} else {
-		eNode.PrevValue = n.Value
 	}
 	}
 
 
 	callback := func(path string) { // notify function
 	callback := func(path string) { // notify function
@@ -424,7 +420,6 @@ func (s *store) Update(nodePath string, newValue string, expireTime time.Time) (
 		return nil, etcdErr.NewError(etcdErr.EcodeNotFile, nodePath, currIndex)
 		return nil, etcdErr.NewError(etcdErr.EcodeNotFile, nodePath, currIndex)
 	}
 	}
 
 
-	eNode.PrevValue = n.Value
 	n.Write(newValue, nextIndex)
 	n.Write(newValue, nextIndex)
 	eNode.Value = newValue
 	eNode.Value = newValue
 
 
@@ -487,7 +482,6 @@ func (s *store) internalCreate(nodePath string, dir bool, value string, unique,
 				return nil, etcdErr.NewError(etcdErr.EcodeNotFile, nodePath, currIndex)
 				return nil, etcdErr.NewError(etcdErr.EcodeNotFile, nodePath, currIndex)
 			}
 			}
 			e.PrevNode = n.Repr(false, false)
 			e.PrevNode = n.Repr(false, false)
-			eNode.PrevValue, _ = n.Read()
 
 
 			n.Remove(false, false, nil)
 			n.Remove(false, false, nil)
 		} else {
 		} else {

+ 0 - 9
store/store_test.go

@@ -93,7 +93,6 @@ func TestSet(t *testing.T) {
 	assert.Equal(t, e.Action, "set", "")
 	assert.Equal(t, e.Action, "set", "")
 	assert.Equal(t, e.Node.Key, "/foo", "")
 	assert.Equal(t, e.Node.Key, "/foo", "")
 	assert.False(t, e.Node.Dir, "")
 	assert.False(t, e.Node.Dir, "")
-	assert.Equal(t, e.Node.PrevValue, "", "")
 	assert.Equal(t, e.Node.Value, "", "")
 	assert.Equal(t, e.Node.Value, "", "")
 	assert.Nil(t, e.Node.Nodes, "")
 	assert.Nil(t, e.Node.Nodes, "")
 	assert.Nil(t, e.Node.Expiration, "")
 	assert.Nil(t, e.Node.Expiration, "")
@@ -106,7 +105,6 @@ func TestSet(t *testing.T) {
 	assert.Equal(t, e.Action, "set", "")
 	assert.Equal(t, e.Action, "set", "")
 	assert.Equal(t, e.Node.Key, "/foo", "")
 	assert.Equal(t, e.Node.Key, "/foo", "")
 	assert.False(t, e.Node.Dir, "")
 	assert.False(t, e.Node.Dir, "")
-	assert.Equal(t, e.Node.PrevValue, "", "")
 	assert.Equal(t, e.Node.Value, "bar", "")
 	assert.Equal(t, e.Node.Value, "bar", "")
 	assert.Nil(t, e.Node.Nodes, "")
 	assert.Nil(t, e.Node.Nodes, "")
 	assert.Nil(t, e.Node.Expiration, "")
 	assert.Nil(t, e.Node.Expiration, "")
@@ -124,7 +122,6 @@ func TestSet(t *testing.T) {
 	assert.Equal(t, e.Action, "set", "")
 	assert.Equal(t, e.Action, "set", "")
 	assert.Equal(t, e.Node.Key, "/dir", "")
 	assert.Equal(t, e.Node.Key, "/dir", "")
 	assert.True(t, e.Node.Dir, "")
 	assert.True(t, e.Node.Dir, "")
-	assert.Equal(t, e.Node.PrevValue, "", "")
 	assert.Equal(t, e.Node.Value, "", "")
 	assert.Equal(t, e.Node.Value, "", "")
 	assert.Nil(t, e.Node.Nodes, "")
 	assert.Nil(t, e.Node.Nodes, "")
 	assert.Nil(t, e.Node.Expiration, "")
 	assert.Nil(t, e.Node.Expiration, "")
@@ -141,7 +138,6 @@ func TestStoreCreateValue(t *testing.T) {
 	assert.Equal(t, e.Action, "create", "")
 	assert.Equal(t, e.Action, "create", "")
 	assert.Equal(t, e.Node.Key, "/foo", "")
 	assert.Equal(t, e.Node.Key, "/foo", "")
 	assert.False(t, e.Node.Dir, "")
 	assert.False(t, e.Node.Dir, "")
-	assert.Equal(t, e.Node.PrevValue, "", "")
 	assert.Equal(t, e.Node.Value, "bar", "")
 	assert.Equal(t, e.Node.Value, "bar", "")
 	assert.Nil(t, e.Node.Nodes, "")
 	assert.Nil(t, e.Node.Nodes, "")
 	assert.Nil(t, e.Node.Expiration, "")
 	assert.Nil(t, e.Node.Expiration, "")
@@ -154,7 +150,6 @@ func TestStoreCreateValue(t *testing.T) {
 	assert.Equal(t, e.Action, "create", "")
 	assert.Equal(t, e.Action, "create", "")
 	assert.Equal(t, e.Node.Key, "/empty", "")
 	assert.Equal(t, e.Node.Key, "/empty", "")
 	assert.False(t, e.Node.Dir, "")
 	assert.False(t, e.Node.Dir, "")
-	assert.Equal(t, e.Node.PrevValue, "", "")
 	assert.Equal(t, e.Node.Value, "", "")
 	assert.Equal(t, e.Node.Value, "", "")
 	assert.Nil(t, e.Node.Nodes, "")
 	assert.Nil(t, e.Node.Nodes, "")
 	assert.Nil(t, e.Node.Expiration, "")
 	assert.Nil(t, e.Node.Expiration, "")
@@ -200,7 +195,6 @@ func TestStoreUpdateValue(t *testing.T) {
 	assert.Equal(t, e.Action, "update", "")
 	assert.Equal(t, e.Action, "update", "")
 	assert.Equal(t, e.Node.Key, "/foo", "")
 	assert.Equal(t, e.Node.Key, "/foo", "")
 	assert.False(t, e.Node.Dir, "")
 	assert.False(t, e.Node.Dir, "")
-	assert.Equal(t, e.Node.PrevValue, "bar", "")
 	assert.Equal(t, e.Node.Value, "baz", "")
 	assert.Equal(t, e.Node.Value, "baz", "")
 	assert.Equal(t, e.Node.TTL, 0, "")
 	assert.Equal(t, e.Node.TTL, 0, "")
 	assert.Equal(t, e.Node.ModifiedIndex, uint64(2), "")
 	assert.Equal(t, e.Node.ModifiedIndex, uint64(2), "")
@@ -219,7 +213,6 @@ func TestStoreUpdateValue(t *testing.T) {
 	assert.Equal(t, e.Action, "update", "")
 	assert.Equal(t, e.Action, "update", "")
 	assert.Equal(t, e.Node.Key, "/foo", "")
 	assert.Equal(t, e.Node.Key, "/foo", "")
 	assert.False(t, e.Node.Dir, "")
 	assert.False(t, e.Node.Dir, "")
-	assert.Equal(t, e.Node.PrevValue, "baz", "")
 	assert.Equal(t, e.Node.Value, "", "")
 	assert.Equal(t, e.Node.Value, "", "")
 	assert.Equal(t, e.Node.TTL, 0, "")
 	assert.Equal(t, e.Node.TTL, 0, "")
 	assert.Equal(t, e.Node.ModifiedIndex, uint64(3), "")
 	assert.Equal(t, e.Node.ModifiedIndex, uint64(3), "")
@@ -436,7 +429,6 @@ func TestStoreCompareAndSwapPrevValue(t *testing.T) {
 	e, err := s.CompareAndSwap("/foo", "bar", 0, "baz", Permanent)
 	e, err := s.CompareAndSwap("/foo", "bar", 0, "baz", Permanent)
 	assert.Nil(t, err, "")
 	assert.Nil(t, err, "")
 	assert.Equal(t, e.Action, "compareAndSwap", "")
 	assert.Equal(t, e.Action, "compareAndSwap", "")
-	assert.Equal(t, e.Node.PrevValue, "bar", "")
 	assert.Equal(t, e.Node.Value, "baz", "")
 	assert.Equal(t, e.Node.Value, "baz", "")
 	// check pervNode
 	// check pervNode
 	assert.NotNil(t, e.PrevNode, "")
 	assert.NotNil(t, e.PrevNode, "")
@@ -469,7 +461,6 @@ func TestStoreCompareAndSwapPrevIndex(t *testing.T) {
 	e, err := s.CompareAndSwap("/foo", "", 1, "baz", Permanent)
 	e, err := s.CompareAndSwap("/foo", "", 1, "baz", Permanent)
 	assert.Nil(t, err, "")
 	assert.Nil(t, err, "")
 	assert.Equal(t, e.Action, "compareAndSwap", "")
 	assert.Equal(t, e.Action, "compareAndSwap", "")
-	assert.Equal(t, e.Node.PrevValue, "bar", "")
 	assert.Equal(t, e.Node.Value, "baz", "")
 	assert.Equal(t, e.Node.Value, "baz", "")
 	// check pervNode
 	// check pervNode
 	assert.NotNil(t, e.PrevNode, "")
 	assert.NotNil(t, e.PrevNode, "")