milvus/docs/developer_guides/chap07_query_service.md

8.2 KiB

8. Query Service

8.1 Overview

8.2 Query Service Interface

type QueryService interface {
  Service
  Component
  
  RegisterNode(ctx context.Context, req *querypb.RegisterNodeRequest) (*querypb.RegisterNodeResponse, error)
  ShowCollections(ctx context.Context, req *querypb.ShowCollectionRequest) (*querypb.ShowCollectionResponse, error)
  LoadCollection(ctx context.Context, req *querypb.LoadCollectionRequest) (*commonpb.Status, error)
  ReleaseCollection(ctx context.Context, req *querypb.ReleaseCollectionRequest) (*commonpb.Status, error)
  ShowPartitions(ctx context.Context, req *querypb.ShowPartitionRequest) (*querypb.ShowPartitionResponse, error)
  LoadPartitions(ctx context.Context, req *querypb.LoadPartitionRequest) (*commonpb.Status, error)
  ReleasePartitions(ctx context.Context, req *querypb.ReleasePartitionRequest) (*commonpb.Status, error)
  CreateQueryChannel(ctx context.Context) (*querypb.CreateQueryChannelResponse, error)
  GetPartitionStates(ctx context.Context, req *querypb.PartitionStatesRequest) (*querypb.PartitionStatesResponse, error)
  GetSegmentInfo(ctx context.Context, req *querypb.SegmentInfoRequest) (*querypb.SegmentInfoResponse, error)
}
  • MsgBase
type MsgBase struct {
  MsgType MsgType
  MsgID	UniqueID
  Timestamp Timestamp
  SourceID UniqueID
}
  • RegisterNode
tyoe Address struct {
  Ip   string
  port int64
}

type RegisterNodeRequest struct {
  Base    *commonpb.MsgBase
  Address *commonpb.Address
}

type RegisterNodeResponse struct {
  Status     *commonpb.Status
  InitParams *internalpb2.InitParams
}
  • ShowCollections
type ShowCollectionRequest struct {
  Base *commonpb.MsgBase
  DbID UniqueID
}

type ShowCollectionResponse struct {
  Status        *commonpb.Status
  CollectionIDs []UniqueID
}
  • LoadCollection
type LoadCollectionRequest struct {
  Base         *commonpb.MsgBase
  DbID         UniqueID
  CollectionID UniqueID
  schema       *schemapb.CollectionSchema
}
  • ReleaseCollection
type ReleaseCollectionRequest struct {
  Base         *commonpb.MsgBase
  DbID         UniqueID
  CollectionID UniqueID
}
  • ShowPartitions
type ShowPartitionRequest struct {
  Base         *commonpb.MsgBase
  DbID         UniqueID
  CollectionID UniqueID
}

type ShowPartitionResponse struct {
  Status       *commonpb.Status
  PartitionIDs []UniqueID
}
  • GetPartitionStates
type PartitionState = int

const (
  PartitionState_NotExist        PartitionState = 0
  PartitionState_NotPresent      PartitionState = 1
  PartitionState_OnDisk          PartitionState = 2
  PartitionState_PartialInMemory PartitionState = 3
  PartitionState_InMemory        PartitionState = 4
  PartitionState_PartialInGPU    PartitionState = 5
  PartitionState_InGPU           PartitionState = 6
)

type PartitionStatesRequest struct {
  Base         *commonpb.MsgBase
  DbID         UniqueID
  CollectionID UniqueID
  PartitionIDs []UniqueID
}

type PartitionStates struct {
  PartitionID UniqueID
  State       PartitionState
}

type PartitionStatesResponse struct {
  Status                *commonpb.Status
  PartitionDescriptions []*PartitionStates
}
  • LoadPartitions
type LoadPartitonRequest struct {
  Base         *commonpb.MsgBase
  DbID         UniqueID
  CollectionID UniqueID
  PartitionIDs []UniqueID
  Schema       *schemapb.CollectionSchema
}
  • ReleasePartitions
type ReleasePartitionRequest struct {
  Base         *commonpb.MsgBase
  DbID         UniqueID
  CollectionID UniqueID
  PartitionIDs []UniqueID
}
  • CreateQueryChannel
type CreateQueryChannelResponse struct {
  Status             *commonpb.Status
  RequestChannelName string
  ResultChannelName  string
}
  • GetSegmentInfo *
type SegmentInfoRequest struct {
  Base       *commonpb.MsgBase
  SegmentIDs []UniqueID
}

type SegmentInfo struct {
  SegmentID    UniqueID
  CollectionID UniqueID
  PartitionID  UniqueID
  MemSize      UniqueID
  NumRows      UniqueID
  IndexName    string
  IndexID      UniqueID
}

type SegmentInfoResponse struct {
  Status *commonpb.Status
  Infos  []*SegmentInfo
}

//TODO

8.2 Query Channel

type SearchRequest struct {
  RequestBase
  DbName string
  CollectionName string
  PartitionNames []string
  DbID UniqueID
  CollectionID UniqueID
  PartitionIDs []UniqueID
  Dsl string
  PlaceholderGroup []byte
}

8.2 Query Node Interface

type QueryNode interface {
  typeutil.Component
  
  AddQueryChannel(ctx context.Context, in *queryPb.AddQueryChannelsRequest) (*commonpb.Status, error)
  RemoveQueryChannel(ctx context.Context, in *queryPb.RemoveQueryChannelsRequest) (*commonpb.Status, error)
  WatchDmChannels(ctx context.Context, in *queryPb.WatchDmChannelsRequest) (*commonpb.Status, error)
  LoadSegments(ctx context.Context, in *queryPb.LoadSegmentRequest) (*commonpb.Status, error)
  ReleaseCollection(ctx context.Context, in *queryPb.ReleaseCollectionRequest) (*commonpb.Status, error)
  ReleasePartitions(ctx context.Context, in *queryPb.ReleasePartitionRequest) (*commonpb.Status, error)
  ReleaseSegments(ctx context.Context, in *queryPb.ReleaseSegmentRequest) (*commonpb.Status, error)
  GetSegmentInfo(ctx context.Context, in *queryPb.SegmentInfoRequest) (*queryPb.SegmentInfoResponse, error)
}
  • AddQueryChannel
type AddQueryChannelRequest struct {
  Base             *commonpb.MsgBase
  RequestChannelID string
  ResultChannelID  string
}
  • RemoveQueryChannel
type RemoveQueryChannelRequest struct {
  Status           *commonpb.Status
  Base             *commonpb.MsgBase
  RequestChannelID string
  ResultChannelID  string
}
  • WatchDmChannels
type WatchDmChannelInfo struct {
  ChannelID            string
  Pos                  *internalpb2.MsgPosition
  ExcludedSegments     []int64
}

type WatchDmChannelsRequest struct {
  Base                 *commonpb.MsgBase 
  CollectionID         int64 
  ChannelIDs           []string
  Infos                []*WatchDmChannelsInfo
}
  • LoadSegments
type LoadSegmentRequest struct {
  Base          *commonpb.MsgBase
  DbID          UniqueID
  CollectionID  UniqueID
  PartitionID   UniqueID
  SegmentIDs    []UniqueID
  FieldIDs      []UniqueID
  SegmentStates []*datapb.SegmentStateInfo
  Schema        *schemapb.CollectionSchema
}
  • ReleaseCollection
type ReleaseCollectionRequest struct {
  Base         *commonpb.MsgBase
  DbID         UniqueID
  CollectionID UniqueID
}
  • ReleasePartitions
type ReleasePartitionRequest struct {
  Base         *commonpb.MsgBase
  DbID         UniqueID
  CollectionID UniqueID
  PartitionIDs []UniqueID
}
  • ReleaseSegments
type ReleaseSegmentRequest struct {
  Base         *commonpb.MsgBas
  DbID         UniqueID
  CollectionID UniqueID
  PartitionIDs []UniqueID
  SegmentIDs   []UniqueID
}
  • GetSegmentInfo
type SegmentInfoRequest struct {
  Base       *commonpb.MsgBase
  SegmentIDs []Unique
}

type SegmentInfoResponse struct {
  Status *commonpb.Status
  Infos  []*SegmentInfo

}

//TODO

8.2 Collection Replica

collectionReplica contains a in-memory local copy of persistent collections. In common cases, the system has multiple query nodes. Data of a collection will be distributed across all the available query nodes, and each query node's collectionReplica will maintain its own share (only part of the collection). Every replica tracks a value called tSafe which is the maximum timestamp that the replica is up-to-date.

8.1.1 Collection
type Collection struct {
  Name string
  Id uint64
  Fields map[string]FieldMeta
  SegmentsId []uint64
  
  cCollectionSchema C.CCollectionSchema
}
8.1.2 Field Meta
type FieldMeta struct {
  Name string
  Id uint64
  IsPrimaryKey bool
  TypeParams map[string]string
  IndexParams map[string]string
}
8.1.3 Segment
type Segment struct {
  Id uint64
  ParitionName string
  CollectionId uint64
  OpenTime Timestamp
  CloseTime Timestamp
  NumRows uint64
  
  cSegment C.CSegmentBase
}

8.3 Data Sync Service

type dataSyncService struct {
	ctx context.Context
	pulsarURL string
	fg *flowgraph.TimeTickedFlowGraph
	msgStream *msgstream.PulsarMsgStream
	dataReplica Replica
}