1
0
Fork 0
mirror of https://github.com/chrislusf/seaweedfs synced 2024-07-03 07:36:45 +02:00

add gocql timeout setting

This commit is contained in:
guol-fnst 2022-01-18 14:41:39 +08:00 committed by root
parent c87b8f4c30
commit da9540e666
2 changed files with 7 additions and 1 deletions

View file

@ -153,6 +153,8 @@ password = ""
superLargeDirectories = [] superLargeDirectories = []
# Name of the datacenter local to this filer, used as host selection fallback. # Name of the datacenter local to this filer, used as host selection fallback.
localDC = "" localDC = ""
# Gocql connection timeout, default: 600ms
connection_timeout_millisecond = 600
[hbase] [hbase]
enabled = false enabled = false

View file

@ -4,6 +4,7 @@ import (
"context" "context"
"fmt" "fmt"
"github.com/gocql/gocql" "github.com/gocql/gocql"
"time"
"github.com/chrislusf/seaweedfs/weed/filer" "github.com/chrislusf/seaweedfs/weed/filer"
"github.com/chrislusf/seaweedfs/weed/glog" "github.com/chrislusf/seaweedfs/weed/glog"
@ -33,6 +34,7 @@ func (store *CassandraStore) Initialize(configuration util.Configuration, prefix
configuration.GetString(prefix+"password"), configuration.GetString(prefix+"password"),
configuration.GetStringSlice(prefix+"superLargeDirectories"), configuration.GetStringSlice(prefix+"superLargeDirectories"),
configuration.GetString(prefix+"localDC"), configuration.GetString(prefix+"localDC"),
configuration.GetInt(prefix+"connection_timeout_millisecond"),
) )
} }
@ -41,12 +43,14 @@ func (store *CassandraStore) isSuperLargeDirectory(dir string) (dirHash string,
return return
} }
func (store *CassandraStore) initialize(keyspace string, hosts []string, username string, password string, superLargeDirectories []string, localDC string) (err error) { func (store *CassandraStore) initialize(keyspace string, hosts []string, username string, password string, superLargeDirectories []string, localDC string, timeout int) (err error) {
store.cluster = gocql.NewCluster(hosts...) store.cluster = gocql.NewCluster(hosts...)
if username != "" && password != "" { if username != "" && password != "" {
store.cluster.Authenticator = gocql.PasswordAuthenticator{Username: username, Password: password} store.cluster.Authenticator = gocql.PasswordAuthenticator{Username: username, Password: password}
} }
store.cluster.Keyspace = keyspace store.cluster.Keyspace = keyspace
store.cluster.Timeout = time.Duration(timeout) * time.Millisecond
glog.V(0).Infof("timeout = %d", timeout)
fallback := gocql.RoundRobinHostPolicy() fallback := gocql.RoundRobinHostPolicy()
if localDC != "" { if localDC != "" {
fallback = gocql.DCAwareRoundRobinPolicy(localDC) fallback = gocql.DCAwareRoundRobinPolicy(localDC)