milvus/pkg/streaming/walimpls/interceptor.go
chyezh d2bc4a53be
enhance: implement rmq and pulsar as wal (#34046)
issue: #33285

- use reader but not consumer for pulsar
- advanced test framework
- move some streaming related package into pkg

---------

Signed-off-by: chyezh <chyezh@outlook.com>
2024-06-27 15:11:05 +08:00

65 lines
2.2 KiB
Go

package walimpls
import (
"context"
"github.com/milvus-io/milvus/pkg/streaming/util/message"
)
type (
// Append is the common function to append a msg to the wal.
Append = func(ctx context.Context, msg message.MutableMessage) (message.MessageID, error)
// Read is the common function to read a msg from the wal.
Read = func(ctx context.Context, opt ReadOption) (ScannerImpls, error)
)
// InterceptorBuilder is the interface to build a interceptor.
// 1. InterceptorBuilder is concurrent safe.
// 2. InterceptorBuilder can used to build a interceptor with cross-wal shared resources.
type InterceptorBuilder interface {
// Build build a interceptor with wal that interceptor will work on.
// the wal object will be sent to the interceptor builder when the wal is constructed with all interceptors.
Build(wal <-chan WALImpls) BasicInterceptor
}
type BasicInterceptor interface {
// Close the interceptor release the resources.
Close()
}
type Interceptor interface {
AppendInterceptor
BasicInterceptor
}
// AppendInterceptor is the interceptor for Append functions.
// All wal extra operations should be done by these function, such as
// 1. time tick setup.
// 2. unique primary key filter and build.
// 3. index builder.
// 4. cache sync up.
// AppendInterceptor should be lazy initialized and fast execution.
type AppendInterceptor interface {
// Execute the append operation with interceptor.
DoAppend(ctx context.Context, msg message.MutableMessage, append Append) (message.MessageID, error)
}
type InterceptorReady interface {
// Ready check if interceptor is ready.
// Close of Interceptor would not notify the ready (closed interceptor is not ready).
// So always apply timeout when waiting for ready.
// Some append interceptor may be stateful, such as index builder and unique primary key filter,
// so it need to implement the recovery logic from crash by itself before notifying ready.
// Append operation will block until ready or canceled.
// Consumer do not blocked by it.
Ready() <-chan struct{}
}
// Some interceptor may need to wait for some resource to be ready or recovery process.
type InterceptorWithReady interface {
Interceptor
InterceptorReady
}