Documentation ¶
Overview ¶
Package netmap provides routines for working with netmap and placement policy. Work is done in 4 steps: 1. Create context containing results shared between steps. 2. Processing filters. 3. Processing selectors. 4. Processing replicas.
Each step depends only on previous ones.
Index ¶
- Constants
- Variables
- func GetBucketWeight(ns Nodes, a aggregator, wf weightFunc) float64
- func GetDefaultWeightFunc(ns Nodes) weightFunc
- func GetNodesCount(_ *PlacementPolicy, s *Selector) (int, int)
- type Clause
- type ContainerNodes
- type Context
- type Filter
- func (f *Filter) InnerFilters() []*Filter
- func (f *Filter) Key() string
- func (f *Filter) Marshal(b ...[]byte) ([]byte, error)
- func (f *Filter) MarshalJSON() ([]byte, error)
- func (f *Filter) Name() string
- func (f *Filter) Operation() Operation
- func (f *Filter) SetInnerFilters(fs ...*Filter)
- func (f *Filter) SetKey(key string)
- func (f *Filter) SetName(name string)
- func (f *Filter) SetOperation(op Operation)
- func (f *Filter) SetValue(val string)
- func (f *Filter) ToV2() *netmap.Filter
- func (f *Filter) Unmarshal(data []byte) error
- func (f *Filter) UnmarshalJSON(data []byte) error
- func (f *Filter) Value() string
- type Netmap
- type NetworkInfo
- func (i *NetworkInfo) CurrentEpoch() uint64
- func (i *NetworkInfo) MagicNumber() uint64
- func (i *NetworkInfo) Marshal(b ...[]byte) ([]byte, error)
- func (i *NetworkInfo) MarshalJSON() ([]byte, error)
- func (i *NetworkInfo) SetCurrentEpoch(epoch uint64)
- func (i *NetworkInfo) SetMagicNumber(epoch uint64)
- func (i *NetworkInfo) ToV2() *netmap.NetworkInfo
- func (i *NetworkInfo) Unmarshal(data []byte) error
- func (i *NetworkInfo) UnmarshalJSON(data []byte) error
- type Node
- type NodeAttribute
- func (a *NodeAttribute) Key() string
- func (a *NodeAttribute) Marshal(b ...[]byte) ([]byte, error)
- func (a *NodeAttribute) MarshalJSON() ([]byte, error)
- func (a *NodeAttribute) ParentKeys() []string
- func (a *NodeAttribute) SetKey(key string)
- func (a *NodeAttribute) SetParentKeys(keys ...string)
- func (a *NodeAttribute) SetValue(val string)
- func (a *NodeAttribute) ToV2() *netmap.Attribute
- func (a *NodeAttribute) Unmarshal(data []byte) error
- func (a *NodeAttribute) UnmarshalJSON(data []byte) error
- func (a *NodeAttribute) Value() string
- type NodeInfo
- func (i *NodeInfo) Address() string
- func (i *NodeInfo) Attributes() []*NodeAttribute
- func (i *NodeInfo) Marshal(b ...[]byte) ([]byte, error)
- func (i *NodeInfo) MarshalJSON() ([]byte, error)
- func (i *NodeInfo) PublicKey() []byte
- func (i *NodeInfo) SetAddress(addr string)
- func (i *NodeInfo) SetAttributes(as ...*NodeAttribute)
- func (i *NodeInfo) SetPublicKey(key []byte)
- func (i *NodeInfo) SetState(s NodeState)
- func (i *NodeInfo) State() NodeState
- func (i *NodeInfo) ToV2() *netmap.NodeInfo
- func (i *NodeInfo) Unmarshal(data []byte) error
- func (i *NodeInfo) UnmarshalJSON(data []byte) error
- type NodeState
- type Nodes
- type Operation
- type PlacementPolicy
- func (p *PlacementPolicy) ContainerBackupFactor() uint32
- func (p *PlacementPolicy) Filters() []*Filter
- func (p *PlacementPolicy) Marshal(b ...[]byte) ([]byte, error)
- func (p *PlacementPolicy) MarshalJSON() ([]byte, error)
- func (p *PlacementPolicy) Replicas() []*Replica
- func (p *PlacementPolicy) Selectors() []*Selector
- func (p *PlacementPolicy) SetContainerBackupFactor(f uint32)
- func (p *PlacementPolicy) SetFilters(fs ...*Filter)
- func (p *PlacementPolicy) SetReplicas(rs ...*Replica)
- func (p *PlacementPolicy) SetSelectors(ss ...*Selector)
- func (p *PlacementPolicy) ToV2() *netmap.PlacementPolicy
- func (p *PlacementPolicy) Unmarshal(data []byte) error
- func (p *PlacementPolicy) UnmarshalJSON(data []byte) error
- type Replica
- func (r *Replica) Count() uint32
- func (r *Replica) Marshal(b ...[]byte) ([]byte, error)
- func (r *Replica) MarshalJSON() ([]byte, error)
- func (r *Replica) Selector() string
- func (r *Replica) SetCount(c uint32)
- func (r *Replica) SetSelector(s string)
- func (r *Replica) ToV2() *netmap.Replica
- func (r *Replica) Unmarshal(data []byte) error
- func (r *Replica) UnmarshalJSON(data []byte) error
- type Selector
- func (s *Selector) Attribute() string
- func (s *Selector) Clause() Clause
- func (s *Selector) Count() uint32
- func (s *Selector) Filter() string
- func (s *Selector) Marshal(b ...[]byte) ([]byte, error)
- func (s *Selector) MarshalJSON() ([]byte, error)
- func (s *Selector) Name() string
- func (s *Selector) SetAttribute(a string)
- func (s *Selector) SetClause(c Clause)
- func (s *Selector) SetCount(c uint32)
- func (s *Selector) SetFilter(f string)
- func (s *Selector) SetName(name string)
- func (s *Selector) ToV2() *netmap.Selector
- func (s *Selector) Unmarshal(data []byte) error
- func (s *Selector) UnmarshalJSON(data []byte) error
Constants ¶
const ( // AttrPrice is a key to the node attribute that indicates the // price in GAS tokens for storing one GB of data during one Epoch. AttrPrice = "Price" // AttrCapacity is a key to the node attribute that indicates the // total available disk space in Gigabytes. AttrCapacity = "Capacity" // AttrSubnet is a key to the node attribute that indicates the // string ID of node's storage subnet. AttrSubnet = "Subnet" // AttrUNLOCODE is a key to the node attribute that indicates the // node's geographic location in UN/LOCODE format. AttrUNLOCODE = "UN-LOCODE" // AttrCountryCode is a key to the node attribute that indicates the // Country code in ISO 3166-1_alpha-2 format. AttrCountryCode = "CountryCode" // AttrCountry is a key to the node attribute that indicates the // country short name in English, as defined in ISO-3166. AttrCountry = "Country" // AttrLocation is a key to the node attribute that indicates the // place name of the node location. AttrLocation = "Location" // AttrSubDivCode is a key to the node attribute that indicates the // country's administrative subdivision where node is located // in ISO 3166-2 format. AttrSubDivCode = "SubDivCode" // AttrSubDiv is a key to the node attribute that indicates the // country's administrative subdivision name, as defined in // ISO 3166-2. AttrSubDiv = "SubDiv" // AttrContinent is a key to the node attribute that indicates the // node's continent name according to the Seven-Continent model. AttrContinent = "Continent" )
Enumeration of well-known attributes.
const MainFilterName = "*"
MainFilterName is a name of the filter which points to the whole netmap.
Variables ¶
var ( ErrMissingField = errors.New("netmap: nil field") ErrInvalidFilterName = errors.New("netmap: filter name is invalid") ErrInvalidNumber = errors.New("netmap: number value expected") ErrInvalidFilterOp = errors.New("netmap: invalid filter operation") ErrFilterNotFound = errors.New("netmap: filter not found") ErrNonEmptyFilters = errors.New("netmap: simple filter must no contain sub-filters") ErrNotEnoughNodes = errors.New("netmap: not enough nodes to SELECT from") ErrSelectorNotFound = errors.New("netmap: selector not found") ErrUnnamedTopFilter = errors.New("netmap: all filters on top level must be named") )
Various validation errors.
Functions ¶
func GetBucketWeight ¶
GetBucketWeight computes weight for a Bucket.
func GetDefaultWeightFunc ¶
func GetDefaultWeightFunc(ns Nodes) weightFunc
GetDefaultWeightFunc returns default weighting function.
func GetNodesCount ¶
func GetNodesCount(_ *PlacementPolicy, s *Selector) (int, int)
GetNodesCount returns amount of buckets and minimum number of nodes in every bucket for the given selector.
Types ¶
type Clause ¶
type Clause uint32
Clause is an enumeration of selector modifiers that shows how the node set will be formed.
func ClauseFromV2 ¶
ClauseFromV2 converts v2 Clause to Clause.
type ContainerNodes ¶
ContainerNodes represents nodes in the container.
type Context ¶
type Context struct { // Netmap is a netmap structure to operate on. Netmap *Netmap // Filters stores processed filters. Filters map[string]*Filter // Selectors stores processed selectors. Selectors map[string]*Selector // Selections stores result of selector processing. Selections map[string][]Nodes // contains filtered or unexported fields }
Context contains references to named filters and cached numeric values.
func NewContext ¶
NewContext creates new context. It contains various caches. In future it may create hierarchical netmap structure to work with.
type Filter ¶
Filter represents v2-compatible netmap filter.
func NewFilterFromV2 ¶
NewFilterFromV2 converts v2 Filter to Filter.
func (*Filter) InnerFilters ¶
InnerFilters returns list of inner filters.
func (*Filter) Marshal ¶
Marshal marshals Filter into a protobuf binary form.
Buffer is allocated when the argument is empty. Otherwise, the first buffer is used.
func (*Filter) MarshalJSON ¶
MarshalJSON encodes Filter to protobuf JSON format.
func (*Filter) SetInnerFilters ¶
SetInnerFilters sets list of inner filters.
func (*Filter) SetOperation ¶
SetOperation sets filtering operation.
func (*Filter) UnmarshalJSON ¶
UnmarshalJSON decodes Filter from protobuf JSON format.
type Netmap ¶
type Netmap struct {
Nodes Nodes
}
Netmap represents netmap which contains preprocessed nodes.
func (*Netmap) GetContainerNodes ¶
func (m *Netmap) GetContainerNodes(p *PlacementPolicy, pivot []byte) (ContainerNodes, error)
GetContainerNodes returns nodes corresponding to each replica. Order of returned nodes corresponds to order of replicas in p. pivot is a seed for HRW sorting.
func (*Netmap) GetPlacementVectors ¶
func (m *Netmap) GetPlacementVectors(cnt ContainerNodes, pivot []byte) ([]Nodes, error)
GetPlacementVectors returns placement vectors for an object given containerNodes cnt.
type NetworkInfo ¶ added in v1.24.0
type NetworkInfo netmap.NetworkInfo
NetworkInfo represents v2-compatible structure with information about NeoFS network.
func NewNetworkInfo ¶ added in v1.24.0
func NewNetworkInfo() *NetworkInfo
NewNetworkInfo creates and initializes blank NetworkInfo.
func NewNetworkInfoFromV2 ¶ added in v1.24.0
func NewNetworkInfoFromV2(iV2 *netmap.NetworkInfo) *NetworkInfo
NewNetworkInfoFromV2 wraps v2 NetworkInfo message to NetworkInfo.
func (*NetworkInfo) CurrentEpoch ¶ added in v1.24.0
func (i *NetworkInfo) CurrentEpoch() uint64
CurrentEpoch returns current epoch of the NeoFS network.
func (*NetworkInfo) MagicNumber ¶ added in v1.24.0
func (i *NetworkInfo) MagicNumber() uint64
MagicNumber returns magic number of the sidechain.
func (*NetworkInfo) Marshal ¶ added in v1.24.0
func (i *NetworkInfo) Marshal(b ...[]byte) ([]byte, error)
Marshal marshals NetworkInfo into a protobuf binary form.
Buffer is allocated when the argument is empty. Otherwise, the first buffer is used.
func (*NetworkInfo) MarshalJSON ¶ added in v1.24.0
func (i *NetworkInfo) MarshalJSON() ([]byte, error)
MarshalJSON encodes NetworkInfo to protobuf JSON format.
func (*NetworkInfo) SetCurrentEpoch ¶ added in v1.24.0
func (i *NetworkInfo) SetCurrentEpoch(epoch uint64)
SetCurrentEpoch sets current epoch of the NeoFS network.
func (*NetworkInfo) SetMagicNumber ¶ added in v1.24.0
func (i *NetworkInfo) SetMagicNumber(epoch uint64)
SetMagicNumber sets magic number of the sidechain.
func (*NetworkInfo) ToV2 ¶ added in v1.24.0
func (i *NetworkInfo) ToV2() *netmap.NetworkInfo
ToV2 converts NetworkInfo to v2 NetworkInfo.
func (*NetworkInfo) Unmarshal ¶ added in v1.24.0
func (i *NetworkInfo) Unmarshal(data []byte) error
Unmarshal unmarshals protobuf binary representation of NetworkInfo.
func (*NetworkInfo) UnmarshalJSON ¶ added in v1.24.0
func (i *NetworkInfo) UnmarshalJSON(data []byte) error
UnmarshalJSON decodes NetworkInfo from protobuf JSON format.
type Node ¶
type Node struct { ID uint64 Index int Capacity uint64 Price uint64 AttrMap map[string]string *NodeInfo }
Node is a wrapper over NodeInfo.
type NodeAttribute ¶
NodeAttribute represents v2 compatible attribute of the NeoFS Storage Node.
func NewNodeAttribute ¶
func NewNodeAttribute() *NodeAttribute
NewNodeAttribute creates and returns new NodeAttribute instance.
func NewNodeAttributeFromV2 ¶
func NewNodeAttributeFromV2(a *netmap.Attribute) *NodeAttribute
NodeAttributeFromV2 converts v2 node Attribute to NodeAttribute.
func (*NodeAttribute) Key ¶
func (a *NodeAttribute) Key() string
Key returns key to the node attribute.
func (*NodeAttribute) Marshal ¶
func (a *NodeAttribute) Marshal(b ...[]byte) ([]byte, error)
Marshal marshals NodeAttribute into a protobuf binary form.
Buffer is allocated when the argument is empty. Otherwise, the first buffer is used.
func (*NodeAttribute) MarshalJSON ¶
func (a *NodeAttribute) MarshalJSON() ([]byte, error)
MarshalJSON encodes NodeAttribute to protobuf JSON format.
func (*NodeAttribute) ParentKeys ¶
func (a *NodeAttribute) ParentKeys() []string
ParentKeys returns list of parent keys.
func (*NodeAttribute) SetKey ¶
func (a *NodeAttribute) SetKey(key string)
SetKey sets key to the node attribute.
func (*NodeAttribute) SetParentKeys ¶
func (a *NodeAttribute) SetParentKeys(keys ...string)
SetParentKeys sets list of parent keys.
func (*NodeAttribute) SetValue ¶
func (a *NodeAttribute) SetValue(val string)
SetValue sets value of the node attribute.
func (*NodeAttribute) ToV2 ¶
func (a *NodeAttribute) ToV2() *netmap.Attribute
ToV2 converts NodeAttribute to v2 node Attribute.
func (*NodeAttribute) Unmarshal ¶
func (a *NodeAttribute) Unmarshal(data []byte) error
Unmarshal unmarshals protobuf binary representation of NodeAttribute.
func (*NodeAttribute) UnmarshalJSON ¶
func (a *NodeAttribute) UnmarshalJSON(data []byte) error
UnmarshalJSON decodes NodeAttribute from protobuf JSON format.
func (*NodeAttribute) Value ¶
func (a *NodeAttribute) Value() string
Value returns value of the node attribute.
type NodeInfo ¶
NodeInfo represents v2 compatible descriptor of the NeoFS node.
func NewNodeInfo ¶
func NewNodeInfo() *NodeInfo
NewNodeInfo creates and returns new NodeInfo instance.
func NewNodeInfoFromV2 ¶
NewNodeInfoFromV2 converts v2 NodeInfo to NodeInfo.
func (*NodeInfo) Attributes ¶
func (i *NodeInfo) Attributes() []*NodeAttribute
Attributes returns list of the node attributes.
func (*NodeInfo) Marshal ¶
Marshal marshals NodeInfo into a protobuf binary form.
Buffer is allocated when the argument is empty. Otherwise, the first buffer is used.
func (*NodeInfo) MarshalJSON ¶
MarshalJSON encodes NodeInfo to protobuf JSON format.
func (*NodeInfo) SetAddress ¶
SetAddress sets network endpoint address of the node.
func (*NodeInfo) SetAttributes ¶
func (i *NodeInfo) SetAttributes(as ...*NodeAttribute)
SetAttributes sets list of the node attributes.
func (*NodeInfo) SetPublicKey ¶
SetPublicKey sets public key of the node in a binary format.
func (*NodeInfo) UnmarshalJSON ¶
UnmarshalJSON decodes NodeInfo from protobuf JSON format.
type NodeState ¶
type NodeState uint32
NodeState is an enumeration of various states of the NeoFS node.
const ( // NodeStateOffline is network unavailable state. NodeStateOffline NodeState // NodeStateOnline is an active state in the network. NodeStateOnline )
func NodeStateFromV2 ¶
NodeStateFromV2 converts v2 NodeState to NodeState.
type Nodes ¶
type Nodes []*Node
Nodes represents slice of graph leafs.
func NodesFromInfo ¶
NodesFromInfo converts slice of NodeInfo to a generic node slice.
type Operation ¶
type Operation uint32
Operation is an enumeration of v2-compatible filtering operations.
const ( // OpEQ is an "Equal" operation. OpEQ Operation // OpNE is a "Not equal" operation. OpNE // OpGT is a "Greater than" operation. OpGT // OpGE is a "Greater than or equal to" operation. OpGE // OpLT is a "Less than" operation. OpLT // OpLE is a "Less than or equal to" operation. OpLE // OpOR is an "OR" operation. OpOR // OpAND is an "AND" operation. OpAND )
func OperationFromV2 ¶
OperationFromV2 converts v2 Operation to Operation.
type PlacementPolicy ¶
type PlacementPolicy netmap.PlacementPolicy
PlacementPolicy represents v2-compatible placement policy.
func NewPlacementPolicy ¶
func NewPlacementPolicy() *PlacementPolicy
NewPlacementPolicy creates and returns new PlacementPolicy instance.
func NewPlacementPolicyFromV2 ¶
func NewPlacementPolicyFromV2(f *netmap.PlacementPolicy) *PlacementPolicy
NewPlacementPolicyFromV2 converts v2 PlacementPolicy to PlacementPolicy.
func (*PlacementPolicy) ContainerBackupFactor ¶
func (p *PlacementPolicy) ContainerBackupFactor() uint32
ContainerBackupFactor returns container backup factor.
func (*PlacementPolicy) Filters ¶
func (p *PlacementPolicy) Filters() []*Filter
Filters returns list of named filters to reference in selectors.
func (*PlacementPolicy) Marshal ¶
func (p *PlacementPolicy) Marshal(b ...[]byte) ([]byte, error)
Marshal marshals PlacementPolicy into a protobuf binary form.
Buffer is allocated when the argument is empty. Otherwise, the first buffer is used.
func (*PlacementPolicy) MarshalJSON ¶
func (p *PlacementPolicy) MarshalJSON() ([]byte, error)
MarshalJSON encodes PlacementPolicy to protobuf JSON format.
func (*PlacementPolicy) Replicas ¶
func (p *PlacementPolicy) Replicas() []*Replica
Replicas returns list of object replica descriptors.
func (*PlacementPolicy) Selectors ¶
func (p *PlacementPolicy) Selectors() []*Selector
Selector returns set of selectors to form the container's nodes subset.
func (*PlacementPolicy) SetContainerBackupFactor ¶
func (p *PlacementPolicy) SetContainerBackupFactor(f uint32)
SetContainerBackupFactor sets container backup factor.
func (*PlacementPolicy) SetFilters ¶
func (p *PlacementPolicy) SetFilters(fs ...*Filter)
SetFilters sets list of named filters to reference in selectors.
func (*PlacementPolicy) SetReplicas ¶
func (p *PlacementPolicy) SetReplicas(rs ...*Replica)
SetReplicas sets list of object replica descriptors.
func (*PlacementPolicy) SetSelectors ¶
func (p *PlacementPolicy) SetSelectors(ss ...*Selector)
SetSelectors sets set of selectors to form the container's nodes subset.
func (*PlacementPolicy) ToV2 ¶
func (p *PlacementPolicy) ToV2() *netmap.PlacementPolicy
ToV2 converts PlacementPolicy to v2 PlacementPolicy.
func (*PlacementPolicy) Unmarshal ¶
func (p *PlacementPolicy) Unmarshal(data []byte) error
Unmarshal unmarshals protobuf binary representation of PlacementPolicy.
func (*PlacementPolicy) UnmarshalJSON ¶
func (p *PlacementPolicy) UnmarshalJSON(data []byte) error
UnmarshalJSON decodes PlacementPolicy from protobuf JSON format.
type Replica ¶
Replica represents v2-compatible object replica descriptor.
func NewReplicaFromV2 ¶
NewReplicaFromV2 converts v2 Replica to Replica.
func (*Replica) Marshal ¶
Marshal marshals Replica into a protobuf binary form.
Buffer is allocated when the argument is empty. Otherwise, the first buffer is used.
func (*Replica) MarshalJSON ¶
MarshalJSON encodes Replica to protobuf JSON format.
func (*Replica) SetSelector ¶
SetSelector sets name of selector bucket to put replicas.
func (*Replica) UnmarshalJSON ¶
UnmarshalJSON decodes Replica from protobuf JSON format.
type Selector ¶
Selector represents v2-compatible netmap selector.
func NewSelector ¶
func NewSelector() *Selector
NewSelector creates and returns new Selector instance.
func NewSelectorFromV2 ¶
NewSelectorFromV2 converts v2 Selector to Selector.
func (*Selector) Marshal ¶
Marshal marshals Selector into a protobuf binary form.
Buffer is allocated when the argument is empty. Otherwise, the first buffer is used.
func (*Selector) MarshalJSON ¶
MarshalJSON encodes Selector to protobuf JSON format.
func (*Selector) SetAttribute ¶
SetAttribute sets attribute bucket to select from.
func (*Selector) UnmarshalJSON ¶
UnmarshalJSON decodes Selector from protobuf JSON format.