reserve

package
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: BSD-3-Clause Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ChunkType

func ChunkType(ch swarm.Chunk) swarm.ChunkType

Types

type BatchRadiusItem

type BatchRadiusItem struct {
	Bin     uint8
	BatchID []byte
	Address swarm.Address
	BinID   uint64
}

BatchRadiusItem allows iteration of the chunks with respect to bin and batchID. Used for batch evictions of certain bins.

func (*BatchRadiusItem) Clone

func (b *BatchRadiusItem) Clone() storage.Item

func (*BatchRadiusItem) ID

func (b *BatchRadiusItem) ID() string

batchID/bin/ChunkAddr

func (*BatchRadiusItem) Marshal

func (b *BatchRadiusItem) Marshal() ([]byte, error)

func (*BatchRadiusItem) Namespace

func (b *BatchRadiusItem) Namespace() string

func (*BatchRadiusItem) String

func (b *BatchRadiusItem) String() string

func (*BatchRadiusItem) Unmarshal

func (b *BatchRadiusItem) Unmarshal(buf []byte) error

type BinItem

type BinItem struct {
	Bin   uint8
	BinID uint64
}

BinItem stores the latest binIDs for each bin between 0 and swarm.MaxBins

func (*BinItem) Clone

func (b *BinItem) Clone() storage.Item

func (*BinItem) ID

func (b *BinItem) ID() string

func (*BinItem) Marshal

func (c *BinItem) Marshal() ([]byte, error)

func (*BinItem) Namespace

func (b *BinItem) Namespace() string

func (*BinItem) String

func (c *BinItem) String() string

func (*BinItem) Unmarshal

func (c *BinItem) Unmarshal(buf []byte) error

type ChunkBinItem

type ChunkBinItem struct {
	Bin       uint8
	BinID     uint64
	Address   swarm.Address
	BatchID   []byte
	ChunkType swarm.ChunkType
}

ChunkBinItem allows for iterating on ranges of bin and binIDs for chunks. BinIDs come in handy when syncing the reserve contents with other peers.

func (*ChunkBinItem) Clone

func (c *ChunkBinItem) Clone() storage.Item

func (*ChunkBinItem) ID

func (c *ChunkBinItem) ID() string

bin/binID

func (*ChunkBinItem) Marshal

func (c *ChunkBinItem) Marshal() ([]byte, error)

func (*ChunkBinItem) Namespace

func (c *ChunkBinItem) Namespace() string

func (*ChunkBinItem) String

func (c *ChunkBinItem) String() string

func (*ChunkBinItem) Unmarshal

func (c *ChunkBinItem) Unmarshal(buf []byte) error

type ChunkItem

type ChunkItem struct {
	ChunkAddress swarm.Address
	BatchID      []byte
	Type         swarm.ChunkType
	BinID        uint64
	Bin          uint8
}

type EpochItem

type EpochItem struct {
	Timestamp uint64
}

EpochItem stores the timetamp in seconds of the initial creation of the reserve.

func (*EpochItem) Clone

func (e *EpochItem) Clone() storage.Item

func (*EpochItem) ID

func (e *EpochItem) ID() string

func (*EpochItem) Marshal

func (e *EpochItem) Marshal() ([]byte, error)

func (*EpochItem) Namespace

func (e *EpochItem) Namespace() string

func (*EpochItem) String

func (e *EpochItem) String() string

func (*EpochItem) Unmarshal

func (e *EpochItem) Unmarshal(buf []byte) error

type Reserve

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

func New

func New(
	baseAddr swarm.Address,
	store storage.Store,
	capacity int,
	radiusSetter topology.SetStorageRadiuser,
	logger log.Logger,
	cb func(context.Context, internal.Storage, ...swarm.Address) error,
) (*Reserve, error)

func (*Reserve) AddSize

func (r *Reserve) AddSize(diff int)

func (*Reserve) Capacity

func (r *Reserve) Capacity() int

func (*Reserve) DeleteChunk

func (r *Reserve) DeleteChunk(
	ctx context.Context,
	store internal.Storage,
	batch storage.Writer,
	chunkAddress swarm.Address,
	batchID []byte,
) error

func (*Reserve) EvictBatchBin

func (r *Reserve) EvictBatchBin(
	ctx context.Context,
	txExecutor internal.TxExecutor,
	bin uint8,
	batchID []byte,
) (int, error)

EvictBatchBin evicts all chunks from bins upto the bin provided.

func (*Reserve) EvictionTarget

func (r *Reserve) EvictionTarget() int

func (*Reserve) Get

func (r *Reserve) Get(ctx context.Context, storage internal.Storage, addr swarm.Address, batchID []byte) (swarm.Chunk, error)

func (*Reserve) Has

func (r *Reserve) Has(store storage.Store, addr swarm.Address, batchID []byte) (bool, error)

func (*Reserve) IncBinID

func (r *Reserve) IncBinID(store storage.Store, bin uint8) (uint64, error)

should be called under lock

func (*Reserve) IsWithinCapacity

func (r *Reserve) IsWithinCapacity() bool

func (*Reserve) IterateBin

func (r *Reserve) IterateBin(store storage.Store, bin uint8, startBinID uint64, cb func(swarm.Address, uint64, []byte) (bool, error)) error

func (*Reserve) IterateChunks

func (r *Reserve) IterateChunks(store internal.Storage, startBin uint8, cb func(swarm.Chunk) (bool, error)) error

func (*Reserve) IterateChunksItems

func (r *Reserve) IterateChunksItems(store internal.Storage, startBin uint8, cb func(ChunkItem) (bool, error)) error

func (*Reserve) LastBinIDs

func (r *Reserve) LastBinIDs(store storage.Store) ([]uint64, uint64, error)

func (*Reserve) Put

func (r *Reserve) Put(ctx context.Context, store internal.Storage, chunk swarm.Chunk) (bool, error)

Put stores a new chunk in the reserve and returns if the reserve size should increase.

func (*Reserve) Radius

func (r *Reserve) Radius() uint8

func (*Reserve) SetRadius

func (r *Reserve) SetRadius(store storage.Store, rad uint8) error

func (*Reserve) Size

func (r *Reserve) Size() int

Jump to

Keyboard shortcuts

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