fstree

package
v0.48.3 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2025 License: GPL-3.0 Imports: 29 Imported by: 0

Documentation

Overview

Package fstree implements a storage subsystem that saves objects as files in FS tree.

The main concept behind it is rather simple: each object is stored as a file in a directory. Given that handling many files in the same directory is usually problematic for file systems objects are being put into subdirectories by their IDs. This directory tree can have different [FSTree.Depth] and each component of the path (single directory name) is a DirNameLen number of ID bytes from its string representation. File name then is a leftover of object ID (after stripping [FSTree.Depth] bytes off of it) concatenated with container ID.

For example, an object with ID of WCdSV7F9TnDHFmbgKY7BNCbPs6g7meaVbh6DMNXbytB from Hh6qJ2Fa9WzSK7PESResS4mmuoZ2a47Z7F6ZvmR7AEHU container will be stored in W/C/d/S/V directory and a name of 7F9TnDHFmbgKY7BNCbPs6g7meaVbh6DMNXbytB.Hh6qJ2Fa9WzSK7PESResS4mmuoZ2a47Z7F6ZvmR7AEHU if the depth is 5. The overall structure may look like this (a part of it):

/W/
├── 7
│   └── 2
│       └── F
│           └── 6
│               └── 32vhigDXRPkSwaCTw3FtxWbKjoDGoDvVTJqxBb.J4SkhNifjANvYGr56vh4NbGBRCxvk8PT9YE5EgFSb7cc
├── C
│   └── d
│       └── S
│           └── V
│               └── 7F9TnDHFmbgKY7BNCbPs6g7meaVbh6DMNXbytB.Hh6qJ2Fa9WzSK7PESResS4mmuoZ2a47Z7F6ZvmR7AEHU

Binary file format can differ depending on the FSTree version. The basic format that was used from the beginning is storing serialized protobuf representation of the object as is. In this case file can be decoded into an object directly. If compression is configured then the same file can have a compressed (ZSTD) serialized protobuf.

Version 0.44.0 of the node has introduced a new file format that is used for small files, the so-called "combined" one. It has a special prefix (0x7F) that can not collide with protobuf-encoded or ZSTD-compressed data. Files using this prefix can contain an unspecified number of objects (configured via WithCombinedCountLimit) that all follow the same serialization pattern:

  • the first byte is magic 0x7F described above
  • one byte version of the subsequent structure (currently zero only)
  • 32-byte OID of the next object then
  • 4-byte BE integer length of the next object
  • followed by protobuf-encoded or ZSTD-compressed object data (of the length specified in the previous field)

Overall the structure is like this:

[0x7F 0x00 [OID A] [uint32 size]][object A][0x7F 0x00 [OID B] [uint32 size]][object B]...

Even though this file contains several objects it has hard links for all of them in the FS tree, so finding a file containing some object doesn't require any additional effort. Finding it in the file contents however requires reading the prefix described above, comparing the target OID and either skipping the object length specified there or reading it after the prefix.

Index

Constants

View Source
const (
	// DirNameLen is how many bytes is used to group keys into directories.
	DirNameLen = 1 // in bytes
	// MaxDepth is maximum depth of nested directories. 58^8 is 128e12 of
	// directories, enough for a single FSTree.
	MaxDepth = 8
)
View Source
const Type = "fstree"

Type is fstree storage type used in logs and configuration.

Variables

This section is empty.

Functions

This section is empty.

Types

type FSTree

type FSTree struct {
	Info

	*compression.Config

	Depth      uint64
	DirNameLen int
	// contains filtered or unexported fields
}

FSTree represents an object storage as a filesystem tree.

func New added in v0.32.0

func New(opts ...Option) *FSTree

func (*FSTree) CleanUpTmp added in v0.44.0

func (t *FSTree) CleanUpTmp() error

CleanUpTmp removes all temporary files garbage.

func (*FSTree) Close added in v0.32.0

func (t *FSTree) Close() error

Close implements common.Storage.

func (*FSTree) Delete

func (t *FSTree) Delete(addr oid.Address) error

Delete removes the object with the specified address from the storage.

func (*FSTree) Exists

func (t *FSTree) Exists(addr oid.Address) (bool, error)

Exists returns the path to the file with object contents if it exists in the storage and an error otherwise.

func (*FSTree) Get

func (t *FSTree) Get(addr oid.Address) (*objectSDK.Object, error)

Get returns an object from the storage by address.

func (*FSTree) GetBytes added in v0.41.0

func (t *FSTree) GetBytes(addr oid.Address) ([]byte, error)

GetBytes reads object from the FSTree by address into memory buffer in a canonical NeoFS binary format. Returns apistatus.ObjectNotFound if object is missing.

func (*FSTree) GetRange added in v0.32.0

func (t *FSTree) GetRange(addr oid.Address, from uint64, length uint64) ([]byte, error)

GetRange implements common.Storage.

func (*FSTree) GetStream added in v0.48.0

func (t *FSTree) GetStream(addr oid.Address) (*objectSDK.Object, io.ReadCloser, error)

GetStream returns an object from the storage by address as a stream. It returns the object with header only, and a reader for the payload. The caller is responsible for closing the returned io.ReadCloser if it is not nil.

func (*FSTree) Head added in v0.48.0

func (t *FSTree) Head(addr oid.Address) (*objectSDK.Object, error)

Head returns an object's header from the storage by address without reading the full payload.

func (*FSTree) Init added in v0.32.0

func (t *FSTree) Init() error

Init implements common.Storage.

func (*FSTree) Iterate

func (t *FSTree) Iterate(objHandler func(addr oid.Address, data []byte) error, errorHandler func(addr oid.Address, err error) error) error

Iterate iterates over all stored objects.

func (*FSTree) IterateAddresses added in v0.44.1

func (t *FSTree) IterateAddresses(f func(addr oid.Address) error, ignoreErrors bool) error

IterateAddresses iterates over all objects stored in the underlying storage and passes their addresses into f. If f returns an error, IterateAddresses returns it and breaks. ignoreErrors allows to continue if internal errors happen.

func (*FSTree) IterateSizes added in v0.45.0

func (t *FSTree) IterateSizes(f func(addr oid.Address, size uint64) error, ignoreErrors bool) error

IterateSizes iterates over all objects stored in the underlying storage and passes their addresses and sizes into f. If f returns an error, IterateSizes returns it and breaks. ignoreErrors allows to continue if internal errors happen.

func (*FSTree) Open added in v0.32.0

func (t *FSTree) Open(ro bool) error

Open implements common.Storage.

func (*FSTree) Path added in v0.33.0

func (t *FSTree) Path() string

Path implements common.Storage.

func (*FSTree) Put

func (t *FSTree) Put(addr oid.Address, data []byte) error

Put puts an object in the storage.

func (*FSTree) PutBatch added in v0.46.0

func (t *FSTree) PutBatch(objs map[oid.Address][]byte) error

PutBatch puts a batch of objects in the storage.

func (*FSTree) SetCompressor added in v0.32.0

func (t *FSTree) SetCompressor(cc *compression.Config)

SetCompressor implements common.Storage.

func (*FSTree) SetLogger added in v0.44.0

func (t *FSTree) SetLogger(l *zap.Logger)

SetLogger sets logger. It is used after the shard ID was generated to use it in logs.

func (*FSTree) Type added in v0.32.0

func (*FSTree) Type() string

Type implements common.Storage.

type Info

type Info struct {
	// Permission bits of the root directory.
	Permissions fs.FileMode

	// Full path to the root directory.
	RootPath string
}

Info groups the information about file storage.

type Option added in v0.32.0

type Option func(*FSTree)

func WithCombinedCountLimit added in v0.44.0

func WithCombinedCountLimit(limit int) Option

func WithCombinedSizeLimit added in v0.44.0

func WithCombinedSizeLimit(size int) Option

func WithCombinedSizeThreshold added in v0.44.0

func WithCombinedSizeThreshold(size int) Option

func WithCombinedWriteInterval added in v0.44.0

func WithCombinedWriteInterval(t time.Duration) Option

func WithDepth added in v0.32.0

func WithDepth(d uint64) Option

func WithDirNameLen added in v0.32.0

func WithDirNameLen(l int) Option

func WithNoSync added in v0.36.0

func WithNoSync(noSync bool) Option

func WithPath added in v0.32.0

func WithPath(p string) Option

func WithPerm added in v0.32.0

func WithPerm(p fs.FileMode) Option

Jump to

Keyboard shortcuts

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