#53729·milvus

[Bug]: QueryCoord stale orphan segment cleanup tasks block cleanup on other nodes after replica changes

Author: xiaofan-luanCreated Sep 22, 2026Updated Sep 28, 2026
Labelskind/bugtriage/accepted

Is there an existing issue for this?

  • I have searched the existing issues.

Environment

  • Milvus commit: 0a3af91b261dcf288cd1ece2ccf7c8141ac27a25 (PR #53677, based on master 9fcbbec31bba4958e6642f7c0109257207e591fe).
  • Deployment: integration MiniCluster with QueryNodes and StreamingNodes; Pulsar appears in recovery-position logs.
  • Test: TestReplicas/TestDynamicUpdateLoadConfigs, package tests/integration/replicas/load.
  • Observed in CI build #589, September 21, 2026.

Current Behavior

During successive replica/resource-group changes, obsolete orphan-segment cleanup tasks remain active after their release RPCs succeed. The same segments are immediately reloaded on the same node, so the old tasks cannot observe segment absence. Since all orphan cleanup tasks share replicaID=-1 and the task conflict key does not include the node, they can also block cleanup of the same segments on another node.

The integration test failed at load_test.go:464:

Error: Condition never satisfied
Test:  TestReplicas/TestDynamicUpdateLoadConfigs

After changing from three replicas to two replicas in different resource groups, the test waits 30 seconds for the total distribution to reach six sealed segment copies and two channels. Replica metadata had already reached two replicas, but the distribution assertion timed out. Cleanup of the old node did not start until approximately five minutes later.

This issue tracks the QueryCoord behavior independently of #53677, whose changes only affect REST request validation. This test uses protobuf/gRPC and does not exercise that validation.

Expected Behavior

  • Cleanup of the same segment on different orphan nodes should not block each other.
  • When a node is reused by an active replica of the collection, an obsolete orphan cleanup task should stop waiting on, or accounting for, the newly loaded segment copy.
  • Replica changes should converge without depending on the five-minute segment-task timeout.
  • Retain distribution-aware workload accounting and protect newly loaded copies from obsolete release operations.

Steps To Reproduce

The existing integration test provides the observed workload; a deterministic standalone reproducer has not yet been added.

  1. Use the test's MiniCluster setup: five resource groups, each requesting/limiting one QueryNode; five StreamingNodes. Automatic compaction is disabled in this suite.
  2. Create one collection with one channel and three segments of 2,000 rows each.
  3. Load five replicas across all five resource groups.
  4. Reduce to three replicas in the first three resource groups, then change to two replicas in the other two groups.
  5. Hit the timing window where an orphan release on node10 succeeds, but node10 reloads the same segment before QueryCoord observes its absence. At the same time, node4 requires cleanup of that segment.
  6. Observe the 30-second distribution assertion failing and the old cleanup tasks occupying the scheduler until around the task timeout.

With the normal integration-test dependencies and native build available, a focused invocation is:

bash
go test -tags dynamic,test -gcflags='all=-N -l' -count=1 \
  ./tests/integration/replicas/load \
  -run '^TestReplicas$/^TestDynamicUpdateLoadConfigs$' -timeout 20m

This command is a suggested focused invocation, not a claim of deterministic reproduction. Failure frequency is unknown.

Milvus Log

Full integration log · Failure summary

Collection: 469227704269145075 (test_load_collection). Segment IDs: 469227704269346087, 469227704269396107, 469227704269446128.

All timestamps below are UTC on September 21:

Time Observation
03:34:10.560 Three dirty segment exists Reduce tasks added for node10, replicaID=-1, task IDs 1789961640574–1789961640576.
03:34:10.594–.595 The three release RPCs complete successfully.
03:34:10.699–.711 Collection changes to two replicas in rg_3 and rg_4; nodes9/10 are reused, with segment moves node8→9 and node7→10.
03:34:11.071–.089 The segments are loaded again on nodes9/10.
03:34:40.56 The 30-second distribution assertion fails. The three old node10 tasks remain processing; node4 has not received a release for these segments.
03:39:11.073 The three old tasks are removed, matched by their original trace IDs, approximately 300.5 seconds after admission.
03:39:12.749–03:39:13.059 Node4 cleanup tasks are finally admitted and release the three segments.

The test does not log each sampled segment/channel total, so an exact final count is not asserted here. The task-removal messages do not explicitly give a timeout reason; the approximately 300-second lifetime matches the configured default timeout.

Analysis and suggested fix direction

The following mechanism is strongly supported by the logs and source, but still needs a deterministic regression test:

  1. Orphan cleanup uses meta.NilReplica (ID=-1).
  2. The task key is (ReplicaID, SegmentID, IsGrowing). Equal-priority duplicates are rejected regardless of the cleanup node.
  3. Reduce completion requires the RPC to return and the segment to disappear from distribution. Reloading the same segment can keep an obsolete task waiting and leave a stale negative workload delta.

Suggested scope: include node identity in the key for NilReplica segment cleanup only, preserving normal replica-level task serialization; cancel obsolete orphan cleanup when the collection remains loaded and the node belongs to that collection's replica again, removing the task/index/delta together. Keep real collection-release cleanup valid even if replica metadata temporarily remains. Do not simply mark every release successful at RPC return or increase the test timeout.

Tests should cover different-node cleanup admission, same-node deduplication, normal-replica serialization, release/reload without an observed absence, stale delta removal, and preservation of the newly loaded copy. Cancelling a scheduler task alone does not fence an already in-flight release RPC; that ordering boundary also needs explicit validation.

Relevant history

  • #49861, merged June 23, 2026 (UTC+8), changed segment completion from RPC-return-only to RPC-return plus distribution confirmation. This introduced the waiting behavior involved here; the task key without node identity predates it.
  • #53525, merged September 18, reduced the shared load-wait polling interval from 500ms to 100ms. This could expose the timing window more often, but no before/after reproduction has established that relationship.
  • #45865 concerns a different failure in the same test (stale replica/shard-leader selection), rather than the orphan segment task collision described here.