Files
seaweedfs/weed/server/blockcmd/host_effects.go
T
pingqiuandClaude Opus 4.6 1453274988 refactor: extract host effects adapter and define Phase 17 stop line
Move dispatcher-facing host effects out of volume_server_block.go into
blockcmd while keeping server-owned cache/state semantics in weed/server.
Document Batch 10 delivery and Batch 11 stop-line review so the
separation line closes without over-extracting readiness-state mutation.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-04 08:43:21 -07:00

67 lines
1.8 KiB
Go

package blockcmd
import engine "github.com/seaweedfs/seaweedfs/sw-block/engine/replication"
// CommandRecorder records one executed command on the host side.
type CommandRecorder func(volumeID, name string)
// CoreEventEmitter feeds one runtime observation back into the core.
type CoreEventEmitter func(ev engine.Event)
// ProjectionCacheWriter stores the latest published projection in a host-local
// cache owned by the server adapter.
type ProjectionCacheWriter interface {
StoreProjection(volumeID string, projection engine.PublicationProjection)
}
type hostEffects struct {
recordCommand CommandRecorder
emitCoreEvent CoreEventEmitter
projection ProjectionReader
cache ProjectionCacheWriter
}
// NewHostEffects keeps host-side command completion effects in the server
// adapter layer while exposing only the narrow Dispatcher-facing surface.
func NewHostEffects(
recordCommand CommandRecorder,
emitCoreEvent CoreEventEmitter,
projection ProjectionReader,
cache ProjectionCacheWriter,
) HostEffects {
return &hostEffects{
recordCommand: recordCommand,
emitCoreEvent: emitCoreEvent,
projection: projection,
cache: cache,
}
}
func (effects *hostEffects) RecordCommand(volumeID, name string) {
if effects == nil || effects.recordCommand == nil {
return
}
effects.recordCommand(volumeID, name)
}
func (effects *hostEffects) EmitCoreEvent(ev engine.Event) {
if effects == nil || effects.emitCoreEvent == nil {
return
}
effects.emitCoreEvent(ev)
}
func (effects *hostEffects) PublishProjection(volumeID string, projection engine.PublicationProjection) error {
if effects == nil || effects.cache == nil {
return nil
}
proj := projection
if effects.projection != nil {
if latest, ok := effects.projection.Projection(volumeID); ok {
proj = latest
}
}
effects.cache.StoreProjection(volumeID, proj)
return nil
}