mirror of
https://gitee.com/milvus-io/milvus.git
synced 2025-12-06 17:18:35 +08:00
design doc about master service recover on power failure Signed-off-by: yefu.chen <yefu.chen@zilliz.com>
8.2 KiB
8.2 KiB
Master service recovery on power failure
1. Basic idea
master servicereads meta from etcd when it startsmaster serviceneeds to store thepositionof the msgstream into etcd every time it consumes the msgstream.master servicereads thepositionof msgstream from etcd when it starts up, then seek to the specifiedpositionand re-consume the msgstream- Ensure that all messages from the msgstream are processed in idempotent fashion, so that repeated consumption of the same message does not cause system inconsistencies
master serviceregisters itself in etcd and finds out if the dependentdata serviceandindex serviceare online via etcd
2. Specific tasks
2.1 Read meta from etcd
master serviceneeds to load meta from etcd when it starts, this part is already done
2.2 dd requests from grpc
- The
dd requests, such as create_collection, create_partition, etc., from grpc are marked as done only if the related meata have been writen into etcd. - The
dd requestsshould be send todd msgstreamwhen the operation is done. - There may be a fault here, that is, the
dd requesthas been written to etcd, but it has not been sent todd msgstreamyet, then themaster servicehas crashed. - For the scenarios mentioned in item 3,
master serviceneeds to check if alldd requestsare sent todd msgstreamwhen it starts up. master service's built-in scheduler ensures that all grpc requests are executed serially, so it only needs to check whether the most recentdd requestsare sent to thedd msgstream, and resend them if not.- Take
create_collectionas an example to illustrate the process- When
create collectionis written to etcd, 2 additional keys are updated,dd_msganddd_type dd_msgis the serialization of thedd_msgdd_typeis the message type ofdd_msg, such ascreate_collection,create_partition,drop_collection,etc. It's used to deserializesdd_msg.- Update the meta of
create_collection,dd_msganddd_typeat the same time in a transactional manner. - When
dd_msghas been sent todd msgstream, deletedd_msganddd_typefrom etcd. - When the
master servicestarts, first check whether there aredd_msganddd_typein etcd, if so, then deserializedd_msgaccording todd_type, and then send it to thedd msgstream, otherwise no processing will be done - There may be a failure here, that is,
dd_msghas been sent to thedd msgstream, but has not been deleted from etcd yet, then themaster servicecrashed, at this case, thedd_msgwould be sent todd msgstreamrepeatedly, so the receiver needs to count this case.
- When
2.3 create index requests from grpc
- In the processing of
create index,master servicecallsmetaTable'sGetNotIndexedSegmentsto get all segment ids that are not indexed - After getting the segment ids,
master servicecallindex servicecreate the index on these segment ids. - In the current implementation, the
create indexrequests will return after the segment ids are put into a go channel. - The
master servicestarts a background task that keeps reading the segment ids from the go channel, and then calls theindex serviceto create the index. - There is a fault here, the segment ids have been put into the go channel in the processing function of the grpc request, and then the grpc returns, but the
master service's background task has not yet read them from the go channel, thebmaster servicecrashes. At this time, the client thinks that the index is created, but themaster servicedoes not callindex serviceto create the index. - The solution for the fault mentioned in item 5
- Remove the go channel and
master service's background task - In the request processing function of
create index, the call will return only when all segment ids have been sendindex service - Some segment ids may be send to
index servicerepeatedly, andindex serviceneeds to handle such requests
- Remove the go channel and
2.4 New segment from data service
- Each time a new segment is created, the
data servicesends the segment id to themaster servicevia msgstream master serviceneeds to update the segment id to the collection meta and record the position of the msgstream in etcd- Step 2 is transactional and the operation will be successful only if the collection meta in etcd is updated
- So the
master serviceonly needs to restore the msgstream to the position when recovering from a power failure
2.5 Flushed segment from data node
- Each time the
data nodefinishes flushing a segment, it sends the segment id to themaster servicevia msgstream. master serviceneeds to fetch binlog fromdata serviceby id and send request toindex serviceto create index on this segment- When the
index serviceis called successfully, it will return a build id, and thenmaster servicewill update the build id to thecollection metaand record the position of the msgstream in etcd. - Step 3 is transactional and the operation will be successful only if the
collection metain etcd is updated - So the
master serviceonly needs to restore the msgstream to the position when recovering from a power failure
2.6 Failed to call external grpc service
master serviceneeds grpc service fromdata serviceandindex service, if the grpc call failed, it needs to reconnect.master servicedoes not listen to the status of thedata serviceandindex servicein real time
2.7 Add virtual channel assignment when creating collection
- Add a new field, "number of shards" in the
create collectionrequest, the "num of shards" tell themaster serviceto create the number of virtual channel for this collection. - In the current implementation, virtual channels and physical channels have a one-to-one relationship, and the total number of physical channels increases as the number of virtual channels increases; later, the total number of physical channels needs to be fixed, and multiple virtual channels share one physical channel
- The name of the virtual channel is globally unique, and the
collection metarecords the correspondence between the virtual channel and the physical channel
Add processing of time synchronization signals from proxy node
- A virtual channel can be inserted by multiple proxies, so the timestamp in the virtual channel is not increase monotonically
- All proxies report the timestamp of all the virtual channels to the
master serviceperiodically - The
master servicecollects the timestamps from the proxies on each virtual channel and gets the minimum one as the timestamp of that virtual channel, and then inserts the timestamp into the virtual channel - The proxy reports the timestamp to the
master servicevia grpc - The proxy needs to register itself in etcd when it starts,
master servicewill listen to the corresponding key to determine how many active proxies there are, and thus determine if all of them have sent timestamps to master - If a proxy is not registered in etcd but sends a timestamp or any other grpc request to master, master will ignore the grpc request
2.9 Register service in etcd
master serviceneeds to register itself with etcd when it starts- The registration should include ip address, port, its own id, global incremental timestamp
2.10 Remove the code related to proxy service
- The
proxy servicerelated code will be removed - The the job of time synchronization which done by the
proxy serviceis partially simplified and handed over to the master (subsection 2.8)
2.11 Query collection meta based on timeline
- Add a new field of
timestampto the grpc request ofdescribe collection master serviceshould provide snapshot on thecollection mate- Return the
collection metaat the point of timestamp mentioned in the request
2.12 Timestamp of dd operations
master serviceresponse to set the timestamp ofdd operations, create collection, create partition, drop collection, drop partitionmaster serviceresponse to send timestamp todd msgstream, if there is a dd message, then use the current latest timestamp from that message, if not, get a timestamp from tso