mirror of
https://github.com/milvus-io/milvus.git
synced 2026-07-21 10:15:43 +00:00
issue: #50344 ## Summary After a `force_promote`, the persisted `SalvageCheckpoint` was unreachable from any client. Two compounding defects: ### Defect 1 — `GetReplicateInfo` returns early, never reaching `GetSalvageCheckpoint` `internal/proxy/impl.go`: the handler called `GetReplicateCheckpoint` first and returned on any error. On a standalone-primary (post `force_promote`) the WAL is no longer a secondary, so `GetReplicateCheckpoint` fails with `STREAMING_CODE_REPLICATE_VIOLATION` ("wal is not a secondary cluster in replicating topology") and the follow-up `GetSalvageCheckpoint` — the whole point — was never reached. **Fix:** treat **only** `REPLICATE_VIOLATION` as non-fatal — leave the live checkpoint `nil` and continue to the salvage checkpoint. All other errors stay fatal (no blanket swallow). ### Defect 2 — client retries `REPLICATE_VIOLATION` to the deadline `internal/streamingnode/client/handler/handler_client_impl.go`: `createHandlerAfterStreamingNodeReady` retried the (permanent) violation in a backoff loop until the caller's context cancelled, so it surfaced as `DEADLINE_EXCEEDED` rather than a typed error. **Fix:** return immediately on `status.AsStreamingError(err).IsUnrecoverable()` — a category that **already** includes replicate violation (and is documented as "Stop resuming retry and report to user"). The retry loop simply wasn't honoring it. Fixing Defect 2 is also what lets Defect 1 detect the violation: otherwise the error would have been swallowed into a deadline before the proxy could classify it. ## Changes - `internal/proxy/impl.go`: `GetReplicateInfo` continues to `GetSalvageCheckpoint` on `REPLICATE_VIOLATION`, returns `checkpoint=nil` in that case. - `internal/streamingnode/client/handler/handler_client_impl.go`: stop retrying unrecoverable errors; return them within RTT. - `internal/streamingnode/client/handler/handler_client_test.go`: add `TestHandlerClient_GetReplicateCheckpointReplicateViolation` asserting an immediate, typed return (no retry loop / `Watch` call). ## Test Plan - [x] gofmt clean; `internal/util/streamingutil/status` builds - [x] New unit test mirrors the existing handler-client mock harness - [ ] CI: `TestHandlerClient_GetReplicateCheckpointReplicateViolation` passes - [ ] CI: `replication/data_salvage` integration suite — `TestGetReplicateInfoOnPrimaryCluster` now returns cleanly on a primary instead of erroring > Note: the proxy / streamingnode packages can't be fully built locally in this environment due to a pre-existing stale C++ artifact mismatch in the unrelated `internal/storagev2/packed` cgo package (reproducible on a clean master checkout). The changed packages are pure-Go and use already-existing `StreamingError` APIs; CI compiles and runs them. --------- Signed-off-by: bigsheeper <yihao.dai@zilliz.com> Signed-off-by: Yihao Dai <yihao.dai@zilliz.com>
275 lines
11 KiB
Go
275 lines
11 KiB
Go
// Licensed to the LF AI & Data foundation under one
|
|
// or more contributor license agreements. See the NOTICE file
|
|
// distributed with this work for additional information
|
|
// regarding copyright ownership. The ASF licenses this file
|
|
// to you under the Apache License, Version 2.0 (the
|
|
// "License"); you may not use this file except in compliance
|
|
// with the License. You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package proxy
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/cockroachdb/errors"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/mock"
|
|
"google.golang.org/grpc/codes"
|
|
grpcstatus "google.golang.org/grpc/status"
|
|
|
|
"github.com/milvus-io/milvus-proto/go-api/v3/commonpb"
|
|
"github.com/milvus-io/milvus-proto/go-api/v3/milvuspb"
|
|
"github.com/milvus-io/milvus/internal/distributed/streaming"
|
|
"github.com/milvus-io/milvus/internal/mocks/distributed/mock_streaming"
|
|
"github.com/milvus-io/milvus/internal/streamingnode/server/wal/utility"
|
|
streamingstatus "github.com/milvus-io/milvus/internal/util/streamingutil/status"
|
|
"github.com/milvus-io/milvus/pkg/v3/util/merr"
|
|
)
|
|
|
|
func TestProxy_GetReplicateInfo_NodeUnhealthy(t *testing.T) {
|
|
node := &Proxy{}
|
|
node.UpdateStateCode(commonpb.StateCode_Abnormal)
|
|
|
|
resp, err := node.GetReplicateInfo(context.Background(), &milvuspb.GetReplicateInfoRequest{
|
|
TargetPchannel: "test-pchannel",
|
|
})
|
|
assert.Error(t, err)
|
|
assert.True(t, errors.Is(err, merr.ErrServiceNotReady))
|
|
assert.Nil(t, resp)
|
|
}
|
|
|
|
func TestProxy_GetReplicateInfo_GetCheckpointError(t *testing.T) {
|
|
replicateService := mock_streaming.NewMockReplicateService(t)
|
|
replicateService.EXPECT().GetReplicateCheckpoint(mock.Anything, "test-pchannel").
|
|
Return(nil, errors.New("checkpoint error"))
|
|
|
|
mockWAL := mock_streaming.NewMockWALAccesser(t)
|
|
mockWAL.EXPECT().Replicate().Return(replicateService)
|
|
prevWAL := streaming.WAL()
|
|
streaming.SetWALForTest(mockWAL)
|
|
defer streaming.SetWALForTest(prevWAL)
|
|
|
|
node := &Proxy{}
|
|
node.UpdateStateCode(commonpb.StateCode_Healthy)
|
|
|
|
resp, err := node.GetReplicateInfo(context.Background(), &milvuspb.GetReplicateInfoRequest{
|
|
TargetPchannel: "test-pchannel",
|
|
})
|
|
assert.EqualError(t, err, "checkpoint error")
|
|
assert.Nil(t, resp)
|
|
}
|
|
|
|
func TestProxy_GetReplicateInfo_GetSalvageCheckpointError(t *testing.T) {
|
|
replicateService := mock_streaming.NewMockReplicateService(t)
|
|
replicateService.EXPECT().GetReplicateCheckpoint(mock.Anything, "test-pchannel").
|
|
Return(&utility.ReplicateCheckpoint{ClusterID: "cluster-a", TimeTick: 100}, nil)
|
|
replicateService.EXPECT().GetSalvageCheckpoint(mock.Anything, "test-pchannel").
|
|
Return(nil, errors.New("salvage error"))
|
|
|
|
mockWAL := mock_streaming.NewMockWALAccesser(t)
|
|
mockWAL.EXPECT().Replicate().Return(replicateService)
|
|
prevWAL := streaming.WAL()
|
|
streaming.SetWALForTest(mockWAL)
|
|
defer streaming.SetWALForTest(prevWAL)
|
|
|
|
node := &Proxy{}
|
|
node.UpdateStateCode(commonpb.StateCode_Healthy)
|
|
|
|
resp, err := node.GetReplicateInfo(context.Background(), &milvuspb.GetReplicateInfoRequest{
|
|
TargetPchannel: "test-pchannel",
|
|
SourceClusterId: "source-cluster",
|
|
})
|
|
assert.EqualError(t, err, "salvage error")
|
|
assert.Nil(t, resp)
|
|
}
|
|
|
|
func TestProxy_GetReplicateInfo_GetSalvageCheckpointUnimplemented(t *testing.T) {
|
|
replicateService := mock_streaming.NewMockReplicateService(t)
|
|
replicateService.EXPECT().GetReplicateCheckpoint(mock.Anything, "test-pchannel").
|
|
Return(&utility.ReplicateCheckpoint{ClusterID: "cluster-a", PChannel: "test-pchannel", TimeTick: 100}, nil)
|
|
replicateService.EXPECT().GetSalvageCheckpoint(mock.Anything, "test-pchannel").
|
|
Return(nil, grpcstatus.Error(codes.Unimplemented, "method GetSalvageCheckpoint not implemented"))
|
|
|
|
mockWAL := mock_streaming.NewMockWALAccesser(t)
|
|
mockWAL.EXPECT().Replicate().Return(replicateService)
|
|
prevWAL := streaming.WAL()
|
|
streaming.SetWALForTest(mockWAL)
|
|
defer streaming.SetWALForTest(prevWAL)
|
|
|
|
node := &Proxy{}
|
|
node.UpdateStateCode(commonpb.StateCode_Healthy)
|
|
|
|
resp, err := node.GetReplicateInfo(context.Background(), &milvuspb.GetReplicateInfoRequest{
|
|
TargetPchannel: "test-pchannel",
|
|
SourceClusterId: "source-cluster",
|
|
})
|
|
assert.NoError(t, err)
|
|
assert.NotNil(t, resp)
|
|
assert.Equal(t, "cluster-a", resp.GetCheckpoint().GetClusterId())
|
|
assert.Nil(t, resp.GetSalvageCheckpoint())
|
|
}
|
|
|
|
func TestProxy_GetReplicateInfo_Success_NoSalvageCheckpoints(t *testing.T) {
|
|
replicateService := mock_streaming.NewMockReplicateService(t)
|
|
replicateService.EXPECT().GetReplicateCheckpoint(mock.Anything, "test-pchannel").
|
|
Return(&utility.ReplicateCheckpoint{ClusterID: "cluster-a", PChannel: "test-pchannel", TimeTick: 100}, nil)
|
|
replicateService.EXPECT().GetSalvageCheckpoint(mock.Anything, "test-pchannel").
|
|
Return(nil, nil)
|
|
|
|
mockWAL := mock_streaming.NewMockWALAccesser(t)
|
|
mockWAL.EXPECT().Replicate().Return(replicateService)
|
|
prevWAL := streaming.WAL()
|
|
streaming.SetWALForTest(mockWAL)
|
|
defer streaming.SetWALForTest(prevWAL)
|
|
|
|
node := &Proxy{}
|
|
node.UpdateStateCode(commonpb.StateCode_Healthy)
|
|
|
|
resp, err := node.GetReplicateInfo(context.Background(), &milvuspb.GetReplicateInfoRequest{
|
|
TargetPchannel: "test-pchannel",
|
|
SourceClusterId: "source-cluster",
|
|
})
|
|
assert.NoError(t, err)
|
|
assert.NotNil(t, resp)
|
|
assert.Equal(t, "cluster-a", resp.GetCheckpoint().GetClusterId())
|
|
assert.Equal(t, uint64(100), resp.GetCheckpoint().GetTimeTick())
|
|
assert.Nil(t, resp.GetSalvageCheckpoint())
|
|
}
|
|
|
|
func TestProxy_GetReplicateInfo_Success_MatchingSourceCluster(t *testing.T) {
|
|
salvageCPs := []*utility.ReplicateCheckpoint{
|
|
{ClusterID: "other-cluster", PChannel: "other-pchannel", TimeTick: 50},
|
|
{ClusterID: "source-cluster", PChannel: "source-pchannel", TimeTick: 200},
|
|
}
|
|
replicateService := mock_streaming.NewMockReplicateService(t)
|
|
replicateService.EXPECT().GetReplicateCheckpoint(mock.Anything, "test-pchannel").
|
|
Return(&utility.ReplicateCheckpoint{ClusterID: "cluster-a", PChannel: "test-pchannel", TimeTick: 100}, nil)
|
|
replicateService.EXPECT().GetSalvageCheckpoint(mock.Anything, "test-pchannel").
|
|
Return(salvageCPs, nil)
|
|
|
|
mockWAL := mock_streaming.NewMockWALAccesser(t)
|
|
mockWAL.EXPECT().Replicate().Return(replicateService)
|
|
prevWAL := streaming.WAL()
|
|
streaming.SetWALForTest(mockWAL)
|
|
defer streaming.SetWALForTest(prevWAL)
|
|
|
|
node := &Proxy{}
|
|
node.UpdateStateCode(commonpb.StateCode_Healthy)
|
|
|
|
resp, err := node.GetReplicateInfo(context.Background(), &milvuspb.GetReplicateInfoRequest{
|
|
TargetPchannel: "test-pchannel",
|
|
SourceClusterId: "source-cluster",
|
|
})
|
|
assert.NoError(t, err)
|
|
assert.NotNil(t, resp)
|
|
assert.Equal(t, "cluster-a", resp.GetCheckpoint().GetClusterId())
|
|
assert.NotNil(t, resp.GetSalvageCheckpoint())
|
|
assert.Equal(t, "source-cluster", resp.GetSalvageCheckpoint().GetClusterId())
|
|
assert.Equal(t, "source-pchannel", resp.GetSalvageCheckpoint().GetPchannel())
|
|
assert.Equal(t, uint64(200), resp.GetSalvageCheckpoint().GetTimeTick())
|
|
}
|
|
|
|
func TestProxy_GetReplicateInfo_Success_NoMatchingSourceCluster(t *testing.T) {
|
|
salvageCPs := []*utility.ReplicateCheckpoint{
|
|
{ClusterID: "other-cluster", PChannel: "other-pchannel", TimeTick: 50},
|
|
}
|
|
replicateService := mock_streaming.NewMockReplicateService(t)
|
|
replicateService.EXPECT().GetReplicateCheckpoint(mock.Anything, "test-pchannel").
|
|
Return(&utility.ReplicateCheckpoint{ClusterID: "cluster-a", PChannel: "test-pchannel", TimeTick: 100}, nil)
|
|
replicateService.EXPECT().GetSalvageCheckpoint(mock.Anything, "test-pchannel").
|
|
Return(salvageCPs, nil)
|
|
|
|
mockWAL := mock_streaming.NewMockWALAccesser(t)
|
|
mockWAL.EXPECT().Replicate().Return(replicateService)
|
|
prevWAL := streaming.WAL()
|
|
streaming.SetWALForTest(mockWAL)
|
|
defer streaming.SetWALForTest(prevWAL)
|
|
|
|
node := &Proxy{}
|
|
node.UpdateStateCode(commonpb.StateCode_Healthy)
|
|
|
|
resp, err := node.GetReplicateInfo(context.Background(), &milvuspb.GetReplicateInfoRequest{
|
|
TargetPchannel: "test-pchannel",
|
|
SourceClusterId: "source-cluster", // not in salvage list
|
|
})
|
|
assert.NoError(t, err)
|
|
assert.NotNil(t, resp)
|
|
assert.Equal(t, "cluster-a", resp.GetCheckpoint().GetClusterId())
|
|
assert.Nil(t, resp.GetSalvageCheckpoint()) // no match
|
|
}
|
|
|
|
func TestProxy_GetReplicateInfo_Success_NoSourceClusterIDFilter(t *testing.T) {
|
|
// When SourceClusterId is empty, no salvage checkpoint is returned
|
|
salvageCPs := []*utility.ReplicateCheckpoint{
|
|
{ClusterID: "some-cluster", PChannel: "some-pchannel", TimeTick: 75},
|
|
}
|
|
replicateService := mock_streaming.NewMockReplicateService(t)
|
|
replicateService.EXPECT().GetReplicateCheckpoint(mock.Anything, "test-pchannel").
|
|
Return(&utility.ReplicateCheckpoint{ClusterID: "cluster-a", PChannel: "test-pchannel", TimeTick: 100}, nil)
|
|
replicateService.EXPECT().GetSalvageCheckpoint(mock.Anything, "test-pchannel").
|
|
Return(salvageCPs, nil)
|
|
|
|
mockWAL := mock_streaming.NewMockWALAccesser(t)
|
|
mockWAL.EXPECT().Replicate().Return(replicateService)
|
|
prevWAL := streaming.WAL()
|
|
streaming.SetWALForTest(mockWAL)
|
|
defer streaming.SetWALForTest(prevWAL)
|
|
|
|
node := &Proxy{}
|
|
node.UpdateStateCode(commonpb.StateCode_Healthy)
|
|
|
|
resp, err := node.GetReplicateInfo(context.Background(), &milvuspb.GetReplicateInfoRequest{
|
|
TargetPchannel: "test-pchannel",
|
|
// SourceClusterId intentionally empty
|
|
})
|
|
assert.NoError(t, err)
|
|
assert.NotNil(t, resp)
|
|
assert.Equal(t, "cluster-a", resp.GetCheckpoint().GetClusterId())
|
|
assert.Nil(t, resp.GetSalvageCheckpoint()) // no source cluster filter → no match
|
|
}
|
|
|
|
func TestProxy_GetReplicateInfo_ReplicateViolation_ReturnsSalvageCheckpoint(t *testing.T) {
|
|
// On a standalone-primary cluster (e.g. after force_promote) the live
|
|
// replicate checkpoint is unavailable (REPLICATE_VIOLATION). GetReplicateInfo
|
|
// must treat that as non-fatal: leave the live checkpoint nil and still return
|
|
// the salvage checkpoint, which is exactly what callers need post-promote.
|
|
salvageCPs := []*utility.ReplicateCheckpoint{
|
|
{ClusterID: "source-cluster", PChannel: "source-pchannel", TimeTick: 200},
|
|
}
|
|
replicateService := mock_streaming.NewMockReplicateService(t)
|
|
replicateService.EXPECT().GetReplicateCheckpoint(mock.Anything, "test-pchannel").
|
|
Return(nil, streamingstatus.NewReplicateViolation("wal is not a secondary cluster in replicating topology"))
|
|
replicateService.EXPECT().GetSalvageCheckpoint(mock.Anything, "test-pchannel").
|
|
Return(salvageCPs, nil)
|
|
|
|
mockWAL := mock_streaming.NewMockWALAccesser(t)
|
|
mockWAL.EXPECT().Replicate().Return(replicateService)
|
|
prevWAL := streaming.WAL()
|
|
streaming.SetWALForTest(mockWAL)
|
|
defer streaming.SetWALForTest(prevWAL)
|
|
|
|
node := &Proxy{}
|
|
node.UpdateStateCode(commonpb.StateCode_Healthy)
|
|
|
|
resp, err := node.GetReplicateInfo(context.Background(), &milvuspb.GetReplicateInfoRequest{
|
|
TargetPchannel: "test-pchannel",
|
|
SourceClusterId: "source-cluster",
|
|
})
|
|
assert.NoError(t, err)
|
|
assert.NotNil(t, resp)
|
|
assert.Nil(t, resp.GetCheckpoint()) // live checkpoint unavailable on a primary
|
|
assert.NotNil(t, resp.GetSalvageCheckpoint())
|
|
assert.Equal(t, "source-cluster", resp.GetSalvageCheckpoint().GetClusterId())
|
|
assert.Equal(t, "source-pchannel", resp.GetSalvageCheckpoint().GetPchannel())
|
|
assert.Equal(t, uint64(200), resp.GetSalvageCheckpoint().GetTimeTick())
|
|
}
|