Documentation
¶
Overview ¶
Package common defines reusable objects for APIs.
Index ¶
- Constants
- Variables
- func DBLabelNames() []string
- func IsInternalGroup(name string) bool
- func NewRowDropError(reason DropReason, err error) error
- func ParseNodeFlags() map[string]string
- func RecordRowFailure(ctx context.Context, row int, err error)
- func RecordWriteFailure(ctx context.Context, err error)
- func RetryUntil(ctx context.Context, deadline time.Time, again func() (done bool)) bool
- func RetryWrite(ctx context.Context, write func() error) error
- func SegLabelNames() []string
- func SetPosition(ctx context.Context, fn func(p Position) Position) context.Context
- func ShardLabelNames() []string
- func WithWriteRecorder(ctx context.Context, r *WriteRecorder) context.Context
- type DropReason
- type Error
- type ItemID
- type KindVersion
- type Node
- type NodeHostProvider
- type Position
- type RowDropError
- type RowFailure
- type SeriesID
- type ShardID
- type WriteDrops
- type WriteRecorder
Constants ¶
const ( // DeletionTaskGroup holds the property group deletion tasks. DeletionTaskGroup = "_deletion_task" // PropertyGossipGroup holds the stream of the property gossip traces. PropertyGossipGroup = "_property_gossip" )
The groups a server creates for its own bookkeeping. They are not user data: a data export leaves them out, and every target creates its own.
Variables ¶
var ( // FlagNodeHost is the node id from flag. FlagNodeHost string // FlagNodeHostProvider is the node id provider from flag. FlagNodeHostProvider NodeHostProvider // FlagNodeLabels is the node labels from flag. FlagNodeLabels []string )
var ContextNodeKey = contextNodeKey{}
ContextNodeKey is a context key to store the node id.
var ContextNodeRolesKey = contextNodeRolesKey{}
ContextNodeRolesKey is a context key to store the node roles.
var ContextNodeSelectorKey = contextNodeSelectorKey{}
ContextNodeSelectorKey is a context key to store the node selector.
Functions ¶
func DBLabelNames ¶ added in v0.7.0
func DBLabelNames() []string
DBLabelNames returns the label names of Position in the database level.
func IsInternalGroup ¶ added in v0.12.0
IsInternalGroup reports whether name is a group the server creates for its own bookkeeping.
func NewRowDropError ¶ added in v0.12.0
func NewRowDropError(reason DropReason, err error) error
NewRowDropError tags err with reason.
func ParseNodeFlags ¶ added in v0.8.0
ParseNodeFlags parses the node labels from flag.
func RecordRowFailure ¶ added in v0.12.0
RecordRowFailure records that row row of the message failed before it was stored, in the recorder ctx carries; without one it does nothing. The first failure of a row is kept.
func RecordWriteFailure ¶ added in v0.12.0
RecordWriteFailure records a failure after the rows were stored, such as an index write, in the recorder ctx carries; without one it does nothing.
func RetryUntil ¶ added in v0.12.0
RetryUntil runs again after a back-off that doubles from 100ms up to 2s between attempts, until again reports done, deadline passes or ctx ends. It returns whether again reported done. The caller makes the first attempt itself.
func RetryWrite ¶ added in v0.12.0
RetryWrite runs write, which must be safe to repeat, and returns its error. Under a recorder it retries a failed write with back-off until the recorder's deadline or the end of ctx, and returns the last error; without one it runs write once.
func SegLabelNames ¶ added in v0.7.0
func SegLabelNames() []string
SegLabelNames returns the label names of Position in the segment level.
func SetPosition ¶
SetPosition sets a position returned from fn to attach it to ctx, then return a new context.
func ShardLabelNames ¶ added in v0.4.0
func ShardLabelNames() []string
ShardLabelNames returns the label names of Position. It is used for shard level metrics.
func WithWriteRecorder ¶ added in v0.12.0
func WithWriteRecorder(ctx context.Context, r *WriteRecorder) context.Context
WithWriteRecorder returns ctx carrying r, so that the write listener called with it records its failures in r.
Types ¶
type DropReason ¶ added in v0.12.0
type DropReason string
DropReason is why a write listener skipped a row of a message. A skipped row is logged and not reported to the writer (the acknowledgement covers the batch), so the listener counts it under its reason in its <model>_write_dropped_total counter.
const ( // DropReasonDecode is a row whose bytes are not a write request. DropReasonDecode DropReason = "decode" // DropReasonInvalidType is a row, or a whole message, of a type the listener does not take. DropReasonInvalidType DropReason = "invalid_type" // DropReasonInvalidTimestamp is a row whose timestamp is out of the supported range. DropReasonInvalidTimestamp DropReason = "invalid_timestamp" // DropReasonGroupNotFound is a row for a group this node does not hold. DropReasonGroupNotFound DropReason = "group_not_found" // DropReasonSchemaNotFound is a row for a resource this node has no schema for, in a group // it holds. DropReasonSchemaNotFound DropReason = "schema_not_found" // DropReasonInvalidElement is any other row the listener cannot store, such as one that // does not match its schema. DropReasonInvalidElement DropReason = "invalid_element" )
The reasons a write listener skips a row for.
func ReasonOf ¶ added in v0.12.0
func ReasonOf(err error) DropReason
ReasonOf returns the reason err was tagged with by NewRowDropError, anywhere in its chain, and DropReasonInvalidElement for an error that carries none.
type Error ¶ added in v0.2.0
type Error struct {
// contains filtered or unexported fields
}
Error wraps a error msg.
func NewErrorWithStatus ¶ added in v0.8.0
NewErrorWithStatus returns a new Error with status.
type KindVersion ¶
KindVersion contains elements which identify the API uniquely.
func (*KindVersion) String ¶
func (s *KindVersion) String() string
type Node ¶ added in v0.5.0
type Node struct {
Labels map[string]string
NodeID string
GrpcAddress string
HTTPAddress string
PropertyGossipGrpcAddress string
PropertySchemaGrpcAddress string
PropertySchemaGossipGrpcAddress string
}
Node contains the node id and address.
func GenerateNode ¶ added in v0.5.0
func GenerateNode(grpcPort, httpPort, propertyGrpcPort, propertySchemaGrpcPort, propertySchemaGossipPort *uint32) (node Node, err error)
GenerateNode generates a node id.
func (Node) ToProtoNode ¶ added in v0.10.0
func (n Node) ToProtoNode(roles []databasev1.Role) *databasev1.Node
ToProtoNode converts a Node to a databasev1.Node with the given roles. The version and time zone describe the running process, so consumers of the node registry can tell which file formats the node reads and which segment boundaries its timestamps fall on.
type NodeHostProvider ¶ added in v0.5.0
type NodeHostProvider int
NodeHostProvider is the provider of node id.
const ( NodeHostProviderHostname NodeHostProvider = iota NodeHostProviderIP NodeHostProviderFlag )
NodeIDProvider constants.
func ParseNodeHostProvider ¶ added in v0.5.0
func ParseNodeHostProvider(s string) (NodeHostProvider, error)
ParseNodeHostProvider parses the string to NodeIDProvider.
func (*NodeHostProvider) String ¶ added in v0.5.0
func (n *NodeHostProvider) String() string
String returns the string representation of NodeIDProvider.
type Position ¶
Position is stored in the context. The logger could attach it for debugging.
func GetPosition ¶ added in v0.4.0
GetPosition returns the position from ctx.
func (Position) DBLabelValues ¶ added in v0.7.0
DBLabelValues returns the label values of Position in the database level.
func (Position) SegLabelValues ¶ added in v0.7.0
SegLabelValues returns the label values of Position.
func (Position) ShardLabelValues ¶ added in v0.4.0
ShardLabelValues returns the label values of Position. It is used for shard level metrics.
type RowDropError ¶ added in v0.12.0
type RowDropError struct {
Err error
Reason DropReason
}
RowDropError is the error a write listener skips a row for, tagged with the reason the row is counted under. Its message is the one of the error it wraps.
func (*RowDropError) Error ¶ added in v0.12.0
func (e *RowDropError) Error() string
func (*RowDropError) Unwrap ¶ added in v0.12.0
func (e *RowDropError) Unwrap() error
type RowFailure ¶ added in v0.12.0
RowFailure is a row of a message that failed before it was stored.
type SeriesID ¶
type SeriesID uint64
SeriesID identities a series in a shard.
func (SeriesID) AppendToBytes ¶ added in v0.6.0
AppendToBytes appends series id to bytes.
type WriteDrops ¶ added in v0.12.0
type WriteDrops struct {
// contains filtered or unexported fields
}
WriteDrops is where a write listener reports the rows it skips. A nil *WriteDrops, a listener built without metrics, still records the rows for a caller that asked for them.
func NewWriteDrops ¶ added in v0.12.0
func NewWriteDrops[G any](counter meter.Counter, groups interface{ LoadGroup(name string) (G, bool) }) *WriteDrops
NewWriteDrops returns the WriteDrops that counts in counter, labeling a row with its group only when groups holds it, so the label is bounded by the groups the node holds whatever a row names. A nil counter returns nil.
func (*WriteDrops) SkipMessage ¶ added in v0.12.0
func (d *WriteDrops) SkipMessage(ctx context.Context, reason DropReason)
SkipMessage reports that a whole message, which is not a batch of rows, was skipped for reason. It is counted once, under no group, unless the write's caller records failures.
func (*WriteDrops) SkipRow ¶ added in v0.12.0
func (d *WriteDrops) SkipRow(ctx context.Context, row int, group string, reason DropReason, err error)
SkipRow reports that row row of the message, of group, was skipped for reason with err.
A write whose ctx carries a WriteRecorder gets err recorded: its caller is told which rows failed and may write them again, so the row is neither lost silently nor counted once per attempt. Any other write counts the row. Each row is thus counted at most once, by the node whose listener skipped it.
type WriteRecorder ¶ added in v0.12.0
type WriteRecorder struct {
// contains filtered or unexported fields
}
WriteRecorder collects the failures a write listener meets while it writes one message. A write listener logs such a failure and goes on with the rest of the message; a caller that needs to know about them puts a recorder in the context it calls the listener with. A row that failed before it was stored is recorded by its index in the message, so the caller can write it again; a failure after the rows were stored is recorded on its own. Until its deadline, the recorder also lets RetryWrite retry a write that may be repeated.
func NewWriteRecorder ¶ added in v0.12.0
func NewWriteRecorder(deadline time.Time) *WriteRecorder
NewWriteRecorder returns a recorder whose RetryWrite retries until deadline; a zero deadline never retries.
func (*WriteRecorder) Failures ¶ added in v0.12.0
func (r *WriteRecorder) Failures() []error
Failures returns the failures after the rows were stored, in the order they were recorded.
func (*WriteRecorder) RowFailures ¶ added in v0.12.0
func (r *WriteRecorder) RowFailures() []RowFailure
RowFailures returns the rows that failed before they were stored, by row.