* chore: remove unreachable dead code across the codebase Remove ~50,000 lines of unreachable code identified by static analysis. Major removals: - weed/filer/redis_lua: entire unused Redis Lua filer store implementation - weed/wdclient/net2, resource_pool: unused connection/resource pool packages - weed/plugin/worker/lifecycle: unused lifecycle plugin worker - weed/s3api: unused S3 policy templates, presigned URL IAM, streaming copy, multipart IAM, key rotation, and various SSE helper functions - weed/mq/kafka: unused partition mapping, compression, schema, and protocol functions - weed/mq/offset: unused SQL storage and migration code - weed/worker: unused registry, task, and monitoring functions - weed/query: unused SQL engine, parquet scanner, and type functions - weed/shell: unused EC proportional rebalance functions - weed/storage/erasure_coding/distribution: unused distribution analysis functions - Individual unreachable functions removed from 150+ files across admin, credential, filer, iam, kms, mount, mq, operation, pb, s3api, server, shell, storage, topology, and util packages * fix(s3): reset shared memory store in IAM test to prevent flaky failure TestLoadIAMManagerFromConfig_EmptyConfigWithFallbackKey was flaky because the MemoryStore credential backend is a singleton registered via init(). Earlier tests that create anonymous identities pollute the shared store, causing LookupAnonymous() to unexpectedly return true. Fix by calling Reset() on the memory store before the test runs. * style: run gofmt on changed files * fix: restore KMS functions used by integration tests * fix(plugin): prevent panic on send to closed worker session channel The Plugin.sendToWorker method could panic with "send on closed channel" when a worker disconnected while a message was being sent. The race was between streamSession.close() closing the outgoing channel and sendToWorker writing to it concurrently. Add a done channel to streamSession that is closed before the outgoing channel, and check it in sendToWorker's select to safely detect closed sessions without panicking.
152 lines
4.3 KiB
Go
152 lines
4.3 KiB
Go
package base
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/admin/config"
|
|
"github.com/seaweedfs/seaweedfs/weed/glog"
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/worker_pb"
|
|
"github.com/seaweedfs/seaweedfs/weed/worker/tasks"
|
|
"github.com/seaweedfs/seaweedfs/weed/worker/types"
|
|
)
|
|
|
|
// GenericFactory creates task instances using a TaskDefinition
|
|
type GenericFactory struct {
|
|
*tasks.BaseTaskFactory
|
|
taskDef *TaskDefinition
|
|
}
|
|
|
|
// NewGenericFactory creates a generic task factory
|
|
func NewGenericFactory(taskDef *TaskDefinition) *GenericFactory {
|
|
return &GenericFactory{
|
|
BaseTaskFactory: tasks.NewBaseTaskFactory(
|
|
taskDef.Type,
|
|
taskDef.Capabilities,
|
|
taskDef.Description,
|
|
),
|
|
taskDef: taskDef,
|
|
}
|
|
}
|
|
|
|
// Create creates a task instance using the task definition
|
|
func (f *GenericFactory) Create(params *worker_pb.TaskParams) (types.Task, error) {
|
|
if f.taskDef.CreateTask == nil {
|
|
return nil, fmt.Errorf("no task creation function defined for %s", f.taskDef.Type)
|
|
}
|
|
return f.taskDef.CreateTask(params)
|
|
}
|
|
|
|
// Type returns the task type
|
|
func (f *GenericFactory) Type() string {
|
|
return string(f.taskDef.Type)
|
|
}
|
|
|
|
// Description returns a description of what this task does
|
|
func (f *GenericFactory) Description() string {
|
|
return f.taskDef.Description
|
|
}
|
|
|
|
// Capabilities returns the task capabilities
|
|
func (f *GenericFactory) Capabilities() []string {
|
|
return f.taskDef.Capabilities
|
|
}
|
|
|
|
// GenericSchemaProvider provides config schema from TaskDefinition
|
|
type GenericSchemaProvider struct {
|
|
taskDef *TaskDefinition
|
|
}
|
|
|
|
// GetConfigSchema returns the schema from task definition
|
|
func (p *GenericSchemaProvider) GetConfigSchema() *tasks.TaskConfigSchema {
|
|
return &tasks.TaskConfigSchema{
|
|
TaskName: string(p.taskDef.Type),
|
|
DisplayName: p.taskDef.DisplayName,
|
|
Description: p.taskDef.Description,
|
|
Icon: p.taskDef.Icon,
|
|
Schema: config.Schema{
|
|
Fields: p.taskDef.ConfigSpec.Fields,
|
|
},
|
|
}
|
|
}
|
|
|
|
// GenericUIProvider provides UI functionality from TaskDefinition
|
|
type GenericUIProvider struct {
|
|
taskDef *TaskDefinition
|
|
}
|
|
|
|
// GetCurrentConfig returns current config as TaskConfig
|
|
func (ui *GenericUIProvider) GetCurrentConfig() types.TaskConfig {
|
|
return ui.taskDef.Config
|
|
}
|
|
|
|
// ApplyTaskPolicy applies protobuf TaskPolicy configuration
|
|
func (ui *GenericUIProvider) ApplyTaskPolicy(policy *worker_pb.TaskPolicy) error {
|
|
return ui.taskDef.Config.FromTaskPolicy(policy)
|
|
}
|
|
|
|
// ApplyTaskConfig applies TaskConfig interface configuration
|
|
func (ui *GenericUIProvider) ApplyTaskConfig(config types.TaskConfig) error {
|
|
taskPolicy := config.ToTaskPolicy()
|
|
return ui.taskDef.Config.FromTaskPolicy(taskPolicy)
|
|
}
|
|
|
|
// RegisterTask registers a complete task definition with all registries
|
|
func RegisterTask(taskDef *TaskDefinition) {
|
|
// Validate task definition
|
|
if err := validateTaskDefinition(taskDef); err != nil {
|
|
glog.Errorf("Invalid task definition for %s: %v", taskDef.Type, err)
|
|
return
|
|
}
|
|
|
|
// Create and register factory
|
|
factory := NewGenericFactory(taskDef)
|
|
tasks.AutoRegister(taskDef.Type, factory)
|
|
|
|
// Create and register detector/scheduler
|
|
detector := NewGenericDetector(taskDef)
|
|
scheduler := NewGenericScheduler(taskDef)
|
|
|
|
tasks.AutoRegisterTypes(func(registry *types.TaskRegistry) {
|
|
registry.RegisterTask(detector, scheduler)
|
|
})
|
|
|
|
// Create and register schema provider
|
|
schemaProvider := &GenericSchemaProvider{taskDef: taskDef}
|
|
tasks.RegisterTaskConfigSchema(string(taskDef.Type), schemaProvider)
|
|
|
|
// Create and register UI provider
|
|
uiProvider := &GenericUIProvider{taskDef: taskDef}
|
|
tasks.AutoRegisterUI(func(uiRegistry *types.UIRegistry) {
|
|
baseUIProvider := tasks.NewBaseUIProvider(
|
|
taskDef.Type,
|
|
taskDef.DisplayName,
|
|
taskDef.Description,
|
|
taskDef.Icon,
|
|
schemaProvider.GetConfigSchema,
|
|
uiProvider.GetCurrentConfig,
|
|
uiProvider.ApplyTaskPolicy,
|
|
uiProvider.ApplyTaskConfig,
|
|
)
|
|
uiRegistry.RegisterUI(baseUIProvider)
|
|
})
|
|
|
|
glog.V(1).Infof("Registered complete task definition: %s", taskDef.Type)
|
|
}
|
|
|
|
// validateTaskDefinition ensures the task definition is complete
|
|
func validateTaskDefinition(taskDef *TaskDefinition) error {
|
|
if taskDef.Type == "" {
|
|
return fmt.Errorf("task type is required")
|
|
}
|
|
if taskDef.Name == "" {
|
|
return fmt.Errorf("task name is required")
|
|
}
|
|
if taskDef.Config == nil {
|
|
return fmt.Errorf("task config is required")
|
|
}
|
|
if taskDef.CreateTask == nil {
|
|
return fmt.Errorf("task creation function is required")
|
|
}
|
|
return nil
|
|
}
|