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.

116 lines
2.5 KiB

6 years ago
7 years ago
7 years ago
7 years ago
7 years ago
  1. package filer2
  2. import (
  3. "os"
  4. "github.com/chrislusf/seaweedfs/weed/glog"
  5. "github.com/spf13/viper"
  6. )
  7. const (
  8. FILER_TOML_EXAMPLE = `
  9. # A sample TOML config file for SeaweedFS filer store
  10. [memory]
  11. # local in memory, mostly for testing purpose
  12. enabled = false
  13. [leveldb]
  14. # local on disk, mostly for simple single-machine setup, fairly scalable
  15. enabled = false
  16. dir = "." # directory to store level db files
  17. ####################################################
  18. # multiple filers on shared storage, fairly scalable
  19. ####################################################
  20. [mysql]
  21. # CREATE TABLE IF NOT EXISTS filemeta (
  22. # dirhash BIGINT COMMENT 'first 64 bits of MD5 hash value of directory field',
  23. # name VARCHAR(1000) COMMENT 'directory or file name',
  24. # directory VARCHAR(4096) COMMENT 'full path to parent directory',
  25. # meta BLOB,
  26. # PRIMARY KEY (dirhash, name)
  27. # ) DEFAULT CHARSET=utf8;
  28. enabled = true
  29. hostname = "localhost"
  30. port = 3306
  31. username = "root"
  32. password = ""
  33. database = "" # create or use an existing database
  34. connection_max_idle = 2
  35. connection_max_open = 100
  36. [postgres]
  37. # CREATE TABLE IF NOT EXISTS filemeta (
  38. # dirhash BIGINT,
  39. # name VARCHAR(1000),
  40. # directory VARCHAR(4096),
  41. # meta bytea,
  42. # PRIMARY KEY (dirhash, name)
  43. # );
  44. enabled = false
  45. hostname = "localhost"
  46. port = 5432
  47. username = "postgres"
  48. password = ""
  49. database = "" # create or use an existing database
  50. sslmode = "disable"
  51. connection_max_idle = 100
  52. connection_max_open = 100
  53. [cassandra]
  54. # CREATE TABLE filemeta (
  55. # directory varchar,
  56. # name varchar,
  57. # meta blob,
  58. # PRIMARY KEY (directory, name)
  59. # ) WITH CLUSTERING ORDER BY (name ASC);
  60. enabled = false
  61. keyspace="seaweedfs"
  62. hosts=[
  63. "localhost:9042",
  64. ]
  65. [redis]
  66. enabled = true
  67. address = "localhost:6379"
  68. password = ""
  69. db = 0
  70. [redis_cluster]
  71. enabled = false
  72. addresses = [
  73. "localhost:6379",
  74. ]
  75. `
  76. )
  77. var (
  78. Stores []FilerStore
  79. )
  80. func (f *Filer) LoadConfiguration(config *viper.Viper) {
  81. for _, store := range Stores {
  82. if config.GetBool(store.GetName() + ".enabled") {
  83. viperSub := config.Sub(store.GetName())
  84. if err := store.Initialize(viperSub); err != nil {
  85. glog.Fatalf("Failed to initialize store for %s: %+v",
  86. store.GetName(), err)
  87. }
  88. f.SetStore(store)
  89. glog.V(0).Infof("Configure filer for %s", store.GetName())
  90. return
  91. }
  92. }
  93. println()
  94. println("Supported filer stores are:")
  95. for _, store := range Stores {
  96. println(" " + store.GetName())
  97. }
  98. os.Exit(-1)
  99. }