layerfs

package
v0.0.0-...-8b3ab32 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2017 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	//PathSeparator is used to join path into database keys. Bolt stores values in a bucket in byte-order, choosing a unicode code point all the way at the end allows us to make assumptions when we use a cursor to iterate over directory entries
	PathSeparator = "\uFFFF"

	//PathPrintSeparator is used instead of the character above to print a path
	PathPrintSeparator = "/"

	//RootBasename is returned when the root is asked for its basename
	RootBasename = PathSeparator
)

Variables

View Source
var (
	//LayerBucketName is the name of the bucket that will hold the layers
	LayerBucketName = []byte("Layer")
	//NodeBucketName is the name of the bucket that will hold the nodes
	NodeBucketName = []byte("Node")
	//ChunkBucketName is the name of the bucket that will hold the chunks
	ChunkBucketName = []byte("Chunk")
)
View Source
var (
	//ErrSerialize is returned when we couldnt serialize
	ErrSerialize = errors.New("failed to serialize")

	//ErrDeserialize is returned when we couldnt deserialize
	ErrDeserialize = errors.New("failed to deserialize")
)
View Source
var (
	//ChunkOffsetSeparator separates a node key from a chunk offset
	ChunkOffsetSeparator = ":"
)
View Source
var (
	// ErrInvalidPath is returned when no valid filename can be created from path components
	ErrInvalidPath = errors.New("invalid path components")
)
View Source
var (
	//Root is a path with zero components: len(Root) = 0
	Root = P{}
)
View Source
var (
	//ZeroKey is a empty key
	ZeroKey = K{}
)

Functions

This section is empty.

Types

type BranchWriter

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

BranchWriter acts as a handle for modifying a branch Node in our hierarchy. Upon initiating, the key of the node will be determined although an actual value for this key will only be written upon committing. Operations on the node can span different database transactions.

func NewBranchWriter

func NewBranchWriter(k []byte, tx *bolt.Tx, mChildren map[string][]byte) (*BranchWriter, error)

NewBranchWriter allow writing a (new) branch node while merging children 'mChildren' and chunks 'mChunks' with the existing node at key 'nodeK'.

When the node's key 'k' is nil a new node is instead created with just the provided children 'mChildren' and chunks 'mChunks'

When the key of a merged child is a ZeroKey the child acts as a tombstone and is removed from the new node instead.

When the first new chunk is mapped to a lower file offset then existing chunks only chunks positioned lower than the new offset are copied over. If the first merged chunk has an offset of zero we are rewriting the node completely, and if then the first chunk has a zerokey we are truncating the node's content.

func (*BranchWriter) Commit

func (nw *BranchWriter) Commit(tx *bolt.Tx, n *Node) (err error)

Commit the branch node with its, merged children while serialize file information and calculate the final checksum, the size field 'S' and modTime filed 'T' will be set by the commit.

func (*BranchWriter) WriteChild

func (nw *BranchWriter) WriteChild(tx *bolt.Tx, name string, k []byte) error

WriteChild will write a reference to child node at 'k' in the branch node

type K

type K [sha256.Size]byte

K is used as the database key for content addressing

type Layer

type Layer struct {
	Root *Node //the top node
}

A Layer represents a point-in-time snapshot of a node tree with file chunks. The fileystem is always created with a specific "top" layer to which new data can be written.

type LayerFS

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

LayerFS is an userland, append only, deduplicated filesystem build on top of boltdb

func New

func New(layerk K, db *bolt.DB) (fs *LayerFS, err error)

New sets up a new filesystem at the specified layer, if the provided layer is a ZeroKey key, writes will be played in a new layer. If the layer is not the latest layer the filesystem will be read-only, else writes will be added to the top layer

type Node

type Node struct {
	N string      //base name
	T time.Time   //mod time
	S int64       //size
	M os.FileMode //portable mode bits
}

A Node can either contain links to other nodes (a directory) or to opaque content chunks when representing a file. Node implements os.FileInfo. It is stores as a header under the node's key (hash), directly followed by a list of its nested values (other nodes for branches, chunk offsets for a leaf): | Key | Data | Comment | 00000001 : <CHECKSUM>{ ... } #file info, checksum as prefix 00000001/a.txt : 00000002 #to another node 00000001/b.txt : 00000003 #to another node 00000001:0 : 2511E0F94...979AF0F #chunk at file offset 0 00000001:332111 : 2511E0F94...979AF0F #chunk at offset 332111

func (*Node) IsDir

func (n *Node) IsDir() bool

IsDir reports whether m describes a directory. That is, it tests for the ModeDir bit being set in m.

func (*Node) ModTime

func (n *Node) ModTime() time.Time

ModTime holds when the file was last modified

func (*Node) Mode

func (n *Node) Mode() os.FileMode

Mode returns a file's mode and permission bits. The bits have the same definition on all systems, so that information about files can be moved from one system to another portably. Not all bits apply to all systems. The only required bit is ModeDir for directories.

func (*Node) Name

func (n *Node) Name() string

Name of the file

func (*Node) Size

func (n *Node) Size() int64

Size returns the number of bytes in a file

func (*Node) Sys

func (n *Node) Sys() interface{}

Sys returns underlying system values

type P

type P []string

P describes a platform agnostic path on the file system and is stored as a slice of path components

func (P) Base

func (p P) Base() string

Base returns the base component of a path

func (P) Equals

func (p P) Equals(d P) bool

Equals compare paths based on their joined components

func (P) Err

func (p P) Err(op string, err error) *os.PathError

Err allows easy creation of PathErrors

func (P) Parent

func (p P) Parent() P

Parent returns a path that refers to a parent, if the current path is the root the root is still returned

func (P) String

func (p P) String() string

String implements stringer for the Path type that returns something more human friendly that shows familiar forward slashes

func (P) Validate

func (p P) Validate() error

Validate is used to check if a given Path is valid, it returns an ErrInvalidPath if the path is invalid nil otherwise

Jump to

Keyboard shortcuts

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