mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge pull request #4513 from gyuho/f1
etcd-tester: use Hash method to get both revision and hash
This commit is contained in:
commit
a30201c1d2
@ -297,3 +297,47 @@ func setHealthKeyV2(us []string) error {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *cluster) getRevisionHash() (map[string]int64, map[string]int64, error) {
|
||||||
|
revs := make(map[string]int64)
|
||||||
|
hashes := make(map[string]int64)
|
||||||
|
for _, u := range c.GRPCURLs {
|
||||||
|
conn, err := grpc.Dial(u, grpc.WithInsecure(), grpc.WithTimeout(5*time.Second))
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
kvc := pb.NewKVClient(conn)
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||||
|
resp, err := kvc.Hash(ctx, &pb.HashRequest{})
|
||||||
|
cancel()
|
||||||
|
conn.Close()
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
revs[u] = resp.Header.Revision
|
||||||
|
hashes[u] = int64(resp.Hash)
|
||||||
|
}
|
||||||
|
return revs, hashes, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *cluster) compactKV(rev int64) error {
|
||||||
|
var (
|
||||||
|
conn *grpc.ClientConn
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
for _, u := range c.GRPCURLs {
|
||||||
|
conn, err = grpc.Dial(u, grpc.WithInsecure(), grpc.WithTimeout(5*time.Second))
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
kvc := pb.NewKVClient(conn)
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||||
|
_, err = kvc.Compact(ctx, &pb.CompactionRequest{Revision: rev})
|
||||||
|
cancel()
|
||||||
|
conn.Close()
|
||||||
|
if err == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
@ -18,11 +18,6 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/coreos/etcd/Godeps/_workspace/src/golang.org/x/net/context"
|
|
||||||
"github.com/coreos/etcd/Godeps/_workspace/src/google.golang.org/grpc"
|
|
||||||
|
|
||||||
pb "github.com/coreos/etcd/etcdserver/etcdserverpb"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type tester struct {
|
type tester struct {
|
||||||
@ -93,13 +88,14 @@ func (tt *tester) runLoop() {
|
|||||||
log.Printf("etcd-tester: [round#%d case#%d] checking current revisions...", i, j)
|
log.Printf("etcd-tester: [round#%d case#%d] checking current revisions...", i, j)
|
||||||
var (
|
var (
|
||||||
revs map[string]int64
|
revs map[string]int64
|
||||||
|
hashes map[string]int64
|
||||||
rerr error
|
rerr error
|
||||||
ok bool
|
ok bool
|
||||||
)
|
)
|
||||||
for k := 0; k < 5; k++ {
|
for k := 0; k < 5; k++ {
|
||||||
time.Sleep(time.Second)
|
time.Sleep(time.Second)
|
||||||
|
|
||||||
revs, rerr = tt.cluster.getRevision()
|
revs, hashes, rerr = tt.cluster.getRevisionHash()
|
||||||
if rerr != nil {
|
if rerr != nil {
|
||||||
log.Printf("etcd-tester: [round#%d case#%d.%d] failed to get current revisions (%v)", i, j, k, rerr)
|
log.Printf("etcd-tester: [round#%d case#%d.%d] failed to get current revisions (%v)", i, j, k, rerr)
|
||||||
continue
|
continue
|
||||||
@ -121,15 +117,6 @@ func (tt *tester) runLoop() {
|
|||||||
log.Printf("etcd-tester: [round#%d case#%d] all members are consistent with current revisions", i, j)
|
log.Printf("etcd-tester: [round#%d case#%d] all members are consistent with current revisions", i, j)
|
||||||
|
|
||||||
log.Printf("etcd-tester: [round#%d case#%d] checking current storage hashes...", i, j)
|
log.Printf("etcd-tester: [round#%d case#%d] checking current storage hashes...", i, j)
|
||||||
hashes, err := tt.cluster.getKVHash()
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("etcd-tester: [round#%d case#%d] getKVHash error (%v)", i, j, err)
|
|
||||||
if err := tt.cleanup(i, j); err != nil {
|
|
||||||
log.Printf("etcd-tester: [round#%d case#%d] cleanup error: %v", i, j, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if _, ok = getSameValue(hashes); !ok {
|
if _, ok = getSameValue(hashes); !ok {
|
||||||
log.Printf("etcd-tester: [round#%d case#%d] checking current storage hashes failed (%v)", i, j, hashes)
|
log.Printf("etcd-tester: [round#%d case#%d] checking current storage hashes failed (%v)", i, j, hashes)
|
||||||
if err := tt.cleanup(i, j); err != nil {
|
if err := tt.cleanup(i, j); err != nil {
|
||||||
@ -207,65 +194,3 @@ func (s *Status) setCase(c int) {
|
|||||||
defer s.mu.Unlock()
|
defer s.mu.Unlock()
|
||||||
s.Case = c
|
s.Case = c
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *cluster) getRevision() (map[string]int64, error) {
|
|
||||||
revs := make(map[string]int64)
|
|
||||||
for _, u := range c.GRPCURLs {
|
|
||||||
conn, err := grpc.Dial(u, grpc.WithInsecure(), grpc.WithTimeout(5*time.Second))
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
kvc := pb.NewKVClient(conn)
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
|
||||||
resp, err := kvc.Range(ctx, &pb.RangeRequest{Key: []byte("foo")})
|
|
||||||
cancel()
|
|
||||||
conn.Close()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
revs[u] = resp.Header.Revision
|
|
||||||
}
|
|
||||||
return revs, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *cluster) getKVHash() (map[string]int64, error) {
|
|
||||||
hashes := make(map[string]int64)
|
|
||||||
for _, u := range c.GRPCURLs {
|
|
||||||
conn, err := grpc.Dial(u, grpc.WithInsecure(), grpc.WithTimeout(5*time.Second))
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
kvc := pb.NewKVClient(conn)
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
|
||||||
resp, err := kvc.Hash(ctx, &pb.HashRequest{})
|
|
||||||
cancel()
|
|
||||||
conn.Close()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
hashes[u] = int64(resp.Hash)
|
|
||||||
}
|
|
||||||
return hashes, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *cluster) compactKV(rev int64) error {
|
|
||||||
var (
|
|
||||||
conn *grpc.ClientConn
|
|
||||||
err error
|
|
||||||
)
|
|
||||||
for _, u := range c.GRPCURLs {
|
|
||||||
conn, err = grpc.Dial(u, grpc.WithInsecure(), grpc.WithTimeout(5*time.Second))
|
|
||||||
if err != nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
kvc := pb.NewKVClient(conn)
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
|
||||||
_, err = kvc.Compact(ctx, &pb.CompactionRequest{Revision: rev})
|
|
||||||
cancel()
|
|
||||||
conn.Close()
|
|
||||||
if err == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user