Skip to content

Commit

Permalink
add a switch in cfg to enable the read ts validator
Browse files Browse the repository at this point in the history
Signed-off-by: ekexium <[email protected]>
  • Loading branch information
ekexium committed Feb 24, 2025
1 parent ddec823 commit c306eb7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
4 changes: 3 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ type Config struct {
// RegionsRefreshInterval indicates the interval of loading regions info, the unit is second, if RegionsRefreshInterval == 0, it will be disabled.
RegionsRefreshInterval uint64
// EnablePreload indicates whether to preload region info when initializing the client.
EnablePreload bool
EnablePreload bool
EnableReadTSValidator bool
}

// DefaultConfig returns the default configuration.
Expand All @@ -99,6 +100,7 @@ func DefaultConfig() Config {
TxnScope: "",
EnableAsyncCommit: false,
Enable1PC: false,
EnableReadTSValidator: true,
}
}

Expand Down
27 changes: 16 additions & 11 deletions internal/locate/region_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ package locate
import (
"context"
"fmt"
"github.com/tikv/client-go/v2/config"

Check failure on line 40 in internal/locate/region_request.go

View workflow job for this annotation

GitHub Actions / golangci

File is not `goimports`-ed (goimports)
"maps"
"math/rand"
"strconv"
Expand Down Expand Up @@ -105,17 +106,18 @@ func LoadShuttingDown() uint32 {
// For other region errors, since region range have changed, the request may need to
// split, so we simply return the error to caller.
type RegionRequestSender struct {
regionCache *RegionCache
apiVersion kvrpcpb.APIVersion
client client.Client
readTSValidator oracle.ReadTSValidator
storeAddr string
rpcError error
replicaSelector *replicaSelector
failStoreIDs map[uint64]struct{}
failProxyStoreIDs map[uint64]struct{}
Stats *RegionRequestRuntimeStats
AccessStats *ReplicaAccessStats
regionCache *RegionCache
apiVersion kvrpcpb.APIVersion
client client.Client
readTSValidator oracle.ReadTSValidator
storeAddr string
rpcError error
replicaSelector *replicaSelector
failStoreIDs map[uint64]struct{}
failProxyStoreIDs map[uint64]struct{}
Stats *RegionRequestRuntimeStats
AccessStats *ReplicaAccessStats
enableReadTsValidator bool

Check failure on line 120 in internal/locate/region_request.go

View workflow job for this annotation

GitHub Actions / golangci

field `enableReadTsValidator` is unused (unused)
}

func (s *RegionRequestSender) String() string {
Expand Down Expand Up @@ -402,6 +404,9 @@ func (s *ReplicaAccessStats) String() string {

// NewRegionRequestSender creates a new sender.
func NewRegionRequestSender(regionCache *RegionCache, client client.Client, readTSValidator oracle.ReadTSValidator) *RegionRequestSender {
if !config.GetGlobalConfig().EnableReadTSValidator {
readTSValidator = oracle.NoopReadTSValidator{}
}
return &RegionRequestSender{
regionCache: regionCache,
apiVersion: regionCache.codec.GetAPIVersion(),
Expand Down
6 changes: 6 additions & 0 deletions oracle/oracles/pd.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ package oracles
import (
"context"
"fmt"
"github.com/pingcap/failpoint"

Check failure on line 40 in oracle/oracles/pd.go

View workflow job for this annotation

GitHub Actions / golangci

File is not `goimports`-ed (goimports)
"math"
"strings"
"sync"
Expand Down Expand Up @@ -695,6 +696,11 @@ func (o *pdOracle) ValidateReadTS(ctx context.Context, readTS uint64, isStaleRea
o.adjustUpdateLowResolutionTSIntervalWithRequestedStaleness(readTS, estimatedCurrentTS, time.Now())
}
}

failpoint.Inject("failOnValidateReadTS", func(val failpoint.Value) {
errRet = errors.New(val.(string))
})

return nil
}

Expand Down

0 comments on commit c306eb7

Please sign in to comment.