mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-07-31 20:36:47 +00:00
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>
67 lines
1.8 KiB
Go
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
|
|
}
|