mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
avoid concurrent map updates to viper
This commit is contained in:
parent
38d516251e
commit
cfb9342a15
|
@ -14,7 +14,6 @@ import (
|
||||||
_ "github.com/chrislusf/seaweedfs/weed/replication/sink/s3sink"
|
_ "github.com/chrislusf/seaweedfs/weed/replication/sink/s3sink"
|
||||||
"github.com/chrislusf/seaweedfs/weed/replication/sub"
|
"github.com/chrislusf/seaweedfs/weed/replication/sub"
|
||||||
"github.com/chrislusf/seaweedfs/weed/util"
|
"github.com/chrislusf/seaweedfs/weed/util"
|
||||||
"github.com/spf13/viper"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -123,7 +122,7 @@ func runFilerReplicate(cmd *Command, args []string) bool {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func validateOneEnabledInput(config *viper.Viper) {
|
func validateOneEnabledInput(config *util.ViperProxy) {
|
||||||
enabledInput := ""
|
enabledInput := ""
|
||||||
for _, input := range sub.NotificationInputs {
|
for _, input := range sub.NotificationInputs {
|
||||||
if config.GetBool("notification." + input.GetName() + ".enabled") {
|
if config.GetBool("notification." + input.GetName() + ".enabled") {
|
||||||
|
|
|
@ -2,7 +2,7 @@ package filer
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/chrislusf/seaweedfs/weed/glog"
|
"github.com/chrislusf/seaweedfs/weed/glog"
|
||||||
"github.com/spf13/viper"
|
"github.com/chrislusf/seaweedfs/weed/util"
|
||||||
"os"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -12,7 +12,7 @@ var (
|
||||||
Stores []FilerStore
|
Stores []FilerStore
|
||||||
)
|
)
|
||||||
|
|
||||||
func (f *Filer) LoadConfiguration(config *viper.Viper) {
|
func (f *Filer) LoadConfiguration(config *util.ViperProxy) {
|
||||||
|
|
||||||
validateOneEnabledStore(config)
|
validateOneEnabledStore(config)
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ func (f *Filer) LoadConfiguration(config *viper.Viper) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func validateOneEnabledStore(config *viper.Viper) {
|
func validateOneEnabledStore(config *util.ViperProxy) {
|
||||||
enabledStore := ""
|
enabledStore := ""
|
||||||
for _, store := range Stores {
|
for _, store := range Stores {
|
||||||
if config.GetBool(store.GetName() + ".enabled") {
|
if config.GetBool(store.GetName() + ".enabled") {
|
||||||
|
|
|
@ -4,7 +4,6 @@ import (
|
||||||
"github.com/chrislusf/seaweedfs/weed/glog"
|
"github.com/chrislusf/seaweedfs/weed/glog"
|
||||||
"github.com/chrislusf/seaweedfs/weed/util"
|
"github.com/chrislusf/seaweedfs/weed/util"
|
||||||
"github.com/golang/protobuf/proto"
|
"github.com/golang/protobuf/proto"
|
||||||
"github.com/spf13/viper"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type MessageQueue interface {
|
type MessageQueue interface {
|
||||||
|
@ -21,7 +20,7 @@ var (
|
||||||
Queue MessageQueue
|
Queue MessageQueue
|
||||||
)
|
)
|
||||||
|
|
||||||
func LoadConfiguration(config *viper.Viper, prefix string) {
|
func LoadConfiguration(config *util.ViperProxy, prefix string) {
|
||||||
|
|
||||||
if config == nil {
|
if config == nil {
|
||||||
return
|
return
|
||||||
|
@ -43,7 +42,7 @@ func LoadConfiguration(config *viper.Viper, prefix string) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func validateOneEnabledQueue(config *viper.Viper) {
|
func validateOneEnabledQueue(config *util.ViperProxy) {
|
||||||
enabledQueue := ""
|
enabledQueue := ""
|
||||||
for _, queue := range MessageQueues {
|
for _, queue := range MessageQueues {
|
||||||
if config.GetBool(queue.GetName() + ".enabled") {
|
if config.GetBool(queue.GetName() + ".enabled") {
|
||||||
|
|
|
@ -3,17 +3,16 @@ package security
|
||||||
import (
|
import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"crypto/x509"
|
"crypto/x509"
|
||||||
|
"github.com/chrislusf/seaweedfs/weed/util"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
|
||||||
"github.com/spf13/viper"
|
|
||||||
|
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
"google.golang.org/grpc/credentials"
|
"google.golang.org/grpc/credentials"
|
||||||
|
|
||||||
"github.com/chrislusf/seaweedfs/weed/glog"
|
"github.com/chrislusf/seaweedfs/weed/glog"
|
||||||
)
|
)
|
||||||
|
|
||||||
func LoadServerTLS(config *viper.Viper, component string) grpc.ServerOption {
|
func LoadServerTLS(config *util.ViperProxy, component string) grpc.ServerOption {
|
||||||
if config == nil {
|
if config == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -40,7 +39,7 @@ func LoadServerTLS(config *viper.Viper, component string) grpc.ServerOption {
|
||||||
return grpc.Creds(ta)
|
return grpc.Creds(ta)
|
||||||
}
|
}
|
||||||
|
|
||||||
func LoadClientTLS(config *viper.Viper, component string) grpc.DialOption {
|
func LoadClientTLS(config *util.ViperProxy, component string) grpc.DialOption {
|
||||||
if config == nil {
|
if config == nil {
|
||||||
return grpc.WithInsecure()
|
return grpc.WithInsecure()
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package backend
|
package backend
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/chrislusf/seaweedfs/weed/util"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -9,7 +10,6 @@ import (
|
||||||
"github.com/chrislusf/seaweedfs/weed/glog"
|
"github.com/chrislusf/seaweedfs/weed/glog"
|
||||||
"github.com/chrislusf/seaweedfs/weed/pb/master_pb"
|
"github.com/chrislusf/seaweedfs/weed/pb/master_pb"
|
||||||
"github.com/chrislusf/seaweedfs/weed/pb/volume_server_pb"
|
"github.com/chrislusf/seaweedfs/weed/pb/volume_server_pb"
|
||||||
"github.com/spf13/viper"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type BackendStorageFile interface {
|
type BackendStorageFile interface {
|
||||||
|
@ -45,7 +45,7 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
// used by master to load remote storage configurations
|
// used by master to load remote storage configurations
|
||||||
func LoadConfiguration(config *viper.Viper) {
|
func LoadConfiguration(config *util.ViperProxy) {
|
||||||
|
|
||||||
StorageBackendPrefix := "storage.backend"
|
StorageBackendPrefix := "storage.backend"
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ package util
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
|
|
||||||
|
@ -46,9 +47,20 @@ func LoadConfiguration(configFileName string, required bool) (loaded bool) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetViper() *viper.Viper {
|
type ViperProxy struct {
|
||||||
v := &viper.Viper{}
|
*viper.Viper
|
||||||
*v = *viper.GetViper()
|
sync.Mutex
|
||||||
|
}
|
||||||
|
|
||||||
|
func (vp *ViperProxy) SetDefault(key string, value interface{}) {
|
||||||
|
vp.Lock()
|
||||||
|
defer vp.Unlock()
|
||||||
|
vp.Viper.SetDefault(key, value)
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetViper() *ViperProxy {
|
||||||
|
v := &ViperProxy{}
|
||||||
|
v.Viper = viper.GetViper()
|
||||||
v.AutomaticEnv()
|
v.AutomaticEnv()
|
||||||
v.SetEnvPrefix("weed")
|
v.SetEnvPrefix("weed")
|
||||||
v.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
|
v.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
|
||||||
|
|
Loading…
Reference in a new issue