aof

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2022 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// RDONLY maps the memory read-only.
	// Attempts to write to the MMap object will result in undefined behavior.
	RDONLY = 0
	// RDWR maps the memory as read-write. Writes to the MMap object will update the
	// underlying file.
	RDWR = 1 << iota
	// COPY maps the memory as copy-on-write. Writes to the MMap object will affect
	// memory, but the underlying file will remain unchanged.
	COPY
	// If EXEC is set, the mapped memory is marked as executable.
	EXEC
)
View Source
const (
	// If the ANON flag is set, the mapped memory will not be backed by a file.
	ANON = 1 << iota
)

Variables

View Source
var (
	ErrReadOnly          = errors.New("read-only")
	ErrMultipleWriters   = errors.New("multiple-writers")
	ErrExtendFailed      = errors.New("extend failed")
	ErrRandomWriteUnsafe = errors.New("random write is unsafe when file has open consumers")
)

Functions

func FastUID

func FastUID() uint64

func GenerateCryptoRandomString

func GenerateCryptoRandomString(n int, runes string) (string, error)

GenerateCryptoRandomString generates a random string for cryptographic usage.

func UID

func UID() (uint64, error)

UID returns cryptographic random uint64.

Types

type AppendEvent

type AppendEvent struct {
	Begin int64
	End   int64
	Data  []byte
}

type AppendFunc

type AppendFunc func(event AppendEvent) (int64, error)

type Consumer

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

func (*Consumer) Close

func (c *Consumer) Close() error

func (*Consumer) IsClosed

func (c *Consumer) IsClosed() bool

func (*Consumer) Load

func (c *Consumer) Load() int64

func (*Consumer) ReadAt

func (c *Consumer) ReadAt(b []byte, index int64) (int, error)

func (*Consumer) ReadView

func (c *Consumer) ReadView(callback ViewCallback) error

type ConsumerFunc

type ConsumerFunc func(event ReadEvent) error

type Create

type Create struct {
	Id          string
	Name        string
	InitialSize int64
	ExtendBy    int64
	WLock       sync.Locker
	RLock       sync.Locker
	Perm        os.FileMode
}

type File

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

File

func (*File) Append

func (f *File) Append(reserve int64, appender AppendFunc) error

Append allocates the requested size to the end of the file

func (*File) Close

func (f *File) Close() error

func (*File) Finalize

func (f *File) Finalize() error

func (*File) ID

func (f *File) ID() string

func (*File) IsAnonymous

func (f *File) IsAnonymous() bool

func (*File) IsClosed

func (f *File) IsClosed() bool

func (*File) IsReadOnly

func (f *File) IsReadOnly() bool

func (*File) ReadAt

func (f *File) ReadAt(b []byte, index int64) (int, error)

func (*File) ReadView

func (f *File) ReadView(cb ViewCallback) error

func (*File) Size

func (f *File) Size() int64

func (*File) Subscribe

func (f *File) Subscribe(
	wait waiter.Waiter,
	consumer ConsumerFunc,
) (*Consumer, error)

func (*File) Truncate

func (f *File) Truncate(size int64) error

func (*File) Write

func (f *File) Write(b []byte) (int, error)

func (*File) WriteAt

func (f *File) WriteAt(b []byte, index int64) (int, error)

func (*File) WriteView

func (f *File) WriteView(begin, end int64, cb ViewCallback) error

type MMap

type MMap []byte

MMap represents a file mapped into memory.

func Map

func Map(f *os.File, prot, flags int) (MMap, error)

Map maps an entire file into memory. If ANON is set in flags, f is ignored.

func MapRegion

func MapRegion(f *os.File, length int, prot, flags int, offset int64) (MMap, error)

MapRegion maps part of a file into memory. The offset parameter must be a multiple of the system's page size. If size < 0, the entire file will be mapped. If ANON is set in flags, f is ignored.

func (MMap) Flush

func (m MMap) Flush() error

Flush synchronizes the mapping's contents to the file's contents on disk.

func (MMap) Lock

func (m MMap) Lock() error

Lock keeps the mapped region in physical memory, ensuring that it will not be swapped out.

func (MMap) Unlock

func (m MMap) Unlock() error

Unlock reverses the effect of Lock, allowing the mapped region to potentially be swapped out. If data is already unlocked, aan error will result.

func (*MMap) Unmap

func (m *MMap) Unmap() error

Unmap deletes the memory mapped region, flushes any remaining changes, and sets data to nil. Trying to read or write any remaining references to data after Unmap is called will result in undefined behavior. Unmap should only be called on the slice value that was originally returned from a call to Map. Calling Unmap on a derived slice may cause errors.

type Manager

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

func NewManager

func NewManager(dir string, perm os.FileMode) (*Manager, error)

func (*Manager) Close

func (m *Manager) Close() error

func (*Manager) Create

func (m *Manager) Create(args Create) (*File, error)

func (*Manager) Open

func (m *Manager) Open(args Open) (*File, error)

func (*Manager) Stats

func (m *Manager) Stats() Stats

type Open

type Open struct {
	Id       string
	Name     string
	ExtendBy int64
	WLock    sync.Locker
	RLock    sync.Locker
	Perm     os.FileMode
}

type ReadEvent

type ReadEvent struct {
	Begin  int64
	End    int64
	File   []byte
	Data   []byte
	EOF    bool
	Closed bool
}

type Stats

type Stats struct {
	Creates               Counter
	CreatesDur            TimeCounter
	Opens                 Counter
	OpensDur              TimeCounter
	Closes                Counter
	CloseDur              TimeCounter
	ActiveMaps            Counter
	ActiveMemory          Counter
	ActiveAnonymousMemory Counter
	LifetimeMemory        Counter
	Flushes               Counter
	FlushesDur            TimeCounter
	FlushErrors           Counter
	FlushErrorsDur        TimeCounter
	Extends               Counter
	ExtendsDur            TimeCounter
	Maps                  Counter
	MapsDur               TimeCounter
	MapErrors             Counter
	MapErrorsDur          TimeCounter
	Unmaps                Counter
	UnmapsDur             TimeCounter
	UnmapErrors           Counter
	UnmapErrorsDur        TimeCounter
	Finalizes             Counter
	FinalizesDur          TimeCounter
	Truncates             Counter
	TruncatesDur          TimeCounter
	TruncateErrors        Counter
	TruncateErrorsDur     TimeCounter
}

type ViewCallback

type ViewCallback func(b []byte) error

Jump to

Keyboard shortcuts

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