mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
functional-tester: add "Member.Compact" method
Signed-off-by: Gyuho Lee <gyuhox@gmail.com>
This commit is contained in:
parent
a729b88463
commit
5423100def
@ -126,6 +126,21 @@ func (m *Member) Rev(ctx context.Context) (int64, error) {
|
|||||||
return resp.Header.Revision, nil
|
return resp.Header.Revision, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Compact compacts member storage with given revision.
|
||||||
|
// It blocks until it's physically done.
|
||||||
|
func (m *Member) Compact(rev int64, timeout time.Duration) error {
|
||||||
|
cli, err := m.CreateEtcdClient()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("%v (%q)", err, m.EtcdClientEndpoint)
|
||||||
|
}
|
||||||
|
defer cli.Close()
|
||||||
|
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
||||||
|
_, err = cli.Compact(ctx, rev, clientv3.WithCompactPhysical())
|
||||||
|
cancel()
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// IsLeader returns true if this member is the current cluster leader.
|
// IsLeader returns true if this member is the current cluster leader.
|
||||||
func (m *Member) IsLeader() (bool, error) {
|
func (m *Member) IsLeader() (bool, error) {
|
||||||
cli, err := m.CreateEtcdClient()
|
cli, err := m.CreateEtcdClient()
|
||||||
|
@ -25,7 +25,6 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
pb "github.com/coreos/etcd/etcdserver/etcdserverpb"
|
|
||||||
"github.com/coreos/etcd/pkg/debugutil"
|
"github.com/coreos/etcd/pkg/debugutil"
|
||||||
"github.com/coreos/etcd/tools/functional-tester/rpcpb"
|
"github.com/coreos/etcd/tools/functional-tester/rpcpb"
|
||||||
|
|
||||||
@ -681,31 +680,14 @@ func (clus *Cluster) compactKV(rev int64, timeout time.Duration) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for i, m := range clus.Members {
|
for i, m := range clus.Members {
|
||||||
conn, derr := m.DialEtcdGRPCServer()
|
|
||||||
if derr != nil {
|
|
||||||
clus.lg.Warn(
|
|
||||||
"compactKV dial failed",
|
|
||||||
zap.String("endpoint", m.EtcdClientEndpoint),
|
|
||||||
zap.Error(derr),
|
|
||||||
)
|
|
||||||
err = derr
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
kvc := pb.NewKVClient(conn)
|
|
||||||
|
|
||||||
clus.lg.Info(
|
clus.lg.Info(
|
||||||
"compacting",
|
"compacting",
|
||||||
zap.String("endpoint", m.EtcdClientEndpoint),
|
zap.String("endpoint", m.EtcdClientEndpoint),
|
||||||
zap.Int64("compact-revision", rev),
|
zap.Int64("compact-revision", rev),
|
||||||
zap.Duration("timeout", timeout),
|
zap.Duration("timeout", timeout),
|
||||||
)
|
)
|
||||||
|
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
cerr := m.Compact(rev, timeout)
|
||||||
_, cerr := kvc.Compact(ctx, &pb.CompactionRequest{Revision: rev, Physical: true}, grpc.FailFast(false))
|
|
||||||
cancel()
|
|
||||||
|
|
||||||
conn.Close()
|
|
||||||
succeed := true
|
succeed := true
|
||||||
if cerr != nil {
|
if cerr != nil {
|
||||||
if strings.Contains(cerr.Error(), "required revision has been compacted") && i > 0 {
|
if strings.Contains(cerr.Error(), "required revision has been compacted") && i > 0 {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user