diff --git a/weed/filer/redis3/ItemList.go b/weed/filer/redis3/ItemList.go index 33855d22d..9f84d57f6 100644 --- a/weed/filer/redis3/ItemList.go +++ b/weed/filer/redis3/ItemList.go @@ -73,7 +73,7 @@ func (nl *ItemList) canAddMember(node *skiplist.SkipListElementReference, name s key := fmt.Sprintf("%s%dm", nl.prefix, node.ElementPointer) countOperation := pipe.ZLexCount(ctx, key, "-", "+") scoreOperationt := pipe.ZScore(ctx, key, name) - if _, err = pipe.Exec(ctx); err != nil && err != redis.Nil{ + if _, err = pipe.Exec(ctx); err != nil && err != redis.Nil { return false, 0, err } if err == redis.Nil { @@ -286,7 +286,7 @@ func (nl *ItemList) DeleteName(name string) error { return nil } nextSize := nl.NodeSize(nextNode.Reference()) - if nextSize > 0 && prevSize + nextSize < nl.batchSize { + if nextSize > 0 && prevSize+nextSize < nl.batchSize { // case 3.1 merge nextNode and prevNode if _, err := nl.skipList.DeleteByKey(nextNode.Key); err != nil { return err @@ -414,7 +414,7 @@ func (nl *ItemList) NodeInnerPosition(node *skiplist.SkipListElementReference, n func (nl *ItemList) NodeMin(node *skiplist.SkipListElementReference) string { key := fmt.Sprintf("%s%dm", nl.prefix, node.ElementPointer) slice := nl.client.ZPopMin(context.Background(), key).Val() - if len(slice)>0{ + if len(slice) > 0 { s := slice[0].Member.(string) return s } diff --git a/weed/filer/redis3/kv_directory_children.go b/weed/filer/redis3/kv_directory_children.go index 624d17374..d92dddfe6 100644 --- a/weed/filer/redis3/kv_directory_children.go +++ b/weed/filer/redis3/kv_directory_children.go @@ -12,7 +12,7 @@ const maxNameBatchSizeLimit = 1000000 func insertChild(ctx context.Context, redisStore *UniversalRedis3Store, key string, name string) error { // lock and unlock - mutex := redisStore.redsync.NewMutex(key+"lock") + mutex := redisStore.redsync.NewMutex(key + "lock") if err := mutex.Lock(); err != nil { return fmt.Errorf("lock %s: %v", key, err) } @@ -49,7 +49,7 @@ func insertChild(ctx context.Context, redisStore *UniversalRedis3Store, key stri func removeChild(ctx context.Context, redisStore *UniversalRedis3Store, key string, name string) error { // lock and unlock - mutex := redisStore.redsync.NewMutex(key+"lock") + mutex := redisStore.redsync.NewMutex(key + "lock") if err := mutex.Lock(); err != nil { return fmt.Errorf("lock %s: %v", key, err) } @@ -82,7 +82,7 @@ func removeChild(ctx context.Context, redisStore *UniversalRedis3Store, key stri func removeChildren(ctx context.Context, redisStore *UniversalRedis3Store, key string, onDeleteFn func(name string) error) error { // lock and unlock - mutex := redisStore.redsync.NewMutex(key+"lock") + mutex := redisStore.redsync.NewMutex(key + "lock") if err := mutex.Lock(); err != nil { return fmt.Errorf("lock %s: %v", key, err) } @@ -111,7 +111,7 @@ func removeChildren(ctx context.Context, redisStore *UniversalRedis3Store, key s if err = nameList.RemoteAllListElement(); err != nil { return err } - + return nil } diff --git a/weed/filer/redis3/kv_directory_children_test.go b/weed/filer/redis3/kv_directory_children_test.go index 03c15ec35..78979cb21 100644 --- a/weed/filer/redis3/kv_directory_children_test.go +++ b/weed/filer/redis3/kv_directory_children_test.go @@ -94,7 +94,7 @@ func BenchmarkNameList(b *testing.B) { for i := 0; i < b.N; i++ { nameList := LoadItemList(data, "/yyy/bin", client, store, maxNameBatchSizeLimit) - nameList.WriteName(strconv.Itoa(i)+"namexxxxxxxxxxxxxxxxxxx") + nameList.WriteName(strconv.Itoa(i) + "namexxxxxxxxxxxxxxxxxxx") if nameList.HasChanges() { data = nameList.ToBytes() @@ -116,7 +116,7 @@ func BenchmarkRedis(b *testing.B) { }) for i := 0; i < b.N; i++ { - client.ZAddNX(context.Background(),"/yyy/bin", &redis.Z{Score: 0, Member: strconv.Itoa(i)+"namexxxxxxxxxxxxxxxxxxx"}) + client.ZAddNX(context.Background(), "/yyy/bin", &redis.Z{Score: 0, Member: strconv.Itoa(i) + "namexxxxxxxxxxxxxxxxxxx"}) } } @@ -149,24 +149,24 @@ func xTestNameListAdd(t *testing.T) { ts1 := time.Now() for i := 0; i < N; i++ { - client.ZAddNX(context.Background(),"/x", &redis.Z{Score: 0, Member: fmt.Sprintf("name %8d", i)}) + client.ZAddNX(context.Background(), "/x", &redis.Z{Score: 0, Member: fmt.Sprintf("name %8d", i)}) } ts2 := time.Now() fmt.Printf("%v %v", ts1.Sub(ts0), ts2.Sub(ts1)) /* - keys := client.Keys(context.Background(), "/*m").Val() - for _, k := range keys { - println("key", k) - for i, v := range client.ZRangeByLex(context.Background(), k, &redis.ZRangeBy{ - Min: "-", - Max: "+", - }).Val() { - println(" ", i, v) + keys := client.Keys(context.Background(), "/*m").Val() + for _, k := range keys { + println("key", k) + for i, v := range client.ZRangeByLex(context.Background(), k, &redis.ZRangeBy{ + Min: "-", + Max: "+", + }).Val() { + println(" ", i, v) + } } - } - */ + */ } func xBenchmarkNameList(b *testing.B) { @@ -205,6 +205,6 @@ func xBenchmarkRedis(b *testing.B) { }) for i := 0; i < b.N; i++ { - client.ZAddNX(context.Background(),"/xxx/bin", &redis.Z{Score: 0, Member: fmt.Sprintf("name %8d", i)}) + client.ZAddNX(context.Background(), "/xxx/bin", &redis.Z{Score: 0, Member: fmt.Sprintf("name %8d", i)}) } } diff --git a/weed/filer/redis3/skiplist_element_store.go b/weed/filer/redis3/skiplist_element_store.go index bcad356dd..8c101d006 100644 --- a/weed/filer/redis3/skiplist_element_store.go +++ b/weed/filer/redis3/skiplist_element_store.go @@ -49,7 +49,7 @@ func (m *SkipListElementStore) LoadElement(id int64) (*skiplist.SkipListElement, t := &skiplist.SkipListElement{} err = proto.Unmarshal([]byte(data), t) if err == nil { - for i:=0;i