aboutsummaryrefslogtreecommitdiff
path: root/weed/filer/configuration.go
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2020-12-19 01:27:09 -0800
committerChris Lu <chris.lu@gmail.com>2020-12-19 01:27:09 -0800
commit41c0f3ad2495508cdcea8ec22c18db46a925fecb (patch)
tree3fc35c9fd4b3d56f65c5b5b0368e24390f34b943 /weed/filer/configuration.go
parent0d5683fb0e6b1afe5fe7dadaa05361c0d698e795 (diff)
downloadseaweedfs-41c0f3ad2495508cdcea8ec22c18db46a925fecb.tar.xz
seaweedfs-41c0f3ad2495508cdcea8ec22c18db46a925fecb.zip
filer: support path-specific filer store
Diffstat (limited to 'weed/filer/configuration.go')
-rw-r--r--weed/filer/configuration.go61
1 files changed, 49 insertions, 12 deletions
diff --git a/weed/filer/configuration.go b/weed/filer/configuration.go
index d04ab06cb..5f5dfed25 100644
--- a/weed/filer/configuration.go
+++ b/weed/filer/configuration.go
@@ -1,10 +1,11 @@
package filer
import (
- "os"
-
"github.com/chrislusf/seaweedfs/weed/glog"
"github.com/spf13/viper"
+ "os"
+ "reflect"
+ "strings"
)
var (
@@ -15,28 +16,64 @@ func (f *Filer) LoadConfiguration(config *viper.Viper) {
validateOneEnabledStore(config)
+ // load configuration for default filer store
+ hasDefaultStoreConfigured := false
for _, store := range Stores {
if config.GetBool(store.GetName() + ".enabled") {
+ store = reflect.New(reflect.ValueOf(store).Elem().Type()).Interface().(FilerStore)
if err := store.Initialize(config, store.GetName()+"."); err != nil {
- glog.Fatalf("Failed to initialize store for %s: %+v",
- store.GetName(), err)
+ glog.Fatalf("failed to initialize store for %s: %+v", store.GetName(), err)
}
f.SetStore(store)
- glog.V(0).Infof("Configure filer for %s", store.GetName())
- return
+ glog.V(0).Infof("configured filer for %s", store.GetName())
+ hasDefaultStoreConfigured = true
+ break
}
}
- // TODO load path-specific filer store here
- // f.Store.AddPathSpecificStore(path, store)
+ if !hasDefaultStoreConfigured {
+ println()
+ println("Supported filer stores are:")
+ for _, store := range Stores {
+ println(" " + store.GetName())
+ }
+ os.Exit(-1)
+ }
- println()
- println("Supported filer stores are:")
+ // load path-specific filer store here
+ // f.Store.AddPathSpecificStore(path, store)
+ storeNames := make(map[string]FilerStore)
for _, store := range Stores {
- println(" " + store.GetName())
+ storeNames[store.GetName()] = store
+ }
+ allKeys := config.AllKeys()
+ for _, key := range allKeys {
+ if !strings.HasSuffix(key, ".enabled") {
+ continue
+ }
+ key = key[:len(key)-len(".enabled")]
+ if !strings.Contains(key, ".") {
+ continue
+ }
+
+ parts := strings.Split(key, ".")
+ storeName, storeId := parts[0], parts[1]
+
+ store := storeNames[storeName]
+ store = reflect.New(reflect.ValueOf(store).Elem().Type()).Interface().(FilerStore)
+ if err := store.Initialize(config, key+"."); err != nil {
+ glog.Fatalf("Failed to initialize store for %s: %+v", key, err)
+ }
+ location := config.GetString(key+".location")
+ if location == "" {
+ glog.Errorf("path-specific filer store needs %s", key+".location")
+ os.Exit(-1)
+ }
+ f.Store.AddPathSpecificStore(location, storeId, store)
+
+ glog.V(0).Infof("configure filer %s for %s", store.GetName(), location)
}
- os.Exit(-1)
}
func validateOneEnabledStore(config *viper.Viper) {