aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruitao.liu <ruitao.liu@cloudminds.com>2020-09-10 23:35:20 +0800
committerruitao.liu <ruitao.liu@cloudminds.com>2020-09-10 23:35:20 +0800
commit5b0676049a78a82f94c3d6ff1311e71e7905ff88 (patch)
treecf4ee81fb1718e3c43cc2ffb109af71e24e40f72
parent660d7c0edddf82d3aecb71ea29a097cc6eaf0970 (diff)
downloadseaweedfs-5b0676049a78a82f94c3d6ff1311e71e7905ff88.tar.xz
seaweedfs-5b0676049a78a82f94c3d6ff1311e71e7905ff88.zip
change elastic initialize process similar as others.
-rw-r--r--weed/filer/elastic/v7/elastic_store.go41
1 files changed, 21 insertions, 20 deletions
diff --git a/weed/filer/elastic/v7/elastic_store.go b/weed/filer/elastic/v7/elastic_store.go
index 8f2af25da..ec88e10a5 100644
--- a/weed/filer/elastic/v7/elastic_store.go
+++ b/weed/filer/elastic/v7/elastic_store.go
@@ -15,10 +15,10 @@ import (
)
var (
- indexType = "_doc"
- indexPrefix = ".seaweedfs_"
- indexKV = ".seaweedfs_kv_entries"
- mappingWithoutQuery = ` {
+ indexType = "_doc"
+ indexPrefix = ".seaweedfs_"
+ indexKV = ".seaweedfs_kv_entries"
+ kvMappings = ` {
"mappings": {
"enabled": false,
"properties": {
@@ -53,21 +53,7 @@ func (store *ElasticStore) GetName() string {
}
func (store *ElasticStore) Initialize(configuration weed_util.Configuration, prefix string) (err error) {
- options := store.initialize(configuration, prefix)
- store.client, err = elastic.NewClient(options...)
- if err != nil {
- return fmt.Errorf("init elastic %v.", err)
- }
- if ok, err := store.client.IndexExists(indexKV).Do(context.Background()); err == nil && !ok {
- _, err = store.client.CreateIndex(indexKV).Body(mappingWithoutQuery).Do(context.Background())
- if err != nil {
- return fmt.Errorf("create index(%s) %v.", indexKV, err)
- }
- }
- return nil
-}
-
-func (store *ElasticStore) initialize(configuration weed_util.Configuration, prefix string) (options []elastic.ClientOptionFunc) {
+ options := []elastic.ClientOptionFunc{}
servers := configuration.GetStringSlice(prefix + "servers")
options = append(options, elastic.SetURL(servers...))
username := configuration.GetString(prefix + "username")
@@ -82,7 +68,22 @@ func (store *ElasticStore) initialize(configuration weed_util.Configuration, pre
store.maxPageSize = 10000
}
glog.Infof("filer store elastic endpoints: %v.", servers)
- return options
+ return store.initialize(options)
+}
+
+func (store *ElasticStore) initialize(options []elastic.ClientOptionFunc) (err error) {
+ ctx := context.Background()
+ store.client, err = elastic.NewClient(options...)
+ if err != nil {
+ return fmt.Errorf("init elastic %v.", err)
+ }
+ if ok, err := store.client.IndexExists(indexKV).Do(ctx); err == nil && !ok {
+ _, err = store.client.CreateIndex(indexKV).Body(kvMappings).Do(ctx)
+ if err != nil {
+ return fmt.Errorf("create index(%s) %v.", indexKV, err)
+ }
+ }
+ return nil
}
func (store *ElasticStore) BeginTransaction(ctx context.Context) (context.Context, error) {