Xiang Li 12 years ago
parent
commit
c6a4321310
3 changed files with 15 additions and 18 deletions
  1. 8 9
      store/store.go
  2. 2 3
      store/tree.go
  3. 5 6
      store/tree_store_test.go

+ 8 - 9
store/store.go

@@ -5,8 +5,8 @@ import (
 	"fmt"
 	"path"
 	"strconv"
-	"time"
 	"sync"
+	"time"
 )
 
 //------------------------------------------------------------------------------
@@ -21,7 +21,7 @@ type Store struct {
 	// key-value store structure
 	Tree *tree
 
-	mutex       sync.Mutex
+	mutex sync.Mutex
 
 	// WatcherHub is where we register all the clients
 	// who issue a watch request
@@ -350,7 +350,6 @@ func (s *Store) RawGet(key string) ([]*Response, error) {
 			return resps, nil
 		}
 
-
 		nodes, _ := nodes.([]*Node)
 
 		resps := make([]*Response, len(nodes))
@@ -573,12 +572,12 @@ func (s *Store) addToResponseMap(index uint64, resp *Response) {
 }
 
 func (s *Store) clone() *Store {
-	newStore := & Store{
-		ResponseMaxSize: s.ResponseMaxSize,
-		ResponseCurrSize: s.ResponseCurrSize,
-		ResponseStartIndex: s.ResponseStartIndex, 
-		Index:	s.Index,
-		BasicStats: s.BasicStats,
+	newStore := &Store{
+		ResponseMaxSize:    s.ResponseMaxSize,
+		ResponseCurrSize:   s.ResponseCurrSize,
+		ResponseStartIndex: s.ResponseStartIndex,
+		Index:              s.Index,
+		BasicStats:         s.BasicStats,
 	}
 
 	newStore.Tree = s.Tree.clone()

+ 2 - 3
store/tree.go

@@ -230,10 +230,10 @@ func (t *tree) clone() *tree {
 			"/",
 			time.Unix(0, 0),
 			nil,
-			},
+		},
 		true,
 		make(map[string]*treeNode),
-		}
+	}
 	recursiveClone(t.Root, newTree.Root)
 	return newTree
 }
@@ -316,4 +316,3 @@ func split(key string) []string {
 	nodesName = nodesName[1:]
 	return nodesName
 }
-

+ 5 - 6
store/tree_store_test.go

@@ -103,16 +103,16 @@ func TestTreeClone(t *testing.T) {
 			NewTestNode("/"),
 			true,
 			make(map[string]*treeNode),
-			},
-		}
+		},
+	}
 
 	backTs := &tree{
 		&treeNode{
 			NewTestNode("/"),
 			true,
 			make(map[string]*treeNode),
-			},
-		}
+		},
+	}
 
 	// generate the first tree
 	for _, key := range keys {
@@ -206,11 +206,10 @@ func BenchmarkTreeStoreCopy(b *testing.B) {
 	}
 }
 
-
 func BenchmarkMakeSlice(b *testing.B) {
 
 	for i := 0; i < b.N; i++ {
-		for i:=0; i < 100000; i++ {
+		for i := 0; i < 100000; i++ {
 			_ = make([]Node, 1)
 		}
 	}