zerodisk

package module
v0.0.0-...-837f88b Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2017 License: Apache-2.0 Imports: 8 Imported by: 0

README

Zero-OS 0-Disk

GoDoc Build Status Sourcegraph

This repository implements the components required for supporting block storage in Zero-OS nodes.

The Zero-OS block storage components allow you to create and use block devices (vdisks) from within virtual machines hosted on a Zero-OS node.

0-Disk overview

A vdisk can be deduped, persistent, redundant and depending on the underlying storage, have different speed characteristics.

Components:

  • NBD Server
    • A network block device (NBD) server to expose the vdisks to virtual machines
  • TLOG Server/Client
    • A transaction log server and client to record block changes
  • zeroctl
    • A command line tool to manage vdisks

Make sure to have Golang version 1.8 or above installed.

More

All documentation is in the /docs directory, including a table of contents and a glossary of terminology used in this project.

All code is also documented, which can be found at godoc.

In Getting Started with NBD Server you find the recommended path to quickly get up and running.

Documentation

Index

Examples

Constants

View Source
const (
	//HashSize is the length of a hash in bytes
	HashSize = 32
)

Variables

View Source
var (
	// CurrentVersion represents the current global
	// version of the zerodisk modules
	CurrentVersion = NewVersion(1, 1, 0, versionLabel("beta-1"))
	// NilVersion represents the Nil Version.
	NilVersion = Version{}
	// CommitHash represents the Git commit hash at built time
	CommitHash string
	// BuildDate represents the date when this tool suite was built
	BuildDate string

	// DefaultVersion is the default version that can be assumed,
	// when a version is empty.
	DefaultVersion = NewVersion(1, 1, 0, nil)
)
View Source
var (
	//NilHash is a hash with only '0'bytes
	NilHash = NewHash()
)

Functions

func LogVersion

func LogVersion()

LogVersion prints the version at log level info meant to log the version at startup of a server

func PrintVersion

func PrintVersion()

PrintVersion prints the current version

Types

type Hash

type Hash []byte

Hash is just a bytearray of size HashSize

func HashBytes

func HashBytes(data []byte) Hash

HashBytes takes a byte slice and returns a hashed version of it.

Example
// given we have two sets of data ...
dataA := []byte("data to hash")
dataB := []byte("other data to hash")

// we can obtain obtain hashes
hexA := zerodisk.HashBytes(dataA)
printHex(hexA)

hexB := zerodisk.HashBytes(dataB)
printHex(hexB)

// we can compare hashes
sameHash := hexA.Equals(hexA)
fmt.Printf("it is %v that hashes are equal\n", sameHash)

sameHash = hexA.Equals(hexB)
fmt.Printf("it is %v that hashes are equal\n", sameHash)
Output:
ae1c89d781f63c4dd6c8ec4703b711bed45966af278446749dbe0eed34eaedf3
4154c68e4df38451a009232697d3da08cbc02aa411bb1e03f1006aa046a84bd4
it is true that hashes are equal
it is false that hashes are equal

func NewHash

func NewHash() (hash Hash)

NewHash initializes a new empty hash

func (Hash) Bytes

func (h Hash) Bytes() []byte

Bytes returns the hash as a slice of bytes

func (Hash) Equals

func (h Hash) Equals(compareTo Hash) bool

Equals returns true if two hashes are the same

type Hasher

type Hasher interface {
	HashBytes([]byte) Hash
}

Hasher is the crypto hasher interface used, for all zerodisk crypto-hash purposes, where we want to reuse a hasher for some reason.

func NewHasher

func NewHasher() (Hasher, error)

NewHasher returns a new instance of the default hasher used in 0-Disk, using the given key.

Example
// given we have data ...
data := []byte("data to hash")

// we can define a new instance of default hasher
hasher, err := zerodisk.NewHasher()
panicOnError(err)

// hasher is used to hash the data
h := hasher.HashBytes(data)
printHex(h)
Output:
ae1c89d781f63c4dd6c8ec4703b711bed45966af278446749dbe0eed34eaedf3

func NewKeyedHasher

func NewKeyedHasher(key []byte) (Hasher, error)

NewKeyedHasher returns a new instance of the default keyed hasher used in 0-Disk, using the given key.

Example
// given we have data and key ...
data := []byte("data to hash")
key := []byte("key")

// we can define a new instance of default keyed hasher
hasher, err := zerodisk.NewKeyedHasher(key)
panicOnError(err)

// hasher is used to hash the data
h := hasher.HashBytes(data)
printHex(h)
Output:
5e09ed568017f03f66d6cca8c37272d0c55be86e9c27cf459721037c8fc3b5bb

type Version

type Version struct {
	Number VersionNumber `valid:"required"`
	Label  *VersionLabel `valid:"optional"`
}

Version defines the version information, used by zerodisk services.

func NewVersion

func NewVersion(major, minor, patch uint8, label *VersionLabel) Version

NewVersion creates a new version

Example
// we can define a new version of the zerodisk modules
label := zerodisk.VersionLabel{'b', 'e', 't', 'a', '-', '2'}
ver := zerodisk.NewVersion(2, 3, 4, &label)

fmt.Println(ver)
Output:
2.3.4-beta-2

func VersionFromString

func VersionFromString(ver string) (Version, error)

VersionFromString returns a Version object from the string representation

Example
v, err := zerodisk.VersionFromString("1.2.3-alpha")
if err != nil {
	panic(err)
}

fmt.Println(v.Number.Major())
fmt.Println(v.Number.Minor())
fmt.Println(v.Number.Patch())
fmt.Println(v.Label)
Output:
1
2
3
alpha

func VersionFromUInt32

func VersionFromUInt32(v uint32) Version

VersionFromUInt32 creates a version from a given uint32 number.

func (Version) Compare

func (v Version) Compare(other Version) int

Compare returns an integer comparing this version with another version. { lt=-1 ; eq=0 ; gt=1 }

Example
// given we have several versions of the zerodisk modules
versA := zerodisk.NewVersion(2, 3, 4, nil)
versB := zerodisk.NewVersion(2, 3, 4, nil)
versC := zerodisk.NewVersion(1, 1, 0, nil)

// we can compare versions
diff := versA.Compare(versB)
fmt.Println(diff)

diff = versB.Compare(versC)
fmt.Println(diff)

diff = versC.Compare(versA)
fmt.Println(diff)
Output:
0
1
-1

func (Version) MarshalText

func (v Version) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.MarshalText

func (Version) String

func (v Version) String() string

String returns the string version of this Version.

func (Version) UInt32

func (v Version) UInt32() uint32

UInt32 returns the integral version of this Version.

func (*Version) UnmarshalText

func (v *Version) UnmarshalText(b []byte) error

UnmarshalText implements encoding.TextUnmarshaler.UnmarshalText

type VersionLabel

type VersionLabel [8]byte

VersionLabel defines an optional version extension, used by zerodisk services.

func (*VersionLabel) String

func (l *VersionLabel) String() string

String returns the string version of this VersionLabel.

type VersionNumber

type VersionNumber uint32

VersionNumber defines the semantic version number, used by zerodisk services.

func (VersionNumber) Major

func (n VersionNumber) Major() uint8

Major returns the Major version of this version number.

func (VersionNumber) Minor

func (n VersionNumber) Minor() uint8

Minor returns the Minor version of this version number.

func (VersionNumber) Patch

func (n VersionNumber) Patch() uint8

Patch returns the Patch version of this version number.

Directories

Path Synopsis
Package config defines a package used for managing the configuration of 0-Disk services
Package config defines a package used for managing the configuration of 0-Disk services
docs
Package errors defines a package used for error handling in 0-Disk.
Package errors defines a package used for error handling in 0-Disk.
Package log defines a complete logging API and is to be used for all 0-Disk info/error logging purposes.
Package log defines a complete logging API and is to be used for all 0-Disk info/error logging purposes.
nbd
gonbdserver command
nbdserver command
Package redisstub is a minimal package providing redis-related (in-memory) implementations meant for testing and dev purposes only.
Package redisstub is a minimal package providing redis-related (in-memory) implementations meant for testing and dev purposes only.
tlogserver command
tools
cmd

Jump to

Keyboard shortcuts

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