consistency

package
v1.48.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 9, 2025 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package consistency defines middleware to set, based on the request's consistency level, the right datastore revision to use.

Index

Constants

This section is empty.

Variables

View Source
var ConsistencyCounter = promauto.NewCounterVec(prometheus.CounterOpts{
	Namespace: "spicedb",
	Subsystem: "middleware",
	Name:      "consistency_assigned_total",
	Help:      "Count of the consistencies used per request",
}, []string{"method", "source", "service"})

Functions

func AddRevisionToContext added in v1.39.0

func AddRevisionToContext(ctx context.Context, req any, ds datastore.Datastore, serviceLabel string, option MismatchingTokenOption) error

AddRevisionToContext adds a revision to the given context, based on the consistency block found in the given request (if applicable).

func ContextWithHandle added in v1.39.0

func ContextWithHandle(ctx context.Context) context.Context

ContextWithHandle adds a placeholder to a context that will later be filled by the revision

func ForceFullConsistencyStreamServerInterceptor added in v1.39.0

func ForceFullConsistencyStreamServerInterceptor(serviceLabel string) grpc.StreamServerInterceptor

ForceFullConsistencyStreamServerInterceptor returns a new stream server interceptor that enforces full consistency for all requests, except for those in the bypassServiceWhitelist.

func ForceFullConsistencyUnaryServerInterceptor added in v1.39.0

func ForceFullConsistencyUnaryServerInterceptor(serviceLabel string) grpc.UnaryServerInterceptor

ForceFullConsistencyUnaryServerInterceptor returns a new unary server interceptor that enforces full consistency for all requests, except for those in the bypassServiceWhitelist.

func RevisionFromContext

func RevisionFromContext(ctx context.Context) (datastore.Revision, *v1.ZedToken, error)

RevisionFromContext reads the selected revision out of a context.Context, computes a zedtoken from it, and returns an error if it has not been set on the context.

func StreamServerInterceptor added in v1.39.0

func StreamServerInterceptor(serviceLabel string, option MismatchingTokenOption) grpc.StreamServerInterceptor

StreamServerInterceptor returns a new stream server interceptor that performs per-request exchange of the specified consistency configuration for the revision at which to perform the request.

func UnaryServerInterceptor added in v1.39.0

func UnaryServerInterceptor(serviceLabel string, option MismatchingTokenOption) grpc.UnaryServerInterceptor

UnaryServerInterceptor returns a new unary server interceptor that performs per-request exchange of the specified consistency configuration for the revision at which to perform the request.

Types

type MismatchingTokenOption added in v1.46.0

type MismatchingTokenOption int

MismatchingTokenOption is the option specifying the behavior of the consistency middleware when a ZedToken provided references a different datastore instance than the current datastore instance.

const (
	// TreatMismatchingTokensAsFullConsistency specifies that the middleware should treat
	// a ZedToken that references a different datastore instance as a request for full
	// consistency.
	TreatMismatchingTokensAsFullConsistency MismatchingTokenOption = iota

	// TreatMismatchingTokensAsMinLatency specifies that the middleware should treat
	// a ZedToken that references a different datastore instance as a request for min
	// latency.
	TreatMismatchingTokensAsMinLatency

	// TreatMismatchingTokensAsError specifies that the middleware should raise an error
	// when a ZedToken that references a different datastore instance is provided.
	TreatMismatchingTokensAsError
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL