Documentation ¶
Overview ¶
WIP: Package storage defines and implements storage providers and store accessors.
Index ¶
- func LockedMutate(a Accessor, l sync.Locker, f func() error) (err error)
- func Mutate(a Accessor, f func() error) (err error)
- type Accessor
- type Cache
- func (c *Cache) Accessor() Accessor
- func (c *Cache) BeginUpdate() error
- func (c *Cache) Close() (err error)
- func (c *Cache) EndUpdate() error
- func (c *Cache) Name() (s string)
- func (c *Cache) ReadAt(b []byte, off int64) (n int, err error)
- func (c *Cache) Stat() (fi os.FileInfo, err error)
- func (c *Cache) Sync() (err error)
- func (c *Cache) Truncate(size int64) (err error)
- func (c *Cache) WriteAt(b []byte, off int64) (n int, err error)
- type FileAccessor
- type FileInfo
- type Probe
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LockedMutate ¶
LockedMutate wraps Mutate in yet another layer consisting of a l.Lock/l.Unlock pair. All other limitations apply as in Mutate, e.g. no panics are allowed to happen - otherwise no guarantees can be made about Unlock matching the Lock.
func Mutate ¶
Mutate is a helper/wrapper for executing f in between a.BeginUpdate and a.EndUpdate. Any parameters and/or return values except an error should be captured by a function literal passed as f. The returned err is either nil or the first non nil error returned from the sequence of execution: BeginUpdate, [f,] EndUpdate. The pair BeginUpdate/EndUpdate *is* invoked always regardles of any possible errors produced. Mutate doesn't handle panic, it should be used only with a function [literal] which doesn't panic. Otherwise the pairing of BeginUpdate/EndUpdate is not guaranteed.
NOTE: If BeginUpdate, which is invoked before f, returns a non-nil error, then f is not invoked at all (but EndUpdate still is).
Types ¶
type Accessor ¶
type Accessor interface { // Close closes the store, rendering it unusable for I/O. It returns an // error, if any. Close() error // Name returns the name of the file as presented to Open. Name() string // ReadAt reads len(b) bytes from the store starting at byte offset off. // It returns the number of bytes read and the error, if any. // EOF is signaled by a zero count with err set to os.EOF. // ReadAt always returns a non-nil Error when n != len(b). ReadAt(b []byte, off int64) (n int, err error) // Stat returns the FileInfo structure describing the store. It returns // the os.FileInfo and an error, if any. Stat() (fi os.FileInfo, err error) // Sync commits the current contents of the store to stable storage. // Typically, this means flushing the file system's in-memory copy of // recently written data to disk. Sync() (err error) // Truncate changes the size of the store. It does not change the I/O // offset. Truncate(size int64) error // WriteAt writes len(b) bytes to the store starting at byte offset off. // It returns the number of bytes written and an error, if any. // WriteAt returns a non-nil Error when n != len(b). WriteAt(b []byte, off int64) (n int, err error) // Before every [structural] change of a store the BeginUpdate is to be // called and paired with EndUpdate after the change makes the store's // state consistent again. Invocations of BeginUpdate may nest. On // invoking the last non nested EndUpdate an implicit "commit" should // be performed by the store/provider. The concrete mechanism is // unspecified. It could be for example a write-ahead log. Stores may // implement BeginUpdate and EndUpdate as a (documented) no op. BeginUpdate() error EndUpdate() error }
Accessor provides I/O methods to access a store.
func NewFile ¶
NewFile returns an Accessor backed by an os.File named name, It opens the named file with specified flag (os.O_RDWR etc.) and perm, (0666 etc.) if applicable. If successful, methods on the returned Accessor can be used for I/O. It returns the Accessor and an Error, if any.
NOTE: The returned Accessor implements BeginUpdate and EndUpdate as a no op.
func NewMem ¶
NewMem returns a new Accessor backed by an os.File. The returned Accessor keeps all of the store content in memory. The memory and file images are synced only by Sync and Close. Recomended for small amounts of data only and content which may be lost on process kill/crash. NewMem return the Accessor or an error of any.
NOTE: The returned Accessor implements BeginUpdate and EndUpdate as a no op.
func OpenFile ¶
OpenFile returns an Accessor backed by an existing os.File named name, It opens the named file with specified flag (os.O_RDWR etc.) and perm, (0666 etc.) if applicable. If successful, methods on the returned Accessor can be used for I/O. It returns the Accessor and an Error, if any.
NOTE: The returned Accessor implements BeginUpdate and EndUpdate as a no op.
func OpenMem ¶
OpenMem return a new Accessor backed by an os.File. The store content is loaded from f. The returned Accessor keeps all of the store content in memory. The memory and file images are synced only Sync and Close. Recomended for small amounts of data only and content which may be lost on process kill/crash. OpenMem return the Accessor or an error of any.
NOTE: The returned Accessor implements BeginUpdate and EndUpdate as a no op.
type Cache ¶
type Cache struct { Rq int64 // Pages requested from cache Load int64 // Pages loaded (cache miss) Purge int64 // Pages purged Top int // "High water" pages // contains filtered or unexported fields }
Cache provides caching support for another store Accessor.
type FileAccessor ¶
FileAccessor is the concrete type returned by NewFile and OpenFile.
func (*FileAccessor) BeginUpdate ¶
func (f *FileAccessor) BeginUpdate() error
Implementation of Accessor.
func (*FileAccessor) EndUpdate ¶
func (f *FileAccessor) EndUpdate() error
Implementation of Accessor.
type FileInfo ¶
type FileInfo struct { FName string // base name of the file FSize int64 // length in bytes FMode os.FileMode // file mode bits FModTime time.Time // modification time FIsDir bool // abbreviation for Mode().IsDir() // contains filtered or unexported fields }
FileInfo is a type implementing os.FileInfo which has setable fields, like the older os.FileInfo used to have. It is used wehere e.g. the Size is needed to be faked (encapsulated/memory only file, file cache, etc.).
func NewFileInfo ¶
NewFileInfo creates FileInfo from os.FileInfo fi.
type Probe ¶
type Probe struct { Accessor Chain *Probe OpsRd int64 OpsWr int64 BytesRd int64 BytesWr int64 SectorsRd int64 // Assuming 512 byte sector size SectorsWr int64 }
Probe collects usage statistics of the embeded Accessor. Probe itself IS an Accessor.