sbs

package
v0.0.0-...-a9890c3 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2020 License: MIT Imports: 39 Imported by: 0

Documentation

Index

Constants

View Source
const (
	//OpWrite write block
	OpWrite StoreCommandOp = iota
	//OpZeros replace block with zeros
	OpZeros
	//OpTrim _may_ be discarded
	OpTrim
	//OpFlush asked to persist all data
	OpFlush

	//BlockSize block size per raft log
	BlockSize = 16 * 1 << 10 //16KB
	//BlocksPerFile maximum number of blocks that should be in a file
	BlocksPerFile = 100 * 1 << 20 / BlockSize //100MB files

	//VolDescSizeMultiplier is the conversion factor for the volume description to bytes
	VolDescSizeMultiplier = 1 << 30 //volume definition size is in GB
)
View Source
const (
	NBDCMDRead = iota
	NBDCMDWrite
	NBDCMDDisc
	NBDCMDFlush
	NBDCMDTrim
	NBDCMDCache
	NBDCMDWriteZeroes
	NBDCMDBlockStatus
)

NBD commands

View Source
const (
	NBDCMDFlagFUA = uint16(1 << iota)
	NBDCMDFlagMayTrim
	NBDCMDFlagDF
)

NBD command flags

View Source
const (
	NBDFLAGHasFlags = uint16(1 << iota)
	NBDFLAGReadOnly
	NBDFLAGSendFlush
	NBDFLAGSendFUA
	NBDFLAGRotational
	NBDFLAGSendTrim
	NBDFLAGSendWriteZeroes
	NBDFLAGSendDF
	NBDFLAGMultiCon
	NBDFLAGSendResize
	NBDFLAGSendCache
	NBDFLAGFastZero
)

NBD negotiation flags

View Source
const (
	NBDMAGIC                = 0x4e42444d41474943
	NBDMAGICRequest         = 0x25609513
	NBDMAGICReply           = 0x67446698
	NBDMAGICCliserv         = 0x00420281861253
	NBDMAGICOpts            = 0x49484156454F5054
	NBDMAGICRep             = 0x3e889045565a9
	NBDMAGICStructuredReply = 0x668e33ef

	// NBD default port
	NBDDefaultPort = 10809
)

NBD magic numbers

View Source
const (
	NBDOPTExportName = iota + 1
	NBDOPTAbort
	NBDOPTList
	NBDOPTPeekExport
	NBDOPTStartTLS
	NBDOPTInfo
	NBDOPTGo
	NBDOPTStructuredReply

	// NBD option reply types
	NBDREPAck              = uint32(1)
	NBDREPServer           = uint32(2)
	NBDREPInfo             = uint32(3)
	NBDREPFlagError        = uint32(1 << 31)
	NBDREPErrUnsup         = uint32(1 | NBDREPFlagError)
	NBDREPErrPolicy        = uint32(2 | NBDREPFlagError)
	NBDREPErrInvalid       = uint32(3 | NBDREPFlagError)
	NBDREPErrPlatform      = uint32(4 | NBDREPFlagError)
	NBDREPErrTLSReqd       = uint32(5 | NBDREPFlagError)
	NBDREPErrUnknown       = uint32(6 | NBDREPFlagError)
	NBDREPErrShutdown      = uint32(7 | NBDREPFlagError)
	NBDREPErrBlockSizeReqd = uint32(8 | NBDREPFlagError)

	// NBD reply flags
	NBDReplyFlagDone = 1 << 0
)

NBD options

View Source
const (
	NBDREPLYTYPENone = iota
	NBDREPLYTYPEError
	NBDREPLYTYPEErrorOffset
	NBDREPLYTYPEOffsetData
	NBDREPLYTYPEOffsetHole
)

NBD reply types

View Source
const (
	NBDFLAGFixedNewstyle = 1 << iota
	NBDFLAGNoZeroes
)

NBD hanshake flags

View Source
const (
	NBDFLAGCFixedNewstyle = 1 << iota
	NBDFLAGCNoZeroes

	// NBD errors
	NBDEPERM     = 1
	NBDEIO       = 5
	NBDENOMEM    = 12
	NBDEINVAL    = 22
	NBDENOSPC    = 28
	NBDEOVERFLOW = 75
)

NBD client flags

View Source
const (
	NBDINFOExport = iota
	NBDINFOName
	NBDINFODescription
	NBDINFOBlockSize
)

NBD info types

View Source
const (
	//DefaultListenPort main peer listening port
	DefaultListenPort = 32546
)

Variables

This section is empty.

Functions

func NewRaft

func NewRaft(s *Server, bs *BlockStore, ls raft.LogStore, trans raft.Transport) (*raft.Raft, error)

NewRaft creats a new raft instance

Types

type BlockStore

type BlockStore struct {
	BaseDir string
	// contains filtered or unexported fields
}

BlockStore block store backing e.g. local disks

func NewBlockStore

func NewBlockStore(peerID string, d *volumesAPI.Volume, baseDir string, l *logrus.Logger) *BlockStore

NewBlockStore provides a new store for volumes

func (*BlockStore) Apply

func (b *BlockStore) Apply(l *raft.Log) interface{}

Apply log is invoked once a log entry is committed and commits the change to the block store

func (*BlockStore) Close

func (b *BlockStore) Close()

Close closes all open blocks

func (*BlockStore) ReadAt

func (b *BlockStore) ReadAt(p []byte, offset uint64) (int, error)

ReadAt allows for the block store to be read from block sets

func (*BlockStore) Restore

func (b *BlockStore) Restore(r io.ReadCloser) error

Restore is used to restore the block store data from a snapshot

func (*BlockStore) SizeOnDisk

func (b *BlockStore) SizeOnDisk() (uint64, error)

SizeOnDisk goes through each block and queries the underlying filesystem for it's current size

func (*BlockStore) Snapshot

func (b *BlockStore) Snapshot() (raft.FSMSnapshot, error)

Snapshot is used to support log compaction

type BlockStoreStats

type BlockStoreStats struct {
	Available uint64
	Used      uint64
	Allocated uint64
}

BlockStoreStats provides OS status on the block store/volume

type LogStore

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

LogStore provides a way for raft to store logs

func NewLogStore

func NewLogStore(id string, db *badger.DB) *LogStore

NewLogStore creates a new log store used in raft

func (*LogStore) DeleteRange

func (rls *LogStore) DeleteRange(min, max uint64) error

DeleteRange deletes a range of log entries. The range is inclusive.

func (*LogStore) FirstIndex

func (rls *LogStore) FirstIndex() (uint64, error)

FirstIndex returns the first index written. 0 for no entries.

func (*LogStore) GetLog

func (rls *LogStore) GetLog(index uint64, l *raft.Log) error

GetLog gets a log entry at a given index.

func (*LogStore) LastIndex

func (rls *LogStore) LastIndex() (uint64, error)

LastIndex returns the last index written. 0 for no entries.

func (*LogStore) StoreLog

func (rls *LogStore) StoreLog(log *raft.Log) error

StoreLog stores a log entry.

func (*LogStore) StoreLogs

func (rls *LogStore) StoreLogs(logs []*raft.Log) error

StoreLogs stores multiple log entries.

type NBDServer

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

NBDServer provides Linux NBD connectivity to a SBS cluster

func NewNBDServer

func NewNBDServer(s *Server, port int, c control.Controller) *NBDServer

NewNBDServer provisions a new NBD listening server attached to the volume server

func (*NBDServer) Attach

func (s *NBDServer) Attach(vol *Volume, peers []*Peer) error

Attach adds a volume as a NBD export

func (*NBDServer) Listen

func (s *NBDServer) Listen() error

Listen starts listening for and accepts new connections

func (*NBDServer) Shutdown

func (s *NBDServer) Shutdown()

Shutdown terminates the NBD listener

type OutOfBounds

type OutOfBounds uint64

OutOfBounds when the given offset+data len is greater than allocated volume size

func (OutOfBounds) Error

func (oob OutOfBounds) Error() string

type Peer

type Peer struct {
	PeerID     string
	RemoteAddr net.Addr
	Status     PeerStatus

	Channels map[string]*streamChannel
	// contains filtered or unexported fields
}

Peer remote volume peer

func (*Peer) Conn

func (p *Peer) Conn() quic.Session

Conn remote connection to the peer

func (*Peer) ID

func (p *Peer) ID() string

ID peer ID

type PeerStatus

type PeerStatus uint32

PeerStatus connection status of peer

const (

	//PeerStatusConnected Peer is successfully connected
	PeerStatusConnected PeerStatus = iota

	//PeerStatusReconnecting peer is current being reconnected
	PeerStatusReconnecting
)

type RaftTransport

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

RaftTransport allows for raft rpcs via the main p2p comms loosely based around raft.NetworkTransport

func NewRaftTransport

func NewRaftTransport(s *Server, volumeID string) *RaftTransport

NewRaftTransport creates a new transport compatible with raft

func (*RaftTransport) AppendEntries

AppendEntries sends the appropriate RPC to the target node.

func (*RaftTransport) AppendEntriesPipeline

func (r *RaftTransport) AppendEntriesPipeline(id raft.ServerID, target raft.ServerAddress) (raft.AppendPipeline, error)

AppendEntriesPipeline returns an interface that can be used to pipeline AppendEntries requests.

func (*RaftTransport) Consumer

func (r *RaftTransport) Consumer() <-chan raft.RPC

Consumer returns a channel that can be used to consume and respond to RPC requests.

func (*RaftTransport) DecodePeer

func (r *RaftTransport) DecodePeer(p []byte) raft.ServerAddress

DecodePeer is used to deserialize a peer's address.

func (*RaftTransport) EncodePeer

func (r *RaftTransport) EncodePeer(id raft.ServerID, addr raft.ServerAddress) []byte

EncodePeer is used to serialize a peer's address.

func (*RaftTransport) HandleCommand

func (r *RaftTransport) HandleCommand(s quic.Stream, p *volumesAPI.RaftRPC) error

HandleCommand handles a remote Raft RPC command

func (*RaftTransport) InstallSnapshot

InstallSnapshot is used to push a snapshot down to a follower. The data is read from the ReadCloser and streamed to the client.

func (*RaftTransport) LocalAddr

func (r *RaftTransport) LocalAddr() raft.ServerAddress

LocalAddr is used to return our local address to distinguish from our peers.

func (*RaftTransport) RequestVote

RequestVote sends the appropriate RPC to the target node.

func (*RaftTransport) SetHeartbeatHandler

func (r *RaftTransport) SetHeartbeatHandler(cb func(rpc raft.RPC))

SetHeartbeatHandler is used to setup a heartbeat handler as a fast-pass. This is to avoid head-of-line blocking from disk IO.

func (*RaftTransport) TimeoutNow

TimeoutNow is used to start a leadership transfer to the target node.

type Server

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

Server Simple Block Storage server instance

func NewServer

func NewServer() *Server

NewServer constructs a new SBS server

func NewServerWithPort

func NewServerWithPort(port int) *Server

NewServerWithPort constructs a new SBS server on a specific listening port

func (*Server) AddPeer

func (s *Server) AddPeer(peerID string, remoteAddr *net.UDPAddr) error

AddPeer connects with a remote peer

func (*Server) AddPeerWithRetry

func (s *Server) AddPeerWithRetry(peerID string, remoteAddr *net.UDPAddr, retryCount int) error

AddPeerWithRetry tries to connect with a peer for given number of times

func (*Server) AddVolume

func (s *Server) AddVolume(d *volumesAPI.Volume, placementPeers []string) error

AddVolume attaches a volume to the server

func (*Server) BlockStoreStats

func (s *Server) BlockStoreStats() (*BlockStoreStats, error)

BlockStoreStats provides status for the block store overall

func (*Server) BlockVolumeStats

func (s *Server) BlockVolumeStats(vol *Volume) (*BlockStoreStats, error)

BlockVolumeStats provides status for specific volumes

func (*Server) BootPeers

func (s *Server) BootPeers(peerInfo []string)

BootPeers bootstraps a list of peers in the format peerID@addr:port

func (*Server) Export

func (s *Server) Export(volume string)

Export exposes a volume directly via NBD without attachment

func (*Server) GetPeer

func (s *Server) GetPeer(id string) *Peer

GetPeer sends back a peer given it's ID. If the peer does not exist, it will try to discover it via the controller

func (*Server) GetPeers

func (s *Server) GetPeers(ids []string) []*Peer

GetPeers discovers and returns a set of peers

func (*Server) Listen

func (s *Server) Listen() error

Listen starts listening for remote connections

func (*Server) LocalAddr

func (s *Server) LocalAddr() *net.UDPAddr

LocalAddr provides the server listening address

func (*Server) PeerID

func (s *Server) PeerID() string

PeerID returns the current peer ID of the server

func (*Server) PeerIDs

func (s *Server) PeerIDs() []string

PeerIDs provides a list of peer IDs

func (*Server) SendMsg

func (s *Server) SendMsg(stream quic.Stream, rpc proto.Message) error

SendMsg send a protobuf msg into a stream

func (*Server) SendReqViaChannel

func (s *Server) SendReqViaChannel(p *Peer, channel string, m proto.Message) (proto.Message, error)

SendReqViaChannel sends via a channel/persistent stream if the channel doesn't exist, it will be created

func (*Server) SetController

func (s *Server) SetController(cont control.Controller)

SetController provides the server with a controller for volume assignments

func (*Server) SetPeerID

func (s *Server) SetPeerID(id string)

SetPeerID overwrites the local peer id

func (*Server) Shutdown

func (s *Server) Shutdown()

Shutdown gracefully

func (*Server) Volume

func (s *Server) Volume(id string) *Volume

Volume returns the volume associated with the volume ID

type StoreCommand

type StoreCommand struct {
	Op     StoreCommandOp `json:"op"`
	Offset uint64         `json:"offset"`
	Length uint32         `json:"length"`
	Data   []byte         `json:"data,omitempty"`
}

StoreCommand block store mutation command

func (*StoreCommand) Decode

func (bsc *StoreCommand) Decode(p []byte) error

Decode decodes the block command from transmission

func (*StoreCommand) Encode

func (bsc *StoreCommand) Encode() ([]byte, error)

Encode encodes the block command to binary formats transmission

type StoreCommandOp

type StoreCommandOp uint16

StoreCommandOp block command operation

type Volume

type Volume struct {
	PlacementPeers map[string]struct{}
	Blocks         *BlockStore
	Raft           *raft.Raft
	Transport      *RaftTransport
	// contains filtered or unexported fields
}

Volume instance

func NewVolume

func NewVolume(s *Server, d *volumesAPI.Volume, peers []string) (*Volume, error)

NewVolume constructs a raft-backed distributed volume

func (*Volume) AddPeer

func (v *Volume) AddPeer(p *Peer) error

AddPeer adds a placment peer where the volume is expected to reside

func (*Volume) ID

func (v *Volume) ID() string

ID of the volume

func (*Volume) RemovePeer

func (v *Volume) RemovePeer(p *Peer) error

RemovePeer adds a placment peer where the volume is expected to reside

func (*Volume) Shutdown

func (v *Volume) Shutdown() error

Shutdown closes the volume

func (*Volume) Size

func (v *Volume) Size() int64

Size of the volume in GB

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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