Documentation ¶
Overview ¶
Torus is a distributed storage system, allowing for the creation and coordination of sharded, replicated files. For more details, see the README at https://github.com/alternative-storage/torus
Index ¶
- Constants
- Variables
- func InitMDS(name string, cfg Config, gmd GlobalMetadata, ringType RingType) error
- func MarshalBlocksetToProto(bs Blockset) ([]*models.BlockLayer, error)
- func MkdirsFor(dir string) error
- func RegisterBlockStore(name string, newFunc NewBlockStoreFunc)
- func RegisterMetadataInit(name string, newFunc InitMDSFunc)
- func RegisterMetadataService(name string, newFunc CreateMetadataServiceFunc)
- func RegisterMetadataWipe(name string, newFunc WipeMDSFunc)
- func RegisterSetRing(name string, newFunc SetRingFunc)
- func SetRing(name string, cfg Config, r Ring) error
- func WipeMDS(name string, cfg Config) error
- type BlockIterator
- type BlockLayer
- type BlockLayerKind
- type BlockLayerSpec
- type BlockRef
- func (b BlockRef) BlockType() BlockType
- func (b BlockRef) HasINode(i INodeRef, t BlockType) bool
- func (b BlockRef) IsZero() bool
- func (b *BlockRef) SetBlockType(t BlockType)
- func (b BlockRef) String() string
- func (b BlockRef) ToBytes() []byte
- func (b BlockRef) ToBytesBuf(buf []byte)
- func (b BlockRef) ToProto() *models.BlockRef
- type BlockStore
- type BlockType
- type Blockset
- type Config
- type CreateMetadataServiceFunc
- type DebugMetadataService
- type File
- func (f *File) Close() error
- func (f *File) Read(b []byte) (n int, err error)
- func (f *File) ReadAt(b []byte, off int64) (n int, ferr error)
- func (f *File) Replaces() uint64
- func (f *File) Seek(offset int64, whence int) (int64, error)
- func (f *File) Size() uint64
- func (f *File) SyncAllWrites() (INodeRef, error)
- func (f *File) SyncBlocks() error
- func (f *File) SyncINode(ctx context.Context) (INodeRef, error)
- func (f *File) Trim(offset, length int64) error
- func (f *File) Truncate(size int64) error
- func (f *File) Write(b []byte) (n int, err error)
- func (f *File) WriteAt(b []byte, off int64) (n int, err error)
- func (f *File) WriteOpen() bool
- type GlobalMetadata
- type INodeID
- type INodeIterator
- type INodeRef
- type INodeStore
- func (b *INodeStore) Close() error
- func (b *INodeStore) DeleteINode(ctx context.Context, i INodeRef) error
- func (b *INodeStore) Flush() error
- func (b *INodeStore) GetINode(ctx context.Context, i INodeRef) (*models.INode, error)
- func (b *INodeStore) INodeIterator() *INodeIterator
- func (b *INodeStore) WriteINode(ctx context.Context, i INodeRef, inode *models.INode) error
- type IndexID
- type InitMDSFunc
- type MetadataKind
- type MetadataService
- type ModifyableRing
- type NewBlockStoreFunc
- type PeerInfoList
- func (pi PeerInfoList) AndNot(b PeerList) PeerInfoList
- func (pi PeerInfoList) GetWeights() map[string]int
- func (pi PeerInfoList) HasUUID(uuid string) bool
- func (pi PeerInfoList) Intersect(b PeerInfoList) PeerInfoList
- func (pi PeerInfoList) PeerList() PeerList
- func (pi PeerInfoList) UUIDAt(uuid string) int
- func (pi PeerInfoList) Union(b PeerInfoList) PeerInfoList
- type PeerList
- type PeerPermutation
- type ReadLevel
- type Ring
- type RingAdder
- type RingRemover
- type RingType
- type Server
- func (s *Server) AddTimeoutCallback(f func(uuid string))
- func (s *Server) BeginHeartbeat(addr *url.URL) error
- func (s *Server) Close() error
- func (s *Server) CreateFile(volume *models.Volume, inode *models.INode, blocks Blockset) (*File, error)
- func (s *Server) Debug(w io.Writer) error
- func (s *Server) ExtendContext(ctx context.Context) context.Context
- func (s *Server) GetPeerMap() map[string]*models.PeerInfo
- func (s *Server) Lease() int64
- func (s *Server) UpdatePeerMap() map[string]*models.PeerInfo
- func (s *Server) UpdateRebalanceInfo(ri *models.RebalanceInfo)
- type SetRingFunc
- type Store
- type VolumeID
- type WipeMDSFunc
- type WriteLevel
Constants ¶
const ( CtxWriteLevel int = iota CtxReadLevel )
const BlockRefByteSize = 8 * 3
const INodeRefByteSize = 8 * 2
const VolumeIDByteSize = 5
const (
VolumeMax = 0x000000FFFFFFFFFF
)
Variables ¶
var ( // block. ErrBlockUnavailable = errors.New("torus: block cannot be retrieved") // INode. ErrINodeUnavailable = errors.New("torus: inode cannot be retrieved") // ErrBlockNotExist is returned when a function attempts to manipulate a // non-existent block. ErrBlockNotExist = errors.New("torus: block doesn't exist") // ErrClosed is returned when a function attempts to manipulate a Store // that is not currently open. ErrClosed = errors.New("torus: store is closed") // ErrInvalid is a locally invalid operation (such as Close()ing a nil file pointer) ErrInvalid = errors.New("torus: invalid operation") // ErrOutOfSpace is returned when the block storage is out of space. ErrOutOfSpace = errors.New("torus: out of space on block store") // ErrExists is returned if the entity already exists ErrExists = errors.New("torus: already exists") // ErrNotExist is returned if the entity doesn't already exist ErrNotExist = errors.New("torus: doesn't exist") // ErrAgain is returned if the operation was interrupted. The call was valid, and // may be tried again. ErrAgain = errors.New("torus: interrupted, try again") // ErrNoGlobalMetadata is returned if the metadata service hasn't been formatted. ErrNoGlobalMetadata = errors.New("torus: no global metadata available at mds") // ErrNonSequentialRing is returned if the ring's internal version number appears to jump. ErrNonSequentialRing = errors.New("torus: non-sequential ring") // ErrNoPeer is returned if the peer can't be found. ErrNoPeer = errors.New("torus: no such peer") // ErrCompareFailed is returned if the CAS operation failed to compare. ErrCompareFailed = errors.New("torus: compare failed") // ErrIsSymlink is returned if we're trying to modify a symlink incorrectly. ErrIsSymlink = errors.New("torus: is symlink") // ErrNotDir is returned if we're trying a directory operation on a non-directory path. ErrNotDir = errors.New("torus: not a directory") // ErrWrongVolumeType is returned if the operation cannot be performed on this type of volume. ErrWrongVolumeType = errors.New("torus: wrong volume type") // ErrNotSupported is returned if the interface doesn't implement the // requested subfunctionality. ErrNotSupported = errors.New("torus: not supported") // ErrLocked is returned if the resource is locked. ErrLocked = errors.New("torus: locked") // ErrLeaseNotFound is returned if the lease cannot be found. ErrLeaseNotFound = errors.New("torus: lease not found") // ErrUsage is returned if the command usage is wrong. ErrUsage = errors.New("torus: wrong command usage") )
var BlockLog = capnslog.NewPackageLogger("github.com/alternative-storage/torus", "blocklog")
var Version string
Version is set by build scripts, do not touch.
Functions ¶
func InitMDS ¶
func InitMDS(name string, cfg Config, gmd GlobalMetadata, ringType RingType) error
InitMDS calls the specific init function provided by a metadata package.
func MarshalBlocksetToProto ¶
func MarshalBlocksetToProto(bs Blockset) ([]*models.BlockLayer, error)
func RegisterBlockStore ¶
func RegisterBlockStore(name string, newFunc NewBlockStoreFunc)
func RegisterMetadataInit ¶
func RegisterMetadataInit(name string, newFunc InitMDSFunc)
RegisterMetadataInit is the hook used for implementations of MetadataServices to register their ways of creating base metadata to the system.
func RegisterMetadataService ¶
func RegisterMetadataService(name string, newFunc CreateMetadataServiceFunc)
RegisterMetadataService is the hook used for implementations of MetadataServices to register themselves to the system. This is usually called in the init() of the package that implements the MetadataService. A similar pattern is used in database/sql of the standard library.
func RegisterMetadataWipe ¶
func RegisterMetadataWipe(name string, newFunc WipeMDSFunc)
RegisterMetadataWipe is the hook used for implementations of MetadataServices to register their ways of deleting their metadata from the consistent store
func RegisterSetRing ¶
func RegisterSetRing(name string, newFunc SetRingFunc)
RegisterSetRing is the hook used for implementations of MetadataServices to register their ways of creating base metadata to the system.
Types ¶
type BlockIterator ¶
type BlockLayer ¶
type BlockLayer struct { Kind BlockLayerKind Options string }
type BlockLayerKind ¶
type BlockLayerKind int
type BlockLayerSpec ¶
type BlockLayerSpec []BlockLayer
type BlockRef ¶
BlockRef is the identifier for a unique block in the cluster.
func BlockFromProto ¶
func BlockRefFromBytes ¶
func BlockRefFromUint64s ¶
func (*BlockRef) SetBlockType ¶
func (BlockRef) ToBytesBuf ¶
type BlockStore ¶
type BlockStore interface { Store HasBlock(ctx context.Context, b BlockRef) (bool, error) GetBlock(ctx context.Context, b BlockRef) ([]byte, error) WriteBlock(ctx context.Context, b BlockRef, data []byte) error WriteBuf(ctx context.Context, b BlockRef) ([]byte, error) DeleteBlock(ctx context.Context, b BlockRef) error NumBlocks() uint64 UsedBlocks() uint64 BlockIterator() BlockIterator BlockSize() uint64 }
BlockStore is the interface representing the standardized methods to interact with something storing blocks.
func CreateBlockStore ¶
func CreateBlockStore(kind string, name string, cfg Config, gmd GlobalMetadata) (BlockStore, error)
type Blockset ¶
type Blockset interface { // Length returns the number of blocks in the Blockset. Length() int // Kind returns the kind of the Blockset. Kind() uint32 // GetBlock returns the ith block in the Blockset. GetBlock(ctx context.Context, i int) ([]byte, error) // PutBlock puts a block with data `b` into the Blockset as its ith block. // The block belongs to the given inode. PutBlock(ctx context.Context, inode INodeRef, i int, b []byte) error // GetLiveInodes returns the current INode representation of the Blockset. // The returned INode might not be synced. GetLiveINodes() *roaring.Bitmap // GetAllBlockRefs returns the BlockRef of the blocks in the Blockset. // The ith BlockRef in the returned slice is the Ref of the ith Block in the // Blockset. GetAllBlockRefs() []BlockRef // Marshal returns the bytes representation of the Blockset. Marshal() ([]byte, error) // Unmarshal parses the bytes representation of the Blockset and stores the result // in the Blockset. Unmarshal(data []byte) error // GetSubBlockset gets the sub-Blockset of the Blockset if exists. // If there is no sub-Blockset, nil will be returned. GetSubBlockset() Blockset // Truncate changes the length of the Blockset and the block. If the Blockset has less // blocks than the required size, truncate adds zero blocks. If the block has less bytes // than required size, truncate add bytes into block. Truncate(lastIndex int, blocksize uint64) error // Trim zeros the blocks in range [from, to). Trim(from, to int) error // String implements the fmt.Stringer interface. String() string }
Blockset is the interface representing the standardized methods to interact with a set of blocks.
type CreateMetadataServiceFunc ¶
type CreateMetadataServiceFunc func(cfg Config) (MetadataService, error)
CreateMetadataServiceFunc is the signature of a constructor used to create a registered MetadataService.
type DebugMetadataService ¶
type File ¶
type File struct { ReadOnly bool // contains filtered or unexported fields }
func (*File) SyncAllWrites ¶
func (*File) SyncBlocks ¶
type GlobalMetadata ¶
type GlobalMetadata struct { BlockSize uint64 DefaultBlockSpec BlockLayerSpec }
type INodeIterator ¶
type INodeIterator struct {
// contains filtered or unexported fields
}
func (*INodeIterator) Close ¶
func (i *INodeIterator) Close() error
func (*INodeIterator) Err ¶
func (i *INodeIterator) Err() error
func (*INodeIterator) INodeRef ¶
func (i *INodeIterator) INodeRef() INodeRef
func (*INodeIterator) Next ¶
func (i *INodeIterator) Next() bool
type INodeRef ¶
type INodeRef struct { INode INodeID // contains filtered or unexported fields }
INodeRef is a reference to a unique INode in the cluster.
func INodeFromProto ¶
func INodeRefFromBytes ¶
func NewINodeRef ¶
type INodeStore ¶
type INodeStore struct {
// contains filtered or unexported fields
}
func NewINodeStore ¶
func NewINodeStore(bs BlockStore) *INodeStore
func (*INodeStore) Close ¶
func (b *INodeStore) Close() error
func (*INodeStore) DeleteINode ¶
func (b *INodeStore) DeleteINode(ctx context.Context, i INodeRef) error
func (*INodeStore) Flush ¶
func (b *INodeStore) Flush() error
func (*INodeStore) INodeIterator ¶
func (b *INodeStore) INodeIterator() *INodeIterator
func (*INodeStore) WriteINode ¶
type InitMDSFunc ¶
type InitMDSFunc func(cfg Config, gmd GlobalMetadata, ringType RingType) error
InitMDSFunc is the signature of a function which preformats a metadata service.
type MetadataService ¶
type MetadataService interface { GetVolumes() ([]*models.Volume, VolumeID, error) GetVolume(volume string) (*models.Volume, error) NewVolumeID() (VolumeID, error) Kind() MetadataKind // GlobalMetadata backing struct must be instantiated upon the // service creation. If it can not be created the MetadataService // creation must fail. GlobalMetadata() GlobalMetadata // Returns a UUID based on the underlying datadir. Should be // unique for every created datadir. UUID() string GetRing() (Ring, error) SubscribeNewRings(chan Ring) UnsubscribeNewRings(chan Ring) SetRing(ring Ring) error WithContext(ctx context.Context) MetadataService GetLease() (int64, error) RenewLease(int64) error RegisterPeer(lease int64, pi *models.PeerInfo) error GetPeers() (PeerInfoList, error) Close() error CommitINodeIndex(VolumeID) (INodeID, error) GetINodeIndex(VolumeID) (INodeID, error) GetLockStatus(vid uint64) string }
MetadataService is the interface representing the basic ways to manipulate consistently stored fileystem metadata.
func CreateMetadataService ¶
func CreateMetadataService(name string, cfg Config) (MetadataService, error)
CreateMetadataService calls the constructor of the specified MetadataService with the provided address.
type ModifyableRing ¶
type NewBlockStoreFunc ¶
type NewBlockStoreFunc func(string, Config, GlobalMetadata) (BlockStore, error)
type PeerInfoList ¶
func (PeerInfoList) AndNot ¶
func (pi PeerInfoList) AndNot(b PeerList) PeerInfoList
func (PeerInfoList) GetWeights ¶
func (pi PeerInfoList) GetWeights() map[string]int
func (PeerInfoList) HasUUID ¶
func (pi PeerInfoList) HasUUID(uuid string) bool
func (PeerInfoList) Intersect ¶
func (pi PeerInfoList) Intersect(b PeerInfoList) PeerInfoList
func (PeerInfoList) PeerList ¶
func (pi PeerInfoList) PeerList() PeerList
func (PeerInfoList) UUIDAt ¶
func (pi PeerInfoList) UUIDAt(uuid string) int
func (PeerInfoList) Union ¶
func (pi PeerInfoList) Union(b PeerInfoList) PeerInfoList
type PeerPermutation ¶
type RingAdder ¶
type RingAdder interface { ModifyableRing AddPeers(PeerInfoList) (Ring, error) }
type RingRemover ¶
type RingRemover interface { ModifyableRing RemovePeers(PeerList) (Ring, error) }
type Server ¶
type Server struct { Blocks BlockStore MDS MetadataService INodes *INodeStore Cfg Config ReplicationOpen bool // contains filtered or unexported fields }
Server is the type representing the generic distributed block store.
func NewServerByImpl ¶
func NewServerByImpl(cfg Config, mds MetadataService, blocks BlockStore) (*Server, error)
func (*Server) AddTimeoutCallback ¶
func (*Server) BeginHeartbeat ¶
BeginHeartbeat spawns a goroutine for heartbeats. Non-blocking.
func (*Server) CreateFile ¶
func (*Server) UpdateRebalanceInfo ¶
func (s *Server) UpdateRebalanceInfo(ri *models.RebalanceInfo)
type SetRingFunc ¶
type Store ¶
Store is the interface that represents methods that should be common across all types of storage providers.
type WipeMDSFunc ¶
type WriteLevel ¶
type WriteLevel int
const ( WriteAll WriteLevel = iota WriteOne WriteLocal )
func ParseWriteLevel ¶
func ParseWriteLevel(s string) (wl WriteLevel, err error)
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
block provides the implementation of the "block" volume type, using a Torus file as a block device.
|
block provides the implementation of the "block" volume type, using a Torus file as a block device. |
aoe
aoe provides the implementation of an ATA over Ethernet server, backed by a Torus block volume.
|
aoe provides the implementation of an ATA over Ethernet server, backed by a Torus block volume. |
Package blockset provides a registry of BlockLayers, that can be (Un)Marshaled and retrieve blocks from a Torus storage interface.
|
Package blockset provides a registry of BlockLayers, that can be (Un)Marshaled and retrieve blocks from a Torus storage interface. |
cmd
|
|
Package distributor is a complex implementation of a Torus storage interface, that understands rebalancing it's underlying storage and fetching data from peers, as necessary.
|
Package distributor is a complex implementation of a Torus storage interface, that understands rebalancing it's underlying storage and fetching data from peers, as necessary. |
protocols
Package protocols is the metapackage for the RPC protocols for how Torus' storage layer communicates with other storage servers.
|
Package protocols is the metapackage for the RPC protocols for how Torus' storage layer communicates with other storage servers. |
rebalance
Package rebalance provides the implementation of the rebalancer, which continually checks the data stored on a host, knows where data should live, and moves it to the appropriate servers.
|
Package rebalance provides the implementation of the rebalancer, which continually checks the data stored on a host, knows where data should live, and moves it to the appropriate servers. |
Package gc provides the Torus interface for how garbage collection is implemented.
|
Package gc provides the Torus interface for how garbage collection is implemented. |
internal
|
|
flagconfig
Package flagconfig is a generic set of flags dedicated to configuring a Torus client.
|
Package flagconfig is a generic set of flags dedicated to configuring a Torus client. |
nbd
Package nbd uses the Linux NBD layer to emulate a block device in user space
|
Package nbd uses the Linux NBD layer to emulate a block device in user space |
Package metadata is the metapackage for the implementations of the metadata interface, for each potential backend.
|
Package metadata is the metapackage for the implementations of the metadata interface, for each potential backend. |
Package models is the package containing all the protos used for serializing data for Torus.
|
Package models is the package containing all the protos used for serializing data for Torus. |
Package ring is the package containing implementations of the consistent hash ring, a pure function which provides a permutation of peers where a block can live, known by all members of the cluster.
|
Package ring is the package containing implementations of the consistent hash ring, a pure function which provides a permutation of peers where a block can live, known by all members of the cluster. |
Package storage is the package which implements the underlying, on-disk storage API for Torus servers.
|
Package storage is the package which implements the underlying, on-disk storage API for Torus servers. |