diff options
| author | Chris Lu <chrislusf@users.noreply.github.com> | 2021-07-02 13:51:53 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-07-02 13:51:53 -0700 |
| commit | 2cb8b31ea72dc53a3adac04295b76dcd73203fee (patch) | |
| tree | b98cb547914f08d542a92b21b3f88249c5944e02 /weed/filer | |
| parent | d8bda0b2294afe59f0edc062fd145cd24ea725db (diff) | |
| parent | 8425705643695df7e8f910c41b2f40ad71ecdedc (diff) | |
| download | seaweedfs-2cb8b31ea72dc53a3adac04295b76dcd73203fee.tar.xz seaweedfs-2cb8b31ea72dc53a3adac04295b76dcd73203fee.zip | |
Merge pull request #2179 from nivekuil/tokenpolicy
Cassandra: Use TokenAwareHostPolicy with fallback to localDC by default
Diffstat (limited to 'weed/filer')
| -rw-r--r-- | weed/filer/cassandra/cassandra_store.go | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/weed/filer/cassandra/cassandra_store.go b/weed/filer/cassandra/cassandra_store.go index 0398f5117..f4856657e 100644 --- a/weed/filer/cassandra/cassandra_store.go +++ b/weed/filer/cassandra/cassandra_store.go @@ -32,6 +32,7 @@ func (store *CassandraStore) Initialize(configuration util.Configuration, prefix configuration.GetString(prefix+"username"), configuration.GetString(prefix+"password"), configuration.GetStringSlice(prefix+"superLargeDirectories"), + configuration.GetString(prefix+"localDC"), ) } @@ -40,13 +41,19 @@ func (store *CassandraStore) isSuperLargeDirectory(dir string) (dirHash string, 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...) if username != "" && password != "" { store.cluster.Authenticator = gocql.PasswordAuthenticator{Username: username, Password: password} } 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.session, err = store.cluster.CreateSession() if err != nil { glog.V(0).Infof("Failed to open cassandra store, hosts %v, keyspace %s", hosts, keyspace) |
