Files
wehub-resource-sync 498b235461
Build and test / Build and test AMD64 Ubuntu 22.04 (push) Failing after 0s
Publish Builder / amazonlinux2023 (push) Failing after 1s
Build and test / UT for Go (push) Has been skipped
Publish KRTE Images / KRTE (push) Failing after 1s
Build and test / Integration Test (push) Has been skipped
Build and test / Upload Code Coverage (push) Has been skipped
Publish Builder / rockylinux9 (push) Failing after 1s
Publish Builder / ubuntu22.04 (push) Failing after 0s
Publish Builder / ubuntu24.04 (push) Failing after 0s
Publish Gpu Builder / publish-gpu-builder (push) Failing after 1s
Publish Test Images / PyTest (push) Failing after 0s
Build and test / UT for Cpp (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:31:17 +08:00

100 lines
4.0 KiB
Go

package flusherimpl
import (
"context"
"math"
"github.com/cockroachdb/errors"
"github.com/milvus-io/milvus/internal/streamingnode/server/resource"
"github.com/milvus-io/milvus/pkg/v3/mlog"
"github.com/milvus-io/milvus/pkg/v3/proto/datapb"
"github.com/milvus-io/milvus/pkg/v3/streaming/util/message"
"github.com/milvus-io/milvus/pkg/v3/streaming/util/message/adaptor"
"github.com/milvus-io/milvus/pkg/v3/util/conc"
"github.com/milvus-io/milvus/pkg/v3/util/merr"
"github.com/milvus-io/milvus/pkg/v3/util/retry"
)
var defaultCollectionNotFoundTolerance = 10
// getRecoveryInfos gets the recovery info of the vchannels from datacoord
func (impl *WALFlusherImpl) getRecoveryInfos(ctx context.Context, vchannel []string) (map[string]*datapb.GetChannelRecoveryInfoResponse, message.MessageID, error) {
futures := make([]*conc.Future[interface{}], 0, len(vchannel))
for _, v := range vchannel {
v := v
future := GetExecPool().Submit(func() (interface{}, error) {
return impl.getRecoveryInfo(ctx, v)
})
futures = append(futures, future)
}
recoveryInfos := make(map[string]*datapb.GetChannelRecoveryInfoResponse, len(futures))
for i, future := range futures {
resp, err := future.Await()
if err == nil {
recoveryInfos[vchannel[i]] = resp.(*datapb.GetChannelRecoveryInfoResponse)
continue
}
if errors.Is(err, errChannelLifetimeUnrecoverable) {
impl.logger.Warn(ctx, "channel has been dropped, skip to recover flusher for vchannel", mlog.FieldVChannel(vchannel[i]))
continue
}
return nil, nil, errors.Wrapf(err, "when get recovery info of vchannel %s", vchannel[i])
}
var checkpoint message.MessageID
walName := impl.wal.Get().WALName()
for _, info := range recoveryInfos {
messageID := adaptor.MustGetMessageIDFromMQWrapperIDBytesWithWALName(walName, info.GetInfo().GetSeekPosition().GetMsgID())
if checkpoint == nil || messageID.LT(checkpoint) {
checkpoint = messageID
}
}
return recoveryInfos, checkpoint, nil
}
// getRecoveryInfo gets the recovery info of the vchannel.
func (impl *WALFlusherImpl) getRecoveryInfo(ctx context.Context, vchannel string) (*datapb.GetChannelRecoveryInfoResponse, error) {
var resp *datapb.GetChannelRecoveryInfoResponse
retryCnt := -1
logger := impl.logger.With(mlog.FieldVChannel(vchannel))
err := retry.Do(ctx, func() error {
retryCnt++
logger := logger.With(mlog.Int("retryCnt", retryCnt))
dc, err := resource.Resource().MixCoordClient().GetWithContext(ctx)
if err != nil {
return err
}
resp, err = dc.GetChannelRecoveryInfo(ctx, &datapb.GetChannelRecoveryInfoRequest{Vchannel: vchannel})
err = merr.CheckRPCCall(resp, err)
if errors.Is(err, merr.ErrChannelNotAvailable) {
logger.Warn(ctx, "channel not available because of collection dropped", mlog.Err(err))
return retry.Unrecoverable(errChannelLifetimeUnrecoverable)
}
if errors.Is(err, merr.ErrCollectionNotFound) {
if retryCnt >= defaultCollectionNotFoundTolerance {
// TODO: It's not strong guarantee to make no resource lost or leak. Should be removed after wal-driven-ddl framework is ready.
logger.Warn(ctx, "too many collection not found, the create collection may undone by coord", mlog.Err(err))
return retry.Unrecoverable(errChannelLifetimeUnrecoverable)
}
logger.Warn(ctx, "collection not found, maybe the create collection is not done or create collection undone by coord", mlog.Err(err))
return err
}
if err != nil {
logger.Warn(ctx, "get channel recovery info failed", mlog.Err(err))
return err
}
// The channel has been dropped, skip to recover it.
if isDroppedChannel(resp) {
logger.Info(ctx, "channel has been dropped, the vchannel can not be recovered")
return retry.Unrecoverable(errChannelLifetimeUnrecoverable)
}
return nil
}, retry.AttemptAlways(), retry.RetryErr(func(error) bool { return true }))
return resp, err
}
func isDroppedChannel(resp *datapb.GetChannelRecoveryInfoResponse) bool {
return len(resp.GetInfo().GetSeekPosition().GetMsgID()) == 0 && resp.GetInfo().GetSeekPosition().GetTimestamp() == math.MaxUint64
}