mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
go fmt
This commit is contained in:
parent
0a856241fe
commit
e4830bd93d
|
@ -73,7 +73,7 @@ func (nl *ItemList) canAddMember(node *skiplist.SkipListElementReference, name s
|
||||||
key := fmt.Sprintf("%s%dm", nl.prefix, node.ElementPointer)
|
key := fmt.Sprintf("%s%dm", nl.prefix, node.ElementPointer)
|
||||||
countOperation := pipe.ZLexCount(ctx, key, "-", "+")
|
countOperation := pipe.ZLexCount(ctx, key, "-", "+")
|
||||||
scoreOperationt := pipe.ZScore(ctx, key, name)
|
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
|
return false, 0, err
|
||||||
}
|
}
|
||||||
if err == redis.Nil {
|
if err == redis.Nil {
|
||||||
|
@ -286,7 +286,7 @@ func (nl *ItemList) DeleteName(name string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
nextSize := nl.NodeSize(nextNode.Reference())
|
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
|
// case 3.1 merge nextNode and prevNode
|
||||||
if _, err := nl.skipList.DeleteByKey(nextNode.Key); err != nil {
|
if _, err := nl.skipList.DeleteByKey(nextNode.Key); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -414,7 +414,7 @@ func (nl *ItemList) NodeInnerPosition(node *skiplist.SkipListElementReference, n
|
||||||
func (nl *ItemList) NodeMin(node *skiplist.SkipListElementReference) string {
|
func (nl *ItemList) NodeMin(node *skiplist.SkipListElementReference) string {
|
||||||
key := fmt.Sprintf("%s%dm", nl.prefix, node.ElementPointer)
|
key := fmt.Sprintf("%s%dm", nl.prefix, node.ElementPointer)
|
||||||
slice := nl.client.ZPopMin(context.Background(), key).Val()
|
slice := nl.client.ZPopMin(context.Background(), key).Val()
|
||||||
if len(slice)>0{
|
if len(slice) > 0 {
|
||||||
s := slice[0].Member.(string)
|
s := slice[0].Member.(string)
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ const maxNameBatchSizeLimit = 1000000
|
||||||
func insertChild(ctx context.Context, redisStore *UniversalRedis3Store, key string, name string) error {
|
func insertChild(ctx context.Context, redisStore *UniversalRedis3Store, key string, name string) error {
|
||||||
|
|
||||||
// lock and unlock
|
// lock and unlock
|
||||||
mutex := redisStore.redsync.NewMutex(key+"lock")
|
mutex := redisStore.redsync.NewMutex(key + "lock")
|
||||||
if err := mutex.Lock(); err != nil {
|
if err := mutex.Lock(); err != nil {
|
||||||
return fmt.Errorf("lock %s: %v", key, err)
|
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 {
|
func removeChild(ctx context.Context, redisStore *UniversalRedis3Store, key string, name string) error {
|
||||||
|
|
||||||
// lock and unlock
|
// lock and unlock
|
||||||
mutex := redisStore.redsync.NewMutex(key+"lock")
|
mutex := redisStore.redsync.NewMutex(key + "lock")
|
||||||
if err := mutex.Lock(); err != nil {
|
if err := mutex.Lock(); err != nil {
|
||||||
return fmt.Errorf("lock %s: %v", key, err)
|
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 {
|
func removeChildren(ctx context.Context, redisStore *UniversalRedis3Store, key string, onDeleteFn func(name string) error) error {
|
||||||
|
|
||||||
// lock and unlock
|
// lock and unlock
|
||||||
mutex := redisStore.redsync.NewMutex(key+"lock")
|
mutex := redisStore.redsync.NewMutex(key + "lock")
|
||||||
if err := mutex.Lock(); err != nil {
|
if err := mutex.Lock(); err != nil {
|
||||||
return fmt.Errorf("lock %s: %v", key, err)
|
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 {
|
if err = nameList.RemoteAllListElement(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,7 +94,7 @@ func BenchmarkNameList(b *testing.B) {
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
nameList := LoadItemList(data, "/yyy/bin", client, store, maxNameBatchSizeLimit)
|
nameList := LoadItemList(data, "/yyy/bin", client, store, maxNameBatchSizeLimit)
|
||||||
|
|
||||||
nameList.WriteName(strconv.Itoa(i)+"namexxxxxxxxxxxxxxxxxxx")
|
nameList.WriteName(strconv.Itoa(i) + "namexxxxxxxxxxxxxxxxxxx")
|
||||||
|
|
||||||
if nameList.HasChanges() {
|
if nameList.HasChanges() {
|
||||||
data = nameList.ToBytes()
|
data = nameList.ToBytes()
|
||||||
|
@ -116,7 +116,7 @@ func BenchmarkRedis(b *testing.B) {
|
||||||
})
|
})
|
||||||
|
|
||||||
for i := 0; i < b.N; i++ {
|
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()
|
ts1 := time.Now()
|
||||||
|
|
||||||
for i := 0; i < N; i++ {
|
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()
|
ts2 := time.Now()
|
||||||
|
|
||||||
fmt.Printf("%v %v", ts1.Sub(ts0), ts2.Sub(ts1))
|
fmt.Printf("%v %v", ts1.Sub(ts0), ts2.Sub(ts1))
|
||||||
|
|
||||||
/*
|
/*
|
||||||
keys := client.Keys(context.Background(), "/*m").Val()
|
keys := client.Keys(context.Background(), "/*m").Val()
|
||||||
for _, k := range keys {
|
for _, k := range keys {
|
||||||
println("key", k)
|
println("key", k)
|
||||||
for i, v := range client.ZRangeByLex(context.Background(), k, &redis.ZRangeBy{
|
for i, v := range client.ZRangeByLex(context.Background(), k, &redis.ZRangeBy{
|
||||||
Min: "-",
|
Min: "-",
|
||||||
Max: "+",
|
Max: "+",
|
||||||
}).Val() {
|
}).Val() {
|
||||||
println(" ", i, v)
|
println(" ", i, v)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
*/
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func xBenchmarkNameList(b *testing.B) {
|
func xBenchmarkNameList(b *testing.B) {
|
||||||
|
@ -205,6 +205,6 @@ func xBenchmarkRedis(b *testing.B) {
|
||||||
})
|
})
|
||||||
|
|
||||||
for i := 0; i < b.N; i++ {
|
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)})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,7 @@ func (m *SkipListElementStore) LoadElement(id int64) (*skiplist.SkipListElement,
|
||||||
t := &skiplist.SkipListElement{}
|
t := &skiplist.SkipListElement{}
|
||||||
err = proto.Unmarshal([]byte(data), t)
|
err = proto.Unmarshal([]byte(data), t)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
for i:=0;i<len(t.Next);i++{
|
for i := 0; i < len(t.Next); i++ {
|
||||||
if t.Next[i].IsNil() {
|
if t.Next[i].IsNil() {
|
||||||
t.Next[i] = nil
|
t.Next[i] = nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -323,7 +323,7 @@ func (vl *VolumeLayout) AddGrowRequest() {
|
||||||
vl.growRequestCount++
|
vl.growRequestCount++
|
||||||
}
|
}
|
||||||
func (vl *VolumeLayout) DoneGrowRequest() {
|
func (vl *VolumeLayout) DoneGrowRequest() {
|
||||||
vl.growRequestTime = time.Unix(0,0)
|
vl.growRequestTime = time.Unix(0, 0)
|
||||||
vl.growRequestCount = 0
|
vl.growRequestCount = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -249,7 +249,7 @@ func (nl *NameList) DeleteName(name string) error {
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if nextNameBatch != nil && len(nextNameBatch.names) + len(prevNameBatch.names) < nl.batchSize {
|
if nextNameBatch != nil && len(nextNameBatch.names)+len(prevNameBatch.names) < nl.batchSize {
|
||||||
// case 3.1 merge nextNode and prevNode
|
// case 3.1 merge nextNode and prevNode
|
||||||
if _, err := nl.skipList.DeleteByKey(nextNode.Key); err != nil {
|
if _, err := nl.skipList.DeleteByKey(nextNode.Key); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -300,7 +300,7 @@ func (nl *NameList) ListNames(startFrom string, visitNamesFn func(name string) b
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (nl *NameList) RemoteAllListElement() error {
|
func (nl *NameList) RemoteAllListElement() error {
|
||||||
|
@ -323,4 +323,4 @@ func (nl *NameList) RemoteAllListElement() error {
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,4 +68,4 @@ func (nl *NameList) ToBytes() []byte {
|
||||||
glog.Errorf("marshal skiplist: %v", err)
|
glog.Errorf("marshal skiplist: %v", err)
|
||||||
}
|
}
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ func TestNameList(t *testing.T) {
|
||||||
// list.skipList.println()
|
// list.skipList.println()
|
||||||
|
|
||||||
deleteBase := 5
|
deleteBase := 5
|
||||||
deleteCount := maxNameCount - 3 * deleteBase
|
deleteCount := maxNameCount - 3*deleteBase
|
||||||
|
|
||||||
for i := deleteBase; i < deleteBase+deleteCount; i++ {
|
for i := deleteBase; i < deleteBase+deleteCount; i++ {
|
||||||
list.DeleteName(String(i))
|
list.DeleteName(String(i))
|
||||||
|
|
|
@ -467,7 +467,7 @@ func (t *SkipList) GetSmallestNode() (*SkipListElement, error) {
|
||||||
func (t *SkipList) GetLargestNode() (*SkipListElement, error) {
|
func (t *SkipList) GetLargestNode() (*SkipListElement, error) {
|
||||||
return t.LoadElement(t.EndLevels[0])
|
return t.LoadElement(t.EndLevels[0])
|
||||||
}
|
}
|
||||||
func (t *SkipList) GetLargestNodeReference() (*SkipListElementReference) {
|
func (t *SkipList) GetLargestNodeReference() *SkipListElementReference {
|
||||||
return t.EndLevels[0]
|
return t.EndLevels[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,4 +48,4 @@ func (ref *SkipListElementReference) IsNil() bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,6 @@ func TestReverseInsert(t *testing.T) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func TestInsertAndFind(t *testing.T) {
|
func TestInsertAndFind(t *testing.T) {
|
||||||
|
|
||||||
k0 := []byte("0")
|
k0 := []byte("0")
|
||||||
|
|
Loading…
Reference in a new issue