2020-09-01 07:21:19 +00:00
|
|
|
package filer
|
2018-05-26 10:49:46 +00:00
|
|
|
|
|
|
|
import (
|
2022-07-29 07:17:28 +00:00
|
|
|
"github.com/seaweedfs/seaweedfs/weed/glog"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/util"
|
2020-12-19 09:27:09 +00:00
|
|
|
"os"
|
|
|
|
"reflect"
|
|
|
|
"strings"
|
2018-05-26 10:49:46 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
Stores []FilerStore
|
|
|
|
)
|
|
|
|
|
2022-05-31 04:27:48 +00:00
|
|
|
func (f *Filer) LoadConfiguration(config *util.ViperProxy) (isFresh bool) {
|
2018-05-26 10:49:46 +00:00
|
|
|
|
2018-12-06 08:44:41 +00:00
|
|
|
validateOneEnabledStore(config)
|
2018-12-06 08:32:36 +00:00
|
|
|
|
2020-12-19 09:27:09 +00:00
|
|
|
// load configuration for default filer store
|
|
|
|
hasDefaultStoreConfigured := false
|
2018-05-26 10:49:46 +00:00
|
|
|
for _, store := range Stores {
|
2018-08-19 22:17:55 +00:00
|
|
|
if config.GetBool(store.GetName() + ".enabled") {
|
2020-12-19 09:27:09 +00:00
|
|
|
store = reflect.New(reflect.ValueOf(store).Elem().Type()).Interface().(FilerStore)
|
2020-01-29 17:09:55 +00:00
|
|
|
if err := store.Initialize(config, store.GetName()+"."); err != nil {
|
2020-12-19 09:27:09 +00:00
|
|
|
glog.Fatalf("failed to initialize store for %s: %+v", store.GetName(), err)
|
2018-05-26 10:49:46 +00:00
|
|
|
}
|
2022-05-31 04:27:48 +00:00
|
|
|
isFresh = f.SetStore(store)
|
2020-12-23 01:30:26 +00:00
|
|
|
glog.V(0).Infof("configured filer store to %s", store.GetName())
|
2020-12-19 09:27:09 +00:00
|
|
|
hasDefaultStoreConfigured = true
|
|
|
|
break
|
2018-05-26 10:49:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-19 09:27:09 +00:00
|
|
|
if !hasDefaultStoreConfigured {
|
|
|
|
println()
|
|
|
|
println("Supported filer stores are:")
|
|
|
|
for _, store := range Stores {
|
|
|
|
println(" " + store.GetName())
|
|
|
|
}
|
|
|
|
os.Exit(-1)
|
|
|
|
}
|
2020-12-18 11:05:42 +00:00
|
|
|
|
2020-12-19 09:27:09 +00:00
|
|
|
// load path-specific filer store here
|
|
|
|
// f.Store.AddPathSpecificStore(path, store)
|
|
|
|
storeNames := make(map[string]FilerStore)
|
2018-05-26 10:49:46 +00:00
|
|
|
for _, store := range Stores {
|
2020-12-19 09:27:09 +00:00
|
|
|
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]
|
|
|
|
|
2020-12-21 20:43:52 +00:00
|
|
|
store, found := storeNames[storeName]
|
|
|
|
if !found {
|
2020-12-22 10:46:24 +00:00
|
|
|
continue
|
2020-12-21 20:43:52 +00:00
|
|
|
}
|
2022-11-14 07:30:23 +00:00
|
|
|
|
|
|
|
if !config.GetBool(key + ".enabled") {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2020-12-19 09:27:09 +00:00
|
|
|
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)
|
|
|
|
}
|
2020-12-22 10:34:08 +00:00
|
|
|
location := config.GetString(key + ".location")
|
2020-12-19 09:27:09 +00:00
|
|
|
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)
|
2018-05-26 10:49:46 +00:00
|
|
|
}
|
|
|
|
|
2022-05-31 04:27:48 +00:00
|
|
|
return
|
2018-05-26 10:49:46 +00:00
|
|
|
}
|
2018-12-06 08:44:41 +00:00
|
|
|
|
2021-01-12 10:28:13 +00:00
|
|
|
func validateOneEnabledStore(config *util.ViperProxy) {
|
2018-12-06 08:44:41 +00:00
|
|
|
enabledStore := ""
|
|
|
|
for _, store := range Stores {
|
|
|
|
if config.GetBool(store.GetName() + ".enabled") {
|
|
|
|
if enabledStore == "" {
|
|
|
|
enabledStore = store.GetName()
|
|
|
|
} else {
|
|
|
|
glog.Fatalf("Filer store is enabled for both %s and %s", enabledStore, store.GetName())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|