db

package
v0.0.0-...-330f150 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2016 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package db contains a database abstraction layer.

Index

Constants

View Source
const VolumeIDLen = 64

Variables

View Source
var (
	ErrPeerNotFound      = errors.New("peer not found")
	ErrNoStorageForPeer  = errors.New("no storage offered to peer")
	ErrNoLocationForPeer = errors.New("no network location known for peer")
)
View Source
var (
	ErrSharingKeyNameInvalid = errors.New("invalid sharing key name")
	ErrSharingKeyNotFound    = errors.New("sharing key not found")
	ErrSharingKeyExist       = errors.New("sharing key exists already")
)
View Source
var (
	ErrVolNameInvalid        = errors.New("invalid volume name")
	ErrVolNameNotFound       = errors.New("volume name not found")
	ErrVolNameExist          = errors.New("volume name exists already")
	ErrVolumeIDExist         = errors.New("volume ID exists already")
	ErrVolumeIDNotFound      = errors.New("volume ID not found")
	ErrVolumeEpochWraparound = errors.New("volume epoch wraparound")
)
View Source
var (
	ErrVolumeStorageExist = errors.New("volume storage name exists already")
)

Functions

This section is empty.

Types

type ClockNotFoundError

type ClockNotFoundError struct {
	ParentInode uint64
	Name        string
}

func (*ClockNotFoundError) Error

func (e *ClockNotFoundError) Error() string

type DB

type DB struct {
	*bolt.DB
}

DB provides abstracted access to the Bolt database used by the server.

func Open

func Open(path string, mode os.FileMode, options *bolt.Options) (*DB, error)

func (*DB) Update

func (db *DB) Update(fn func(*Tx) error) error

Update makes changes to the database. There can be only one Update call at a time.

If a lock L is held while calling db.Update, L must never be taken inside a write transaction, at the risk of a deadlock.

func (*DB) View

func (db *DB) View(fn func(*Tx) error) error

type DirEntry

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

func (*DirEntry) Name

func (e *DirEntry) Name() string

Name returns the basename of this directory entry.

name is valid after the transaction.

func (*DirEntry) Unmarshal

func (e *DirEntry) Unmarshal(out *wirefs.Dirent) error

Unmarshal the directory entry to out.

out is valid after the transaction.

type Dirs

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

func (*Dirs) Delete

func (b *Dirs) Delete(parentInode uint64, name string) error

Delete the entry in parent directory with the given name.

Returns fuse.ENOENT if an entry does not exist.

func (*Dirs) Get

func (b *Dirs) Get(parentInode uint64, name string) (*wirefs.Dirent, error)

Get the entry in parent directory with the given name.

Returned value is valid after the transaction.

func (*Dirs) List

func (b *Dirs) List(inode uint64) *DirsCursor

func (*Dirs) Put

func (b *Dirs) Put(parentInode uint64, name string, de *wirefs.Dirent) error

Put an entry in parent directory with the given name.

func (*Dirs) Rename

func (b *Dirs) Rename(parentInode uint64, oldName string, newName string) (*DirEntry, error)

Rename renames an entry in the parent directory from oldName to newName.

Returns the overwritten entry, or nil.

func (*Dirs) Tombstone

func (b *Dirs) Tombstone(parentInode uint64, name string) error

Tombstone marks the entry in parent directory with the given name as removed, but leaves a hint of its existence.

Returns fuse.ENOENT if an entry does not exist.

func (*Dirs) TombstoneCreate

func (b *Dirs) TombstoneCreate(parentInode uint64, name string) error

TombstoneCreate marks the entry in parent directory with the given name as removed, but leaves a hint of its existence. It creates a new entry if one does not exist yet.

type DirsCursor

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

func (*DirsCursor) First

func (c *DirsCursor) First() *DirEntry

func (*DirsCursor) Next

func (c *DirsCursor) Next() *DirEntry

func (*DirsCursor) Seek

func (c *DirsCursor) Seek(name string) *DirEntry

Seek to first name equal to name, or the next one if exact match is not found.

Passing an empty name seeks to the beginning of the directory.

type Peer

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

func (*Peer) ID

func (p *Peer) ID() peer.ID

func (*Peer) Locations

func (p *Peer) Locations() *PeerLocations

func (*Peer) Pub

func (p *Peer) Pub() *peer.PublicKey

func (*Peer) Storage

func (p *Peer) Storage() *PeerStorage

func (*Peer) Volumes

func (p *Peer) Volumes() *PeerVolumes

type PeerLocations

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

func (*PeerLocations) Get

func (p *PeerLocations) Get() (addr string, err error)

Get an address to try, to connect to the peer.

Returned addr is valid after the transaction.

TODO support multiple addresses to attempt, with some idea of preferring recent ones.

func (*PeerLocations) Set

func (p *PeerLocations) Set(addr string) error

Set the network location where the peer can be contacted.

TODO support multiple addresses to attempt, with some idea of preferring recent ones.

type PeerStorage

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

func (*PeerStorage) Allow

func (p *PeerStorage) Allow(backend string) error

func (*PeerStorage) Open

func (p *PeerStorage) Open(opener func(string) (kv.KV, error)) (kv.KV, error)

Open key-value stores as allowed for this peer. Uses the opener function for the actual open action.

If the peer is not allowed to use any storage, returns ErrNoStorageForPeer.

Returned KV is valid after the transaction. Strings passed to the opener function are valid after the transaction.

type PeerVolumes

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

func (*PeerVolumes) Allow

func (p *PeerVolumes) Allow(vol *Volume) error

func (*PeerVolumes) IsAllowed

func (p *PeerVolumes) IsAllowed(vol *Volume) bool

type Peers

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

func (*Peers) Cursor

func (b *Peers) Cursor() *PeersCursor

func (*Peers) Get

func (b *Peers) Get(pub *peer.PublicKey) (*Peer, error)

Get returns a Peer for the given public key.

If the peer does not exist, returns ErrPeerNotFound.

func (*Peers) Make

func (b *Peers) Make(pub *peer.PublicKey) (*Peer, error)

Make returns a Peer for the given public key, adding it if necessary.

type PeersCursor

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

func (*PeersCursor) First

func (c *PeersCursor) First() *Peer

func (*PeersCursor) Next

func (c *PeersCursor) Next() *Peer

type SharingKey

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

func (*SharingKey) Name

func (s *SharingKey) Name() string

Name returns the name of the sharing key.

Returned value is valid after the transaction.

func (*SharingKey) Secret

func (s *SharingKey) Secret(out *[32]byte)

Secret copies the secret key to out.

out is valid after the transaction.

type SharingKeys

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

func (*SharingKeys) Add

func (b *SharingKeys) Add(name string, key *[32]byte) (*SharingKey, error)

Add a sharing key.

If name is invalid, returns ErrSharingKeyNameInvalid.

If a sharing key by that name already exists, returns ErrSharingKeyExist.

func (*SharingKeys) Get

func (b *SharingKeys) Get(name string) (*SharingKey, error)

Get a sharing key.

If the sharing key name is not found, returns ErrSharingKeyNotFound.

type Tx

type Tx struct {
	*bolt.Tx
}

Tx is a database transaction.

Unless otherwise stated, any values returned by methods here (and transitively from their methods) are only valid while the transaction is alive. This does not apply to returned error values.

func (*Tx) Peers

func (tx *Tx) Peers() *Peers

func (*Tx) SharingKeys

func (tx *Tx) SharingKeys() *SharingKeys

func (*Tx) Volumes

func (tx *Tx) Volumes() *Volumes

type Volume

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

func (*Volume) Clock

func (v *Volume) Clock() *VolumeClock

func (*Volume) Conflicts

func (v *Volume) Conflicts() *VolumeConflicts

func (*Volume) Dirs

func (v *Volume) Dirs() *Dirs

Dirs provides a way of accessing the directory entries stored in this volume.

func (*Volume) Epoch

func (v *Volume) Epoch() (clock.Epoch, error)

Epoch returns the current mutation epoch of the volume.

Returned value is valid after the transaction.

func (*Volume) InodeBucket

func (v *Volume) InodeBucket() *bolt.Bucket

InodeBucket returns a bolt bucket for storing inodes in.

func (*Volume) NextEpoch

func (v *Volume) NextEpoch() (clock.Epoch, error)

NextEpoch increments the epoch and returns the new value. The value is only safe to use if the transaction commits.

If epoch wraps around, returns ErrVolumeEpochWraparound. This should be boil-the-oceans rare.

Returned value is valid after the transaction.

func (*Volume) SnapBucket

func (v *Volume) SnapBucket() *bolt.Bucket

SnapBucket returns a bolt bucket for storing snapshots in.

func (*Volume) Storage

func (v *Volume) Storage() *VolumeStorage

func (*Volume) VolumeID

func (v *Volume) VolumeID(out *VolumeID)

VolumeID copies the volume ID to out.

out is valid after the transaction.

type VolumeClock

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

VolumeClock tracks the logical clocks for files and directories stored in the volume.

Logical clocks are kept separate from the directory entries, as they modified at different rates. Specifically, Vector Time Pairs cause modification times to trickle upward in the tree, and keeping the clocks separate allows us to do this as a pure database operation, without coordinating with the active FS Node objects.

func (*VolumeClock) Create

func (vc *VolumeClock) Create(parentInode uint64, name string, now clock.Epoch) (*clock.Clock, error)

func (*VolumeClock) Get

func (vc *VolumeClock) Get(parentInode uint64, name string) (*clock.Clock, error)

func (*VolumeClock) Put

func (vc *VolumeClock) Put(parentInode uint64, name string, c *clock.Clock) error

func (*VolumeClock) Tombstone

func (vc *VolumeClock) Tombstone(parentInode uint64, name string, now clock.Epoch) error

func (*VolumeClock) Update

func (vc *VolumeClock) Update(parentInode uint64, name string, now clock.Epoch) (c *clock.Clock, changed bool, err error)

func (*VolumeClock) UpdateFromChild

func (vc *VolumeClock) UpdateFromChild(parentInode uint64, name string, child *clock.Clock) (changed bool, err error)

func (*VolumeClock) UpdateOrCreate

func (vc *VolumeClock) UpdateOrCreate(parentInode uint64, name string, now clock.Epoch) (c *clock.Clock, changed bool, err error)

type VolumeConflicts

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

VolumeConflicts tracks the alternate versions of directory entries.

func (*VolumeConflicts) Add

func (vc *VolumeConflicts) Add(parentInode uint64, c *clock.Clock, de *wirepeer.Dirent) error

func (*VolumeConflicts) Delete

func (vc *VolumeConflicts) Delete(parentInode uint64, name string, clockBuf []byte) error

func (*VolumeConflicts) Get

func (vc *VolumeConflicts) Get(parentInode uint64, name string, clockBuf []byte) *VolumeConflictsItem

func (*VolumeConflicts) List

func (vc *VolumeConflicts) List(parentInode uint64, name string) *VolumeConflictsCursor

func (*VolumeConflicts) ListAll

func (vc *VolumeConflicts) ListAll(parentInode uint64) *VolumeConflictsCursor

ListAll iterates over all of the conflict entries for this directory.

type VolumeConflictsCursor

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

func (*VolumeConflictsCursor) Delete

func (c *VolumeConflictsCursor) Delete() error

Delete the current item.

func (*VolumeConflictsCursor) First

func (*VolumeConflictsCursor) Next

type VolumeConflictsItem

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

func (*VolumeConflictsItem) Clock

func (item *VolumeConflictsItem) Clock() (*clock.Clock, error)

Clock returns the clock for this item.

Returned value is valid after the transaction.

func (*VolumeConflictsItem) Dirent

func (item *VolumeConflictsItem) Dirent(out *wirepeer.Dirent) error

Dirent returns the directory entry for this item.

out is valid after the transaction.

func (*VolumeConflictsItem) Name

func (item *VolumeConflictsItem) Name() string

Name returns the file name for this item.

This is mostly useful when used with ListAll.

Returned value is valid after the transaction.

type VolumeID

type VolumeID [VolumeIDLen]byte

func (*VolumeID) MarshalBinary

func (v *VolumeID) MarshalBinary() (data []byte, err error)

func (*VolumeID) MarshalText

func (v *VolumeID) MarshalText() ([]byte, error)

func (*VolumeID) Set

func (v *VolumeID) Set(value string) error

func (*VolumeID) String

func (v *VolumeID) String() string

func (*VolumeID) UnmarshalBinary

func (v *VolumeID) UnmarshalBinary(data []byte) error

func (*VolumeID) UnmarshalText

func (v *VolumeID) UnmarshalText(text []byte) error

type VolumeStorage

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

func (*VolumeStorage) Add

func (vs *VolumeStorage) Add(name string, backend string, sharingKey *SharingKey) error

Add a storage backend to be used by the volume.

Active Volume instances are not notified.

If volume has storage by that name already, returns ErrVolumeStorageExist.

func (*VolumeStorage) Cursor

func (vs *VolumeStorage) Cursor() *VolumeStorageCursor

type VolumeStorageCursor

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

func (*VolumeStorageCursor) First

func (*VolumeStorageCursor) Next

type VolumeStorageItem

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

func (*VolumeStorageItem) Backend

func (item *VolumeStorageItem) Backend() (string, error)

Backend returns the storage backend for this item.

Returned value is valid after the transaction.

func (*VolumeStorageItem) SharingKeyName

func (item *VolumeStorageItem) SharingKeyName() (string, error)

SharingKeyName returns the sharing key name for this item.

Returned value is valid after the transaction.

type Volumes

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

func (*Volumes) Add

func (b *Volumes) Add(name string, volID *VolumeID, storage string, sharingKey *SharingKey) (*Volume, error)

Add adds a volume that was created elsewhere to this node.

If the name exists already, returns ErrVolNameExist.

func (*Volumes) Create

func (b *Volumes) Create(name string, storage string, sharingKey *SharingKey) (*Volume, error)

Create a totally new volume, not yet shared with any peers.

If the name exists already, returns ErrVolNameExist.

func (*Volumes) GetByName

func (b *Volumes) GetByName(name string) (*Volume, error)

func (*Volumes) GetByVolumeID

func (b *Volumes) GetByVolumeID(volID *VolumeID) (*Volume, error)

Directories

Path Synopsis
Package wire is a generated protocol buffer package.
Package wire is a generated protocol buffer package.

Jump to

Keyboard shortcuts

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