You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
2.4 KiB

6 years ago
4 years ago
4 years ago
6 years ago
6 years ago
  1. package filer
  2. import (
  3. "github.com/chrislusf/seaweedfs/weed/glog"
  4. "github.com/chrislusf/seaweedfs/weed/util"
  5. "os"
  6. "reflect"
  7. "strings"
  8. )
  9. var (
  10. Stores []FilerStore
  11. )
  12. func (f *Filer) LoadConfiguration(config *util.ViperProxy) (isFresh bool) {
  13. validateOneEnabledStore(config)
  14. // load configuration for default filer store
  15. hasDefaultStoreConfigured := false
  16. for _, store := range Stores {
  17. if config.GetBool(store.GetName() + ".enabled") {
  18. store = reflect.New(reflect.ValueOf(store).Elem().Type()).Interface().(FilerStore)
  19. if err := store.Initialize(config, store.GetName()+"."); err != nil {
  20. glog.Fatalf("failed to initialize store for %s: %+v", store.GetName(), err)
  21. }
  22. isFresh = f.SetStore(store)
  23. glog.V(0).Infof("configured filer store to %s", store.GetName())
  24. hasDefaultStoreConfigured = true
  25. break
  26. }
  27. }
  28. if !hasDefaultStoreConfigured {
  29. println()
  30. println("Supported filer stores are:")
  31. for _, store := range Stores {
  32. println(" " + store.GetName())
  33. }
  34. os.Exit(-1)
  35. }
  36. // load path-specific filer store here
  37. // f.Store.AddPathSpecificStore(path, store)
  38. storeNames := make(map[string]FilerStore)
  39. for _, store := range Stores {
  40. storeNames[store.GetName()] = store
  41. }
  42. allKeys := config.AllKeys()
  43. for _, key := range allKeys {
  44. if !strings.HasSuffix(key, ".enabled") {
  45. continue
  46. }
  47. key = key[:len(key)-len(".enabled")]
  48. if !strings.Contains(key, ".") {
  49. continue
  50. }
  51. parts := strings.Split(key, ".")
  52. storeName, storeId := parts[0], parts[1]
  53. store, found := storeNames[storeName]
  54. if !found {
  55. continue
  56. }
  57. store = reflect.New(reflect.ValueOf(store).Elem().Type()).Interface().(FilerStore)
  58. if err := store.Initialize(config, key+"."); err != nil {
  59. glog.Fatalf("Failed to initialize store for %s: %+v", key, err)
  60. }
  61. location := config.GetString(key + ".location")
  62. if location == "" {
  63. glog.Errorf("path-specific filer store needs %s", key+".location")
  64. os.Exit(-1)
  65. }
  66. f.Store.AddPathSpecificStore(location, storeId, store)
  67. glog.V(0).Infof("configure filer %s for %s", store.GetName(), location)
  68. }
  69. return
  70. }
  71. func validateOneEnabledStore(config *util.ViperProxy) {
  72. enabledStore := ""
  73. for _, store := range Stores {
  74. if config.GetBool(store.GetName() + ".enabled") {
  75. if enabledStore == "" {
  76. enabledStore = store.GetName()
  77. } else {
  78. glog.Fatalf("Filer store is enabled for both %s and %s", enabledStore, store.GetName())
  79. }
  80. }
  81. }
  82. }