Documentation ¶
Index ¶
- type Hugger
- func (self *Hugger) AssertNoTransactions()
- func (self *Hugger) Flush()
- func (self *Hugger) GetCachedNodeData(id ibtree.BlockId) (*ibtree.NodeData, bool)
- func (self *Hugger) GetNestableTransaction() *Transaction
- func (self *Hugger) GetStorageBlock(st storage.BlockStatus, b []byte, nd *ibtree.NodeData, deps *util.StringList) *storage.StorageBlock
- func (self *Hugger) GetTransaction() *Transaction
- func (self *Hugger) Init(cacheSize int) *Hugger
- func (self *Hugger) LoadNode(id ibtree.BlockId) *ibtree.NodeData
- func (self *Hugger) LoadNodeByName(name string) (*ibtree.Node, string, bool)
- func (self *Hugger) NewRootNode() *ibtree.Node
- func (self *Hugger) RootBlock() *storage.StorageBlock
- func (self *Hugger) RootIsNew() bool
- func (self *Hugger) SaveNode(nd *ibtree.NodeData) ibtree.BlockId
- func (self *Hugger) SetCachedNodeData(id ibtree.BlockId, nd *ibtree.NodeData)
- func (self *Hugger) String() string
- func (self *Hugger) Update(cb func(tr *Transaction))
- func (self *Hugger) Update2(cb func(tr *Transaction) bool) bool
- type MergeCallback
- type NodeIterateReferencesCallback
- type Transaction
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) GetCachedNodeData ¶
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) LoadNodeByName ¶
func (*Hugger) NewRootNode ¶
func (*Hugger) RootBlock ¶
func (self *Hugger) RootBlock() *storage.StorageBlock
func (*Hugger) SetCachedNodeData ¶
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.