Milvus Storage-Compute Separation Series-2: Target Mechanism
First published on Medium
Preface
No matter the framework of system is storage-compute separation or integrated storage-compute, clients’ requirements for query correctness are consistent. No customers are willing to sacrifice correctness for the sake of “architectural advantages,” even in the case of approximate nearest neighbor (ANN) queries. For a storage-compute separation architecture, where “storage” and “computation” occur in separate processes, ensuring the integrity, consistency, and real-time property of data becomes a more complex problem compared to an integrated storage-compute architecture. This article starts from this problem and introduces how Milvus ensures the integrity, consistency, and real-time property of data under a storage-compute separation architecture. This article involves some prerequisite knowledge. If it causes confusion for readers, you can refer to MrPresent-Han: Milvus Storage-Compute Separation Series-1: Introduction to Milvus Architecture.
The main challenge of storage-compute separation: Real-time data updates
Before discussing data integrity, we first need to clarify the challenges brought about by real-time data updates. If data is not written in real-time but is instead imported in batches, the “write once, read many” scenario can be simplified to a download and copy problem, thereby ensuring excellent scalability and relatively low complexity. However, the problem is that databases are not data lakes, and the vast majority of users cannot accept data visibility delays of hours or even minutes. Some users even require newly written data to be immediately visible, which adds additional complexity to the storage-compute separation architecture.
How does Milvus ensure real-time visibility and data integrity in a storage-compute separation architecture?
Two points: the target mechanism and storage-compute dual writing.
Target Mechanism
As mentioned earlier, in Milvus, a segment is a horizontal slice of a table and serves as the smallest distributed unit. The target in Milvus can be understood, for the time being, as a set of “readable segments.”
As shown in the diagram above, as time progresses, clients continuously insert data, generating new segments on the storage side. Since targets are immutable, new targets are created. The mixCoord periodically checks the target status. When it discovers the existence of a new target, it commands compute nodes to load the new segment for client queries, thereby ensuring that newly written data can be correctly queried by clients.
It may seem that advancing and updating the target mechanism is a straightforward process — simply downloading the new segment files from object storage onto compute nodes. However, in reality, it’s not that simple. The main challenges lie in two areas:
- Compaction issues
- Indexing issues
The article begins by discussing compaction.
Essentially, the storage design of LSM (Log-Structured Merge-tree) structures must accept the additional complexity introduced by compaction. Since the generated segments are immutable, controlling small files and applying delete operations both rely on compaction. And with compaction in mind, the target mechanism is not as simple as depicted in the previous diagram.
As shown in the diagram above, during the time period between target3 and target4, segment1 and segment2 are compacted into segment4, and new data is written, generating segment5. At this point, for the client, the effective target is [segment3, segment4, segment5], excluding segment1 and segment2. Otherwise, there would be errors in duplicated query results and wasteful resource consumption due to duplicate computation. Therefore, segment1 and segment2 need to be unloaded, and segment5 needs to be loaded to complete the target update.
Handling Intermediate States in Targets
In the design process of complex systems, a headache point is often the design of state transitions. Only when the system’s state transitions are correct can consistency and availability be guaranteed. In the state transition process, the Todo and Done states are often relatively controllable, but the Doing state between them is very tricky during which the system is most prone to produce errors or even crashes. Regarding the Milvus Target mechanism, some typical intermediate states are shown in the diagram below.
New Up before Old Down
First is the scenario of “New Up before Old Down,” where at a certain point in time, segment4 has been loaded, but segment2 has not been unloaded yet. In this case, the client may see redundant data on segment2.
Old Down before New Up
Then there is the opposite scenario, where old segments 1 and 2 have already been unloaded, but the new segment 4 has not been loaded yet. In this case, the client’s queries may find missing data.
Both of these situations are essentially “Doing” problems. To address these “Doing” problems, two points can be considered: order and commit point. In the target mechanism of Milvus, we design it as follows.
Define order: All segments in the target must be “up before down,” meaning new segments must be loaded before corresponding old segments can be unloaded.
Define commit point: All new segments must be loaded before the target update is considered complete. Only then can the target used by the client be advanced.
Handling Segment Redundancy: targetVersion
Some readers may have already noticed a loophole in the previous context: when reaching the commit point, the old segments have not been unloaded yet, resulting in segment redundancy. So, how can we prevent clients from reading old segments? The answer is to establish a targetVersion relationship between targets and segments.
Advancing from target3 to target4
As shown in the diagram above, when mixCoord detects that the commit point has been reached, it updates the targetVersion of segments 3–4–5 still included in target4 to t4. However, segments 1–2, which are no longer in the target, have their targetVersion unchanged and remain t3. When a client query occurs, the currently available targetVersion is t4, so the query will ignore segments 1 and 2, thereby avoiding querying redundant segments.
Summary
This article primarily introduced Milvus’s target advancement mechanism under a storage-compute separation architecture. In the actual system construction and operation process, there are many other intermediate states and detailed issues that need to be addressed, such as multiple replicas, load balancing, and resource isolation. We will address these detailed issues one by one in subsequent articles.
— MrPresent-Han




