Skip to content

Commit

Permalink
ignore errors in ts validator
Browse files Browse the repository at this point in the history
Signed-off-by: ekexium <eke@fastmail.com>
  • Loading branch information
ekexium committed Feb 25, 2025
1 parent ad4338d commit 53b6c32
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 18 deletions.
12 changes: 5 additions & 7 deletions oracle/oracles/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ import (
"sync"
"time"

"github.com/pingcap/errors"
"github.com/tikv/client-go/v2/internal/logutil"
"github.com/tikv/client-go/v2/oracle"
"go.uber.org/zap"
)

var _ oracle.Oracle = &localOracle{}
Expand Down Expand Up @@ -140,20 +141,17 @@ func (l *localOracle) GetExternalTimestamp(ctx context.Context) (uint64, error)
func (l *localOracle) ValidateReadTS(ctx context.Context, readTS uint64, isStaleRead bool, opt *oracle.Option) error {
if readTS == math.MaxUint64 {
if isStaleRead {
return oracle.ErrLatestStaleRead{}
logutil.Logger(ctx).Error("stale read use MaxUint64 as readTS")
}
return nil
}

currentTS, err := l.GetTimestamp(ctx, opt)
if err != nil {
return errors.Errorf("fail to validate read timestamp: %v", err)
logutil.Logger(ctx).Error("fail to get timestamp when validating", zap.Error(err))
}
if currentTS < readTS {
return oracle.ErrFutureTSRead{
ReadTS: readTS,
CurrentTS: currentTS,
}
logutil.Logger(ctx).Error("ts validation failed", zap.Uint64("readTS", readTS), zap.Uint64("currentTS", currentTS))
}
return nil
}
9 changes: 4 additions & 5 deletions oracle/oracles/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ import (
"time"

"github.com/pkg/errors"
"github.com/tikv/client-go/v2/internal/logutil"
"github.com/tikv/client-go/v2/oracle"
"go.uber.org/zap"
)

var errStopped = errors.New("stopped")
Expand Down Expand Up @@ -134,13 +136,10 @@ func (o *MockOracle) ValidateReadTS(ctx context.Context, readTS uint64, isStaleR

currentTS, err := o.GetTimestamp(ctx, opt)
if err != nil {
return errors.Errorf("fail to validate read timestamp: %v", err)
logutil.Logger(ctx).Error("fail to get timestamp when validating", zap.Error(err))
}
if currentTS < readTS {
return oracle.ErrFutureTSRead{
ReadTS: readTS,
CurrentTS: currentTS,
}
logutil.Logger(ctx).Error("ts validation failed", zap.Uint64("readTS", readTS), zap.Uint64("currentTS", currentTS))
}
return nil
}
Expand Down
9 changes: 3 additions & 6 deletions oracle/oracles/pd.go
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ func (o *pdOracle) getCurrentTSForValidation(ctx context.Context, opt *oracle.Op
func (o *pdOracle) ValidateReadTS(ctx context.Context, readTS uint64, isStaleRead bool, opt *oracle.Option) (errRet error) {
if readTS == math.MaxUint64 {
if isStaleRead {
return oracle.ErrLatestStaleRead{}
logutil.Logger(ctx).Error("stale read use MaxUint64 as readTS")
}
return nil
}
Expand All @@ -661,16 +661,13 @@ func (o *pdOracle) ValidateReadTS(ctx context.Context, readTS uint64, isStaleRea
if !exists || readTS > latestTSInfo.tso {
currentTS, err := o.getCurrentTSForValidation(ctx, opt)
if err != nil {
return errors.Errorf("fail to validate read timestamp: %v", err)
logutil.Logger(ctx).Error("fail to get timestamp when validating", zap.Error(err))
}
if isStaleRead {
o.adjustUpdateLowResolutionTSIntervalWithRequestedStaleness(readTS, currentTS, time.Now())
}
if readTS > currentTS {
return oracle.ErrFutureTSRead{
ReadTS: readTS,
CurrentTS: currentTS,
}
logutil.Logger(ctx).Error("ts validation failed", zap.Uint64("readTS", readTS), zap.Uint64("currentTS", currentTS))
}
} else if isStaleRead {
estimatedCurrentTS, err := o.getStaleTimestampWithLastTS(latestTSInfo, 0)
Expand Down

0 comments on commit 53b6c32

Please sign in to comment.