Skip to content

SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.

better locks

Chris Lue2c7e3fe6d44
diff --git a/weed/util/config.go b/weed/util/config.go
index e746b0bd19..2af1ad09ec 100644
--- a/weed/util/config.go
+++ b/weed/util/config.go
@@ -52,6 +52,10 @@ type ViperProxy struct {
sync.Mutex
}
+var (
+ vp = &ViperProxy{}
+)
+
func (vp *ViperProxy) SetDefault(key string, value interface{}) {
vp.Lock()
defer vp.Unlock()
@@ -83,10 +87,15 @@ func (vp *ViperProxy) GetStringSlice(key string) []string {
}
func GetViper() *ViperProxy {
- v := &ViperProxy{}
- v.Viper = viper.GetViper()
- v.AutomaticEnv()
- v.SetEnvPrefix("weed")
- v.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
- return v
+ vp.Lock()
+ defer vp.Unlock()
+
+ if vp.Viper == nil {
+ vp.Viper = viper.GetViper()
+ vp.AutomaticEnv()
+ vp.SetEnvPrefix("weed")
+ vp.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
+ }
+
+ return vp
}