mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
Cassandra: Use TokenAwareHostPolicy by default with fallback
See https://pkg.go.dev/github.com/gocql/gocql#hdr-Data_center_awareness_and_query_routing
This commit is contained in:
parent
17477b37d5
commit
8425705643
|
@ -217,6 +217,8 @@ username=""
|
||||||
password=""
|
password=""
|
||||||
# This changes the data layout. Only add new directories. Removing/Updating will cause data loss.
|
# This changes the data layout. Only add new directories. Removing/Updating will cause data loss.
|
||||||
superLargeDirectories = []
|
superLargeDirectories = []
|
||||||
|
# Name of the datacenter local to this filer, used as host selection fallback.
|
||||||
|
localDC=""
|
||||||
|
|
||||||
[hbase]
|
[hbase]
|
||||||
enabled = false
|
enabled = false
|
||||||
|
|
|
@ -32,6 +32,7 @@ func (store *CassandraStore) Initialize(configuration util.Configuration, prefix
|
||||||
configuration.GetString(prefix+"username"),
|
configuration.GetString(prefix+"username"),
|
||||||
configuration.GetString(prefix+"password"),
|
configuration.GetString(prefix+"password"),
|
||||||
configuration.GetStringSlice(prefix+"superLargeDirectories"),
|
configuration.GetStringSlice(prefix+"superLargeDirectories"),
|
||||||
|
configuration.GetString(prefix+"localDC"),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,13 +41,19 @@ func (store *CassandraStore) isSuperLargeDirectory(dir string) (dirHash string,
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (store *CassandraStore) initialize(keyspace string, hosts []string, username string, password string, superLargeDirectories []string) (err error) {
|
func (store *CassandraStore) initialize(keyspace string, hosts []string, username string, password string, superLargeDirectories []string, localDC string) (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
|
||||||
|
fallback := gocql.RoundRobinHostPolicy()
|
||||||
|
if localDC != "" {
|
||||||
|
fallback = gocql.DCAwareRoundRobinPolicy(localDC)
|
||||||
|
}
|
||||||
|
store.cluster.PoolConfig.HostSelectionPolicy = gocql.TokenAwareHostPolicy(fallback)
|
||||||
store.cluster.Consistency = gocql.LocalQuorum
|
store.cluster.Consistency = gocql.LocalQuorum
|
||||||
|
|
||||||
store.session, err = store.cluster.CreateSession()
|
store.session, err = store.cluster.CreateSession()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.V(0).Infof("Failed to open cassandra store, hosts %v, keyspace %s", hosts, keyspace)
|
glog.V(0).Infof("Failed to open cassandra store, hosts %v, keyspace %s", hosts, keyspace)
|
||||||
|
|
Loading…
Reference in a new issue