blox

package module
v0.0.0-...-0ae6773 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2017 License: MPL-2.0 Imports: 16 Imported by: 2 modules, 3 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

blox Build Status

A Content-Addressable storage system

Command line hash verification

Example:

    # Verify data block
    echo -n -e '\x01' | cat - assembler.go | shasum -a 256 -b

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Assembler

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

Assembler assembles all blocks in a root block

func NewAssembler

func NewAssembler(dev BlockDevice, numRoutines int) *Assembler

NewAssembler inits a new assembler backed by the BlockDevice. It launches numRoutines assemblers to retreive and process blocks.

func (*Assembler) Assemble

func (asm *Assembler) Assemble(wr io.Writer) error

Assemble begins to retreive all blocks in the root and write then to the writer. Sequence order is maintained

func (*Assembler) Runtime

func (asm *Assembler) Runtime() time.Duration

Runtime returns the time taken to assemble the root block

func (*Assembler) SetRoot

func (asm *Assembler) SetRoot(id []byte) (*block.IndexBlock, error)

SetRoot retreives the block associated to the id. This is used to retreive complete indexes ar trees

type BlockDevice

type BlockDevice interface {
	Hasher() func() hash.Hash
	SetBlock(block.Block) ([]byte, error)
	GetBlock(id []byte) (block.Block, error)
	RemoveBlock(id []byte) error
	BlockExists(id []byte) (bool, error)
	Stats() *device.Stats
}

BlockDevice implements a local block storage interface. It abstracts the index, tree and data block operations.

type Blox

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

Blox is used to read and write data streams to a block device

func NewBlox

func NewBlox(dev BlockDevice) *Blox

NewBlox inits a new Blox instance with a block device.

func (*Blox) ReadIndex

func (blox *Blox) ReadIndex(id []byte, wr io.Writer, parallel int) error

ReadIndex reads the index id and writes the block data to the writer

func (*Blox) WriteIndex

func (blox *Blox) WriteIndex(rd io.ReadCloser, parallel int) (idx *block.IndexBlock, err error)

WriteIndex reads from the reader and writes to blox storage

type Header [headerSize]byte

Header is an arbitrary header for future purposes.

type LocalNetTranport

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

LocalNetTranport is an interface to interact with blocks locally and remotely. It selects between making a remote vs a local call based on the given host

func NewLocalNetTranport

func NewLocalNetTranport(host string, remote Transport) *LocalNetTranport

NewLocalNetTranport creates a new instance using the provided store and transport. It registers the store with the transport. The transport is started once the local BlockDevice has been registered.

func (*LocalNetTranport) BlockExists

func (trans *LocalNetTranport) BlockExists(host string, id []byte) (bool, error)

BlockExists calls BlockExists on a local or remote host

func (*LocalNetTranport) GetBlock

func (trans *LocalNetTranport) GetBlock(host string, id []byte) (block.Block, error)

GetBlock calls GetBlock on a local or remote host

func (*LocalNetTranport) Register

func (trans *LocalNetTranport) Register(local BlockDevice)

Register registers the store locally as well as with the network transport

func (*LocalNetTranport) RemoveBlock

func (trans *LocalNetTranport) RemoveBlock(host string, id []byte) error

RemoveBlock calls RemoveBlock on a local or remote host

func (*LocalNetTranport) SetBlock

func (trans *LocalNetTranport) SetBlock(host string, blk block.Block) ([]byte, error)

SetBlock calls a SetBlock on a local or remote host

func (*LocalNetTranport) Shutdown

func (trans *LocalNetTranport) Shutdown() error

Shutdown shuts the remote network transport down

func (*LocalNetTranport) Start

func (trans *LocalNetTranport) Start(ln *net.TCPListener) error

Start starts the the remote transport

type NetBlock

type NetBlock struct {
	*block.StreamedBlock
	// contains filtered or unexported fields
}

NetBlock is network block backed by the network connection. It primarily is used to return the connection back to the pool

func (*NetBlock) Close

func (blk *NetBlock) Close() error

Close returns the connection to the pool. If there was an error closing the underlying StreamedBlock the connection is closed. This is used for a network GetBlock request

type NetClient

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

NetClient is a network client to perform block operations remotely

func NewNetClient

func NewNetClient(opt NetClientOptions) *NetClient

NewNetClient inits a new client transport with the given connection pool, connection reap interval and hash size of ids

func (*NetClient) BlockExists

func (trans *NetClient) BlockExists(host string, id []byte) (bool, error)

BlockExists returns true if the block exists on a remote host

func (*NetClient) GetBlock

func (trans *NetClient) GetBlock(host string, id []byte) (block.Block, error)

GetBlock makes a GetBlock request to the remote host.

func (*NetClient) RemoveBlock

func (trans *NetClient) RemoveBlock(host string, id []byte) error

RemoveBlock makes a RemoveBlock call to the remote host.

func (*NetClient) SetBlock

func (trans *NetClient) SetBlock(host string, blk block.Block) ([]byte, error)

SetBlock makes a SetBlock call on the remote host.

func (*NetClient) Shutdown

func (trans *NetClient) Shutdown()

Shutdown closes all connections in the pool. Connections in flight will be closed when they are returned to the pool.

type NetClientOptions

type NetClientOptions struct {
	Timeout      time.Duration
	MaxIdle      time.Duration
	ReapInterval time.Duration
	Hasher       func() hash.Hash
}

NetClientOptions are options available when using the network client

func DefaultNetClientOptions

func DefaultNetClientOptions(hasher func() hash.Hash) NetClientOptions

DefaultNetClientOptions returns a set of sane defaults. It takes the hash size as input

type NetDevice

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

NetDevice is a network BlockDevice. It allows to make direct block operations on a single remote device.

func NewNetDevice

func NewNetDevice(remote string, opts NetClientOptions) *NetDevice

NewNetDevice inits a new network device connected to the provided single remote. The provided options are used to establish the connection

func (*NetDevice) BlockExists

func (dev *NetDevice) BlockExists(id []byte) (bool, error)

BlockExists returns if the block exists on the remote host

func (*NetDevice) Close

func (dev *NetDevice) Close() error

Close shutdowns the underlying network transport

func (*NetDevice) GetBlock

func (dev *NetDevice) GetBlock(id []byte) (block.Block, error)

GetBlock gets a block from the device

func (*NetDevice) Hasher

func (dev *NetDevice) Hasher() func() hash.Hash

Hasher returns the hash function generator for hash ids for the device

func (*NetDevice) RemoveBlock

func (dev *NetDevice) RemoveBlock(id []byte) error

RemoveBlock submits a request to remove a block on the device

func (*NetDevice) SetBlock

func (dev *NetDevice) SetBlock(blk block.Block) ([]byte, error)

SetBlock writes the block to the device

type NetTransport

type NetTransport struct {
	// Client transport
	*NetClient
	// contains filtered or unexported fields
}

NetTransport is the network transport for block operations

func NewNetTransport

func NewNetTransport(opts NetClientOptions) *NetTransport

NewNetTransport initializes a new network transport for the store

func (*NetTransport) Register

func (trans *NetTransport) Register(dev BlockDevice)

Register registers a BlockDevice with the transport. This must be called before a call to Start is made

func (*NetTransport) Shutdown

func (trans *NetTransport) Shutdown() error

Shutdown issues a shutdown of the transport. It stops taking new incoming connections

func (*NetTransport) Start

func (trans *NetTransport) Start(ln *net.TCPListener) error

Start checks for a block device registration and starts a server to service incoming requests. Register must be called before starting the transport. Register and Start are not thread safe

type StreamSharder

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

StreamSharder takes a stream and shards it by the given block size. It produces an index block of the stream

func NewStreamSharder

func NewStreamSharder(dev BlockDevice, numRoutines int) *StreamSharder

NewStreamSharder creates a new sharder using the block device as storage. It launches numRoutines to write blocks in parallel

func (*StreamSharder) IndexBlock

func (sh *StreamSharder) IndexBlock() *block.IndexBlock

IndexBlock returns the index block os the shard stream

func (*StreamSharder) Runtime

func (sh *StreamSharder) Runtime() time.Duration

Runtime returns the time take to shard the input stream

func (*StreamSharder) SetBlockSize

func (sh *StreamSharder) SetBlockSize(blockSize uint64)

SetBlockSize sets the block size for the sharder. This should be called before Shard is called in order to take affect

func (*StreamSharder) Shard

func (sh *StreamSharder) Shard(rd io.ReadCloser) error

Shard starts sharding a given stream. It returns an IndexBlock or an error

type Transport

type Transport interface {
	GetBlock(host string, id []byte) (block.Block, error)
	SetBlock(host string, blk block.Block) ([]byte, error)
	BlockExists(host string, id []byte) (bool, error)
	RemoveBlock(host string, id []byte) error
	Register(store BlockDevice)
	Start(ln *net.TCPListener) error
	Shutdown() error
}

Transport is the transport interface to access blocks. This is used to abstract and combine local and remote

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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