mirror of
https://github.com/milvus-io/milvus.git
synced 2026-07-21 10:15:43 +00:00
issue: #35917 - mlog package: move logger initialization, zap core, async buffered writes, field helpers, and scoped logger binding into pkg/mlog while removing pkg/log. - logging callsites: migrate Milvus logging usage to context-aware mlog APIs and simplify redundant With chains across components, utilities, tests, and tools. - trace propagation: replace logutil trace interceptors with mlog/tracer integration and add client_request_id fallback propagation for server stats handlers. --------- Signed-off-by: chyezh <chyezh@outlook.com>
120 lines
4.2 KiB
Go
120 lines
4.2 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 datacoord
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/milvus-io/milvus/internal/datacoord/allocator"
|
|
"github.com/milvus-io/milvus/internal/datacoord/task"
|
|
"github.com/milvus-io/milvus/pkg/v3/mlog"
|
|
"github.com/milvus-io/milvus/pkg/v3/proto/datapb"
|
|
"github.com/milvus-io/milvus/pkg/v3/proto/indexpb"
|
|
)
|
|
|
|
// externalCollectionRefreshInspector handles task scheduling and recovery for external collection refresh.
|
|
//
|
|
// This is an internal component of ExternalCollectionRefreshManager, responsible for:
|
|
// 1. Reload InProgress/Init tasks to scheduler on DataCoord restart (idempotent recovery)
|
|
// 2. Periodically enqueue pending tasks to the global task scheduler for execution
|
|
//
|
|
// TASK STATE TRANSITIONS:
|
|
// Init → InProgress (inspector enqueues to scheduler, scheduler dispatches to DataNode)
|
|
// InProgress → Finished/Failed (DataNode reports execution result)
|
|
type externalCollectionRefreshInspector struct {
|
|
ctx context.Context
|
|
refreshMeta *externalCollectionRefreshMeta
|
|
mt *meta // meta for task operations (CreateTaskOnWorker, SetJobInfo)
|
|
scheduler task.GlobalScheduler
|
|
allocator allocator.Allocator
|
|
closeChan chan struct{}
|
|
// wrapTask builds a scheduler-facing task wrapper with all callbacks
|
|
// wired (processFinishedJob → checker.processJobByID). The manager owns
|
|
// the wiring logic and injects this factory so the inspector doesn't
|
|
// need a direct reference to the checker (avoids construction-order
|
|
// circular dependency).
|
|
wrapTask func(t *datapb.ExternalCollectionRefreshTask) *refreshExternalCollectionTask
|
|
}
|
|
|
|
func newRefreshInspector(
|
|
ctx context.Context,
|
|
refreshMeta *externalCollectionRefreshMeta,
|
|
mt *meta,
|
|
scheduler task.GlobalScheduler,
|
|
allocator allocator.Allocator,
|
|
closeChan chan struct{},
|
|
) *externalCollectionRefreshInspector {
|
|
return &externalCollectionRefreshInspector{
|
|
ctx: ctx,
|
|
refreshMeta: refreshMeta,
|
|
mt: mt,
|
|
scheduler: scheduler,
|
|
allocator: allocator,
|
|
closeChan: closeChan,
|
|
}
|
|
}
|
|
|
|
// run starts the inspector loop.
|
|
func (i *externalCollectionRefreshInspector) run() {
|
|
// Reload tasks on startup for idempotent recovery
|
|
i.reloadFromMeta()
|
|
|
|
// Log inspection interval for observability
|
|
inspectInterval := Params.DataCoordCfg.ExternalCollectionCheckInterval.GetAsDuration(time.Second)
|
|
mlog.Info(i.ctx, "start external collection inspector", mlog.Duration("inspectInterval", inspectInterval))
|
|
|
|
ticker := time.NewTicker(inspectInterval)
|
|
defer ticker.Stop()
|
|
|
|
for {
|
|
select {
|
|
case <-i.closeChan:
|
|
mlog.Info(i.ctx, "external collection inspector exited")
|
|
return
|
|
case <-ticker.C:
|
|
i.inspect()
|
|
}
|
|
}
|
|
}
|
|
|
|
// inspect runs a single inspection cycle to re-enqueue any pending tasks.
|
|
func (i *externalCollectionRefreshInspector) inspect() {
|
|
tasks := i.refreshMeta.GetAllTasks()
|
|
for _, t := range tasks {
|
|
switch t.GetState() {
|
|
case indexpb.JobState_JobStateInit, indexpb.JobState_JobStateRetry:
|
|
// Re-enqueue pending tasks (scheduler will deduplicate)
|
|
i.scheduler.Enqueue(i.wrapTask(t))
|
|
}
|
|
}
|
|
}
|
|
|
|
// reloadFromMeta reloads active tasks from metadata on startup.
|
|
func (i *externalCollectionRefreshInspector) reloadFromMeta() {
|
|
tasks := i.refreshMeta.GetAllTasks()
|
|
for _, t := range tasks {
|
|
if t.GetState() != indexpb.JobState_JobStateInit &&
|
|
t.GetState() != indexpb.JobState_JobStateRetry &&
|
|
t.GetState() != indexpb.JobState_JobStateInProgress {
|
|
continue
|
|
}
|
|
// Enqueue active tasks for processing
|
|
i.scheduler.Enqueue(i.wrapTask(t))
|
|
}
|
|
}
|