partition

package
v0.11.2 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: Apache-2.0 Imports: 8 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package partition implements a location system to find a shard or index rule. This system reflects the entity identity which is a intermediate result in calculating the target shard.

Index

Constants

This section is empty.

Variables

View Source
var ErrMalformedElement = errors.New("element is malformed")

ErrMalformedElement indicates the element is malformed.

Functions

func ApplyLocators added in v0.11.0

func ApplyLocators(subject string, tagFamilies []*modelv1.TagFamilyForWrite,
	entityRouter, shardingKeyRouter Router, shardNum uint32,
) (pbv1.EntityValues, common.ShardID, error)

ApplyLocators routes a write by entity tags then, when a non-nil shardingKey Router is supplied, overrides the shard id with the sharding-key derived one. EntityValues always come from the entity router.

func GetTagByOffset

func GetTagByOffset(value []*modelv1.TagFamilyForWrite, fIndex, tIndex int) (*modelv1.TagValue, error)

GetTagByOffset gets a tag value based of a tag family offset and a tag offset in this family.

func ParseIndexRuleLocators

func ParseIndexRuleLocators(entity *databasev1.Entity, families []*databasev1.TagFamilySpec,
	indexRules []*databasev1.IndexRule, indexMode bool,
) (locators IndexRuleLocator, fil FieldIndexLocation)

ParseIndexRuleLocators returns a IndexRuleLocator based on the tag family spec and index rules.

func ShardID

func ShardID(key []byte, shardNum uint32) (uint, error)

ShardID calculates a shard id.

func TraceShardID added in v0.11.0

func TraceShardID(traceID string, shardNum uint32) common.ShardID

TraceShardID returns the shard id derived from a trace id hash. A zero shardNum returns shard 0 to avoid a divide-by-zero panic.

Types

type FieldIndexLocation added in v0.7.0

type FieldIndexLocation map[string]map[string]FieldWithType

FieldIndexLocation is a helper struct to store the field index location.

type FieldWithType added in v0.7.0

type FieldWithType struct {
	Key  index.FieldKey
	Type pbv1.ValueType
}

FieldWithType is a helper struct to store the field type.

type IndexRuleLocator

type IndexRuleLocator struct {
	EntitySet      map[string]int
	TagFamilyTRule []map[string]*databasev1.IndexRule
}

IndexRuleLocator is a helper struct to locate the index rule by tag name.

type Locator added in v0.9.0

type Locator struct {
	TagLocators []TagLocator
	ModRevision int64
}

Locator combines several TagLocators that help find the entity or sharding key value.

func NewEntityLocator

func NewEntityLocator(families []*databasev1.TagFamilySpec, entity *databasev1.Entity, modRevision int64) Locator

NewEntityLocator return a Locator based on tag family spec and entity spec.

func NewShardingKeyLocator added in v0.9.0

func NewShardingKeyLocator(families []*databasev1.TagFamilySpec, shardingKey *databasev1.ShardingKey) Locator

NewShardingKeyLocator returns a Locator based on tag family spec and sharding key spec.

func (Locator) Find added in v0.9.0

func (l Locator) Find(subject string, value []*modelv1.TagFamilyForWrite) (pbv1.Entity, pbv1.EntityValues, error)

Find the entity from a tag family, prepend a subject to the entity.

func (Locator) Locate added in v0.9.0

func (l Locator) Locate(subject string, value []*modelv1.TagFamilyForWrite, shardNum uint32) (pbv1.EntityValues, common.ShardID, error)

Locate a shard and find the entity or sharding key from a tag family, prepend a subject to the entity or sharding key.

type Router added in v0.11.0

type Router interface {
	Locate(subject string, tagFamilies []*modelv1.TagFamilyForWrite, shardNum uint32) (pbv1.EntityValues, common.ShardID, error)
}

Router is anything that can map a write to its target (entityValues, shardID).

type TagLocator

type TagLocator struct {
	FamilyOffset int
	TagOffset    int
}

TagLocator contains offsets to retrieve a tag swiftly.

Jump to

Keyboard shortcuts

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