Skip to content

Commit

Permalink
MB-43280 : [BP] Make Timeout for GetWithCbauth Configurable.
Browse files Browse the repository at this point in the history
Back porting of MB-42063: Make the Timeout for GetWithCbauth Configurable.

Change-Id: I1fc95ada3ea0883d263ccc8846e25230fa5b0500
  • Loading branch information
ksaikrishnateja authored and amithk committed Dec 17, 2020
1 parent bc72f9e commit 4941422
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
7 changes: 7 additions & 0 deletions secondary/common/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,13 @@ var SystemConfig = Config{
false, // mutable
false, // case-insensitive
},
"queryport.client.restRequestTimeout": ConfigValue{
120, // value
"timeout, in seconds, is timeout for REST calls in GetWithCbauth Function of Index Planner.", //help
120, // default
false, // immutable
false, // case-insensitive
},
"indexer.allowPartialQuorum": ConfigValue{
false,
"This boolean flag, when set, allows index creation with partial quorum. " +
Expand Down
15 changes: 14 additions & 1 deletion secondary/planner/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"encoding/json"
"errors"
"fmt"
"sync/atomic"
"github.com/couchbase/indexing/secondary/common"
"github.com/couchbase/indexing/secondary/logging"
mc "github.com/couchbase/indexing/secondary/manager/common"
Expand All @@ -34,6 +35,17 @@ var cinfoClient *common.ClusterInfoClient
// from multiple go-routines
var cinfoClientMutex sync.Mutex

// restRequestTimeout in Seconds
var restRequestTimeout uint32 = 120

func GetRestRequestTimeout() uint32 {
return atomic.LoadUint32(&restRequestTimeout)
}

func SetRestRequestTimeout(val uint32) {
atomic.StoreUint32(&restRequestTimeout, val)
}

//////////////////////////////////////////////////////////////
// Concrete Type/Struct
//////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -1088,7 +1100,8 @@ func getLocalNumReplicas(addr string) (map[common.IndexDefnId]common.Counter, er

func getWithCbauth(url string) (*http.Response, error) {

params := &security.RequestParams{Timeout: time.Duration(10) * time.Second}
t := GetRestRequestTimeout()
params := &security.RequestParams{Timeout: time.Duration(t) * time.Second}
response, err := security.GetWithAuth(url, params)
if err == nil && response.StatusCode != http.StatusOK {
return response, convertError(response)
Expand Down
13 changes: 10 additions & 3 deletions secondary/queryport/client/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
package client

import (
"github.com/couchbase/cbauth/metakv"
"github.com/couchbase/indexing/secondary/common"
"github.com/couchbase/indexing/secondary/logging"
"math"
"sync"
"sync/atomic"
"time"

"github.com/couchbase/cbauth/metakv"
"github.com/couchbase/indexing/secondary/common"
"github.com/couchbase/indexing/secondary/logging"
"github.com/couchbase/indexing/secondary/planner"
)

type ClientSettings struct {
Expand Down Expand Up @@ -210,6 +212,11 @@ func (s *ClientSettings) handleSettings(config common.Config) {
}()
}

restRequestTimeout, ok := config["queryport.client.restRequestTimeout"]
if ok {
planner.SetRestRequestTimeout(uint32(restRequestTimeout.Int()))
}

if s.needRefresh {
logLevel := config["queryport.client.log_level"].String()
level := logging.Level(logLevel)
Expand Down

0 comments on commit 4941422

Please sign in to comment.