7.6 KiB
Drop Collection
Milvus 2.0 uses Collection to represent a set of data, like Table in traditional database. Users can create or drop Collection. Altering the Schema of Collection is not supported yet. This article introduces the execution path of Drop Collection. At the end of this article, you should know which components are involved in Drop Collection.
The execution flow of Drop Collection is shown in the following figure:
- Firstly,
SDKsends aDropCollectionrequest toProxyviaGrpc, theprotois defined as follows:
service MilvusService {
...
rpc DropCollection(DropCollectionRequest) returns (common.Status) {}
...
}
message DropCollectionRequest {
common.MsgBase base = 1; // must
string db_name = 2;
string collection_name = 3; // must
}
- Once the
DropCollectionrequest is received, theProxywould wrap this request intoDropCollectionTask, and push this task intoDdTaskQueuequeue. After that,Proxywould callWatiToFinishmethod to wait until the task is finished.
type task interface {
TraceCtx() context.Context
ID() UniqueID // return ReqID
SetID(uid UniqueID) // set ReqID
Name() string
Type() commonpb.MsgType
BeginTs() Timestamp
EndTs() Timestamp
SetTs(ts Timestamp)
OnEnqueue() error
PreExecute(ctx context.Context) error
Execute(ctx context.Context) error
PostExecute(ctx context.Context) error
WaitToFinish() error
Notify(err error)
}
type DropCollectionTask struct {
Condition
*milvuspb.DropCollectionRequest
ctx context.Context
rootCoord types.RootCoord
result *commonpb.Status
chMgr channelsMgr
chTicker channelsTimeTicker
}
-
There is a background service in
Proxy, this service would get theDropCollectionTaskfromDdTaskQueue, and execute it in three phases:PreExecute, do some static checking at this phase, such as check ifCollection Nameis legal etc.Execute, at this phase,Proxywould sendDropCollectionrequest toRootCoordviaGrpc, and wait the response, theprotois defined as below:
service RootCoord { ... rpc DropCollection(milvus.DropCollectionRequest) returns (common.Status) {} ... }PostExecute,Proxywould deleteCollection's meta from global meta table at this phase.
-
RootCoordwould wrap theDropCollectionrequest intoDropCollectionReqTask, and then call functionexecuteTask.executeTaskwould return until thecontextis done orDropCollectionReqTask.Executeis returned.
type reqTask interface {
Ctx() context.Context
Type() commonpb.MsgType
Execute(ctx context.Context) error
Core() *Core
}
type DropCollectionReqTask struct {
baseReqTask
Req *milvuspb.DropCollectionRequest
}
-
Firstly,
RootCoordwould deleteCollection's meta frommetaTable, includingschema,partition,segment,index. All of these delete operations are committed in one transaction. -
After
Collection's meta has been deleted frommetaTable,Milvuswould consider this collection has been deleted successfully. -
RootCoordwould alloc a timestamp fromTSObefore deletingCollection's meta frommetaTable. This timestamp is considered as the point when the collection was deleted. -
RootCoordwould send a message ofDropCollectionRequestintoMsgStream. Thus other components, who have subscribed to theMsgStream, would be notified. TheProtoofDropCollectionRequestis defined as below:
message DropCollectionRequest {
common.MsgBase base = 1;
string db_name = 2;
string collectionName = 3;
int64 dbID = 4;
int64 collectionID = 5;
}
-
After these operations,
RootCoordwould update internal timestamp. -
Then
RootCoordwould start aReleaseCollectionrequest toQueryCoordviaGrpc, notifyQueryCoordto release all resources that related to thisCollection. ThisGrpcrequest is done in anothergoroutine, so it would not block the main thread. Theprotois defined as follows:
service QueryCoord {
...
rpc ReleaseCollection(ReleaseCollectionRequest) returns (common.Status) {}
...
}
message ReleaseCollectionRequest {
common.MsgBase base = 1;
int64 dbID = 2;
int64 collectionID = 3;
int64 nodeID = 4;
}
- At last,
RootCoordwould sendInvalidateCollectionMetaCacherequest to eachProxy, notifyProxyto removeCollection's meta. Theprotois defined as follows:
service Proxy {
...
rpc InvalidateCollectionMetaCache(InvalidateCollMetaCacheRequest) returns (common.Status) {}
...
}
message InvalidateCollMetaCacheRequest {
common.MsgBase base = 1;
string db_name = 2;
string collection_name = 3;
}
- The execution flow of
QueryCoord.ReleaseCollectionis shown in the following figure:
-
QueryCoordwould wrapReleaseCollectionintoReleaseCollectionTask, and push the task intoTaskScheduler -
There is a background service in
QueryCoord. This service would get theReleaseCollectionTaskfromTaskScheduler, and execute it in three phases:-
PreExecute,ReleaseCollectionTaskwould only print debug log at this phase. -
Execute, there are two jobs at this phase:- send a
ReleaseDQLMessageStreamrequest toRootCoordviaGrpc,RootCoordwould redirect theReleaseDQLMessageStreamrequest to eachProxy, and notify theProxythat stop processing any message of thisCollectionanymore. Theprotois defined as follows:
message ReleaseDQLMessageStreamRequest { common.MsgBase base = 1; int64 dbID = 2; int64 collectionID = 3; }- send a
ReleaseCollectionrequest to eachQueryNodeviaGrpc, and notify theQueryNodeto release all the resources related to thisCollection, includingIndex,Segment,FlowGraph, etc.QueryNodewould no longer read any message from thisCollection'sMsgStreamanymore
service QueryNode { ... rpc ReleaseCollection(ReleaseCollectionRequest) returns (common.Status) {} ... } message ReleaseCollectionRequest { common.MsgBase base = 1; int64 dbID = 2; int64 collectionID = 3; int64 nodeID = 4; } - send a
-
PostExecute,ReleaseCollectionTaskwould only print debug log at this phase.
-
-
After these operations,
QueryCoordwould sendReleaseCollection's response toRootCoord. -
At
Step 8,RootCoordhas sent a message ofDropCollectionRequestintoMsgStream.DataNodewould subscribe thisMsgStream, so that it would be notified to release related resources. The execution flow is shown in the following figure.
- In
DataNode, eachMsgStreamwill have aFlowGraph, which processes all messages. When theDataNodereceives the message ofDropCollectionRequest,DataNodewould notifyBackGroundGC, which is a background service onDataNode, to release resources.
Notes:
- Currently, the
DataCoorddoesn't have response to theDropCollection. So theCollection'ssegment metastill exists in theDataCoord'smetaTable, and theBinlogfiles belonging to thisCollectionstill exist in the persistent storage. - Currently, the
IndexCoorddoesn't have response to theDropCollection. So theCollection'sindex filestill exists in the persistent storage.


