2022-01-13 14:21: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
|
|
|
|
// with the License. You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
|
|
|
|
package datanode
|
|
|
|
|
|
|
|
import (
|
2023-09-20 16:03:23 +08:00
|
|
|
"context"
|
2022-01-13 14:21:34 +08:00
|
|
|
"fmt"
|
2023-03-21 21:37:56 +08:00
|
|
|
|
|
|
|
"go.uber.org/zap"
|
2022-01-13 14:21:34 +08:00
|
|
|
|
2023-06-09 01:28:37 +08:00
|
|
|
"github.com/milvus-io/milvus-proto/go-api/v2/schemapb"
|
2022-01-13 14:21:34 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/datapb"
|
2023-04-06 19:14:32 +08:00
|
|
|
"github.com/milvus-io/milvus/pkg/log"
|
|
|
|
"github.com/milvus-io/milvus/pkg/metrics"
|
|
|
|
"github.com/milvus-io/milvus/pkg/util/paramtable"
|
2023-07-24 10:21:07 +08:00
|
|
|
"github.com/milvus-io/milvus/pkg/util/typeutil"
|
2022-01-13 14:21:34 +08:00
|
|
|
)
|
|
|
|
|
2023-11-30 18:42:32 +08:00
|
|
|
type FlowgraphManager interface {
|
|
|
|
AddFlowgraph(ds *dataSyncService)
|
|
|
|
AddandStartWithEtcdTickler(dn *DataNode, vchan *datapb.VchannelInfo, schema *schemapb.CollectionSchema, tickler *etcdTickler) error
|
|
|
|
RemoveFlowgraph(channel string)
|
|
|
|
ClearFlowgraphs()
|
|
|
|
|
|
|
|
GetFlowgraphService(channel string) (*dataSyncService, bool)
|
|
|
|
HasFlowgraph(channel string) bool
|
|
|
|
HasFlowgraphWithOpID(channel string, opID UniqueID) bool
|
|
|
|
GetFlowgraphCount() int
|
|
|
|
GetCollectionIDs() []int64
|
2023-03-21 21:37:56 +08:00
|
|
|
}
|
|
|
|
|
2023-11-30 18:42:32 +08:00
|
|
|
var _ FlowgraphManager = (*fgManagerImpl)(nil)
|
2023-03-21 21:37:56 +08:00
|
|
|
|
2023-11-30 18:42:32 +08:00
|
|
|
type fgManagerImpl struct {
|
|
|
|
flowgraphs *typeutil.ConcurrentMap[string, *dataSyncService]
|
2023-03-21 21:37:56 +08:00
|
|
|
}
|
|
|
|
|
2023-11-30 18:42:32 +08:00
|
|
|
func newFlowgraphManager() *fgManagerImpl {
|
|
|
|
return &fgManagerImpl{
|
|
|
|
flowgraphs: typeutil.NewConcurrentMap[string, *dataSyncService](),
|
2023-03-21 21:37:56 +08:00
|
|
|
}
|
2022-01-13 14:21:34 +08:00
|
|
|
}
|
|
|
|
|
2023-11-30 18:42:32 +08:00
|
|
|
func (fm *fgManagerImpl) AddFlowgraph(ds *dataSyncService) {
|
2023-10-08 21:37:33 +08:00
|
|
|
fm.flowgraphs.Insert(ds.vchannelName, ds)
|
|
|
|
metrics.DataNodeNumFlowGraphs.WithLabelValues(fmt.Sprint(paramtable.GetNodeID())).Inc()
|
|
|
|
}
|
|
|
|
|
2023-11-30 18:42:32 +08:00
|
|
|
func (fm *fgManagerImpl) AddandStartWithEtcdTickler(dn *DataNode, vchan *datapb.VchannelInfo, schema *schemapb.CollectionSchema, tickler *etcdTickler) error {
|
2023-03-23 19:43:57 +08:00
|
|
|
log := log.With(zap.String("channel", vchan.GetChannelName()))
|
2023-07-24 10:21:07 +08:00
|
|
|
if fm.flowgraphs.Contain(vchan.GetChannelName()) {
|
2023-03-23 19:43:57 +08:00
|
|
|
log.Warn("try to add an existed DataSyncService")
|
2022-01-13 14:21:34 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-09-27 11:07:25 +08:00
|
|
|
dataSyncService, err := newServiceWithEtcdTickler(context.TODO(), dn, &datapb.ChannelWatchInfo{
|
2023-09-20 16:03:23 +08:00
|
|
|
Schema: schema,
|
2023-09-21 09:45:27 +08:00
|
|
|
Vchan: vchan,
|
|
|
|
}, tickler)
|
2022-01-13 14:21:34 +08:00
|
|
|
if err != nil {
|
2023-09-20 16:03:23 +08:00
|
|
|
log.Warn("fail to create new DataSyncService", zap.Error(err))
|
2022-01-13 14:21:34 +08:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
dataSyncService.start()
|
2023-07-24 10:21:07 +08:00
|
|
|
fm.flowgraphs.Insert(vchan.GetChannelName(), dataSyncService)
|
2022-02-28 19:11:55 +08:00
|
|
|
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.DataNodeNumFlowGraphs.WithLabelValues(fmt.Sprint(paramtable.GetNodeID())).Inc()
|
2022-01-13 14:21:34 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-11-30 18:42:32 +08:00
|
|
|
func (fm *fgManagerImpl) RemoveFlowgraph(channel string) {
|
|
|
|
if fg, loaded := fm.flowgraphs.Get(channel); loaded {
|
2023-07-24 10:21:07 +08:00
|
|
|
fg.close()
|
2023-11-30 18:42:32 +08:00
|
|
|
fm.flowgraphs.Remove(channel)
|
2023-09-19 11:53:22 +08:00
|
|
|
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.DataNodeNumFlowGraphs.WithLabelValues(fmt.Sprint(paramtable.GetNodeID())).Dec()
|
2023-11-30 18:42:32 +08:00
|
|
|
rateCol.removeFlowGraphChannel(channel)
|
2022-01-13 14:21:34 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-30 18:42:32 +08:00
|
|
|
func (fm *fgManagerImpl) ClearFlowgraphs() {
|
|
|
|
log.Info("start drop all flowgraph resources in DataNode")
|
|
|
|
fm.flowgraphs.Range(func(key string, value *dataSyncService) bool {
|
|
|
|
value.GracefullyClose()
|
|
|
|
fm.flowgraphs.GetAndRemove(key)
|
|
|
|
|
|
|
|
log.Info("successfully dropped flowgraph", zap.String("vChannelName", key))
|
|
|
|
return true
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (fm *fgManagerImpl) GetFlowgraphService(channel string) (*dataSyncService, bool) {
|
|
|
|
return fm.flowgraphs.Get(channel)
|
2022-01-13 14:21:34 +08:00
|
|
|
}
|
|
|
|
|
2023-11-30 18:42:32 +08:00
|
|
|
func (fm *fgManagerImpl) HasFlowgraph(channel string) bool {
|
|
|
|
_, exist := fm.flowgraphs.Get(channel)
|
2022-01-13 14:21:34 +08:00
|
|
|
return exist
|
|
|
|
}
|
|
|
|
|
2023-11-30 18:42:32 +08:00
|
|
|
func (fm *fgManagerImpl) HasFlowgraphWithOpID(channel string, opID UniqueID) bool {
|
|
|
|
ds, exist := fm.flowgraphs.Get(channel)
|
2023-10-08 21:37:33 +08:00
|
|
|
return exist && ds.opID == opID
|
|
|
|
}
|
|
|
|
|
2023-11-30 18:42:32 +08:00
|
|
|
// GetFlowgraphCount returns number of flow graphs.
|
|
|
|
func (fm *fgManagerImpl) GetFlowgraphCount() int {
|
2023-07-24 10:21:07 +08:00
|
|
|
return fm.flowgraphs.Len()
|
2022-09-16 09:56:47 +08:00
|
|
|
}
|
|
|
|
|
2023-11-30 18:42:32 +08:00
|
|
|
func (fm *fgManagerImpl) GetCollectionIDs() []int64 {
|
2023-09-19 11:53:22 +08:00
|
|
|
collectionSet := typeutil.UniqueSet{}
|
|
|
|
fm.flowgraphs.Range(func(key string, value *dataSyncService) bool {
|
2023-11-15 15:24:18 +08:00
|
|
|
collectionSet.Insert(value.metacache.Collection())
|
2023-09-19 11:53:22 +08:00
|
|
|
return true
|
|
|
|
})
|
|
|
|
|
|
|
|
return collectionSet.Collect()
|
|
|
|
}
|