mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Replaces a number of error equality checks with errors.Is
Signed-off-by: redwrasse <mail@redwrasse.io>
This commit is contained in:
@@ -16,6 +16,7 @@ package v3compactor
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@@ -139,7 +140,7 @@ func (pc *Periodic) Run() {
|
||||
)
|
||||
startTime := pc.clock.Now()
|
||||
_, err := pc.c.Compact(pc.ctx, &pb.CompactionRequest{Revision: rev})
|
||||
if err == nil || err == mvcc.ErrCompacted {
|
||||
if err == nil || errors.Is(err, mvcc.ErrCompacted) {
|
||||
pc.lg.Info(
|
||||
"completed auto periodic compaction",
|
||||
zap.Int64("revision", rev),
|
||||
|
||||
@@ -192,7 +192,7 @@ func newDiscovery(lg *zap.Logger, dcfg *DiscoveryConfig, id types.ID) (*discover
|
||||
func (d *discovery) getCluster() (string, error) {
|
||||
cls, clusterSize, rev, err := d.checkCluster()
|
||||
if err != nil {
|
||||
if err == ErrFullCluster {
|
||||
if errors.Is(err, ErrFullCluster) {
|
||||
return cls.getInitClusterStr(clusterSize)
|
||||
}
|
||||
return "", err
|
||||
@@ -303,7 +303,7 @@ func (d *discovery) checkClusterRetry() (*clusterInfo, int, int64, error) {
|
||||
func (d *discovery) checkCluster() (*clusterInfo, int, int64, error) {
|
||||
clusterSize, err := d.getClusterSize()
|
||||
if err != nil {
|
||||
if err == ErrSizeNotFound || err == ErrBadSizeKey {
|
||||
if errors.Is(err, ErrSizeNotFound) || errors.Is(err, ErrBadSizeKey) {
|
||||
return nil, 0, 0, err
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ package etcdserver
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
errorspkg "errors"
|
||||
"expvar"
|
||||
"fmt"
|
||||
"math"
|
||||
@@ -1445,7 +1446,7 @@ func (s *EtcdServer) PromoteMember(ctx context.Context, id uint64) ([]*membershi
|
||||
learnerPromoteSucceed.Inc()
|
||||
return resp, nil
|
||||
}
|
||||
if err != errors.ErrNotLeader {
|
||||
if !errorspkg.Is(err, errors.ErrNotLeader) {
|
||||
learnerPromoteFailed.WithLabelValues(err.Error()).Inc()
|
||||
return resp, err
|
||||
}
|
||||
@@ -1464,13 +1465,13 @@ func (s *EtcdServer) PromoteMember(ctx context.Context, id uint64) ([]*membershi
|
||||
return resp, nil
|
||||
}
|
||||
// If member promotion failed, return early. Otherwise keep retry.
|
||||
if err == errors.ErrLearnerNotReady || err == membership.ErrIDNotFound || err == membership.ErrMemberNotLearner {
|
||||
if errorspkg.Is(err, errors.ErrLearnerNotReady) || errorspkg.Is(err, membership.ErrIDNotFound) || errorspkg.Is(err, membership.ErrMemberNotLearner) {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if cctx.Err() == context.DeadlineExceeded {
|
||||
if errorspkg.Is(cctx.Err(), context.DeadlineExceeded) {
|
||||
return nil, errors.ErrTimeout
|
||||
}
|
||||
return nil, errors.ErrCanceled
|
||||
@@ -1980,7 +1981,7 @@ func (s *EtcdServer) applyEntryNormal(e *raftpb.Entry, shouldApplyV3 membership.
|
||||
return
|
||||
}
|
||||
|
||||
if ar.Err != errors.ErrNoSpace || len(s.alarmStore.Get(pb.AlarmType_NOSPACE)) > 0 {
|
||||
if !errorspkg.Is(ar.Err, errors.ErrNoSpace) || len(s.alarmStore.Get(pb.AlarmType_NOSPACE)) > 0 {
|
||||
s.w.Trigger(id, ar)
|
||||
return
|
||||
}
|
||||
@@ -2149,7 +2150,7 @@ func (s *EtcdServer) snapshot(snapi uint64, confState raftpb.ConfState) {
|
||||
if err != nil {
|
||||
// the snapshot was done asynchronously with the progress of raft.
|
||||
// raft might have already got a newer snapshot.
|
||||
if err == raft.ErrSnapOutOfDate {
|
||||
if errorspkg.Is(err, raft.ErrSnapOutOfDate) {
|
||||
return
|
||||
}
|
||||
lg.Panic("failed to create snapshot", zap.Error(err))
|
||||
@@ -2190,7 +2191,7 @@ func (s *EtcdServer) snapshot(snapi uint64, confState raftpb.ConfState) {
|
||||
if err != nil {
|
||||
// the compaction was done asynchronously with the progress of raft.
|
||||
// raft log might already been compact.
|
||||
if err == raft.ErrCompacted {
|
||||
if errorspkg.Is(err, raft.ErrCompacted) {
|
||||
return
|
||||
}
|
||||
lg.Panic("failed to compact", zap.Error(err))
|
||||
|
||||
@@ -19,6 +19,7 @@ import (
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"encoding/binary"
|
||||
errorspkg "errors"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
@@ -296,7 +297,7 @@ func (s *EtcdServer) LeaseRenew(ctx context.Context, id lease.LeaseID) (int64, e
|
||||
if err == nil { // already requested to primary lessor(leader)
|
||||
return ttl, nil
|
||||
}
|
||||
if err != lease.ErrNotPrimary {
|
||||
if !errorspkg.Is(err, lease.ErrNotPrimary) {
|
||||
return -1, err
|
||||
}
|
||||
}
|
||||
@@ -313,7 +314,7 @@ func (s *EtcdServer) LeaseRenew(ctx context.Context, id lease.LeaseID) (int64, e
|
||||
for _, url := range leader.PeerURLs {
|
||||
lurl := url + leasehttp.LeasePrefix
|
||||
ttl, err := leasehttp.RenewHTTP(cctx, id, lurl, s.peerRt)
|
||||
if err == nil || err == lease.ErrLeaseNotFound {
|
||||
if err == nil || errorspkg.Is(err, lease.ErrLeaseNotFound) {
|
||||
return ttl, err
|
||||
}
|
||||
}
|
||||
@@ -321,7 +322,7 @@ func (s *EtcdServer) LeaseRenew(ctx context.Context, id lease.LeaseID) (int64, e
|
||||
time.Sleep(50 * time.Millisecond)
|
||||
}
|
||||
|
||||
if cctx.Err() == context.DeadlineExceeded {
|
||||
if errorspkg.Is(cctx.Err(), context.DeadlineExceeded) {
|
||||
return -1, errors.ErrTimeout
|
||||
}
|
||||
return -1, errors.ErrCanceled
|
||||
@@ -402,13 +403,13 @@ func (s *EtcdServer) leaseTimeToLive(ctx context.Context, r *pb.LeaseTimeToLiveR
|
||||
if err == nil {
|
||||
return resp.LeaseTimeToLiveResponse, nil
|
||||
}
|
||||
if err == lease.ErrLeaseNotFound {
|
||||
if errorspkg.Is(err, lease.ErrLeaseNotFound) {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if cctx.Err() == context.DeadlineExceeded {
|
||||
if errorspkg.Is(cctx.Err(), context.DeadlineExceeded) {
|
||||
return nil, errors.ErrTimeout
|
||||
}
|
||||
return nil, errors.ErrCanceled
|
||||
@@ -527,7 +528,7 @@ func (s *EtcdServer) Authenticate(ctx context.Context, r *pb.AuthenticateRequest
|
||||
for {
|
||||
checkedRevision, err := s.AuthStore().CheckPassword(r.Name, r.Password)
|
||||
if err != nil {
|
||||
if err != auth.ErrAuthNotEnabled {
|
||||
if !errorspkg.Is(err, auth.ErrAuthNotEnabled) {
|
||||
lg.Warn(
|
||||
"invalid authentication was requested",
|
||||
zap.String("user", r.Name),
|
||||
@@ -854,7 +855,7 @@ func (s *EtcdServer) linearizableReadLoop() {
|
||||
}
|
||||
|
||||
func isStopped(err error) bool {
|
||||
return err == raft.ErrStopped || err == errors.ErrStopped
|
||||
return errorspkg.Is(err, raft.ErrStopped) || errorspkg.Is(err, errors.ErrStopped)
|
||||
}
|
||||
|
||||
func (s *EtcdServer) requestCurrentIndex(leaderChangedNotifier <-chan struct{}, requestID uint64) (uint64, error) {
|
||||
@@ -942,7 +943,7 @@ func (s *EtcdServer) sendReadIndex(requestIndex uint64) error {
|
||||
cctx, cancel := context.WithTimeout(context.Background(), s.Cfg.ReqTimeout())
|
||||
err := s.r.ReadIndex(cctx, ctxToSend)
|
||||
cancel()
|
||||
if err == raft.ErrStopped {
|
||||
if errorspkg.Is(err, raft.ErrStopped) {
|
||||
return err
|
||||
}
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user