refactor(node_extern.go) remove unused prevValue field

release-0.4
Xiang Li 2014-01-01 20:01:29 +08:00
parent f46fdbf078
commit 189b98c03f
4 changed files with 2 additions and 18 deletions

View File

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

View File

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

View File

@ -228,8 +228,6 @@ func (s *store) CompareAndSwap(nodePath string, prevValue string, prevIndex uint
e.PrevNode = n.Repr(false, false)
eNode := e.Node
eNode.PrevValue = n.Value
// if test succeed, write the value
n.Write(value, s.CurrentIndex)
n.UpdateTTL(expireTime)
@ -273,8 +271,6 @@ func (s *store) Delete(nodePath string, dir, recursive bool) (*Event, error) {
if n.IsDir() {
eNode.Dir = true
} else {
eNode.PrevValue = n.Value
}
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)
}
eNode.PrevValue = n.Value
n.Write(newValue, nextIndex)
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)
}
e.PrevNode = n.Repr(false, false)
eNode.PrevValue, _ = n.Read()
n.Remove(false, false, nil)
} else {

View File

@ -93,7 +93,6 @@ func TestSet(t *testing.T) {
assert.Equal(t, e.Action, "set", "")
assert.Equal(t, e.Node.Key, "/foo", "")
assert.False(t, e.Node.Dir, "")
assert.Equal(t, e.Node.PrevValue, "", "")
assert.Equal(t, e.Node.Value, "", "")
assert.Nil(t, e.Node.Nodes, "")
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.Node.Key, "/foo", "")
assert.False(t, e.Node.Dir, "")
assert.Equal(t, e.Node.PrevValue, "", "")
assert.Equal(t, e.Node.Value, "bar", "")
assert.Nil(t, e.Node.Nodes, "")
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.Node.Key, "/dir", "")
assert.True(t, e.Node.Dir, "")
assert.Equal(t, e.Node.PrevValue, "", "")
assert.Equal(t, e.Node.Value, "", "")
assert.Nil(t, e.Node.Nodes, "")
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.Node.Key, "/foo", "")
assert.False(t, e.Node.Dir, "")
assert.Equal(t, e.Node.PrevValue, "", "")
assert.Equal(t, e.Node.Value, "bar", "")
assert.Nil(t, e.Node.Nodes, "")
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.Node.Key, "/empty", "")
assert.False(t, e.Node.Dir, "")
assert.Equal(t, e.Node.PrevValue, "", "")
assert.Equal(t, e.Node.Value, "", "")
assert.Nil(t, e.Node.Nodes, "")
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.Node.Key, "/foo", "")
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.TTL, 0, "")
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.Node.Key, "/foo", "")
assert.False(t, e.Node.Dir, "")
assert.Equal(t, e.Node.PrevValue, "baz", "")
assert.Equal(t, e.Node.Value, "", "")
assert.Equal(t, e.Node.TTL, 0, "")
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)
assert.Nil(t, err, "")
assert.Equal(t, e.Action, "compareAndSwap", "")
assert.Equal(t, e.Node.PrevValue, "bar", "")
assert.Equal(t, e.Node.Value, "baz", "")
// check pervNode
assert.NotNil(t, e.PrevNode, "")
@ -469,7 +461,6 @@ func TestStoreCompareAndSwapPrevIndex(t *testing.T) {
e, err := s.CompareAndSwap("/foo", "", 1, "baz", Permanent)
assert.Nil(t, err, "")
assert.Equal(t, e.Action, "compareAndSwap", "")
assert.Equal(t, e.Node.PrevValue, "bar", "")
assert.Equal(t, e.Node.Value, "baz", "")
// check pervNode
assert.NotNil(t, e.PrevNode, "")