common

package
v0.11.13 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2025 License: Apache-2.0 Imports: 41 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MetadataTerm      = "term"
	MetadataNamespace = "namespace"
	MetadataShardId   = "shard-id"
	DefaultNamespace  = "default"

	DefaultPublicPort   = 6648
	DefaultInternalPort = 6649
	DefaultMetricsPort  = 8080

	MaxSessionTimeout = 5 * time.Minute
	MinSessionTimeout = 2 * time.Second
)
View Source
const (
	CodeNotInitialized          codes.Code = 100
	CodeInvalidTerm             codes.Code = 101
	CodeInvalidStatus           codes.Code = 102
	CodeCancelled               codes.Code = 103
	CodeAlreadyClosed           codes.Code = 104
	CodeLeaderAlreadyConnected  codes.Code = 105
	CodeNodeIsNotLeader         codes.Code = 106
	CodeNodeIsNotFollower       codes.Code = 107
	CodeSessionNotFound         codes.Code = 108
	CodeInvalidSessionTimeout   codes.Code = 109
	CodeNamespaceNotFound       codes.Code = 110
	CodeNotificationsNotEnabled codes.Code = 111
)
View Source
const AddressSchemaTLS = "tls://"
View Source
const DefaultLogLevel = slog.LevelInfo
View Source
const DefaultRpcTimeout = 30 * time.Second
View Source
const InternalKeyPrefix = "__oxia/"

InternalKeyPrefix is the prefix of keys used by oxia.

Variables

View Source
var (
	ErrorNotInitialized          = status.Error(CodeNotInitialized, "oxia: server not initialized yet")
	ErrorCancelled               = status.Error(CodeCancelled, "oxia: operation was cancelled")
	ErrorInvalidTerm             = status.Error(CodeInvalidTerm, "oxia: invalid term")
	ErrorInvalidStatus           = status.Error(CodeInvalidStatus, "oxia: invalid status")
	ErrorLeaderAlreadyConnected  = status.Error(CodeLeaderAlreadyConnected, "oxia: leader is already connected")
	ErrorAlreadyClosed           = status.Error(CodeAlreadyClosed, "oxia: resource is already closed")
	ErrorNodeIsNotLeader         = status.Error(CodeNodeIsNotLeader, "oxia: node is not leader for shard")
	ErrorNodeIsNotFollower       = status.Error(CodeNodeIsNotFollower, "oxia: node is not follower for shard")
	ErrorSessionNotFound         = status.Error(CodeSessionNotFound, "oxia: session not found")
	ErrorInvalidSessionTimeout   = status.Error(CodeInvalidSessionTimeout, "oxia: invalid session timeout")
	ErrorNamespaceNotFound       = status.Error(CodeNamespaceNotFound, "oxia: namespace not found")
	ErrorNotificationsNotEnabled = status.Error(CodeNotificationsNotEnabled, "oxia: notifications not enabled on namespace")
)
View Source
var (
	// LogLevel Used for flags.
	LogLevel slog.Level
	// LogJSON Used for flags.
	LogJSON bool
)
View Source
var (
	PprofEnable      bool
	PprofBindAddress string
)
View Source
var SystemClock = &systemClock{}

Functions

func ConfigureLogger

func ConfigureLogger()

func DoWithLabels

func DoWithLabels(ctx context.Context, labels map[string]string, f func())

DoWithLabels attaches the labels to the current go-routine Pprof context, for the duration of the call to f.

func GetPeer

func GetPeer(ctx context.Context) string

func Memoize

func Memoize[T any](provider func() T, cacheTime time.Duration) func() T

Memoize is used to cache the result of the invocation of a function for a certain amount of time.

func NewBackOff

func NewBackOff(ctx context.Context) backoff.BackOff

func NewBackOffWithInitialInterval

func NewBackOffWithInitialInterval(ctx context.Context, initialInterval time.Duration) backoff.BackOff

func OptBooleanViperHook added in v0.11.2

func OptBooleanViperHook() mapstructure.DecodeHookFuncType

func ParseLogLevel

func ParseLogLevel(levelStr string) (slog.Level, error)

ParseLogLevel will convert the slog level configuration to slog.Level values.

func RunProcess

func RunProcess(startProcess func() (io.Closer, error))

func RunProfiling

func RunProfiling() io.Closer

func WaitUntilSignal

func WaitUntilSignal(closers ...io.Closer)

func Xxh332

func Xxh332(key string) uint32

Types

type ClientPool

type ClientPool interface {
	io.Closer
	GetClientRpc(target string) (proto.OxiaClientClient, error)
	GetHealthRpc(target string) (grpc_health_v1.HealthClient, io.Closer, error)
	GetCoordinationRpc(target string) (proto.OxiaCoordinationClient, error)
	GetReplicationRpc(target string) (proto.OxiaLogReplicationClient, error)

	// Clear all the pooled client instances for the given target
	Clear(target string)
}

func NewClientPool

func NewClientPool(tlsConf *tls.Config, authentication auth.Authentication) ClientPool

type Clock

type Clock interface {
	Now() time.Time
}

type ConditionContext

type ConditionContext interface {
	// Wait atomically unlocks the locker and suspends execution
	// of the calling goroutine. After later resuming execution,
	// Wait locks c.L before returning. Unlike in other systems,
	// Wait cannot return unless awoken by Broadcast or Signal.
	//
	// Because c.L is not locked when Wait first resumes, the caller
	// typically cannot assume that the condition is true when
	// Wait returns. Instead, the caller should Wait in a loop:
	//
	//	lock.Lock()
	//	for !condition() {
	//	    c.Wait(ctx)
	//	}
	//	... make use of condition ...
	//	lock.Unlock()
	Wait(ctx context.Context) error

	// Signal wakes one goroutine waiting on c, if there is any.
	//
	// It is allowed but not required for the caller to hold c.L
	// during the call.
	//
	// Signal() does not affect goroutine scheduling priority; if other goroutines
	// are attempting to lock c.L, they may be awoken before a "waiting" goroutine.
	Signal()

	// Broadcast wakes all goroutines waiting on c.
	//
	// It is allowed but not required for the caller to hold c.L
	// during the call.
	Broadcast()
}

ConditionContext implements a condition variable, a rendezvous point for goroutines waiting for or announcing the occurrence of an event.

This version of condition takes a `context.Context` in the `Wait()` method, to allow for timeouts and cancellations of the operation.

func NewConditionContext

func NewConditionContext(locker sync.Locker) ConditionContext

type Future added in v0.7.0

type Future[T any] interface {

	// Wait until the future is either completed or failed
	// You should only call wait once
	Wait(ctx context.Context) (T, error)

	//
	Complete(result T)

	// Fail Signal that one party has failed in the operation
	Fail(err error)
}

func NewFuture added in v0.7.0

func NewFuture[T any]() Future[T]

type MockedClock

type MockedClock struct {
	// contains filtered or unexported fields
}

func (*MockedClock) Now

func (c *MockedClock) Now() time.Time

func (*MockedClock) Set

func (c *MockedClock) Set(currentTime int64)

type OptBooleanDefaultTrue added in v0.10.0

type OptBooleanDefaultTrue struct {
	// contains filtered or unexported fields
}

func Bool added in v0.10.0

func Bool(val bool) OptBooleanDefaultTrue

func (*OptBooleanDefaultTrue) Get added in v0.10.0

func (o *OptBooleanDefaultTrue) Get() bool

func (*OptBooleanDefaultTrue) MarshalJSON added in v0.10.0

func (o *OptBooleanDefaultTrue) MarshalJSON() ([]byte, error)

func (OptBooleanDefaultTrue) MarshalYAML added in v0.11.2

func (o OptBooleanDefaultTrue) MarshalYAML() (any, error)

func (*OptBooleanDefaultTrue) UnmarshalJSON added in v0.10.0

func (o *OptBooleanDefaultTrue) UnmarshalJSON(data []byte) error

type RefCount

type RefCount[T io.Closer] interface {
	io.Closer

	Acquire() RefCount[T]

	RefCnt() int32

	Get() T
}

func NewRefCount

func NewRefCount[T io.Closer](t T) RefCount[T]

type Set

type Set[T constraints.Ordered] interface {
	Add(t T)
	Remove(t T)
	Contains(t T) bool
	Count() int
	IsEmpty() bool
	GetSorted() []T
	Complement(other Set[T]) Set[T]
}

func NewSet

func NewSet[T constraints.Ordered]() Set[T]

func NewSetFrom

func NewSetFrom[T constraints.Ordered](i []T) Set[T]

type Shard

type Shard struct {
	Id  int64
	Min uint32
	Max uint32
}

func GenerateShards

func GenerateShards(baseId int64, numShards uint32) []Shard

type WaitGroup

type WaitGroup interface {

	// Wait until all the parties in the group are either done or if there is any failure
	// You should only call wait once
	Wait(ctx context.Context) error

	// Done Signals that one party in the group is done
	Done()

	// Fail Signal that one party has failed in the operation
	Fail(err error)
}

WaitGroup is similar to sync.WaitGroup but adds 2 capabilities:

  1. Returning an error if any operation fails
  2. Accept a context to cancel the Wait

func NewWaitGroup

func NewWaitGroup(parties int) WaitGroup

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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