Skip to content

Commit

Permalink
clientv3: fix sync base
Browse files Browse the repository at this point in the history
It is not correct to use WithPrefix. Range end will change in every
internal batch.
  • Loading branch information
westhood committed Jul 7, 2016
1 parent 88a9cf2 commit 3381f15
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
35 changes: 35 additions & 0 deletions clientv3/integration/mirror_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package integration

import (
"fmt"
"reflect"
"testing"
"time"
Expand Down Expand Up @@ -69,3 +70,37 @@ func TestMirrorSync(t *testing.T) {
t.Fatal("failed to receive update in one second")
}
}

func TestMirrorSyncBase(t *testing.T) {
cluster := integration.NewClusterV3(nil, &integration.ClusterConfig{Size: 1})
defer cluster.Terminate(nil)

cli := cluster.Client(0)
ctx := context.TODO()

for i := 0; i < 2000; i++ {
if _, err := cli.Put(ctx, fmt.Sprintf("test%d", i), "test"); err != nil {
t.Fatal(err)
}
}

syncer := mirror.NewSyncer(cli, "test", 0)
respCh, errCh := syncer.SyncBase(ctx)

count := 0

for resp := range respCh {
count = count + len(resp.Kvs)
if !resp.More {
break
}
}

for err := range errCh {
t.Fatalf("unexpected error %v", err)
}

if count != 2000 {
t.Errorf("unexpected kv count: %d", count)
}
}
2 changes: 1 addition & 1 deletion clientv3/mirror/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (s *syncer) SyncBase(ctx context.Context) (<-chan clientv3.GetResponse, cha
// If len(s.prefix) != 0, we will sync key-value space with given prefix.
// We then range from the prefix to the next prefix if exists. Or we will
// range from the prefix to the end if the next prefix does not exists.
opts = append(opts, clientv3.WithPrefix())
opts = append(opts, clientv3.WithRange(clientv3.GetPrefixRangeEnd(s.prefix)))
key = s.prefix
}

Expand Down

0 comments on commit 3381f15

Please sign in to comment.