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

Releases/v7.21.0 #128

Merged
merged 23 commits into from
May 20, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
now ip chooser & subnet chooser would always returns results
bachue committed Apr 26, 2024
commit ca659f2f149567ee948718aceb1b24a92057914a
2 changes: 1 addition & 1 deletion internal/clientv2/interceptor_retry_hosts.go
Original file line number Diff line number Diff line change
@@ -122,7 +122,7 @@ func (interceptor *hostsRetryInterceptor) Intercept(req *http.Request, handler H
resp.Body.Close()
}

retryInterval := interceptor.options.RetryConfig.RetryInterval()
retryInterval := interceptor.options.RetryConfig.RetryInterval(&RetryInfo{Retried: i})
if retryInterval < time.Microsecond {
continue
}
12 changes: 6 additions & 6 deletions internal/clientv2/interceptor_retry_hosts_test.go
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@ func TestHostsAlwaysRetryInterceptor(t *testing.T) {
hRetryInterceptor := NewHostsRetryInterceptor(HostsRetryConfig{
RetryConfig: RetryConfig{
RetryMax: hRetryMax,
RetryInterval: func() time.Duration {
RetryInterval: func(_ *RetryInfo) time.Duration {
return time.Second
},
ShouldRetry: func(req *http.Request, resp *http.Response, err error) bool {
@@ -39,7 +39,7 @@ func TestHostsAlwaysRetryInterceptor(t *testing.T) {
retryMax := 1
sRetryInterceptor := NewSimpleRetryInterceptor(SimpleRetryConfig{
RetryMax: retryMax,
RetryInterval: func() time.Duration {
RetryInterval: func(_ *RetryInfo) time.Duration {
return time.Second
},
ShouldRetry: func(req *http.Request, resp *http.Response, err error) bool {
@@ -106,7 +106,7 @@ func TestHostsNotRetryInterceptor(t *testing.T) {
hRetryInterceptor := NewHostsRetryInterceptor(HostsRetryConfig{
RetryConfig: RetryConfig{
RetryMax: hRetryMax,
RetryInterval: func() time.Duration {
RetryInterval: func(_ *RetryInfo) time.Duration {
return time.Second
},
//ShouldRetry: func(req *http.Request, resp *http.Response, err error) bool {
@@ -121,7 +121,7 @@ func TestHostsNotRetryInterceptor(t *testing.T) {
retryMax := 1
sRetryInterceptor := NewSimpleRetryInterceptor(SimpleRetryConfig{
RetryMax: retryMax,
RetryInterval: func() time.Duration {
RetryInterval: func(_ *RetryInfo) time.Duration {
return time.Second
},
//ShouldRetry: func(req *http.Request, resp *http.Response, err error) bool {
@@ -188,7 +188,7 @@ func TestHostsRetryInterceptorByRequest(t *testing.T) {
hRetryInterceptor := NewHostsRetryInterceptor(HostsRetryConfig{
RetryConfig: RetryConfig{
RetryMax: hRetryMax,
RetryInterval: func() time.Duration {
RetryInterval: func(_ *RetryInfo) time.Duration {
return time.Second
},
},
@@ -200,7 +200,7 @@ func TestHostsRetryInterceptorByRequest(t *testing.T) {
retryMax := 1
sRetryInterceptor := NewSimpleRetryInterceptor(SimpleRetryConfig{
RetryMax: retryMax,
RetryInterval: func() time.Duration {
RetryInterval: func(_ *RetryInfo) time.Duration {
return time.Second
},
})
58 changes: 31 additions & 27 deletions internal/clientv2/interceptor_retry_simple.go
Original file line number Diff line number Diff line change
@@ -17,13 +17,31 @@ import (
"github.com/qiniu/go-sdk/v7/storagev2/resolver"
)

type contextKeyBufferResponse struct{}
type (
contextKeyBufferResponse struct{}

type RetryConfig struct {
RetryMax int // 最大重试次数
RetryInterval func() time.Duration // 重试时间间隔
ShouldRetry func(req *http.Request, resp *http.Response, err error) bool
}
RetryInfo struct {
Retried int
}

SimpleRetryConfig struct {
RetryMax int // 最大重试次数
RetryInterval func(*RetryInfo) time.Duration // 重试时间间隔
ShouldRetry func(req *http.Request, resp *http.Response, err error) bool
Resolver resolver.Resolver // 主备域名解析器
Chooser chooser.Chooser // 主备域名选择器
}

simpleRetryInterceptor struct {
config SimpleRetryConfig
}

RetryConfig struct {
RetryMax int // 最大重试次数
RetryInterval func(*RetryInfo) time.Duration // 重试时间间隔
ShouldRetry func(req *http.Request, resp *http.Response, err error) bool
}
)

func (c *RetryConfig) init() {
if c == nil {
@@ -35,30 +53,14 @@ func (c *RetryConfig) init() {
}

if c.RetryInterval == nil {
c.RetryInterval = func() time.Duration {
return time.Duration(50+rand.Int()%50) * time.Millisecond
}
c.RetryInterval = defaultRetryInterval
}

if c.ShouldRetry == nil {
c.ShouldRetry = isSimpleRetryable
}
}

type (
SimpleRetryConfig struct {
RetryMax int // 最大重试次数
RetryInterval func() time.Duration // 重试时间间隔
ShouldRetry func(req *http.Request, resp *http.Response, err error) bool
Resolver resolver.Resolver // 主备域名解析器
Chooser chooser.Chooser // 主备域名选择器
}

simpleRetryInterceptor struct {
config SimpleRetryConfig
}
)

func (c *SimpleRetryConfig) init() {
if c == nil {
return
@@ -69,9 +71,7 @@ func (c *SimpleRetryConfig) init() {
}

if c.RetryInterval == nil {
c.RetryInterval = func() time.Duration {
return time.Duration(50+rand.Int()%50) * time.Millisecond
}
c.RetryInterval = defaultRetryInterval
}

if c.ShouldRetry == nil {
@@ -146,7 +146,7 @@ func (interceptor *simpleRetryInterceptor) Intercept(req *http.Request, handler
resp.Body.Close()
}

retryInterval := interceptor.config.RetryInterval()
retryInterval := interceptor.config.RetryInterval(&RetryInfo{Retried: i})
if retryInterval < time.Microsecond {
continue
}
@@ -267,3 +267,7 @@ func isNetworkErrorWithOpError(err *net.OpError) bool {

return false
}

func defaultRetryInterval(_ *RetryInfo) time.Duration {
return time.Duration(50+rand.Int()%50) * time.Millisecond
}
4 changes: 2 additions & 2 deletions internal/clientv2/interceptor_retry_simple_test.go
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ func TestSimpleAlwaysRetryInterceptor(t *testing.T) {
retryMax := 1
rInterceptor := NewSimpleRetryInterceptor(SimpleRetryConfig{
RetryMax: retryMax,
RetryInterval: func() time.Duration {
RetryInterval: func(_ *RetryInfo) time.Duration {
return time.Second
},
ShouldRetry: func(req *http.Request, resp *http.Response, err error) bool {
@@ -69,7 +69,7 @@ func TestSimpleNotRetryInterceptor(t *testing.T) {
retryMax := 1
rInterceptor := NewSimpleRetryInterceptor(SimpleRetryConfig{
RetryMax: retryMax,
RetryInterval: func() time.Duration {
RetryInterval: func(_ *RetryInfo) time.Duration {
return time.Second
},
// 默认状态码是 400,400 不重试
3 changes: 1 addition & 2 deletions storage/bucket.go
Original file line number Diff line number Diff line change
@@ -14,7 +14,6 @@ import (
"strings"
"time"

"github.com/alex-ant/gomath/rational"
"github.com/qiniu/go-sdk/v7/internal/clientv2"
"github.com/qiniu/go-sdk/v7/storagev2/apis"
"github.com/qiniu/go-sdk/v7/storagev2/apis/batch_ops"
@@ -1069,7 +1068,7 @@ func (m *BucketManager) chooser() chooser.Chooser {
if m.options.Chooser != nil {
return m.options.Chooser
}
return chooser.NewNeverEmptyHandedChooser(chooser.NewShuffleChooser(chooser.NewSmartIPChooser(nil)), rational.New(1, 2))
return chooser.NewShuffleChooser(chooser.NewSmartIPChooser(nil))
}

// 构建op的方法,导出的方法支持在Batch操作中使用
3 changes: 1 addition & 2 deletions storage/region_uc_v2.go
Original file line number Diff line number Diff line change
@@ -12,7 +12,6 @@ import (

"golang.org/x/sync/singleflight"

"github.com/alex-ant/gomath/rational"
"github.com/qiniu/go-sdk/v7/client"
"github.com/qiniu/go-sdk/v7/internal/clientv2"
"github.com/qiniu/go-sdk/v7/storagev2/chooser"
@@ -283,7 +282,7 @@ func getRegionByV2(ak, bucket string, options UCApiOptions) (*Region, error) {
}
}
if options.Chooser == nil {
options.Chooser = chooser.NewNeverEmptyHandedChooser(chooser.NewShuffleChooser(chooser.NewSmartIPChooser(nil)), rational.New(1, 2))
options.Chooser = chooser.NewShuffleChooser(chooser.NewSmartIPChooser(nil))
}

var ret UcQueryRet
3 changes: 1 addition & 2 deletions storage/region_uc_v4.go
Original file line number Diff line number Diff line change
@@ -12,7 +12,6 @@ import (

"golang.org/x/sync/singleflight"

"github.com/alex-ant/gomath/rational"
"github.com/qiniu/go-sdk/v7/internal/clientv2"
"github.com/qiniu/go-sdk/v7/storagev2/chooser"
"github.com/qiniu/go-sdk/v7/storagev2/resolver"
@@ -162,7 +161,7 @@ func getRegionByV4(ak, bucket string, options UCApiOptions) (*RegionGroup, error
}
}
if options.Chooser == nil {
options.Chooser = chooser.NewNeverEmptyHandedChooser(chooser.NewShuffleChooser(chooser.NewSmartIPChooser(nil)), rational.New(1, 2))
options.Chooser = chooser.NewShuffleChooser(chooser.NewSmartIPChooser(nil))
}

var ret ucQueryV4Ret
13 changes: 8 additions & 5 deletions storagev2/chooser/chooser.go
Original file line number Diff line number Diff line change
@@ -3,7 +3,6 @@ package chooser
import (
"context"
"net"
"time"
)

type (
@@ -34,10 +33,6 @@ type (
// FeedbackBad 反馈一批 IP 地址请求失败
FeedbackBad(context.Context, *FeedbackOptions)
}

blacklistItem struct {
expiredAt time.Time
}
)

type directChooser struct {
@@ -58,3 +53,11 @@ func (chooser *directChooser) FeedbackGood(_ context.Context, _ *FeedbackOptions
func (chooser *directChooser) FeedbackBad(_ context.Context, _ *FeedbackOptions) {
// do nothing
}

func (options *ChooseOptions) makeSet(makeKey func(string, net.IP) string) map[string]struct{} {
m := make(map[string]struct{}, len(options.IPs))
for _, ip := range options.IPs {
m[makeKey(options.Domain, ip)] = struct{}{}
}
return m
}
Loading