inodedb

package
v0.0.0-...-7570391 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FileNodeT = iota
	DirNodeT
)
View Source
const (
	AllocateNewNodeID = 0
)
View Source
const NoTicket = Ticket(0)

Variables

View Source
var (
	ErrLockInvalid = errors.New("Invalid lock given.")
	ErrLockTaken   = errors.New("Lock is already acquired by someone else.")
)

Functions

func EncodeDBOperationsToJson

func EncodeDBOperationsToJson(ops []DBOperation) ([]byte, error)

func IsErrNotFound

func IsErrNotFound(err error) bool

func SetOpMeta

func SetOpMeta(op DBOperation) error

func SetOpMetas

func SetOpMetas(ops []DBOperation) error

func TypeName

func TypeName(t Type) string

Types

type AlwaysFailForTestingOp

type AlwaysFailForTestingOp struct {
	OpMeta `json:",inline"`
}

func (*AlwaysFailForTestingOp) Apply

func (op *AlwaysFailForTestingOp) Apply(s *DBState) error

type CachedDBTransactionLogIO

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

func NewCachedDBTransactionLogIO

func NewCachedDBTransactionLogIO(be DBTransactionLogIO) *CachedDBTransactionLogIO

func (*CachedDBTransactionLogIO) AppendTransaction

func (txio *CachedDBTransactionLogIO) AppendTransaction(tx DBTransaction) error

func (*CachedDBTransactionLogIO) QueryCachedTransactions

func (txio *CachedDBTransactionLogIO) QueryCachedTransactions(minID TxID) ([]DBTransaction, error)

func (*CachedDBTransactionLogIO) QueryTransactions

func (txio *CachedDBTransactionLogIO) QueryTransactions(minID TxID) ([]DBTransaction, error)

type CreateNodeOp

type CreateNodeOp struct {
	OpMeta   `json:",inline"`
	NodeLock `json:"nodelock"`
	OrigPath string `json:"origpath"`
	Type     `json:"type"`

	ParentID ID `json:"parent_id"` // only valid for DirNodeT

	Uid       uint32    `json:"uid"`
	Gid       uint32    `json:"gid"`
	PermMode  uint16    `json:"perm_mode"`
	ModifiedT time.Time `json:"modified_t"`
}

func (*CreateNodeOp) Apply

func (op *CreateNodeOp) Apply(s *DBState) error

type DB

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

func NewDB

func NewDB(snapshotIO DBStateSnapshotIO, txLogIO DBTransactionLogIO, readOnly bool) (*DB, error)

func NewEmptyDB

func NewEmptyDB(snapshotIO DBStateSnapshotIO, txLogIO DBTransactionLogIO) (*DB, error)

func (*DB) ApplyTransaction

func (db *DB) ApplyTransaction(tx DBTransaction) (TxID, error)

func (*DB) Fsck

func (db *DB) Fsck() ([]string, []error)

func (*DB) GetStats

func (db *DB) GetStats() DBServiceStats

func (*DB) LockNode

func (db *DB) LockNode(id ID) (NodeLock, error)

func (*DB) QueryNode

func (db *DB) QueryNode(id ID, tryLock bool) (NodeView, NodeLock, error)

func (*DB) QueryRecentTransactions

func (db *DB) QueryRecentTransactions() ([]DBTransaction, error)

func (*DB) RestoreVersion

func (db *DB) RestoreVersion(version TxID) error

func (*DB) Sync

func (db *DB) Sync() error

func (*DB) TriggerSync

func (db *DB) TriggerSync() <-chan error

func (*DB) UnlockNode

func (db *DB) UnlockNode(nlock NodeLock) error

type DBFscker

type DBFscker interface {
	Fsck() ([]string, []error)
}

type DBHandler

type DBHandler interface {
	// ApplyTransaction applies DBTransaction to db.state, and returns applied transaction's TxID. If it fails to apply the transaction, it rollbacks intermediate state and returns error.
	ApplyTransaction(tx DBTransaction) (TxID, error)

	// QueryNode returns read-only snapshot of INode id, with a lock if specified
	QueryNode(id ID, tryLock bool) (NodeView, NodeLock, error)

	// FIXME: this should actually take NodeLock for renew ticket operation
	LockNode(id ID) (NodeLock, error)
	UnlockNode(nlock NodeLock) error
}

type DBOperation

type DBOperation interface {
	Apply(s *DBState) error
}

func DecodeDBOperationsFromJson

func DecodeDBOperationsFromJson(jsonb []byte) ([]DBOperation, error)

func ResolveDBOperations

func ResolveDBOperations(msgs []*json.RawMessage) ([]DBOperation, error)

type DBService

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

DBService serializes requests to DBHandler

func NewDBService

func NewDBService(h DBHandler) *DBService

func (*DBService) ApplyTransaction

func (srv *DBService) ApplyTransaction(tx DBTransaction) (txid TxID, err error)

func (*DBService) Fsck

func (srv *DBService) Fsck() (foundblobpaths []string, errs []error)

func (*DBService) GetStats

func (srv *DBService) GetStats() (stats DBServiceStats)

func (*DBService) ImplName

func (*DBService) ImplName() string

func (*DBService) LockNode

func (srv *DBService) LockNode(id ID) (nlock NodeLock, err error)

func (*DBService) QueryNode

func (srv *DBService) QueryNode(id ID, tryLock bool) (v NodeView, nlock NodeLock, err error)

func (*DBService) QueryRecentTransactions

func (srv *DBService) QueryRecentTransactions() (txs []DBTransaction, err error)

func (*DBService) Quit

func (srv *DBService) Quit()

func (*DBService) Sync

func (srv *DBService) Sync() (err error)

func (*DBService) TriggerSync

func (srv *DBService) TriggerSync() (errC <-chan error)

func (*DBService) UnlockNode

func (srv *DBService) UnlockNode(nlock NodeLock) (err error)

type DBServiceStats

type DBServiceStats struct {
	LastSync time.Time `json:"last_sync"` // NOTE: updated w/o lock
	LastTx   time.Time `json:"last_tx"`

	LastID            ID     `json:"last_id"`
	Version           TxID   `json:"version"`
	LastTicket        Ticket `json:"last_ticket"`
	NumberOfNodeLocks int    `json:"number_of_node_locks"`
}

type DBServiceStatsProvider

type DBServiceStatsProvider interface {
	GetStats() DBServiceStats
}

type DBState

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

func DecodeDBStateFromGob

func DecodeDBStateFromGob(dec *gob.Decoder) (*DBState, error)

func NewDBState

func NewDBState() *DBState

func (*DBState) EncodeToGob

func (s *DBState) EncodeToGob(enc *gob.Encoder) error

func (*DBState) Version

func (s *DBState) Version() TxID

type DBStateSnapshotIO

type DBStateSnapshotIO interface {
	SaveSnapshot(s *DBState) <-chan error
	RestoreSnapshot() (*DBState, error)
}

type DBTransaction

type DBTransaction struct {
	TxID `json:"txid"`
	Ops  []DBOperation `json:"ops"`
}

func ResolveDBTransaction

func ResolveDBTransaction(utx UnresolvedDBTransaction) (DBTransaction, error)

func (DBTransaction) String

func (tx DBTransaction) String() string

type DBTransactionLogIO

type DBTransactionLogIO interface {
	AppendTransaction(tx DBTransaction) error
	QueryTransactions(minID TxID) ([]DBTransaction, error)
}

type DirNode

type DirNode struct {
	INodeCommon
	ParentID ID
	Entries  map[string]ID
}

func (*DirNode) EncodeToGob

func (dn *DirNode) EncodeToGob(enc *gob.Encoder) error

func (*DirNode) GetType

func (dn *DirNode) GetType() Type

func (*DirNode) View

func (dn *DirNode) View() NodeView

type DirNodeView

type DirNodeView struct {
	INodeCommon `json:",inline"`
	ParentID    ID            `json:"parent_id"`
	Entries     map[string]ID `json:"entries"`
}

func (DirNodeView) GetType

func (v DirNodeView) GetType() Type

type Errno

type Errno syscall.Errno

func (Errno) Errno

func (e Errno) Errno() bfuse.Errno

func (Errno) Error

func (e Errno) Error() string

type FileChunk

type FileChunk struct {
	Offset   int64
	Length   int64
	BlobPath string
}

func (FileChunk) Left

func (fc FileChunk) Left() int64

func (FileChunk) Right

func (fc FileChunk) Right() int64

type FileNode

type FileNode struct {
	INodeCommon
	Size   int64
	Chunks []FileChunk
}

func (*FileNode) EncodeToGob

func (fn *FileNode) EncodeToGob(enc *gob.Encoder) error

func (*FileNode) GetType

func (fn *FileNode) GetType() Type

func (*FileNode) View

func (fn *FileNode) View() NodeView

type FileNodeView

type FileNodeView struct {
	INodeCommon `json:",inline"`
	Size        int64       `json:"size"`
	Chunks      []FileChunk `json:"chunks"`
}

func (FileNodeView) GetType

func (v FileNodeView) GetType() Type

type GobEncodable

type GobEncodable interface {
	EncodeToGob(enc *gob.Encoder) error
}

type HardLinkOp

type HardLinkOp struct {
	OpMeta   `json:",inline"`
	NodeLock `json:"nodelock"`
	Name     string `json:"name"`
	TargetID ID     `json:"targetid"`
}

func (*HardLinkOp) Apply

func (op *HardLinkOp) Apply(s *DBState) error

type ID

type ID uint64
const RootDirID ID = 1

type INode

type INode interface {
	GetID() ID
	GetType() Type

	GobEncodable

	View() NodeView
}

func DecodeNodeFromGob

func DecodeNodeFromGob(dec *gob.Decoder) (INode, error)

type INodeCommon

type INodeCommon struct {
	ID `json:"id"`

	// OrigPath contains filepath passed to first create and does not necessary follow "rename" operations.
	// To be used for recovery/debug purposes only
	OrigPath string `json:"orig_path"`

	Uid       uint32    `json:"uid"`
	Gid       uint32    `json:"gid"`
	PermMode  uint16    `json:"perm_mode"`
	ModifiedT time.Time `json:"modified_t"`
}

func (INodeCommon) GetGid

func (n INodeCommon) GetGid() uint32

func (INodeCommon) GetID

func (n INodeCommon) GetID() ID

func (INodeCommon) GetModifiedT

func (n INodeCommon) GetModifiedT() time.Time

func (INodeCommon) GetOrigPath

func (n INodeCommon) GetOrigPath() string

func (INodeCommon) GetPermMode

func (n INodeCommon) GetPermMode() uint16

func (INodeCommon) GetUid

func (n INodeCommon) GetUid() uint32

type InitializeFileSystemOp

type InitializeFileSystemOp struct {
	OpMeta `json:",inline"`
}

func (*InitializeFileSystemOp) Apply

func (op *InitializeFileSystemOp) Apply(s *DBState) error

type NodeLock

type NodeLock struct {
	ID     `json:"id"`
	Ticket `json:"ticket"`
}

func (NodeLock) HasTicket

func (nlock NodeLock) HasTicket() bool

type NodeView

type NodeView interface {
	GetID() ID
	GetOrigPath() string
	GetUid() uint32
	GetGid() uint32
	GetPermMode() uint16
	GetModifiedT() time.Time

	GetType() Type
}

type OpMeta

type OpMeta struct {
	Kind string `json:"kind"`
}

type QueryRecentTransactionsProvider

type QueryRecentTransactionsProvider interface {
	QueryRecentTransactions() ([]DBTransaction, error)
}

type RemoveOp

type RemoveOp struct {
	OpMeta   `json:",inline"`
	NodeLock `json:"nodelock"`
	Name     string `json:"name"`
}

func (*RemoveOp) Apply

func (op *RemoveOp) Apply(s *DBState) error

type RenameOp

type RenameOp struct {
	OpMeta   `json:",inline"`
	SrcDirID ID     `json:"srcdir"`
	SrcName  string `json:"srcname"`
	DstDirID ID     `json:"dstdir"`
	DstName  string `json:"dstname"`
}

func (*RenameOp) Apply

func (op *RenameOp) Apply(s *DBState) error

type SimpleDBStateSnapshotIO

type SimpleDBStateSnapshotIO struct {
	Buf bytes.Buffer
}

func NewSimpleDBStateSnapshotIO

func NewSimpleDBStateSnapshotIO() *SimpleDBStateSnapshotIO

func (*SimpleDBStateSnapshotIO) ImplName

func (*SimpleDBStateSnapshotIO) ImplName() string

func (*SimpleDBStateSnapshotIO) RestoreSnapshot

func (io *SimpleDBStateSnapshotIO) RestoreSnapshot() (*DBState, error)

func (*SimpleDBStateSnapshotIO) SaveSnapshot

func (io *SimpleDBStateSnapshotIO) SaveSnapshot(s *DBState) <-chan error

type SimpleDBTransactionLogIO

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

func NewSimpleDBTransactionLogIO

func NewSimpleDBTransactionLogIO() *SimpleDBTransactionLogIO

func (*SimpleDBTransactionLogIO) AppendTransaction

func (io *SimpleDBTransactionLogIO) AppendTransaction(tx DBTransaction) error

func (*SimpleDBTransactionLogIO) QueryTransactions

func (io *SimpleDBTransactionLogIO) QueryTransactions(minID TxID) ([]DBTransaction, error)

func (*SimpleDBTransactionLogIO) SetReadOnly

func (io *SimpleDBTransactionLogIO) SetReadOnly(b bool)

type Ticket

type Ticket uint64

type TriggerSyncer

type TriggerSyncer interface {
	TriggerSync() <-chan error
}

type TxID

type TxID int64
const (
	LatestVersion TxID = math.MaxInt64
	AnyVersion    TxID = 0
)

func (TxID) String

func (id TxID) String() string

type Type

type Type int

type UnresolvedDBTransaction

type UnresolvedDBTransaction struct {
	TxID `json:"txid"`
	Ops  []*json.RawMessage
}

type UpdateChunksOp

type UpdateChunksOp struct {
	OpMeta   `json:",inline"`
	NodeLock `json:"nodelock"`
	Chunks   []FileChunk `json:"chunks"`
}

func (*UpdateChunksOp) Apply

func (op *UpdateChunksOp) Apply(s *DBState) error

type UpdateGidOp

type UpdateGidOp struct {
	OpMeta `json:",inline"`
	ID     `json:"id"`
	Gid    uint32 `json:"gid"`
}

func (*UpdateGidOp) Apply

func (op *UpdateGidOp) Apply(s *DBState) error

type UpdateModifiedTOp

type UpdateModifiedTOp struct {
	OpMeta    `json:",inline"`
	ID        `json:"id"`
	ModifiedT time.Time `json:"modified_t"`
}

func (*UpdateModifiedTOp) Apply

func (op *UpdateModifiedTOp) Apply(s *DBState) error

type UpdatePermModeOp

type UpdatePermModeOp struct {
	OpMeta   `json:",inline"`
	ID       `json:"id"`
	PermMode uint16 `json:"perm_mode"`
}

func (*UpdatePermModeOp) Apply

func (op *UpdatePermModeOp) Apply(s *DBState) error

type UpdateSizeOp

type UpdateSizeOp struct {
	OpMeta   `json:",inline"`
	NodeLock `json:"nodelock"`
	Size     int64 `json:"size"`
}

func (*UpdateSizeOp) Apply

func (op *UpdateSizeOp) Apply(s *DBState) error

type UpdateUidOp

type UpdateUidOp struct {
	OpMeta `json:",inline"`
	ID     `json:"id"`
	Uid    uint32 `json:"uid"`
}

func (*UpdateUidOp) Apply

func (op *UpdateUidOp) Apply(s *DBState) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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