Documentation ¶
Overview ¶
Package dage implements a DAG function engine. TODO: can we rename this to something more interesting?
Index ¶
- type Engine
- func (obj *Engine) AddEdge(f1, f2 interfaces.Func, fe *interfaces.FuncEdge) error
- func (obj *Engine) AddVertex(f interfaces.Func) error
- func (obj *Engine) Apply(fn func(map[interfaces.Func]types.Value) error) error
- func (obj *Engine) Cleanup() error
- func (obj *Engine) DeleteEdge(fe *interfaces.FuncEdge) error
- func (obj *Engine) DeleteVertex(f interfaces.Func) error
- func (obj *Engine) ExecGraphviz(dir string) error
- func (obj *Engine) FindEdge(f1, f2 interfaces.Func) *interfaces.FuncEdge
- func (obj *Engine) Graph() *pgraph.Graph
- func (obj *Engine) HasVertex(f interfaces.Func) bool
- func (obj *Engine) Loaded() <-chan struct{}
- func (obj *Engine) Lock()
- func (obj *Engine) LookupEdge(fe *interfaces.FuncEdge) (interfaces.Func, interfaces.Func, bool)
- func (obj *Engine) NumVertices() int
- func (obj *Engine) Run(ctx context.Context) (reterr error)
- func (obj *Engine) Setup() error
- func (obj *Engine) Started() <-chan struct{}
- func (obj *Engine) Stats() string
- func (obj *Engine) Stream() <-chan error
- func (obj *Engine) Table() map[interfaces.Func]types.Value
- func (obj *Engine) Txn() interfaces.Txn
- func (obj *Engine) Unlock()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Engine ¶
type Engine struct { // Name is the name used for the instance of the engine and in the graph // that is held within it. Name string Hostname string Local *local.API World engine.World Debug bool Logf func(format string, v ...interface{}) // Callback can be specified as an alternative to using the Stream // method to get events. If the context on it is cancelled, then it must // shutdown quickly, because this means we are closing and want to // disconnect. Whether you want to respect that is up to you, but the // engine will not be able to close until you do. If specified, and an // error has occurred, it will set that error property. Callback func(context.Context, error) // contains filtered or unexported fields }
Engine implements a dag engine which lets us "run" a dag of functions, but also allows us to modify it while we are running.
func (*Engine) AddEdge ¶
func (obj *Engine) AddEdge(f1, f2 interfaces.Func, fe *interfaces.FuncEdge) error
AddEdge is the thread-safe way to add an edge. You will need to call the engine Lock method before using this and the Unlock method afterwards. This will automatically run AddVertex on both input vertices if they are not already part of the graph. You should only create DAG's as this function engine cannot handle cycles and this method will error if you cause a cycle.
func (*Engine) AddVertex ¶
func (obj *Engine) AddVertex(f interfaces.Func) error
AddVertex is the thread-safe way to add a vertex. You will need to call the engine Lock method before using this and the Unlock method afterwards.
func (*Engine) Apply ¶
Apply is similar to Table in that it gives you access to the internal output table of data, the difference being that it instead passes this information to a function of your choosing and holds a read/write lock during the entire time that your function is synchronously executing. If you use this function to spawn any goroutines that read or write data, then you're asking for a panic. XXX: does this need to be a Lock? Can it be an RLock? Check callers!
func (*Engine) DeleteEdge ¶
func (obj *Engine) DeleteEdge(fe *interfaces.FuncEdge) error
DeleteEdge is the thread-safe way to delete an edge. You will need to call the engine Lock method before using this and the Unlock method afterwards.
func (*Engine) DeleteVertex ¶
func (obj *Engine) DeleteVertex(f interfaces.Func) error
DeleteVertex is the thread-safe way to delete a vertex. You will need to call the engine Lock method before using this and the Unlock method afterwards.
func (*Engine) ExecGraphviz ¶
ExecGraphviz writes out the diagram of a graph to be used for visualization and debugging. You must not modify the graph (eg: during Lock) when calling this method.
func (*Engine) FindEdge ¶
func (obj *Engine) FindEdge(f1, f2 interfaces.Func) *interfaces.FuncEdge
FindEdge is the thread-safe way to check which edge (if any) exists between two vertices in the graph. 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. You will need to call the engine Lock method before using this and the Unlock method afterwards.
func (*Engine) HasVertex ¶
func (obj *Engine) HasVertex(f interfaces.Func) bool
HasVertex is the thread-safe way to check if a vertex exists in the graph. You will need to call the engine Lock method before using this and the Unlock method afterwards.
func (*Engine) Loaded ¶
func (obj *Engine) Loaded() <-chan struct{}
Loaded returns a channel that closes when the function engine loads.
func (*Engine) Lock ¶
func (obj *Engine) Lock()
Lock must be used before modifying the running graph. Make sure to Unlock when done. XXX: should Lock take a context if we want to bail mid-way? TODO: could we replace pauseChan with SubscribedSignal ?
func (*Engine) LookupEdge ¶
func (obj *Engine) LookupEdge(fe *interfaces.FuncEdge) (interfaces.Func, interfaces.Func, bool)
LookupEdge is the thread-safe way to check which vertices (if any) exist between an edge in the graph. You will need to call the engine Lock method before using this and the Unlock method afterwards.
func (*Engine) NumVertices ¶
NumVertices returns the number of vertices in the current graph.
func (*Engine) Run ¶
Run kicks off the main engine. This takes a mutex. When we're "paused" the mutex is temporarily released until we "resume". Those operations transition with the engine Lock and Unlock methods. It is recommended to only add vertices to the engine after it's running. If you add them before Run, then Run will cause a Lock/Unlock to occur to cycle them in. Lock and Unlock race with the cancellation of this Run main loop. Make sure to only call one at a time.
func (*Engine) Started ¶
func (obj *Engine) Started() <-chan struct{}
Started returns a channel that closes when the Run function finishes starting up. This is useful so that we can wait before calling any of the mutex things that would normally panic if Run wasn't started up first.
func (*Engine) Stream ¶
Stream returns a channel that you can follow to get aggregated graph events. Do not block reading from this channel as you can hold up the entire engine.
func (*Engine) Table ¶
func (obj *Engine) Table() map[interfaces.Func]types.Value
Table returns a copy of the populated data table of values. We return a copy because since these values are constantly changing, we need an atomic snapshot to present to the consumer of this API. TODO: is this globally glitch consistent? TODO: do we need an API to return a single value? (wrapped in read locks)
func (*Engine) Txn ¶
func (obj *Engine) Txn() interfaces.Txn
Txn returns a transaction that is suitable for adding and removing from the graph. You must run Setup before this method is called.