hdb

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2016 License: BSD-3-Clause, BSD-3-Clause, Apache-2.0, + 1 more Imports: 2 Imported by: 0

README

This is a goinstall-able mirror of modified code already published at:
https://git.nic.cz/redmine/projects/gofileutil/repository/show/hdb

Install: $go get github.com/cznic/fileutil/hdb
Godocs: http://gopkgdoc.appspot.com/pkg/github.com/cznic/fileutil/hdb

Documentation

Overview

WIP: Package hdb provides a "handle"/value DB like store, but actually it's closer to the model of a process's virtual memory and its alloc, free and move methods.

The hdb package is a thin layer around falloc.File providing stable-only handles and the basic synchronizing primitives. The central functionality of hdb are the New, Set, Get and Delete methods of Store.

Conceptual analogy:

New	    alloc(sizeof(content)), return new "memory" pointer (a handle).

Get	    memmove() from "memory" "pointed to" by handle to the result content.
	    Note: Handle "knows" the size of its content.

Set	    memmove() from content to "memory" pointed to by handle.
	    In contrast to real memory, the new content may have different
	    size than the previously stored one w/o additional handling
	    and the "pointer" handle remains the same.

Delete	    free() the "memory" "pointed to" by handle.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Store

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

func New

func New(accessor storage.Accessor) (store *Store, err error)

New returns a newly created Store backed by accessor, discarding its conents if any. If successful, methods on the returned Store can be used for I/O. It returns the Store and an error, if any.

func Open

func Open(accessor storage.Accessor) (store *Store, err error)

Open opens the Store from accessor. If successful, methods on the returned Store can be used for data exchange. It returns the Store and an error, if any.

func (*Store) Close

func (s *Store) Close() (err error)

Close closes the store. Further access to the store has undefined behavior and may panic. It returns an error, if any.

func (*Store) Delete

func (s *Store) Delete(handle falloc.Handle) (err error)

Delete deletes the data associated with handle. It returns an error if any.

func (*Store) File

func (s *Store) File() *falloc.File

File returns the underlying falloc.File of 's'.

func (*Store) Get

func (s *Store) Get(handle falloc.Handle) (b []byte, err error)

Get gets the data associated with handle. It returns the data and an error, if any.

func (*Store) Lock

func (s *Store) Lock()

Lock locks 's' for writing. If the lock is already locked for reading or writing, Lock blocks until the lock is available. To ensure that the lock eventually becomes available, a blocked Lock call excludes new readers from acquiring the lock.

func (*Store) LockedDelete

func (s *Store) LockedDelete(handle falloc.Handle) (err error)

LockedDelete wraps Delete in a Lock/Unlock pair.

func (*Store) LockedGet

func (s *Store) LockedGet(handle falloc.Handle) (b []byte, err error)

LockedGet wraps Get in a RLock/RUnlock pair.

func (*Store) LockedNew

func (s *Store) LockedNew(b []byte) (handle falloc.Handle, err error)

LockedNew wraps New in a Lock/Unlock pair.

func (*Store) LockedSet

func (s *Store) LockedSet(handle falloc.Handle, b []byte) (err error)

LockedSet wraps Set in a Lock/Unlock pair.

func (*Store) New

func (s *Store) New(b []byte) (handle falloc.Handle, err error)

New associates data with a new handle. It returns the handle and an error, if any.

func (*Store) RLock

func (s *Store) RLock()

RLock locks 's' for reading. If the lock is already locked for writing or there is a writer already waiting to release the lock, RLock blocks until the writer has released the lock.

func (*Store) RUnlock

func (s *Store) RUnlock()

RUnlock undoes a single RLock call; it does not affect other simultaneous readers. It's a run-time error if 's' is not locked for reading on entry to RUnlock.

func (*Store) Root

func (s *Store) Root() falloc.Handle

Root returns the handle of the DB root (top level directory, ...).

func (*Store) Set

func (s *Store) Set(handle falloc.Handle, b []byte) (err error)

Set associates data with an existing handle. It returns an error, if any.

func (*Store) Unlock

func (s *Store) Unlock()

Unlock unlocks 's' for writing. It's a run-time error if 's' is not locked for writing on entry to Unlock.

As with Mutexes, a locked RWMutex is not associated with a particular goroutine. One goroutine may RLock (Lock) 's' and then arrange for another goroutine to RUnlock (Unlock) it.

Jump to

Keyboard shortcuts

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