satellite/metabase/rangedloop: observer interface

New interface for parallel segment loop.

Closes https://github.com/storj/storj/issues/5239

Change-Id: I2bcce6f836f6625da8ceb4fc0fc030c0ea4380e7
This commit is contained in:
Erik van Velzen 2022-11-15 11:34:42 +01:00
parent c86340e6b9
commit 9fb18a43d8

View File

@ -0,0 +1,34 @@
// Copyright (C) 2022 Storj Labs, Inc.
// See LICENSE for copying information.
package rangedloop
import (
"context"
"time"
"storj.io/storj/satellite/metabase"
"storj.io/storj/satellite/metabase/segmentloop"
)
// Observer subscribes to the parallel segment loop.
// It is intended that a naïve implementation is threadsafe.
type Observer interface {
Start(context.Context, time.Time, metabase.NodeAliasMap) error
// Fork creates a Partial to process a chunk of all the segments.
Fork(context.Context) (Partial, error)
// Join is called after the chunk for Partial is done.
// This gives the opportunity to merge the output like in a reduce step.
Join(context.Context, Partial) error
// Finish is called after all segments are processed by all observers.
Finish(context.Context) error
}
// Partial processes a part of the total range of segments.
type Partial interface {
// Process is called repeatedly with batches of segments.
// It is not called concurrently on the same instance.
Process(context.Context, []segmentloop.Segment) error
}