7.7 KiB
Drop Collection
Milvus 2.0 use 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,
SDKstarts 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
}
- When received the
DropCollectionrequest, theProxywould wraps this request intoDropCollectionTask, and pushs this task intoDdTaskQueuequeue. After that,Proxywould call method ofWatiToFinishto wait until the task 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 backgroud service in
Proxy, this service would get theDropCollectionTaskfromDdTaskQueue, and executes it in three phases.PreExecute, do some static checking at this phase, such as check ifCollection Nameis legal etc.Execute, at thie phase,Proxywould sendDropCollectionrequest toRootCoordviaGrpc,and wait the reponse, theprotois defined as follow:
service RootCoord { ... rpc DropCollection(milvus.DropCollectionRequest) returns (common.Status) {} ... }PostExecute,Proxywould delete theCollection's meta from global meta table at this phase.
-
RootCoordwould wraps theDropCollectionrequest intoDropCollectionReqTask, and then call functionexecuteTask.executeTaskwould return until thecontextis done orDropCollectionReqTask.Executereturned.
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, and this timestamp is considered as the point when the collection was deleted. -
RoooCoordwould send a message ofDropCollectionRequestintoMsgStream, and other components, who has subscribe to theMsgStream, would be notified. TheProtoofDropCollectionRequestis defined as follow:
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 the resouces that related to thisCollection. ThisGrpcrequest is done in anothergoroutine, so it would not block the main thread. Theprotois defined as follow:
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 follow:
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 follwing figure.
-
QueryCoordwould wrapsReleaseCollectionintoReleaseCollectionTask, and push the task intoTaskScheduler -
There is a backgroud service in
QueryCoord, this service would get theReleaseCollectionTaskfromTaskScheduler, and executes 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, notify theProxythat not processing any message of thisCollectionanymore. Theprotois defined as follow:
message ReleaseDQLMessageStreamRequest { common.MsgBase base = 1; int64 dbID = 2; int64 collectionID = 3; }- send a
ReleaseCollectionrequest to eachQueryNodeviaGrpc, 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 reponse to `RootCoord -
At
Step 8,RoooCoordhas sent a message ofDropCollectionRequestintoMsgStream,DataNodewould subscribe thisMsgStream, soDataNodewould be notified to released the resources. The execution flow is shown in the following figure.
- In
DataNode, eachMsgStreamwill have aFlowGraph, all the messages are processed by thatFlowGraph. When theDataNodereceives the message ofDropCollectionRequest,DataNodewould notifyBackouGroundGC, which is a background service onDataNode, to release the resouces.
Notes:
- Currently, the
DataCoordhas not response to theDropCollection, so theCollection'ssegment metaare still exist in theDataCoord'smetaTable, and theBinlogfiles belongs to thisCollectionare still exist on the persistent storage. - Currently, the
IndexCoordhas not response to theDropCollection, so theCollection'sindex fileare still exist on the persistent storage.


