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"
|
|
|
|
"strings"
|
|
|
|
"sync"
|
|
|
|
"syscall"
|
2021-12-07 13:33:43 +08:00
|
|
|
"time"
|
2021-06-18 15:20:08 +08:00
|
|
|
|
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-12-14 18:31:25 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/internalpb"
|
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-12-29 14:35:21 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/etcd"
|
2021-12-14 18:31:25 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/healthz"
|
|
|
|
"github.com/milvus-io/milvus/internal/util/metricsinfo"
|
2021-12-29 14:35:21 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/paramtable"
|
2021-12-14 18:31:25 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/rocksmq/server/rocksmq"
|
2021-06-18 15:20:08 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/trace"
|
2021-12-28 23:12:46 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/typeutil"
|
2021-06-18 15:20:08 +08:00
|
|
|
)
|
|
|
|
|
2022-02-08 20:57:47 +08:00
|
|
|
var Params paramtable.ComponentParam
|
2021-12-29 14:35:21 +08:00
|
|
|
|
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-12-02 10:27:32 +08:00
|
|
|
func initRocksmq() error {
|
|
|
|
err := rocksmq.InitRocksMQ()
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func stopRocksmq() {
|
|
|
|
rocksmq.CloseRocksMQ()
|
|
|
|
}
|
|
|
|
|
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 {
|
2021-12-06 18:20:31 +08:00
|
|
|
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"`
|
2021-06-18 15:20:08 +08:00
|
|
|
}
|
|
|
|
|
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) runRootCoord(ctx context.Context, localMsg bool) *components.RootCoord {
|
|
|
|
var rc *components.RootCoord
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
|
|
|
|
wg.Add(1)
|
|
|
|
go func() {
|
2021-11-10 10:07:37 +08:00
|
|
|
rootcoord.Params.InitOnce()
|
2021-12-28 23:12:46 +08:00
|
|
|
if localMsg {
|
|
|
|
rootcoord.Params.SetLogConfig(typeutil.StandaloneRole)
|
|
|
|
} else {
|
|
|
|
rootcoord.Params.SetLogConfig(typeutil.RootCoordRole)
|
|
|
|
}
|
2021-06-18 15:20:08 +08:00
|
|
|
|
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-12-23 18:39:11 +08:00
|
|
|
proxy.Params.ProxyCfg.InitAlias(alias)
|
2021-11-10 10:07:37 +08:00
|
|
|
proxy.Params.InitOnce()
|
2021-12-28 23:12:46 +08:00
|
|
|
if localMsg {
|
|
|
|
proxy.Params.SetLogConfig(typeutil.StandaloneRole)
|
|
|
|
} else {
|
|
|
|
proxy.Params.SetLogConfig(typeutil.ProxyRole)
|
|
|
|
}
|
2021-06-18 15:20:08 +08:00
|
|
|
|
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-11-10 10:07:37 +08:00
|
|
|
querycoord.Params.InitOnce()
|
2021-12-28 23:12:46 +08:00
|
|
|
if localMsg {
|
|
|
|
querycoord.Params.SetLogConfig(typeutil.StandaloneRole)
|
|
|
|
} else {
|
|
|
|
querycoord.Params.SetLogConfig(typeutil.QueryCoordRole)
|
|
|
|
}
|
2021-06-18 15:20:08 +08:00
|
|
|
|
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-12-23 18:39:11 +08:00
|
|
|
querynode.Params.QueryNodeCfg.InitAlias(alias)
|
2021-11-10 10:07:37 +08:00
|
|
|
querynode.Params.InitOnce()
|
2021-12-28 23:12:46 +08:00
|
|
|
if localMsg {
|
|
|
|
querynode.Params.SetLogConfig(typeutil.StandaloneRole)
|
|
|
|
} else {
|
|
|
|
querynode.Params.SetLogConfig(typeutil.QueryNodeRole)
|
|
|
|
}
|
2021-06-18 15:20:08 +08:00
|
|
|
|
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-11-10 10:07:37 +08:00
|
|
|
datacoord.Params.InitOnce()
|
2021-12-28 23:12:46 +08:00
|
|
|
if localMsg {
|
|
|
|
datacoord.Params.SetLogConfig(typeutil.StandaloneRole)
|
|
|
|
} else {
|
|
|
|
datacoord.Params.SetLogConfig(typeutil.DataCoordRole)
|
|
|
|
}
|
2021-06-18 15:20:08 +08:00
|
|
|
|
2021-08-16 18:46:10 +08:00
|
|
|
factory := newMsgFactory(localMsg)
|
2021-12-28 19:42:19 +08:00
|
|
|
|
|
|
|
dctx := logutil.WithModule(ctx, "DataCoord")
|
2021-06-18 15:20:08 +08:00
|
|
|
var err error
|
2021-12-28 19:42:19 +08:00
|
|
|
ds, err = components.NewDataCoord(dctx, factory)
|
2021-06-18 15:20:08 +08:00
|
|
|
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-12-23 18:39:11 +08:00
|
|
|
datanode.Params.DataNodeCfg.InitAlias(alias)
|
2021-11-10 10:07:37 +08:00
|
|
|
datanode.Params.InitOnce()
|
2021-12-28 23:12:46 +08:00
|
|
|
if localMsg {
|
|
|
|
datanode.Params.SetLogConfig(typeutil.StandaloneRole)
|
|
|
|
} else {
|
|
|
|
datanode.Params.SetLogConfig(typeutil.DataNodeRole)
|
|
|
|
}
|
|
|
|
|
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-11-10 10:07:37 +08:00
|
|
|
indexcoord.Params.InitOnce()
|
2021-12-28 23:12:46 +08:00
|
|
|
if localMsg {
|
|
|
|
indexcoord.Params.SetLogConfig(typeutil.StandaloneRole)
|
|
|
|
} else {
|
|
|
|
indexcoord.Params.SetLogConfig(typeutil.IndexCoordRole)
|
|
|
|
}
|
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-12-23 18:39:11 +08:00
|
|
|
indexnode.Params.IndexNodeCfg.InitAlias(alias)
|
2021-11-10 10:07:37 +08:00
|
|
|
indexnode.Params.InitOnce()
|
2021-12-28 23:12:46 +08:00
|
|
|
if localMsg {
|
|
|
|
indexnode.Params.SetLogConfig(typeutil.StandaloneRole)
|
|
|
|
} else {
|
|
|
|
indexnode.Params.SetLogConfig(typeutil.IndexNodeRole)
|
|
|
|
}
|
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
|
|
|
|
}
|
|
|
|
|
2021-12-13 09:29:50 +08:00
|
|
|
// Run Milvus components.
|
2021-12-29 14:35:21 +08:00
|
|
|
func (mr *MilvusRoles) Run(local 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
|
2021-12-29 14:35:21 +08:00
|
|
|
if local {
|
|
|
|
Params.Init()
|
2021-12-14 18:31:25 +08:00
|
|
|
if err := os.Setenv(metricsinfo.DeployModeEnvKey, metricsinfo.StandaloneDeployMode); err != nil {
|
|
|
|
log.Error("Failed to set deploy mode: ", zap.Error(err))
|
|
|
|
}
|
2021-12-02 10:27:32 +08:00
|
|
|
|
2021-12-14 18:31:25 +08:00
|
|
|
if err := initRocksmq(); err != nil {
|
2021-12-02 10:27:32 +08:00
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
defer stopRocksmq()
|
2021-12-29 14:35:21 +08:00
|
|
|
|
2022-02-07 10:09:45 +08:00
|
|
|
if Params.EtcdCfg.UseEmbedEtcd {
|
2021-12-29 14:35:21 +08:00
|
|
|
// start etcd server
|
2022-02-07 10:09:45 +08:00
|
|
|
etcd.InitEtcdServer(&Params.EtcdCfg)
|
2021-12-29 14:35:21 +08:00
|
|
|
defer etcd.StopEtcdServer()
|
|
|
|
}
|
2021-09-03 19:35:47 +08:00
|
|
|
} else {
|
2021-12-14 18:31:25 +08:00
|
|
|
if err := os.Setenv(metricsinfo.DeployModeEnvKey, metricsinfo.ClusterDeployMode); 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 {
|
2021-12-29 14:35:21 +08:00
|
|
|
rc = mr.runRootCoord(ctx, local)
|
2021-06-18 15:20:08 +08:00
|
|
|
if rc != nil {
|
|
|
|
defer rc.Stop()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var pn *components.Proxy
|
|
|
|
if mr.EnableProxy {
|
2021-12-17 19:07:39 +08:00
|
|
|
pctx := logutil.WithModule(ctx, "Proxy")
|
2021-12-29 14:35:21 +08:00
|
|
|
pn = mr.runProxy(pctx, local, alias)
|
2021-06-18 15:20:08 +08:00
|
|
|
if pn != nil {
|
|
|
|
defer pn.Stop()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var qs *components.QueryCoord
|
|
|
|
if mr.EnableQueryCoord {
|
2021-12-29 14:35:21 +08:00
|
|
|
qs = mr.runQueryCoord(ctx, local)
|
2021-06-18 15:20:08 +08:00
|
|
|
if qs != nil {
|
|
|
|
defer qs.Stop()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var qn *components.QueryNode
|
|
|
|
if mr.EnableQueryNode {
|
2021-12-29 14:35:21 +08:00
|
|
|
qn = mr.runQueryNode(ctx, local, alias)
|
2021-06-18 15:20:08 +08:00
|
|
|
if qn != nil {
|
|
|
|
defer qn.Stop()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var ds *components.DataCoord
|
|
|
|
if mr.EnableDataCoord {
|
2021-12-29 14:35:21 +08:00
|
|
|
ds = mr.runDataCoord(ctx, local)
|
2021-06-18 15:20:08 +08:00
|
|
|
if ds != nil {
|
|
|
|
defer ds.Stop()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var dn *components.DataNode
|
|
|
|
if mr.EnableDataNode {
|
2021-12-29 14:35:21 +08:00
|
|
|
dn = mr.runDataNode(ctx, local, alias)
|
2021-06-18 15:20:08 +08:00
|
|
|
if dn != nil {
|
|
|
|
defer dn.Stop()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var is *components.IndexCoord
|
|
|
|
if mr.EnableIndexCoord {
|
2021-12-29 14:35:21 +08:00
|
|
|
is = mr.runIndexCoord(ctx, local)
|
2021-06-18 15:20:08 +08:00
|
|
|
if is != nil {
|
|
|
|
defer is.Stop()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var in *components.IndexNode
|
|
|
|
if mr.EnableIndexNode {
|
2021-12-29 14:35:21 +08:00
|
|
|
in = mr.runIndexNode(ctx, local, alias)
|
2021-06-18 15:20:08 +08:00
|
|
|
if in != nil {
|
|
|
|
defer in.Stop()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-29 14:35:21 +08:00
|
|
|
if local {
|
2021-09-22 16:18:21 +08:00
|
|
|
standaloneHealthzHandler := func(w http.ResponseWriter, r *http.Request) {
|
2021-12-07 13:33:43 +08:00
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
|
|
|
|
defer cancel()
|
|
|
|
req := &internalpb.GetComponentStatesRequest{}
|
|
|
|
validateResp := func(resp *internalpb.ComponentStates, err error) bool {
|
|
|
|
return err == nil && resp != nil && resp.GetState().GetStateCode() == internalpb.StateCode_Healthy
|
|
|
|
}
|
|
|
|
if rc == nil || !validateResp(rc.GetComponentStates(ctx, req)) {
|
2021-09-22 16:18:21 +08:00
|
|
|
rootCoordNotServingHandler(w, r)
|
|
|
|
return
|
|
|
|
}
|
2021-12-07 13:33:43 +08:00
|
|
|
if qs == nil || !validateResp(qs.GetComponentStates(ctx, req)) {
|
2021-09-22 16:18:21 +08:00
|
|
|
queryCoordNotServingHandler(w, r)
|
|
|
|
return
|
|
|
|
}
|
2021-12-07 13:33:43 +08:00
|
|
|
|
|
|
|
if ds == nil || !validateResp(ds.GetComponentStates(ctx, req)) {
|
2021-09-22 16:18:21 +08:00
|
|
|
dataCoordNotServingHandler(w, r)
|
|
|
|
return
|
|
|
|
}
|
2021-12-07 13:33:43 +08:00
|
|
|
if is == nil || !validateResp(is.GetComponentStates(ctx, req)) {
|
2021-09-22 16:18:21 +08:00
|
|
|
indexCoordNotServingHandler(w, r)
|
|
|
|
return
|
2021-12-07 13:33:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if pn == nil || !validateResp(pn.GetComponentStates(ctx, req)) {
|
|
|
|
proxyNotServingHandler(w, r)
|
|
|
|
return
|
2021-09-22 16:18:21 +08:00
|
|
|
}
|
|
|
|
// 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()
|
|
|
|
}
|