flatfs

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2026 License: Apache-2.0, MIT Imports: 13 Imported by: 1

Documentation

Overview

Package flatfs is a Datastore implementation that stores all objects in a two-level directory structure in the local file system, regardless of the hierarchy of the keys.

Index

Constants

View Source
const PREFIX = "/repo/flatfs/shard/"
View Source
const README_FN = "_README"
View Source
const SHARDING_FN = "SHARDING"
View Source
const SyncThreadsMax = 16

don't block more than 16 threads on sync opearation 16 should be able to saturate most RAIDs in case of two used disks per write (RAID 1, 5) and queue depth of 2, 16 concurrent Sync calls should be able to saturate 16 HDDs RAID TODO: benchmark it out, maybe provide tweak parmeter

Variables

View Source
var (
	// RetryDelay is a timeout for a backoff on retrying operations
	// that fail due to transient errors like too many file descriptors open.
	RetryDelay = time.Millisecond * 200
	// RetryAttempts is the maximum number of retries that will be attempted
	// before giving up.
	RetryAttempts = 6
)
View Source
var (
	ErrStoreExists         = errors.New("datastore already exists")
	ErrStoreDoesNotExist   = errors.New("datastore directory does not exist")
	ErrShardingFileMissing = fmt.Errorf("%s file not found in datastore", SHARDING_FN)
	ErrClosed              = errors.New("datastore closed")
	ErrInvalidKey          = errors.New("key not supported by flatfs")
)
View Source
var NEXT_TO_LAST2_DEF_SHARD = NextToLast(2)
View Source
var README_NEXT_TO_LAST2_DEF_SHARD = `` /* 925-byte string literal not displayed */

Functions

func WriteReadme

func WriteReadme(dir string, id *ShardIdV1) error

func WriteShardFunc

func WriteShardFunc(dir string, id *ShardIdV1) error

Types

type FileObject

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

func (FileObject) Body

func (o FileObject) Body() io.ReadCloser

func (FileObject) Size

func (o FileObject) Size() int64

type ShardFunc

type ShardFunc func(string) string

type ShardIdV1

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

func NextToLast

func NextToLast(suffixLen int) *ShardIdV1

Prefix returns a sharding function taking the suffixLen characters of the key before the very last character. If too short, the key is padded with "_".

func ParseShardFunc

func ParseShardFunc(str string) (*ShardIdV1, error)

func Prefix

func Prefix(prefixLen int) *ShardIdV1

Prefix returns a sharding function taking the first prefixLen characters of the key. If too short, the key is padded with "_".

func ReadShardFunc

func ReadShardFunc(dir string) (*ShardIdV1, error)

func Suffix

func Suffix(suffixLen int) *ShardIdV1

Prefix returns a sharding function taking the last suffixLen characters of the key. If too short, the key is padded with "_".

func (*ShardIdV1) Func

func (f *ShardIdV1) Func() ShardFunc

func (*ShardIdV1) String

func (f *ShardIdV1) String() string

type Store

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

Store implements objectstore.Store. Note this datastore cannot guarantee order of concurrent write operations to the same key. See the explanation in Put().

func New

func New(path string, fun *ShardIdV1, sync bool) (*Store, error)

New creates a new FlatFS object store or opens an existing one.

func (*Store) Close

func (fs *Store) Close() error

func (*Store) Delete

func (fs *Store) Delete(ctx context.Context, key string) error

Delete removes a key/value from the Datastore. Please read the Put() explanation about the handling of concurrent write operations to the same key.

func (*Store) Get

func (fs *Store) Get(ctx context.Context, key string, opts ...objectstore.GetOption) (objectstore.Object, error)

func (*Store) Put

func (fs *Store) Put(ctx context.Context, key string, size uint64, value io.Reader) error

Put stores a key/value in the datastore.

Note, that we do not guarantee order of write operations (Put or Delete) to the same key in this datastore.

For example. i.e. in the case of two concurrent Put, we only guarantee that one of them will come through, but cannot assure which one even if one arrived slightly later than the other. In the case of a concurrent Put and a Delete operation, we cannot guarantee which one will win.

func (*Store) ShardStr

func (fs *Store) ShardStr() string

Jump to

Keyboard shortcuts

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