2020-11-19 10:59:10 +08:00
2020-12-27 09:05:24 +08:00
## 8. Query Service
2020-11-19 10:59:10 +08:00
#### 8.1 Overview
2021-01-18 10:09:17 +08:00
< img src = "./figs/query_service.png" width = 500 >
2021-01-04 14:16:43 +08:00
2020-11-19 10:59:10 +08:00
2021-01-13 11:08:03 +08:00
#### 8.2 Query Service Interface
2020-12-27 09:05:24 +08:00
```go
2021-01-13 11:08:03 +08:00
type QueryService interface {
Service
RegisterNode(req RegisterNodeRequest) (RegisterNodeResponse, error)
2021-01-12 18:03:24 +08:00
ShowCollections(req ShowCollectionRequest) (ShowCollectionResponse, error)
2021-01-13 11:08:03 +08:00
LoadCollection(req LoadCollectionRequest) error
ReleaseCollection(req ReleaseCollectionRequest) error
2021-01-12 18:03:24 +08:00
ShowPartitions(req ShowPartitionRequest) (ShowPartitionResponse, error)
GetPartitionStates(req PartitionStatesRequest) (PartitionStatesResponse, error)
2020-12-29 18:02:44 +08:00
LoadPartitions(req LoadPartitonRequest) error
ReleasePartitions(req ReleasePartitionRequest) error
2021-01-13 11:08:03 +08:00
CreateQueryChannel() (CreateQueryChannelResponse, error)
2020-12-27 09:05:24 +08:00
}
```
2021-01-15 14:38:36 +08:00
* *MsgBase*
2020-12-27 09:05:24 +08:00
```go
2021-01-15 14:38:36 +08:00
type MsgBase struct {
2021-01-13 11:08:03 +08:00
MsgType MsgType
2021-01-15 14:38:36 +08:00
MsgID UniqueID
2021-01-13 11:08:03 +08:00
Timestamp Timestamp
2021-01-15 14:38:36 +08:00
SourceID UniqueID
2021-01-13 11:08:03 +08:00
}
2021-01-11 18:35:54 +08:00
```
2021-01-13 11:08:03 +08:00
* *RegisterNode*
2021-01-11 18:35:54 +08:00
```go
2021-01-13 11:08:03 +08:00
type RegisterNodeRequest struct {
2021-01-15 14:38:36 +08:00
MsgBase
2021-01-13 11:08:03 +08:00
Address string
Port int64
2020-12-27 09:05:24 +08:00
}
2021-01-13 11:08:03 +08:00
type RegisterNodeResponse struct {
//InitParams
2020-12-27 09:05:24 +08:00
}
2021-01-12 18:03:24 +08:00
```
* *ShowCollections*
2020-12-27 09:05:24 +08:00
2021-01-12 18:03:24 +08:00
```go
type ShowCollectionRequest struct {
2021-01-15 14:38:36 +08:00
MsgBase
2021-01-12 18:03:24 +08:00
DbID UniqueID
2021-01-11 18:35:54 +08:00
}
2020-12-27 09:05:24 +08:00
2021-01-12 18:03:24 +08:00
type ShowCollectionResponse struct {
CollectionIDs []UniqueID
2021-01-11 18:35:54 +08:00
}
```
2021-01-13 11:08:03 +08:00
* *LoadCollection*
```go
type LoadCollectionRequest struct {
2021-01-15 14:38:36 +08:00
MsgBase
2021-01-13 11:08:03 +08:00
DbID UniqueID
CollectionID UniqueID
}
```
* *ReleaseCollection*
```go
type ReleaseCollectionRequest struct {
2021-01-15 14:38:36 +08:00
MsgBase
2021-01-13 11:08:03 +08:00
DbID UniqueID
CollectionID UniqueID
}
```
2021-01-12 18:03:24 +08:00
* *ShowPartitions*
2020-12-29 18:02:44 +08:00
2020-12-27 09:05:24 +08:00
```go
2021-01-12 18:03:24 +08:00
type ShowPartitionRequest struct {
2021-01-15 14:38:36 +08:00
MsgBase
2020-12-29 18:02:44 +08:00
DbID UniqueID
CollectionID UniqueID
}
2021-01-12 18:03:24 +08:00
type ShowPartitionResponse struct {
PartitionIDs []UniqueID
}
```
* *GetPartitionStates*
```go
2020-12-27 09:05:24 +08:00
type PartitionState = int
const (
NOT_EXIST PartitionState = 0
2021-01-11 18:35:54 +08:00
NOT_PRESENT PartitionState = 1
ON_DISK PartitionState = 2
PARTIAL_IN_MEMORY PartitionState = 3
IN_MEMORY PartitionState = 4
PARTIAL_IN_GPU PartitionState = 5
IN_GPU PartitionState = 6
2020-12-27 09:05:24 +08:00
)
2021-01-12 18:03:24 +08:00
type PartitionStatesRequest struct {
2021-01-15 14:38:36 +08:00
MsgBase
2021-01-13 11:08:03 +08:00
DbID UniqueID
2021-01-12 18:03:24 +08:00
CollectionID UniqueID
2021-01-13 11:08:03 +08:00
PartitionIDs []UniqueID
2020-12-29 18:02:44 +08:00
}
2021-01-12 18:03:24 +08:00
type PartitionStates struct {
PartitionID UniqueID
2020-12-27 09:05:24 +08:00
State PartitionState
}
2020-12-29 18:02:44 +08:00
2021-01-12 18:03:24 +08:00
type PartitionStatesResponse struct {
States []PartitionStates
2020-12-29 18:02:44 +08:00
}
```
2021-01-13 11:08:03 +08:00
* *LoadPartitions*
2020-12-29 18:02:44 +08:00
2021-01-13 11:08:03 +08:00
```go
type LoadPartitonRequest struct {
2021-01-15 14:38:36 +08:00
MsgBase
2021-01-13 11:08:03 +08:00
DbID UniqueID
CollectionID UniqueID
PartitionIDs []UniqueID
}
```
* *ReleasePartitions*
```go
type ReleasePartitionRequest struct {
2021-01-15 14:38:36 +08:00
MsgBase
2021-01-13 11:08:03 +08:00
DbID UniqueID
CollectionID UniqueID
PartitionIDs []UniqueID
}
```
2020-12-29 18:02:44 +08:00
* *CreateQueryChannel*
```go
2021-01-13 11:08:03 +08:00
type CreateQueryChannelResponse struct {
2021-01-14 20:30:27 +08:00
RequestChannelName string
ResultChannelName string
2020-12-29 18:02:44 +08:00
}
```
2021-01-15 14:38:36 +08:00
#### 8.2 Query Channel
```go
type SearchRequest struct {
RequestBase
DbName string
CollectionName string
PartitionNames []string
DbID UniqueID
CollectionID UniqueID
PartitionIDs []UniqueID
Dsl string
PlaceholderGroup []byte
}
```
2021-01-13 11:08:03 +08:00
#### 8.2 Query Node Interface
2020-12-29 18:02:44 +08:00
```go
2021-01-13 11:08:03 +08:00
type QueryNode interface {
Service
AddQueryChannel(req AddQueryChannelRequest) error
RemoveQueryChannel(req RemoveQueryChannelRequest) error
WatchDmChannels(req WatchDmChannelRequest) error
2021-01-14 20:30:27 +08:00
//SetTimeTickChannel(channelName string) error
//SetStatsChannel(channelName string) error
2021-01-13 11:08:03 +08:00
LoadSegments(req LoadSegmentRequest) error
ReleaseSegments(req ReleaseSegmentRequest) error
//DescribeParition(req DescribeParitionRequest) (PartitionDescriptions, error)
2020-12-29 18:02:44 +08:00
}
```
2021-01-13 11:08:03 +08:00
* *AddQueryChannel*
2020-12-29 18:02:44 +08:00
```go
2021-01-13 11:08:03 +08:00
type AddQueryChannelRequest struct {
2021-01-15 14:38:36 +08:00
MsgBase
2021-01-14 20:30:27 +08:00
RequestChannelName string
ResultChannelName string
2021-01-13 11:08:03 +08:00
}
```
* *RemoveQueryChannel*
```go
type RemoveQueryChannelRequest struct {
2021-01-14 20:30:27 +08:00
RequestChannelName string
ResultChannelName string
2020-12-29 18:02:44 +08:00
}
2020-12-27 09:05:24 +08:00
```
2021-01-13 11:08:03 +08:00
* *WatchDmChannels*
2020-12-27 09:05:24 +08:00
2021-01-13 11:08:03 +08:00
```go
type WatchDmChannelRequest struct {
2021-01-14 20:30:27 +08:00
InsertChannelNames []string
2021-01-18 10:09:17 +08:00
StartSegment UniqueID
//FieldIDs []int64
2021-01-13 11:08:03 +08:00
}
```
2020-12-27 09:05:24 +08:00
2021-01-11 18:35:54 +08:00
* *LoadSegments*
```go
type LoadSegmentRequest struct {
2021-01-15 14:38:36 +08:00
MsgBase
2021-01-11 18:35:54 +08:00
DbID UniqueID
CollectionID UniqueID
PartitionID UniqueID
SegmentIDs []UniqueID
2021-01-18 10:09:17 +08:00
//FieldIDs []int64
2021-01-11 18:35:54 +08:00
}
```
* *ReleaseSegments*
```go
type ReleaseSegmentRequest struct {
2021-01-15 14:38:36 +08:00
MsgBase
2021-01-11 18:35:54 +08:00
DbID UniqueID
CollectionID UniqueID
PartitionID UniqueID
SegmentIDs []UniqueID
}
```
2020-11-19 10:59:10 +08:00
#### 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
``` go
type Collection struct {
Name string
Id uint64
Fields map[string]FieldMeta
SegmentsId []uint64
cCollectionSchema C.CCollectionSchema
}
```
###### 8.1.2 Field Meta
```go
type FieldMeta struct {
Name string
Id uint64
IsPrimaryKey bool
TypeParams map[string]string
IndexParams map[string]string
}
```
###### 8.1.3 Segment
``` go
type Segment struct {
Id uint64
ParitionName string
CollectionId uint64
OpenTime Timestamp
CloseTime Timestamp
NumRows uint64
cSegment C.CSegmentBase
}
```
2021-01-13 11:08:03 +08:00
#### 8.3 Data Sync Service
2020-11-19 10:59:10 +08:00
```go
2021-01-13 11:08:03 +08:00
type dataSyncService struct {
2020-11-19 10:59:10 +08:00
ctx context.Context
pulsarURL string
fg *flowgraph.TimeTickedFlowGraph
msgStream *msgstream.PulsarMsgStream
2021-01-13 11:08:03 +08:00
dataReplica Replica
2020-11-19 10:59:10 +08:00
}
```