2021-10-09 18:03:34 +08:00
|
|
|
// Licensed to the LF AI & Data foundation under one
|
|
|
|
// or more contributor license agreements. See the NOTICE file
|
|
|
|
// distributed with this work for additional information
|
|
|
|
// regarding copyright ownership. The ASF licenses this file
|
|
|
|
// to you under the Apache License, Version 2.0 (the
|
|
|
|
// "License"); you may not use this file except in compliance
|
2021-06-18 15:20:08 +08:00
|
|
|
// with the License. You may obtain a copy of the License at
|
|
|
|
//
|
2021-10-09 18:03:34 +08:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2021-06-18 15:20:08 +08:00
|
|
|
//
|
2021-10-09 18:03:34 +08:00
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
2021-06-18 15:20:08 +08:00
|
|
|
|
|
|
|
package roles
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
2021-09-22 16:18:21 +08:00
|
|
|
"net/http"
|
2021-06-18 15:20:08 +08:00
|
|
|
"os"
|
|
|
|
"os/signal"
|
|
|
|
"path"
|
|
|
|
"strings"
|
|
|
|
"sync"
|
|
|
|
"syscall"
|
|
|
|
|
2021-09-22 16:18:21 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/healthz"
|
|
|
|
|
2021-09-03 19:35:47 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/metricsinfo"
|
2021-09-22 19:48:07 +08:00
|
|
|
"go.uber.org/zap"
|
2021-09-03 19:35:47 +08:00
|
|
|
|
2021-06-18 15:20:08 +08:00
|
|
|
"github.com/milvus-io/milvus/cmd/components"
|
2021-06-22 10:42:07 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/datacoord"
|
2021-06-18 15:20:08 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/datanode"
|
2021-06-21 17:28:03 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/indexcoord"
|
2021-06-18 15:20:08 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/indexnode"
|
|
|
|
"github.com/milvus-io/milvus/internal/log"
|
|
|
|
"github.com/milvus-io/milvus/internal/logutil"
|
|
|
|
"github.com/milvus-io/milvus/internal/metrics"
|
|
|
|
"github.com/milvus-io/milvus/internal/msgstream"
|
2021-06-22 14:40:07 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proxy"
|
2021-06-22 16:44:09 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/querycoord"
|
2021-06-18 15:20:08 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/querynode"
|
2021-06-18 21:30:08 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/rootcoord"
|
2021-06-18 15:20:08 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/paramtable"
|
|
|
|
"github.com/milvus-io/milvus/internal/util/trace"
|
|
|
|
)
|
|
|
|
|
2021-08-16 18:46:10 +08:00
|
|
|
func newMsgFactory(localMsg bool) msgstream.Factory {
|
2021-06-18 15:20:08 +08:00
|
|
|
if localMsg {
|
2021-08-16 18:46:10 +08:00
|
|
|
return msgstream.NewRmsFactory()
|
2021-06-18 15:20:08 +08:00
|
|
|
}
|
|
|
|
return msgstream.NewPmsFactory()
|
|
|
|
}
|
|
|
|
|
2021-11-01 22:35:18 +08:00
|
|
|
// MilvusRoles determines to run which components.
|
2021-06-18 15:20:08 +08:00
|
|
|
type MilvusRoles struct {
|
|
|
|
EnableRootCoord bool `env:"ENABLE_ROOT_COORD"`
|
|
|
|
EnableProxy bool `env:"ENABLE_PROXY"`
|
|
|
|
EnableQueryCoord bool `env:"ENABLE_QUERY_COORD"`
|
|
|
|
EnableQueryNode bool `env:"ENABLE_QUERY_NODE"`
|
|
|
|
EnableDataCoord bool `env:"ENABLE_DATA_COORD"`
|
|
|
|
EnableDataNode bool `env:"ENABLE_DATA_NODE"`
|
|
|
|
EnableIndexCoord bool `env:"ENABLE_INDEX_COORD"`
|
|
|
|
EnableIndexNode bool `env:"ENABLE_INDEX_NODE"`
|
|
|
|
EnableMsgStreamCoord bool `env:"ENABLE_MSGSTREAM_COORD"`
|
|
|
|
}
|
|
|
|
|
2021-11-01 22:35:18 +08:00
|
|
|
// EnvValue not used now.
|
2021-06-18 15:20:08 +08:00
|
|
|
func (mr *MilvusRoles) EnvValue(env string) bool {
|
|
|
|
env = strings.ToLower(env)
|
|
|
|
env = strings.Trim(env, " ")
|
|
|
|
return env == "1" || env == "true"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (mr *MilvusRoles) setLogConfigFilename(filename string) *log.Config {
|
|
|
|
paramtable.Params.Init()
|
|
|
|
cfg := paramtable.Params.LogConfig
|
|
|
|
if len(cfg.File.RootPath) != 0 {
|
|
|
|
cfg.File.Filename = path.Join(cfg.File.RootPath, filename)
|
|
|
|
} else {
|
|
|
|
cfg.File.Filename = ""
|
|
|
|
}
|
|
|
|
return cfg
|
|
|
|
}
|
|
|
|
|
|
|
|
func (mr *MilvusRoles) runRootCoord(ctx context.Context, localMsg bool) *components.RootCoord {
|
|
|
|
var rc *components.RootCoord
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
|
|
|
|
wg.Add(1)
|
|
|
|
go func() {
|
2021-06-18 21:30:08 +08:00
|
|
|
rootcoord.Params.Init()
|
2021-06-18 15:20:08 +08:00
|
|
|
|
2021-10-01 08:52:50 +08:00
|
|
|
f := setLoggerFunc(localMsg)
|
|
|
|
rootcoord.Params.SetLogConfig(f)
|
2021-08-16 18:46:10 +08:00
|
|
|
factory := newMsgFactory(localMsg)
|
2021-06-18 15:20:08 +08:00
|
|
|
var err error
|
|
|
|
rc, err = components.NewRootCoord(ctx, factory)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2021-09-22 16:18:21 +08:00
|
|
|
if !localMsg {
|
|
|
|
http.Handle(healthz.HealthzRouterPath, &componentsHealthzHandler{component: rc})
|
|
|
|
}
|
2021-10-12 19:25:44 +08:00
|
|
|
wg.Done()
|
|
|
|
_ = rc.Run()
|
2021-06-18 15:20:08 +08:00
|
|
|
}()
|
|
|
|
wg.Wait()
|
|
|
|
|
|
|
|
metrics.RegisterRootCoord()
|
|
|
|
return rc
|
|
|
|
}
|
|
|
|
|
2021-06-19 12:38:06 +08:00
|
|
|
func (mr *MilvusRoles) runProxy(ctx context.Context, localMsg bool, alias string) *components.Proxy {
|
2021-06-18 15:20:08 +08:00
|
|
|
var pn *components.Proxy
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
|
|
|
|
wg.Add(1)
|
|
|
|
go func() {
|
2021-06-22 14:40:07 +08:00
|
|
|
proxy.Params.InitAlias(alias)
|
|
|
|
proxy.Params.Init()
|
2021-06-18 15:20:08 +08:00
|
|
|
|
2021-10-01 08:52:50 +08:00
|
|
|
f := setLoggerFunc(localMsg)
|
|
|
|
proxy.Params.SetLogConfig(f)
|
2021-08-16 18:46:10 +08:00
|
|
|
factory := newMsgFactory(localMsg)
|
2021-06-18 15:20:08 +08:00
|
|
|
var err error
|
|
|
|
pn, err = components.NewProxy(ctx, factory)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2021-09-22 16:18:21 +08:00
|
|
|
if !localMsg {
|
|
|
|
http.Handle(healthz.HealthzRouterPath, &componentsHealthzHandler{component: pn})
|
|
|
|
}
|
2021-10-12 19:25:44 +08:00
|
|
|
wg.Done()
|
|
|
|
_ = pn.Run()
|
2021-06-18 15:20:08 +08:00
|
|
|
}()
|
|
|
|
wg.Wait()
|
|
|
|
|
2021-06-22 18:32:08 +08:00
|
|
|
metrics.RegisterProxy()
|
2021-06-18 15:20:08 +08:00
|
|
|
return pn
|
|
|
|
}
|
|
|
|
|
|
|
|
func (mr *MilvusRoles) runQueryCoord(ctx context.Context, localMsg bool) *components.QueryCoord {
|
|
|
|
var qs *components.QueryCoord
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
|
|
|
|
wg.Add(1)
|
|
|
|
go func() {
|
2021-06-22 16:44:09 +08:00
|
|
|
querycoord.Params.Init()
|
2021-06-18 15:20:08 +08:00
|
|
|
|
2021-10-01 08:52:50 +08:00
|
|
|
f := setLoggerFunc(localMsg)
|
|
|
|
querycoord.Params.SetLogConfig(f)
|
2021-08-16 18:46:10 +08:00
|
|
|
factory := newMsgFactory(localMsg)
|
2021-06-18 15:20:08 +08:00
|
|
|
var err error
|
|
|
|
qs, err = components.NewQueryCoord(ctx, factory)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2021-09-22 16:18:21 +08:00
|
|
|
if !localMsg {
|
|
|
|
http.Handle(healthz.HealthzRouterPath, &componentsHealthzHandler{component: qs})
|
|
|
|
}
|
2021-10-12 19:25:44 +08:00
|
|
|
wg.Done()
|
|
|
|
_ = qs.Run()
|
2021-06-18 15:20:08 +08:00
|
|
|
}()
|
|
|
|
wg.Wait()
|
|
|
|
|
|
|
|
metrics.RegisterQueryCoord()
|
|
|
|
return qs
|
|
|
|
}
|
|
|
|
|
2021-06-19 12:38:06 +08:00
|
|
|
func (mr *MilvusRoles) runQueryNode(ctx context.Context, localMsg bool, alias string) *components.QueryNode {
|
2021-06-18 15:20:08 +08:00
|
|
|
var qn *components.QueryNode
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
|
|
|
|
wg.Add(1)
|
|
|
|
go func() {
|
2021-06-19 12:38:06 +08:00
|
|
|
querynode.Params.InitAlias(alias)
|
2021-06-18 15:20:08 +08:00
|
|
|
querynode.Params.Init()
|
|
|
|
|
2021-10-01 08:52:50 +08:00
|
|
|
f := setLoggerFunc(localMsg)
|
|
|
|
querynode.Params.SetLogConfig(f)
|
2021-08-16 18:46:10 +08:00
|
|
|
factory := newMsgFactory(localMsg)
|
2021-06-18 15:20:08 +08:00
|
|
|
var err error
|
|
|
|
qn, err = components.NewQueryNode(ctx, factory)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2021-09-22 16:18:21 +08:00
|
|
|
if !localMsg {
|
|
|
|
http.Handle(healthz.HealthzRouterPath, &componentsHealthzHandler{component: qn})
|
|
|
|
}
|
2021-10-12 19:25:44 +08:00
|
|
|
wg.Done()
|
|
|
|
_ = qn.Run()
|
2021-06-18 15:20:08 +08:00
|
|
|
}()
|
|
|
|
wg.Wait()
|
|
|
|
|
|
|
|
metrics.RegisterQueryNode()
|
|
|
|
return qn
|
|
|
|
}
|
|
|
|
|
|
|
|
func (mr *MilvusRoles) runDataCoord(ctx context.Context, localMsg bool) *components.DataCoord {
|
|
|
|
var ds *components.DataCoord
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
|
|
|
|
wg.Add(1)
|
|
|
|
go func() {
|
2021-06-22 10:42:07 +08:00
|
|
|
datacoord.Params.Init()
|
2021-06-18 15:20:08 +08:00
|
|
|
|
2021-10-01 08:52:50 +08:00
|
|
|
f := setLoggerFunc(localMsg)
|
|
|
|
datacoord.Params.SetLogConfig(f)
|
2021-08-16 18:46:10 +08:00
|
|
|
factory := newMsgFactory(localMsg)
|
2021-06-18 15:20:08 +08:00
|
|
|
var err error
|
|
|
|
ds, err = components.NewDataCoord(ctx, factory)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2021-09-22 16:18:21 +08:00
|
|
|
if !localMsg {
|
|
|
|
http.Handle(healthz.HealthzRouterPath, &componentsHealthzHandler{component: ds})
|
|
|
|
}
|
2021-10-12 19:25:44 +08:00
|
|
|
wg.Done()
|
|
|
|
_ = ds.Run()
|
2021-06-18 15:20:08 +08:00
|
|
|
}()
|
|
|
|
wg.Wait()
|
|
|
|
|
|
|
|
metrics.RegisterDataCoord()
|
|
|
|
return ds
|
|
|
|
}
|
|
|
|
|
2021-06-19 12:38:06 +08:00
|
|
|
func (mr *MilvusRoles) runDataNode(ctx context.Context, localMsg bool, alias string) *components.DataNode {
|
2021-06-18 15:20:08 +08:00
|
|
|
var dn *components.DataNode
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
|
|
|
|
wg.Add(1)
|
|
|
|
go func() {
|
2021-06-19 12:38:06 +08:00
|
|
|
datanode.Params.InitAlias(alias)
|
2021-06-18 15:20:08 +08:00
|
|
|
datanode.Params.Init()
|
2021-10-01 08:52:50 +08:00
|
|
|
f := setLoggerFunc(localMsg)
|
|
|
|
datanode.Params.SetLogConfig(f)
|
2021-08-16 18:46:10 +08:00
|
|
|
factory := newMsgFactory(localMsg)
|
2021-06-18 15:20:08 +08:00
|
|
|
var err error
|
|
|
|
dn, err = components.NewDataNode(ctx, factory)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2021-09-22 16:18:21 +08:00
|
|
|
if !localMsg {
|
|
|
|
http.Handle(healthz.HealthzRouterPath, &componentsHealthzHandler{component: dn})
|
|
|
|
}
|
2021-10-12 19:25:44 +08:00
|
|
|
wg.Done()
|
|
|
|
_ = dn.Run()
|
2021-06-18 15:20:08 +08:00
|
|
|
}()
|
|
|
|
wg.Wait()
|
|
|
|
|
|
|
|
metrics.RegisterDataNode()
|
|
|
|
return dn
|
|
|
|
}
|
|
|
|
|
|
|
|
func (mr *MilvusRoles) runIndexCoord(ctx context.Context, localMsg bool) *components.IndexCoord {
|
|
|
|
var is *components.IndexCoord
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
|
|
|
|
wg.Add(1)
|
|
|
|
go func() {
|
2021-06-21 17:28:03 +08:00
|
|
|
indexcoord.Params.Init()
|
2021-06-18 15:20:08 +08:00
|
|
|
|
2021-10-01 08:52:50 +08:00
|
|
|
f := setLoggerFunc(localMsg)
|
|
|
|
indexcoord.Params.SetLogConfig(f)
|
2021-06-18 15:20:08 +08:00
|
|
|
var err error
|
|
|
|
is, err = components.NewIndexCoord(ctx)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2021-09-22 16:18:21 +08:00
|
|
|
if !localMsg {
|
|
|
|
http.Handle(healthz.HealthzRouterPath, &componentsHealthzHandler{component: is})
|
|
|
|
}
|
2021-10-12 19:25:44 +08:00
|
|
|
wg.Done()
|
|
|
|
_ = is.Run()
|
2021-06-18 15:20:08 +08:00
|
|
|
}()
|
|
|
|
wg.Wait()
|
|
|
|
|
|
|
|
metrics.RegisterIndexCoord()
|
|
|
|
return is
|
|
|
|
}
|
|
|
|
|
2021-06-19 12:38:06 +08:00
|
|
|
func (mr *MilvusRoles) runIndexNode(ctx context.Context, localMsg bool, alias string) *components.IndexNode {
|
2021-06-18 15:20:08 +08:00
|
|
|
var in *components.IndexNode
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
|
|
|
|
wg.Add(1)
|
|
|
|
go func() {
|
2021-06-19 12:38:06 +08:00
|
|
|
indexnode.Params.InitAlias(alias)
|
2021-06-18 15:20:08 +08:00
|
|
|
indexnode.Params.Init()
|
|
|
|
|
2021-10-01 08:52:50 +08:00
|
|
|
f := setLoggerFunc(localMsg)
|
|
|
|
indexnode.Params.SetLogConfig(f)
|
2021-06-18 15:20:08 +08:00
|
|
|
var err error
|
|
|
|
in, err = components.NewIndexNode(ctx)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2021-09-22 16:18:21 +08:00
|
|
|
if !localMsg {
|
|
|
|
http.Handle(healthz.HealthzRouterPath, &componentsHealthzHandler{component: in})
|
|
|
|
}
|
2021-10-12 19:25:44 +08:00
|
|
|
wg.Done()
|
|
|
|
_ = in.Run()
|
2021-06-18 15:20:08 +08:00
|
|
|
}()
|
|
|
|
wg.Wait()
|
|
|
|
|
|
|
|
metrics.RegisterIndexNode()
|
|
|
|
return in
|
|
|
|
}
|
|
|
|
|
|
|
|
func (mr *MilvusRoles) runMsgStreamCoord(ctx context.Context) *components.MsgStream {
|
|
|
|
var mss *components.MsgStream
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
|
|
|
|
wg.Add(1)
|
|
|
|
go func() {
|
|
|
|
var err error
|
|
|
|
mss, err = components.NewMsgStreamCoord(ctx)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
wg.Done()
|
|
|
|
_ = mss.Run()
|
|
|
|
}()
|
|
|
|
wg.Wait()
|
|
|
|
|
|
|
|
metrics.RegisterMsgStreamCoord()
|
|
|
|
return mss
|
|
|
|
}
|
|
|
|
|
2021-11-01 22:35:18 +08:00
|
|
|
// Run runs Milvus components.
|
2021-06-19 12:38:06 +08:00
|
|
|
func (mr *MilvusRoles) Run(localMsg bool, alias string) {
|
2021-09-03 19:35:47 +08:00
|
|
|
if os.Getenv(metricsinfo.DeployModeEnvKey) == metricsinfo.StandaloneDeployMode {
|
2021-06-18 15:20:08 +08:00
|
|
|
closer := trace.InitTracing("standalone")
|
|
|
|
if closer != nil {
|
|
|
|
defer closer.Close()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
|
|
|
|
// only standalone enable localMsg
|
|
|
|
if localMsg {
|
2021-09-03 19:35:47 +08:00
|
|
|
os.Setenv(metricsinfo.DeployModeEnvKey, metricsinfo.StandaloneDeployMode)
|
2021-06-18 15:20:08 +08:00
|
|
|
cfg := mr.setLogConfigFilename("standalone.log")
|
|
|
|
logutil.SetupLogger(cfg)
|
|
|
|
defer log.Sync()
|
2021-09-03 19:35:47 +08:00
|
|
|
} else {
|
|
|
|
err := os.Setenv(metricsinfo.DeployModeEnvKey, metricsinfo.ClusterDeployMode)
|
|
|
|
if err != nil {
|
2021-10-28 18:02:30 +08:00
|
|
|
log.Error("Failed to set deploy mode: ", zap.Error(err))
|
2021-09-03 19:35:47 +08:00
|
|
|
}
|
2021-06-18 15:20:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
var rc *components.RootCoord
|
|
|
|
if mr.EnableRootCoord {
|
|
|
|
rc = mr.runRootCoord(ctx, localMsg)
|
|
|
|
if rc != nil {
|
|
|
|
defer rc.Stop()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var pn *components.Proxy
|
|
|
|
if mr.EnableProxy {
|
2021-06-19 12:38:06 +08:00
|
|
|
pn = mr.runProxy(ctx, localMsg, alias)
|
2021-06-18 15:20:08 +08:00
|
|
|
if pn != nil {
|
|
|
|
defer pn.Stop()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var qs *components.QueryCoord
|
|
|
|
if mr.EnableQueryCoord {
|
|
|
|
qs = mr.runQueryCoord(ctx, localMsg)
|
|
|
|
if qs != nil {
|
|
|
|
defer qs.Stop()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var qn *components.QueryNode
|
|
|
|
if mr.EnableQueryNode {
|
2021-06-19 12:38:06 +08:00
|
|
|
qn = mr.runQueryNode(ctx, localMsg, alias)
|
2021-06-18 15:20:08 +08:00
|
|
|
if qn != nil {
|
|
|
|
defer qn.Stop()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var ds *components.DataCoord
|
|
|
|
if mr.EnableDataCoord {
|
|
|
|
ds = mr.runDataCoord(ctx, localMsg)
|
|
|
|
if ds != nil {
|
|
|
|
defer ds.Stop()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var dn *components.DataNode
|
|
|
|
if mr.EnableDataNode {
|
2021-06-19 12:38:06 +08:00
|
|
|
dn = mr.runDataNode(ctx, localMsg, alias)
|
2021-06-18 15:20:08 +08:00
|
|
|
if dn != nil {
|
|
|
|
defer dn.Stop()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var is *components.IndexCoord
|
|
|
|
if mr.EnableIndexCoord {
|
|
|
|
is = mr.runIndexCoord(ctx, localMsg)
|
|
|
|
if is != nil {
|
|
|
|
defer is.Stop()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var in *components.IndexNode
|
|
|
|
if mr.EnableIndexNode {
|
2021-06-19 12:38:06 +08:00
|
|
|
in = mr.runIndexNode(ctx, localMsg, alias)
|
2021-06-18 15:20:08 +08:00
|
|
|
if in != nil {
|
|
|
|
defer in.Stop()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var mss *components.MsgStream
|
|
|
|
if mr.EnableMsgStreamCoord {
|
|
|
|
mss = mr.runMsgStreamCoord(ctx)
|
|
|
|
if mss != nil {
|
|
|
|
defer mss.Stop()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-22 16:18:21 +08:00
|
|
|
if localMsg {
|
|
|
|
standaloneHealthzHandler := func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
if rc == nil {
|
|
|
|
rootCoordNotServingHandler(w, r)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if qs == nil {
|
|
|
|
queryCoordNotServingHandler(w, r)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if ds == nil {
|
|
|
|
dataCoordNotServingHandler(w, r)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if is == nil {
|
|
|
|
indexCoordNotServingHandler(w, r)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
// TODO(dragondriver): need to check node state?
|
|
|
|
|
|
|
|
w.WriteHeader(http.StatusOK)
|
|
|
|
w.Header().Set(healthz.ContentTypeHeader, healthz.ContentTypeText)
|
|
|
|
_, err := fmt.Fprint(w, "OK")
|
|
|
|
if err != nil {
|
2021-10-28 18:02:30 +08:00
|
|
|
log.Warn("Failed to send response",
|
2021-09-22 16:18:21 +08:00
|
|
|
zap.Error(err))
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO(dragondriver): handle component states
|
|
|
|
}
|
|
|
|
http.HandleFunc(healthz.HealthzRouterPath, standaloneHealthzHandler)
|
|
|
|
}
|
|
|
|
|
2021-06-18 15:20:08 +08:00
|
|
|
metrics.ServeHTTP()
|
|
|
|
|
|
|
|
sc := make(chan os.Signal, 1)
|
|
|
|
signal.Notify(sc,
|
|
|
|
syscall.SIGHUP,
|
|
|
|
syscall.SIGINT,
|
|
|
|
syscall.SIGTERM,
|
|
|
|
syscall.SIGQUIT)
|
|
|
|
sig := <-sc
|
2021-09-22 19:48:07 +08:00
|
|
|
log.Error("Get signal to exit\n", zap.String("signal", sig.String()))
|
2021-06-18 15:20:08 +08:00
|
|
|
|
|
|
|
// some deferred Stop has race with context cancel
|
|
|
|
cancel()
|
|
|
|
}
|
2021-10-01 08:52:50 +08:00
|
|
|
|
|
|
|
func setLoggerFunc(localMsg bool) func(cfg log.Config) {
|
|
|
|
if !localMsg {
|
|
|
|
return func(cfg log.Config) {
|
|
|
|
log.Info("Set log file to ", zap.String("path", cfg.File.Filename))
|
|
|
|
logutil.SetupLogger(&cfg)
|
|
|
|
defer log.Sync()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// no need to setup logger for standalone
|
|
|
|
return func(cfg log.Config) {}
|
|
|
|
}
|