Documentation
¶
Overview ¶
Package txn contains the implementation of the graph transaction system.
Index ¶
- Constants
- type Graph
- func (obj *Graph) AddEdge(f1, f2 interfaces.Func, fe *interfaces.FuncEdge) error
- func (obj *Graph) AddVertex(f interfaces.Func) error
- func (obj *Graph) DeleteEdge(fe *interfaces.FuncEdge) error
- func (obj *Graph) DeleteVertex(f interfaces.Func) error
- func (obj *Graph) FindEdge(f1, f2 interfaces.Func) *interfaces.FuncEdge
- func (obj *Graph) Graph() *pgraph.Graph
- func (obj *Graph) HasVertex(f interfaces.Func) bool
- func (obj *Graph) Init() *Graph
- func (obj *Graph) LookupEdge(fe *interfaces.FuncEdge) (interfaces.Func, interfaces.Func, bool)
- type GraphTxn
- func (obj *GraphTxn) AddEdge(f1, f2 interfaces.Func, fe *interfaces.FuncEdge) interfaces.Txn
- func (obj *GraphTxn) AddGraph(g *pgraph.Graph) interfaces.Txn
- func (obj *GraphTxn) AddVertex(f interfaces.Func) interfaces.Txn
- func (obj *GraphTxn) Clear()
- func (obj *GraphTxn) Commit() error
- func (obj *GraphTxn) Copy() interfaces.Txn
- func (obj *GraphTxn) DeleteVertex(f interfaces.Func) interfaces.Txn
- func (obj *GraphTxn) Erase()
- func (obj *GraphTxn) Free()
- func (obj *GraphTxn) Graph() *pgraph.Graph
- func (obj *GraphTxn) Init() interfaces.Txn
- func (obj *GraphTxn) Reverse() error
Constants ¶
const GraphvizDebug = false
GraphvizDebug enables writing graphviz graphs on each commit. This is very slow.
const PostReverseCommit = false
PostReverseCommit specifies that if we run Reverse, and we had previous items pending for Commit, that we should Commit them after our Reverse runs. Otherwise they remain on the pending queue and wait for you to run Commit.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Graph ¶
type Graph struct { Debug bool Logf func(format string, v ...interface{}) // contains filtered or unexported fields }
Graph is a simple pgraph wrapper that implements the GraphAPI interface. That interface is also implemented by *dage.Engine and the code is very similar.
func (*Graph) AddEdge ¶
func (obj *Graph) AddEdge(f1, f2 interfaces.Func, fe *interfaces.FuncEdge) error
AddEdge adds an edge to the graph. It takes a lock.
func (*Graph) AddVertex ¶
func (obj *Graph) AddVertex(f interfaces.Func) error
AddVertex adds a vertex to the graph. It takes a lock.
func (*Graph) DeleteEdge ¶
func (obj *Graph) DeleteEdge(fe *interfaces.FuncEdge) error
DeleteEdge deletes an edge from the graph. It takes a lock.
func (*Graph) DeleteVertex ¶
func (obj *Graph) DeleteVertex(f interfaces.Func) error
DeleteVertex deletes a vertex from the graph. It takes a lock.
func (*Graph) FindEdge ¶
func (obj *Graph) FindEdge(f1, f2 interfaces.Func) *interfaces.FuncEdge
FindEdge checks which edge (if any) exists between two vertices in the graph. It takes a lock. This is an important method in edge removal, because it's what you really need to know for DeleteEdge to work. Requesting a specific deletion isn't very sensical in this library when specified as the edge pointer, since we might replace it with a new edge that has new arg names. Instead, use this to look up what relationship you want, and then DeleteEdge to remove it.
func (*Graph) HasVertex ¶
func (obj *Graph) HasVertex(f interfaces.Func) bool
HasVertex checks if a vertex exists in the graph. It takes a lock.
func (*Graph) LookupEdge ¶
func (obj *Graph) LookupEdge(fe *interfaces.FuncEdge) (interfaces.Func, interfaces.Func, bool)
LookupEdge checks which vertices (if any) exist between an edge in the graph. It takes a lock.
type GraphTxn ¶
type GraphTxn struct { // Lock is a handle to the lock function to call before the operation. Lock func() // Unlock is a handle to the unlock function to call before the // operation. Unlock func() // GraphAPI is a handle pointing to the graph API implementation we're // using for any txn operations. GraphAPI interfaces.GraphAPI // RefCount keeps track of vertex and edge references across the entire // graph. RefCount *ref.Count // FreeFunc is a function that will get called by a well-behaved user // when we're done with this Txn. FreeFunc func() // contains filtered or unexported fields }
GraphTxn holds the state of a transaction and runs it when needed. When this has been setup and initialized, it implements the Txn API that can be used by functions in their Stream method to modify the function graph while it is "running".
func (*GraphTxn) AddEdge ¶
func (obj *GraphTxn) AddEdge(f1, f2 interfaces.Func, fe *interfaces.FuncEdge) interfaces.Txn
AddEdge adds an edge to the running graph. The operation will get completed when Commit is run. XXX: should this be pgraph.Vertex instead of interfaces.Func ? XXX: should this be pgraph.Edge instead of *interfaces.FuncEdge ?
func (*GraphTxn) AddGraph ¶
func (obj *GraphTxn) AddGraph(g *pgraph.Graph) interfaces.Txn
AddGraph adds a graph to the running graph. The operation will get completed when Commit is run. This function panics if your graph contains vertices that are not of type interfaces.Func or if your edges are not of type *interfaces.FuncEdge.
func (*GraphTxn) AddVertex ¶
func (obj *GraphTxn) AddVertex(f interfaces.Func) interfaces.Txn
AddVertex adds a vertex to the running graph. The operation will get completed when Commit is run. XXX: should this be pgraph.Vertex instead of interfaces.Func ?
func (*GraphTxn) Clear ¶
func (obj *GraphTxn) Clear()
Clear erases any pending transactions that weren't committed yet.
func (*GraphTxn) Commit ¶
Commit runs the pending transaction. If there was a pending reverse transaction that could have run (it would have been available following a Commit success) then this will erase that transaction. Usually you run cycles of Commit, followed by Reverse, or only Commit. (You obviously have to populate operations before the Commit is run.)
func (*GraphTxn) Copy ¶
func (obj *GraphTxn) Copy() interfaces.Txn
Copy returns a new child Txn that has the same handles, but a separate state. This allows you to do an Add*/Commit/Reverse that isn't affected by a different user of this transaction. TODO: FreeFunc isn't well supported here. Replace or remove this entirely?
func (*GraphTxn) DeleteVertex ¶
func (obj *GraphTxn) DeleteVertex(f interfaces.Func) interfaces.Txn
DeleteVertex adds a vertex to the running graph. The operation will get completed when Commit is run. XXX: should this be pgraph.Vertex instead of interfaces.Func ?
func (*GraphTxn) Erase ¶
func (obj *GraphTxn) Erase()
Erase removes the historical information that Reverse would run after Commit.
func (*GraphTxn) Free ¶
func (obj *GraphTxn) Free()
Free releases the wait group that was used to lock around this Txn if needed. It should get called when we're done with any Txn. TODO: this is only used for the initial Txn. Consider expanding it's use. We might need to allow Clear to call it as part of the clearing.
func (*GraphTxn) Graph ¶
Graph returns a copy of the contained graph. It returns what has been already committed.
func (*GraphTxn) Init ¶
func (obj *GraphTxn) Init() interfaces.Txn
Init must be called to initialized the struct before first use. This should be called by the struct creator, not the user.
func (*GraphTxn) Reverse ¶
Reverse is like Commit, but it commits the reverse transaction to the one that previously ran with Commit. If the PostReverseCommit global has been set then if there were pending commit operations when this was run, then they are run at the end of a successful Reverse. It is generally recommended to not queue any operations for Commit if you plan on doing a Reverse, or to run a Clear before running Reverse if you want to discard the pending commits.