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
- type FSTree
- func (t *FSTree) CleanUpTmp() error
- func (t *FSTree) Close() error
- func (t *FSTree) Delete(addr oid.Address) error
- func (t *FSTree) Exists(addr oid.Address) (bool, error)
- func (t *FSTree) Get(addr oid.Address) (*objectSDK.Object, error)
- func (t *FSTree) GetBytes(addr oid.Address) ([]byte, error)
- func (t *FSTree) GetRange(addr oid.Address, from uint64, length uint64) ([]byte, error)
- func (t *FSTree) GetStream(addr oid.Address) (*objectSDK.Object, io.ReadCloser, error)
- func (t *FSTree) Head(addr oid.Address) (*objectSDK.Object, error)
- func (t *FSTree) Init() error
- func (t *FSTree) Iterate(objHandler func(addr oid.Address, data []byte) error, ...) error
- func (t *FSTree) IterateAddresses(f func(addr oid.Address) error, ignoreErrors bool) error
- func (t *FSTree) IterateSizes(f func(addr oid.Address, size uint64) error, ignoreErrors bool) error
- func (t *FSTree) Open(ro bool) error
- func (t *FSTree) Path() string
- func (t *FSTree) Put(addr oid.Address, data []byte) error
- func (t *FSTree) PutBatch(objs map[oid.Address][]byte) error
- func (t *FSTree) SetCompressor(cc *compression.Config)
- func (t *FSTree) SetLogger(l *zap.Logger)
- func (*FSTree) Type() string
- type Info
- type Option
- func WithCombinedCountLimit(limit int) Option
- func WithCombinedSizeLimit(size int) Option
- func WithCombinedSizeThreshold(size int) Option
- func WithCombinedWriteInterval(t time.Duration) Option
- func WithDepth(d uint64) Option
- func WithDirNameLen(l int) Option
- func WithNoSync(noSync bool) Option
- func WithPath(p string) Option
- func WithPerm(p fs.FileMode) Option
Constants ¶
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 )
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 (*FSTree) CleanUpTmp ¶ added in v0.44.0
CleanUpTmp removes all temporary files garbage.
func (*FSTree) Exists ¶
Exists returns the path to the file with object contents if it exists in the storage and an error otherwise.
func (*FSTree) GetBytes ¶ added in v0.41.0
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) GetStream ¶ added in v0.48.0
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
Head returns an object's header from the storage by address without reading the full payload.
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
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
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) SetCompressor ¶ added in v0.32.0
func (t *FSTree) SetCompressor(cc *compression.Config)
SetCompressor 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)