Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

owner, errors: ignore update gc safepoint error #979

Merged
merged 5 commits into from
Oct 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions cdc/owner.go
Original file line number Diff line number Diff line change
Expand Up @@ -577,9 +577,10 @@ func (o *Owner) flushChangeFeedInfos(ctx context.Context) error {
if !o.gcSafepointLastUpdate.IsZero() {
_, err := o.pdClient.UpdateServiceGCSafePoint(ctx, CDCServiceSafePointID, 0, 0)
if err != nil {
return cerror.WrapError(cerror.ErrOwnerUpdateGCSafepoint, err)
log.Warn("failed to update service safe point", zap.Error(err))
} else {
o.gcSafepointLastUpdate = time.Time{}
}
o.gcSafepointLastUpdate = *new(time.Time)
}
return nil
}
Expand Down Expand Up @@ -609,10 +610,10 @@ func (o *Owner) flushChangeFeedInfos(ctx context.Context) error {
if time.Since(o.gcSafepointLastUpdate) > GCSafepointUpdateInterval {
_, err := o.pdClient.UpdateServiceGCSafePoint(ctx, CDCServiceSafePointID, o.gcTTL, minCheckpointTs)
if err != nil {
log.Info("failed to update service safe point", zap.Error(err))
return cerror.WrapError(cerror.ErrOwnerUpdateGCSafepoint, err)
log.Warn("failed to update service safe point", zap.Error(err))
} else {
o.gcSafepointLastUpdate = time.Now()
}
o.gcSafepointLastUpdate = time.Now()
}
return nil
}
Expand Down
25 changes: 25 additions & 0 deletions cdc/owner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package cdc

import (
"context"
"errors"
"net/url"
"time"

Expand All @@ -34,6 +35,7 @@ import (
"github.com/pingcap/ticdc/pkg/util"
"github.com/pingcap/tidb/meta"
"github.com/pingcap/tidb/store/mockstore"
pd "github.com/tikv/pd/client"
"go.etcd.io/etcd/clientv3"
"go.etcd.io/etcd/embed"
"golang.org/x/sync/errgroup"
Expand Down Expand Up @@ -74,6 +76,29 @@ func (s *ownerSuite) TearDownTest(c *check.C) {
}
}

type mockPDClient struct {
pd.Client
invokeCounter int
}

func (m *mockPDClient) UpdateServiceGCSafePoint(ctx context.Context, serviceID string, ttl int64, safePoint uint64) (uint64, error) {
m.invokeCounter++
return 0, errors.New("mock error")
}

func (s *ownerSuite) TestOwnerFlushChangeFeedInfos(c *check.C) {
mockPDCli := &mockPDClient{}
mockOwner := Owner{
pdClient: mockPDCli,
gcSafepointLastUpdate: time.Now(),
}

// Owner should ignore UpdateServiceGCSafePoint error.
err := mockOwner.flushChangeFeedInfos(s.ctx)
c.Assert(err, check.IsNil)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recommend adding the check that mockOwner.gcSafepointLastUpdate is not updated

c.Assert(mockPDCli.invokeCounter, check.Equals, 1)
}

/*
type handlerForPrueDMLTest struct {
mu sync.RWMutex
Expand Down
1 change: 0 additions & 1 deletion pkg/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ var (
ErrAPIInvalidParam = errors.Normalize("invalid api parameter", errors.RFCCodeText("CDC:ErrAPIInvalidParam"))
ErrInternalServerError = errors.Normalize("internal server error", errors.RFCCodeText("CDC:ErrInternalServerError"))
ErrOwnerSortDir = errors.Normalize("owner sort dir", errors.RFCCodeText("CDC:ErrOwnerSortDir"))
ErrOwnerUpdateGCSafepoint = errors.Normalize("owner update gc safepoint", errors.RFCCodeText("CDC:ErrOwnerUpdateGCSafepoint"))
ErrOwnerChangefeedNotFound = errors.Normalize("changefeed %s not found in owner cache", errors.RFCCodeText("CDC:ErrOwnerChangefeedNotFound"))
ErrChangefeedAbnormalState = errors.Normalize("changefeed in abnormal state: %s, replication status: %+v", errors.RFCCodeText("CDC:ErrChangefeedAbnormalState"))
ErrInvalidAdminJobType = errors.Normalize("invalid admin job type: %d", errors.RFCCodeText("CDC:ErrInvalidAdminJobType"))
Expand Down