hugger

package
v0.0.0-...-cdd27d5 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2019 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Hugger

type Hugger struct {
	RootName string
	Storage  *storage.Storage

	// IterateReferencesCallback should be provided; it is much
	// more efficient than fallback on storage's
	// IterateReferencesCallback as it does unmarshal+marshal
	IterateReferencesCallback NodeIterateReferencesCallback

	// MergeCallback MUST be provided if
	// Transaction.CommitUntilSucceeds is used. Otherwise it is
	// optional if only Transaction.TryCommit or Hugger.Update or
	// hugger.Update2 are used.
	MergeCallback MergeCallback
	// contains filtered or unexported fields
}

Hugger, or treehugger, is an abstraction which provides its own transaction mechanism (on top of Tree's own), and atomically updated root pointer to Node root. It also handles persistence to storage. It used to be part of fs/, but as both server/ and fs/ need distinct trees, this was born and fstransaction and parts of fs were moved to hugger submodule.

func (*Hugger) AssertNoTransactions

func (self *Hugger) AssertNoTransactions()

func (*Hugger) Flush

func (self *Hugger) Flush()

func (*Hugger) GetCachedNodeData

func (self *Hugger) GetCachedNodeData(id ibtree.BlockId) (*ibtree.NodeData, bool)

func (*Hugger) GetNestableTransaction

func (self *Hugger) GetNestableTransaction() *Transaction

GetNestableTransaction attempts to provide a transaction even if flush is pending. It should be used only for short-lived things that are done _within_ other transactions (if GetTransaction is used within transactions, deadlock may occur).

func (*Hugger) GetStorageBlock

func (self *Hugger) GetStorageBlock(st storage.BlockStatus, b []byte, nd *ibtree.NodeData, deps *util.StringList) *storage.StorageBlock

GetStorageBlock block ids for given bytes/data.

The blocks are expired during flush.

nd and deps are optional, but may speed up processing (or not).

func (*Hugger) GetTransaction

func (self *Hugger) GetTransaction() *Transaction

func (*Hugger) Init

func (self *Hugger) Init(cacheSize int) *Hugger

func (*Hugger) LoadNode

func (self *Hugger) LoadNode(id ibtree.BlockId) *ibtree.NodeData

ibtree.TreeBackend API

func (*Hugger) LoadNodeByName

func (self *Hugger) LoadNodeByName(name string) (*ibtree.Node, string, bool)

func (*Hugger) NewRootNode

func (self *Hugger) NewRootNode() *ibtree.Node

func (*Hugger) RootBlock

func (self *Hugger) RootBlock() *storage.StorageBlock

func (*Hugger) RootIsNew

func (self *Hugger) RootIsNew() bool

func (*Hugger) SaveNode

func (self *Hugger) SaveNode(nd *ibtree.NodeData) ibtree.BlockId

ibtree.TreeSaver API

func (*Hugger) SetCachedNodeData

func (self *Hugger) SetCachedNodeData(id ibtree.BlockId, nd *ibtree.NodeData)

func (*Hugger) String

func (self *Hugger) String() string

func (*Hugger) Update

func (self *Hugger) Update(cb func(tr *Transaction))

Update is the lazy variant in which the transaction supposedly always works. That may not be really the case in real world though, so Update2 should be used.

func (*Hugger) Update2

func (self *Hugger) Update2(cb func(tr *Transaction) bool) bool

Update2 (repeatedly) calls cb until it manages to update the global state with the content of the transaction. Therefore cb should be idempotent. If cb returns false, the transaction will not be committed.

The return value is the return value of the last cb call.

type MergeCallback

type MergeCallback func(t *Transaction, src, dst *ibtree.Node, local bool)

type NodeIterateReferencesCallback

type NodeIterateReferencesCallback func(*ibtree.NodeData, storage.BlockReferenceCallback)

type Transaction

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

func (*Transaction) Close

func (self *Transaction) Close()

func (*Transaction) CommitUntilSucceeds

func (self *Transaction) CommitUntilSucceeds()

CommitUntilSucceeds repeats commit until it the transaction goes through. This should be done only if the resource under question is locked by other means, as otherwise conflicting writes can occur. In general, using e.g. fs.Update() should be done in all cases.

func (*Transaction) IB

func (self *Transaction) IB() *ibtree.Transaction

func (*Transaction) String

func (self *Transaction) String() string

func (*Transaction) TryCommit

func (self *Transaction) TryCommit() bool

TryCommit attempts to commit once, but if the tree has changed underneath, it will not hold.

Jump to

Keyboard shortcuts

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