maps

package
v0.0.0-...-21cfbab Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2023 License: Apache-2.0, Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const IteratorNumKeys = 16

Batch size established by trial and error; 8-32 seemed to be the sweet spot for the conntrack map.

Variables

View Source
var ErrIterationFinished = errors.New("iteration finished")

ErrIterationFinished is returned by the Iterator's Next() method when there are no more keys.

View Source
var ErrVisitedTooManyKeys = errors.New("visited 10x the max size of the map keys")

ErrVisitedTooManyKeys is returned by the Iterator's Next() method if it sees many more keys than there should be in the map.

Functions

func DeleteMapEntry

func DeleteMapEntry(mapFD FD, k []byte, valueSize int) error

func DeleteMapEntryIfExists

func DeleteMapEntryIfExists(mapFD FD, k []byte, valueSize int) error

func DisableRepin

func DisableRepin()

func DumpMapCmd

func DumpMapCmd(m Map) ([]string, error)

DumpMapCmd returns the command that can be used to dump a map or an error

func EnableRepin

func EnableRepin()

func GetMapEntry

func GetMapEntry(mapFD FD, k []byte, valueSize int) ([]byte, error)

func GetMapIdFromPin

func GetMapIdFromPin(pinPath string) (int, error)

func IsNotExists

func IsNotExists(err error) bool

func JumpMapName

func JumpMapName() string

func MapDeleteKeyCmd

func MapDeleteKeyCmd(m Map, key []byte) ([]string, error)

func NumPossibleCPUs

func NumPossibleCPUs() int

func RepinMap

func RepinMap(name string, filename string) error

RepinMap finds a map by a given name and pins it to a path. Note that if there are multiple maps of the same name in the system, it will use the first one it finds.

func ResetSizes

func ResetSizes()

func SetSize

func SetSize(name string, size int)

func ShowMapCmd

func ShowMapCmd(m Map) ([]string, error)

func Size

func Size(name string) int

func UpdateMapEntry

func UpdateMapEntry(mapFD FD, k, v []byte) error

func UpdateMapEntryWithFlags

func UpdateMapEntryWithFlags(mapFD FD, k, v []byte, flags int) error

func Upgrade

func Upgrade(oldMap, newMap *PinnedMap) error

Types

type AsBytes

type AsBytes interface {
	AsBytes() []byte
}

type FD

type FD uint32

func GetMapFDByID

func GetMapFDByID(mapID int) (FD, error)

func GetMapFDByPin

func GetMapFDByPin(filename string) (FD, error)

func (FD) Close

func (f FD) Close() error

type IterCallback

type IterCallback func(k, v []byte) IteratorAction

type Iterator

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

Iterator handles one pass of iteration over the map.

func NewIterator

func NewIterator(mapFD FD, keySize, valueSize, maxEntries int) (*Iterator, error)

func (*Iterator) Close

func (m *Iterator) Close() error

func (*Iterator) Next

func (m *Iterator) Next() (k, v []byte, err error)

Next gets the next key/value pair from the iteration. The key and value []byte slices returned point to the Iterator's internal buffers (which are allocated on the C heap); they should not be retained or modified. Returns ErrIterationFinished at the end of the iteration or ErrVisitedTooManyKeys if it visits considerably more keys than the maximum size of the map.

type IteratorAction

type IteratorAction string
const (
	IterNone   IteratorAction = ""
	IterDelete IteratorAction = "delete"
)

type Key

type Key interface {
	comparable
	AsBytes
}

type Map

type Map interface {
	GetName() string
	// EnsureExists opens the map, creating and pinning it if needed.
	EnsureExists() error
	// Open opens the map, returns error if it does not exist.
	Open() error
	// Close closes the map, returns error for any error.
	Close() error
	// MapFD gets the file descriptor of the map, only valid after calling EnsureExists().
	MapFD() FD
	// Path returns the path that the map is (to be) pinned to.
	Path() string

	// CopyDeltaFromOldMap() copies data from old map to new map
	CopyDeltaFromOldMap() error

	Iter(IterCallback) error
	Update(k, v []byte) error
	Get(k []byte) ([]byte, error)
	Delete(k []byte) error
}

type MapInfo

type MapInfo struct {
	Type       int
	KeySize    int
	ValueSize  int
	MaxEntries int
}

func GetMapInfo

func GetMapInfo(fd FD) (*MapInfo, error)

type MapParameters

type MapParameters struct {
	PinDir       string
	Type         string
	KeySize      int
	ValueSize    int
	MaxEntries   int
	Name         string
	Flags        int
	Version      int
	UpdatedByBPF bool
}

func (*MapParameters) VersionedFilename

func (mp *MapParameters) VersionedFilename() string

func (*MapParameters) VersionedName

func (mp *MapParameters) VersionedName() string

type MapWithExistsCheck

type MapWithExistsCheck interface {
	Map
	ErrIsNotExists(error) bool
}

func NewPinnedMap

func NewPinnedMap(params MapParameters) MapWithExistsCheck

type MapWithUpdateWithFlags

type MapWithUpdateWithFlags interface {
	Map
	UpdateWithFlags(k, v []byte, flags int) error
}

type PinnedMap

type PinnedMap struct {
	MapParameters

	// Callbacks to handle upgrade
	UpgradeFn      func(*PinnedMap, *PinnedMap) error
	GetMapParams   func(int) MapParameters
	KVasUpgradable func(int, []byte, []byte) (Upgradable, Upgradable)
	// contains filtered or unexported fields
}

func (*PinnedMap) Close

func (b *PinnedMap) Close() error

func (*PinnedMap) CopyDeltaFromOldMap

func (b *PinnedMap) CopyDeltaFromOldMap() error

func (*PinnedMap) Delete

func (b *PinnedMap) Delete(k []byte) error

func (*PinnedMap) EnsureExists

func (b *PinnedMap) EnsureExists() error

func (*PinnedMap) ErrIsNotExists

func (*PinnedMap) ErrIsNotExists(err error) bool

func (*PinnedMap) Get

func (b *PinnedMap) Get(k []byte) ([]byte, error)

func (*PinnedMap) GetName

func (b *PinnedMap) GetName() string

func (*PinnedMap) Iter

func (b *PinnedMap) Iter(f IterCallback) error

Iter iterates over the map, passing each key/value pair to the provided callback function. Warning: The key and value are owned by the iterator and will be clobbered by the next iteration so they must not be retained or modified.

func (*PinnedMap) MapFD

func (b *PinnedMap) MapFD() FD

func (*PinnedMap) Open

func (b *PinnedMap) Open() error

func (*PinnedMap) Path

func (b *PinnedMap) Path() string

func (*PinnedMap) Update

func (b *PinnedMap) Update(k, v []byte) error

func (*PinnedMap) UpdateWithFlags

func (b *PinnedMap) UpdateWithFlags(k, v []byte, flags int) error

type TypedMap

type TypedMap[K Key, V Value] struct {
	MapWithExistsCheck
	// contains filtered or unexported fields
}

func NewTypedMap

func NewTypedMap[K Key, V Value](m MapWithExistsCheck, kConstructor func([]byte) K, vConstructor func([]byte) V) *TypedMap[K, V]

func (*TypedMap[K, V]) Delete

func (m *TypedMap[K, V]) Delete(k K) error

func (*TypedMap[K, V]) Get

func (m *TypedMap[K, V]) Get(k K) (V, error)

func (*TypedMap[K, V]) Load

func (m *TypedMap[K, V]) Load() (map[K]V, error)

func (*TypedMap[K, V]) Update

func (m *TypedMap[K, V]) Update(k K, v V) error

type Upgradable

type Upgradable interface {
	Upgrade() Upgradable
	AsBytes() []byte
}

type Value

type Value interface {
	comparable
	AsBytes
}

Jump to

Keyboard shortcuts

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