|
|
@@ -6,223 +6,172 @@ import ( |
|
|
"github.com/samber/lo" |
|
|
"github.com/samber/lo" |
|
|
"gitlink.org.cn/cloudream/common/pkgs/ipfs" |
|
|
"gitlink.org.cn/cloudream/common/pkgs/ipfs" |
|
|
cdssdk "gitlink.org.cn/cloudream/common/sdks/storage" |
|
|
cdssdk "gitlink.org.cn/cloudream/common/sdks/storage" |
|
|
"gitlink.org.cn/cloudream/common/utils/lo2" |
|
|
|
|
|
"gitlink.org.cn/cloudream/storage/common/pkgs/ec" |
|
|
"gitlink.org.cn/cloudream/storage/common/pkgs/ec" |
|
|
"gitlink.org.cn/cloudream/storage/common/pkgs/ioswitch" |
|
|
"gitlink.org.cn/cloudream/storage/common/pkgs/ioswitch" |
|
|
|
|
|
"gitlink.org.cn/cloudream/storage/common/pkgs/ioswitch/dag" |
|
|
|
|
|
"gitlink.org.cn/cloudream/storage/common/pkgs/ioswitch/exec" |
|
|
"gitlink.org.cn/cloudream/storage/common/pkgs/ioswitch/ops" |
|
|
"gitlink.org.cn/cloudream/storage/common/pkgs/ioswitch/ops" |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
type VarIndex int |
|
|
|
|
|
|
|
|
|
|
|
type StreamVar struct { |
|
|
|
|
|
DataIndex int |
|
|
|
|
|
From *Node |
|
|
|
|
|
Toes []*Node |
|
|
|
|
|
Var *ioswitch.StreamVar |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (v *StreamVar) AddTo(to *Node) { |
|
|
|
|
|
v.Toes = append(v.Toes, to) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (v *StreamVar) RemoveTo(to *Node) { |
|
|
|
|
|
v.Toes = lo2.Remove(v.Toes, to) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
type ValueVarType int |
|
|
|
|
|
|
|
|
|
|
|
const ( |
|
|
|
|
|
StringValueVar ValueVarType = iota |
|
|
|
|
|
SignalValueVar |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
type ValueVar struct { |
|
|
|
|
|
Type ValueVarType |
|
|
|
|
|
From *Node |
|
|
|
|
|
Toes []*Node |
|
|
|
|
|
Var ioswitch.Var |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (v *ValueVar) AddTo(to *Node) { |
|
|
|
|
|
v.Toes = append(v.Toes, to) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (v *ValueVar) RemoveTo(to *Node) { |
|
|
|
|
|
v.Toes = lo2.Remove(v.Toes, to) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
type OpEnv interface { |
|
|
|
|
|
Equals(env OpEnv) bool |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
type AgentEnv struct { |
|
|
|
|
|
Node cdssdk.Node |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (e *AgentEnv) Equals(env OpEnv) bool { |
|
|
|
|
|
if agentEnv, ok := env.(*AgentEnv); ok { |
|
|
|
|
|
return e.Node.NodeID == agentEnv.Node.NodeID |
|
|
|
|
|
} |
|
|
|
|
|
return false |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
type ExecutorEnv struct{} |
|
|
|
|
|
|
|
|
|
|
|
func (e *ExecutorEnv) Equals(env OpEnv) bool { |
|
|
|
|
|
_, ok := env.(*ExecutorEnv) |
|
|
|
|
|
return ok |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
type OpType interface { |
|
|
|
|
|
GenerateOp(node *Node, blder *PlanBuilder) error |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
type Node struct { |
|
|
|
|
|
Env OpEnv // Op将在哪里执行,Agent或者Executor |
|
|
|
|
|
Type OpType |
|
|
|
|
|
InputStreams []*StreamVar |
|
|
|
|
|
OutputStreams []*StreamVar |
|
|
|
|
|
InputValues []*ValueVar |
|
|
|
|
|
OutputValues []*ValueVar |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (o *Node) NewOutputStream(dataIndex int) *StreamVar { |
|
|
|
|
|
v := &StreamVar{DataIndex: dataIndex, From: o} |
|
|
|
|
|
o.OutputStreams = append(o.OutputStreams, v) |
|
|
|
|
|
return v |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (o *Node) AddInputStream(str *StreamVar) { |
|
|
|
|
|
o.InputStreams = append(o.InputStreams, str) |
|
|
|
|
|
str.AddTo(o) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (o *Node) ReplaceInputStream(old *StreamVar, new *StreamVar) { |
|
|
|
|
|
old.RemoveTo(o) |
|
|
|
|
|
new.AddTo(o) |
|
|
|
|
|
|
|
|
|
|
|
idx := lo.IndexOf(o.InputStreams, old) |
|
|
|
|
|
o.InputStreams[idx] = new |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (o *Node) NewOutputVar(typ ValueVarType) *ValueVar { |
|
|
|
|
|
v := &ValueVar{Type: typ, From: o} |
|
|
|
|
|
o.OutputValues = append(o.OutputValues, v) |
|
|
|
|
|
return v |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (o *Node) AddInputVar(v *ValueVar) { |
|
|
|
|
|
o.InputValues = append(o.InputValues, v) |
|
|
|
|
|
v.AddTo(o) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (o *Node) ReplaceInputVar(old *ValueVar, new *ValueVar) { |
|
|
|
|
|
old.RemoveTo(o) |
|
|
|
|
|
new.AddTo(o) |
|
|
|
|
|
|
|
|
|
|
|
idx := lo.IndexOf(o.InputValues, old) |
|
|
|
|
|
o.InputValues[idx] = new |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (o *Node) String() string { |
|
|
|
|
|
return fmt.Sprintf("Node(%T)", o.Type) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
type IPFSReadType struct { |
|
|
type IPFSReadType struct { |
|
|
FileHash string |
|
|
FileHash string |
|
|
Option ipfs.ReadOption |
|
|
Option ipfs.ReadOption |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (t *IPFSReadType) GenerateOp(node *Node, blder *PlanBuilder) error { |
|
|
|
|
|
|
|
|
func (t *IPFSReadType) InitNode(node *Node) { |
|
|
|
|
|
dag.NodeNewOutputStream(node, VarProps{}) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (t *IPFSReadType) GenerateOp(node *Node, blder *exec.PlanBuilder) error { |
|
|
addOpByEnv(&ops.IPFSRead{ |
|
|
addOpByEnv(&ops.IPFSRead{ |
|
|
Output: node.OutputStreams[0].Var, |
|
|
|
|
|
|
|
|
Output: node.OutputStreams[0].Props.Var.(*ioswitch.StreamVar), |
|
|
FileHash: t.FileHash, |
|
|
FileHash: t.FileHash, |
|
|
Option: t.Option, |
|
|
Option: t.Option, |
|
|
}, node.Env, blder) |
|
|
}, node.Env, blder) |
|
|
return nil |
|
|
return nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (t *IPFSReadType) String(node *Node) string { |
|
|
|
|
|
return fmt.Sprintf("IPFSRead[%s,%v+%v]%v%v", t.FileHash, t.Option.Offset, t.Option.Length, formatStreamIO(node), formatValueIO(node)) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
type IPFSWriteType struct { |
|
|
type IPFSWriteType struct { |
|
|
FileHashStoreKey string |
|
|
FileHashStoreKey string |
|
|
Range Range |
|
|
Range Range |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (t *IPFSWriteType) GenerateOp(op *Node, blder *PlanBuilder) error { |
|
|
|
|
|
|
|
|
func (t *IPFSWriteType) InitNode(node *Node) { |
|
|
|
|
|
dag.NodeDeclareInputStream(node, 1) |
|
|
|
|
|
dag.NodeNewOutputValue(node, VarProps{}) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (t *IPFSWriteType) GenerateOp(op *Node, blder *exec.PlanBuilder) error { |
|
|
addOpByEnv(&ops.IPFSWrite{ |
|
|
addOpByEnv(&ops.IPFSWrite{ |
|
|
Input: op.InputStreams[0].Var, |
|
|
|
|
|
FileHash: op.OutputValues[0].Var.(*ioswitch.StringVar), |
|
|
|
|
|
|
|
|
Input: op.InputStreams[0].Props.Var.(*ioswitch.StreamVar), |
|
|
|
|
|
FileHash: op.OutputValues[0].Props.Var.(*ioswitch.StringVar), |
|
|
}, op.Env, blder) |
|
|
}, op.Env, blder) |
|
|
return nil |
|
|
return nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (t *IPFSWriteType) String(node *Node) string { |
|
|
|
|
|
return fmt.Sprintf("IPFSWrite[%s,%v+%v](%v>)", t.FileHashStoreKey, t.Range.Offset, t.Range.Length, formatStreamIO(node), formatValueIO(node)) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
type ChunkedSplitType struct { |
|
|
type ChunkedSplitType struct { |
|
|
ChunkSize int |
|
|
|
|
|
PaddingZeros bool |
|
|
|
|
|
|
|
|
OutputCount int |
|
|
|
|
|
ChunkSize int |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (t *ChunkedSplitType) InitNode(node *Node) { |
|
|
|
|
|
dag.NodeDeclareInputStream(node, 1) |
|
|
|
|
|
for i := 0; i < t.OutputCount; i++ { |
|
|
|
|
|
dag.NodeNewOutputStream(node, VarProps{}) |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (t *ChunkedSplitType) GenerateOp(op *Node, blder *PlanBuilder) error { |
|
|
|
|
|
|
|
|
func (t *ChunkedSplitType) GenerateOp(op *Node, blder *exec.PlanBuilder) error { |
|
|
addOpByEnv(&ops.ChunkedSplit{ |
|
|
addOpByEnv(&ops.ChunkedSplit{ |
|
|
Input: op.InputStreams[0].Var, |
|
|
|
|
|
|
|
|
Input: op.InputStreams[0].Props.Var.(*ioswitch.StreamVar), |
|
|
Outputs: lo.Map(op.OutputStreams, func(v *StreamVar, idx int) *ioswitch.StreamVar { |
|
|
Outputs: lo.Map(op.OutputStreams, func(v *StreamVar, idx int) *ioswitch.StreamVar { |
|
|
return v.Var |
|
|
|
|
|
|
|
|
return v.Props.Var.(*ioswitch.StreamVar) |
|
|
}), |
|
|
}), |
|
|
ChunkSize: t.ChunkSize, |
|
|
ChunkSize: t.ChunkSize, |
|
|
PaddingZeros: t.PaddingZeros, |
|
|
|
|
|
|
|
|
PaddingZeros: true, |
|
|
}, op.Env, blder) |
|
|
}, op.Env, blder) |
|
|
return nil |
|
|
return nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (t *ChunkedSplitType) String(node *Node) string { |
|
|
|
|
|
return fmt.Sprintf("ChunkedSplit[%v]", t.ChunkSize, formatStreamIO(node), formatValueIO(node)) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
type ChunkedJoinType struct { |
|
|
type ChunkedJoinType struct { |
|
|
ChunkSize int |
|
|
|
|
|
|
|
|
InputCount int |
|
|
|
|
|
ChunkSize int |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (t *ChunkedJoinType) GenerateOp(op *Node, blder *PlanBuilder) error { |
|
|
|
|
|
|
|
|
func (t *ChunkedJoinType) InitNode(node *Node) { |
|
|
|
|
|
dag.NodeDeclareInputStream(node, t.InputCount) |
|
|
|
|
|
dag.NodeNewOutputStream(node, VarProps{}) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (t *ChunkedJoinType) GenerateOp(op *Node, blder *exec.PlanBuilder) error { |
|
|
addOpByEnv(&ops.ChunkedJoin{ |
|
|
addOpByEnv(&ops.ChunkedJoin{ |
|
|
Inputs: lo.Map(op.InputStreams, func(v *StreamVar, idx int) *ioswitch.StreamVar { |
|
|
Inputs: lo.Map(op.InputStreams, func(v *StreamVar, idx int) *ioswitch.StreamVar { |
|
|
return v.Var |
|
|
|
|
|
|
|
|
return v.Props.Var.(*ioswitch.StreamVar) |
|
|
}), |
|
|
}), |
|
|
Output: op.OutputStreams[0].Var, |
|
|
|
|
|
|
|
|
Output: op.OutputStreams[0].Props.Var.(*ioswitch.StreamVar), |
|
|
ChunkSize: t.ChunkSize, |
|
|
ChunkSize: t.ChunkSize, |
|
|
}, op.Env, blder) |
|
|
}, op.Env, blder) |
|
|
return nil |
|
|
return nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (t *ChunkedJoinType) String(node *Node) string { |
|
|
|
|
|
return fmt.Sprintf("ChunkedJoin[%v]", t.ChunkSize, formatStreamIO(node), formatValueIO(node)) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
type CloneStreamType struct{} |
|
|
type CloneStreamType struct{} |
|
|
|
|
|
|
|
|
func (t *CloneStreamType) GenerateOp(op *Node, blder *PlanBuilder) error { |
|
|
|
|
|
|
|
|
func (t *CloneStreamType) InitNode(node *Node) { |
|
|
|
|
|
dag.NodeDeclareInputStream(node, 1) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (t *CloneStreamType) GenerateOp(op *Node, blder *exec.PlanBuilder) error { |
|
|
addOpByEnv(&ops.CloneStream{ |
|
|
addOpByEnv(&ops.CloneStream{ |
|
|
Input: op.InputStreams[0].Var, |
|
|
|
|
|
|
|
|
Input: op.InputStreams[0].Props.Var.(*ioswitch.StreamVar), |
|
|
Outputs: lo.Map(op.OutputStreams, func(v *StreamVar, idx int) *ioswitch.StreamVar { |
|
|
Outputs: lo.Map(op.OutputStreams, func(v *StreamVar, idx int) *ioswitch.StreamVar { |
|
|
return v.Var |
|
|
|
|
|
|
|
|
return v.Props.Var.(*ioswitch.StreamVar) |
|
|
}), |
|
|
}), |
|
|
}, op.Env, blder) |
|
|
}, op.Env, blder) |
|
|
return nil |
|
|
return nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (t *CloneStreamType) NewOutput(node *Node) *StreamVar { |
|
|
|
|
|
return dag.NodeNewOutputStream(node, VarProps{}) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (t *CloneStreamType) String(node *Node) string { |
|
|
|
|
|
return fmt.Sprintf("CloneStream[]%v%v", formatStreamIO(node), formatValueIO(node)) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
type CloneVarType struct{} |
|
|
type CloneVarType struct{} |
|
|
|
|
|
|
|
|
func (t *CloneVarType) GenerateOp(op *Node, blder *PlanBuilder) error { |
|
|
|
|
|
|
|
|
func (t *CloneVarType) InitNode(node *Node) { |
|
|
|
|
|
dag.NodeDeclareInputValue(node, 1) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (t *CloneVarType) GenerateOp(op *Node, blder *exec.PlanBuilder) error { |
|
|
addOpByEnv(&ops.CloneVar{ |
|
|
addOpByEnv(&ops.CloneVar{ |
|
|
Raw: op.InputValues[0].Var, |
|
|
|
|
|
|
|
|
Raw: op.InputValues[0].Props.Var, |
|
|
Cloneds: lo.Map(op.OutputValues, func(v *ValueVar, idx int) ioswitch.Var { |
|
|
Cloneds: lo.Map(op.OutputValues, func(v *ValueVar, idx int) ioswitch.Var { |
|
|
return v.Var |
|
|
|
|
|
|
|
|
return v.Props.Var |
|
|
}), |
|
|
}), |
|
|
}, op.Env, blder) |
|
|
}, op.Env, blder) |
|
|
return nil |
|
|
return nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
type MultiplyOp struct { |
|
|
|
|
|
|
|
|
func (t *CloneVarType) NewOutput(node *Node) *ValueVar { |
|
|
|
|
|
return dag.NodeNewOutputValue(node, VarProps{}) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (t *CloneVarType) String(node *Node) string { |
|
|
|
|
|
return fmt.Sprintf("CloneVar[]%v%v", formatStreamIO(node), formatValueIO(node)) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
type MultiplyType struct { |
|
|
EC cdssdk.ECRedundancy |
|
|
EC cdssdk.ECRedundancy |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (t *MultiplyOp) GenerateOp(op *Node, blder *PlanBuilder) error { |
|
|
|
|
|
|
|
|
func (t *MultiplyType) InitNode(node *Node) {} |
|
|
|
|
|
|
|
|
|
|
|
func (t *MultiplyType) GenerateOp(op *Node, blder *exec.PlanBuilder) error { |
|
|
var inputIdxs []int |
|
|
var inputIdxs []int |
|
|
var outputIdxs []int |
|
|
var outputIdxs []int |
|
|
for _, in := range op.InputStreams { |
|
|
for _, in := range op.InputStreams { |
|
|
inputIdxs = append(inputIdxs, in.DataIndex) |
|
|
|
|
|
|
|
|
inputIdxs = append(inputIdxs, in.Props.StreamIndex) |
|
|
} |
|
|
} |
|
|
for _, out := range op.OutputStreams { |
|
|
for _, out := range op.OutputStreams { |
|
|
outputIdxs = append(outputIdxs, out.DataIndex) |
|
|
|
|
|
|
|
|
outputIdxs = append(outputIdxs, out.Props.StreamIndex) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
rs, err := ec.NewRs(t.EC.K, t.EC.N) |
|
|
rs, err := ec.NewRs(t.EC.K, t.EC.N) |
|
|
@@ -233,169 +182,353 @@ func (t *MultiplyOp) GenerateOp(op *Node, blder *PlanBuilder) error { |
|
|
|
|
|
|
|
|
addOpByEnv(&ops.ECMultiply{ |
|
|
addOpByEnv(&ops.ECMultiply{ |
|
|
Coef: coef, |
|
|
Coef: coef, |
|
|
Inputs: lo.Map(op.InputStreams, func(v *StreamVar, idx int) *ioswitch.StreamVar { return v.Var }), |
|
|
|
|
|
Outputs: lo.Map(op.OutputStreams, func(v *StreamVar, idx int) *ioswitch.StreamVar { return v.Var }), |
|
|
|
|
|
|
|
|
Inputs: lo.Map(op.InputStreams, func(v *StreamVar, idx int) *ioswitch.StreamVar { return v.Props.Var.(*ioswitch.StreamVar) }), |
|
|
|
|
|
Outputs: lo.Map(op.OutputStreams, func(v *StreamVar, idx int) *ioswitch.StreamVar { return v.Props.Var.(*ioswitch.StreamVar) }), |
|
|
ChunkSize: t.EC.ChunkSize, |
|
|
ChunkSize: t.EC.ChunkSize, |
|
|
}, op.Env, blder) |
|
|
}, op.Env, blder) |
|
|
return nil |
|
|
return nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
type FileReadOp struct { |
|
|
|
|
|
|
|
|
func (t *MultiplyType) AddInput(node *Node, str *StreamVar) { |
|
|
|
|
|
node.InputStreams = append(node.InputStreams, str) |
|
|
|
|
|
str.To(node, len(node.InputStreams)-1) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (t *MultiplyType) NewOutput(node *Node, dataIndex int) *StreamVar { |
|
|
|
|
|
return dag.NodeNewOutputStream(node, VarProps{StreamIndex: dataIndex}) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (t *MultiplyType) String(node *Node) string { |
|
|
|
|
|
return fmt.Sprintf("Multiply[]%v%v", formatStreamIO(node), formatValueIO(node)) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
type FileReadType struct { |
|
|
FilePath string |
|
|
FilePath string |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (t *FileReadOp) GenerateOp(op *Node, blder *PlanBuilder) error { |
|
|
|
|
|
|
|
|
func (t *FileReadType) InitNode(node *Node) { |
|
|
|
|
|
dag.NodeNewOutputStream(node, VarProps{}) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (t *FileReadType) GenerateOp(op *Node, blder *exec.PlanBuilder) error { |
|
|
addOpByEnv(&ops.FileRead{ |
|
|
addOpByEnv(&ops.FileRead{ |
|
|
Output: op.OutputStreams[0].Var, |
|
|
|
|
|
|
|
|
Output: op.OutputStreams[0].Props.Var.(*ioswitch.StreamVar), |
|
|
FilePath: t.FilePath, |
|
|
FilePath: t.FilePath, |
|
|
}, op.Env, blder) |
|
|
}, op.Env, blder) |
|
|
return nil |
|
|
return nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
type FileWriteOp struct { |
|
|
|
|
|
|
|
|
func (t *FileReadType) String(node *Node) string { |
|
|
|
|
|
return fmt.Sprintf("FileRead[%s]%v%v", t.FilePath, formatStreamIO(node), formatValueIO(node)) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
type FileWriteType struct { |
|
|
FilePath string |
|
|
FilePath string |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (t *FileWriteOp) GenerateOp(op *Node, blder *PlanBuilder) error { |
|
|
|
|
|
|
|
|
func (t *FileWriteType) InitNode(node *Node) { |
|
|
|
|
|
dag.NodeDeclareInputStream(node, 1) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (t *FileWriteType) GenerateOp(op *Node, blder *exec.PlanBuilder) error { |
|
|
addOpByEnv(&ops.FileWrite{ |
|
|
addOpByEnv(&ops.FileWrite{ |
|
|
Input: op.InputStreams[0].Var, |
|
|
|
|
|
|
|
|
Input: op.InputStreams[0].Props.Var.(*ioswitch.StreamVar), |
|
|
FilePath: t.FilePath, |
|
|
FilePath: t.FilePath, |
|
|
}, op.Env, blder) |
|
|
}, op.Env, blder) |
|
|
return nil |
|
|
return nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
type FromExecutorOp struct { |
|
|
|
|
|
Handle *ExecutorWriteStream |
|
|
|
|
|
|
|
|
type FromExecutorType struct { |
|
|
|
|
|
Handle *exec.ExecutorWriteStream |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (t *FromExecutorType) InitNode(node *Node) { |
|
|
|
|
|
dag.NodeNewOutputStream(node, VarProps{}) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (t *FromExecutorOp) GenerateOp(op *Node, blder *PlanBuilder) error { |
|
|
|
|
|
t.Handle.Var = op.OutputStreams[0].Var |
|
|
|
|
|
|
|
|
func (t *FromExecutorType) GenerateOp(op *Node, blder *exec.PlanBuilder) error { |
|
|
|
|
|
t.Handle.Var = op.OutputStreams[0].Props.Var.(*ioswitch.StreamVar) |
|
|
return nil |
|
|
return nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
type ToExecutorOp struct { |
|
|
|
|
|
Handle *ExecutorReadStream |
|
|
|
|
|
|
|
|
func (t *FromExecutorType) String(node *Node) string { |
|
|
|
|
|
return fmt.Sprintf("FromExecutor[]%v%v", formatStreamIO(node), formatValueIO(node)) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
type ToExecutorType struct { |
|
|
|
|
|
Handle *exec.ExecutorReadStream |
|
|
Range Range |
|
|
Range Range |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (t *ToExecutorOp) GenerateOp(op *Node, blder *PlanBuilder) error { |
|
|
|
|
|
t.Handle.Var = op.InputStreams[0].Var |
|
|
|
|
|
|
|
|
func (t *ToExecutorType) InitNode(node *Node) { |
|
|
|
|
|
dag.NodeDeclareInputStream(node, 1) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (t *ToExecutorType) GenerateOp(op *Node, blder *exec.PlanBuilder) error { |
|
|
|
|
|
t.Handle.Var = op.InputStreams[0].Props.Var.(*ioswitch.StreamVar) |
|
|
return nil |
|
|
return nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
type StoreOp struct { |
|
|
|
|
|
|
|
|
func (t *ToExecutorType) String(node *Node) string { |
|
|
|
|
|
return fmt.Sprintf("ToExecutor[%v+%v]%v%v", t.Range.Offset, t.Range.Length, formatStreamIO(node), formatValueIO(node)) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
type StoreType struct { |
|
|
StoreKey string |
|
|
StoreKey string |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (t *StoreOp) GenerateOp(op *Node, blder *PlanBuilder) error { |
|
|
|
|
|
|
|
|
func (t *StoreType) InitNode(node *Node) { |
|
|
|
|
|
dag.NodeDeclareInputValue(node, 1) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (t *StoreType) GenerateOp(op *Node, blder *exec.PlanBuilder) error { |
|
|
blder.AtExecutor().AddOp(&ops.Store{ |
|
|
blder.AtExecutor().AddOp(&ops.Store{ |
|
|
Var: op.InputValues[0].Var, |
|
|
|
|
|
|
|
|
Var: op.InputValues[0].Props.Var, |
|
|
Key: t.StoreKey, |
|
|
Key: t.StoreKey, |
|
|
Store: blder.ExecutorPlan.StoreMap, |
|
|
Store: blder.ExecutorPlan.StoreMap, |
|
|
}) |
|
|
}) |
|
|
return nil |
|
|
return nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
type DropOp struct{} |
|
|
|
|
|
|
|
|
func (t *StoreType) String(node *Node) string { |
|
|
|
|
|
return fmt.Sprintf("Store[%s]%v%v", t.StoreKey, formatStreamIO(node), formatValueIO(node)) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
type DropType struct{} |
|
|
|
|
|
|
|
|
|
|
|
func (t *DropType) InitNode(node *Node) { |
|
|
|
|
|
dag.NodeDeclareInputStream(node, 1) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
func (t *DropOp) GenerateOp(op *Node, blder *PlanBuilder) error { |
|
|
|
|
|
|
|
|
func (t *DropType) GenerateOp(op *Node, blder *exec.PlanBuilder) error { |
|
|
addOpByEnv(&ops.DropStream{ |
|
|
addOpByEnv(&ops.DropStream{ |
|
|
Input: op.InputStreams[0].Var, |
|
|
|
|
|
|
|
|
Input: op.InputStreams[0].Props.Var.(*ioswitch.StreamVar), |
|
|
}, op.Env, blder) |
|
|
}, op.Env, blder) |
|
|
return nil |
|
|
return nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
type SendStreamOp struct{} |
|
|
|
|
|
|
|
|
func (t *DropType) String(node *Node) string { |
|
|
|
|
|
return fmt.Sprintf("Drop[]%v%v", formatStreamIO(node), formatValueIO(node)) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
type SendStreamType struct { |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (t *SendStreamType) InitNode(node *Node) { |
|
|
|
|
|
dag.NodeDeclareInputStream(node, 1) |
|
|
|
|
|
dag.NodeNewOutputStream(node, VarProps{}) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
func (t *SendStreamOp) GenerateOp(op *Node, blder *PlanBuilder) error { |
|
|
|
|
|
toAgt := op.OutputStreams[0].Toes[0].Env.(*AgentEnv) |
|
|
|
|
|
|
|
|
func (t *SendStreamType) GenerateOp(op *Node, blder *exec.PlanBuilder) error { |
|
|
|
|
|
toAgt := op.OutputStreams[0].Toes[0].Node.Env.Worker.(*AgentWorker) |
|
|
addOpByEnv(&ops.SendStream{ |
|
|
addOpByEnv(&ops.SendStream{ |
|
|
Input: op.InputStreams[0].Var, |
|
|
|
|
|
Send: op.OutputStreams[0].Var, |
|
|
|
|
|
|
|
|
Input: op.InputStreams[0].Props.Var.(*ioswitch.StreamVar), |
|
|
|
|
|
Send: op.OutputStreams[0].Props.Var.(*ioswitch.StreamVar), |
|
|
Node: toAgt.Node, |
|
|
Node: toAgt.Node, |
|
|
}, op.Env, blder) |
|
|
}, op.Env, blder) |
|
|
return nil |
|
|
return nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
type GetStreamOp struct{} |
|
|
|
|
|
|
|
|
func (t *SendStreamType) String(node *Node) string { |
|
|
|
|
|
return fmt.Sprintf("SendStream[]%v%v", formatStreamIO(node), formatValueIO(node)) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
func (t *GetStreamOp) GenerateOp(op *Node, blder *PlanBuilder) error { |
|
|
|
|
|
fromAgt := op.InputStreams[0].From.Env.(*AgentEnv) |
|
|
|
|
|
addOpByEnv(&ops.GetStream{ |
|
|
|
|
|
Signal: op.OutputValues[0].Var.(*ioswitch.SignalVar), |
|
|
|
|
|
Output: op.OutputStreams[0].Var, |
|
|
|
|
|
Get: op.InputStreams[0].Var, |
|
|
|
|
|
Node: fromAgt.Node, |
|
|
|
|
|
}, op.Env, blder) |
|
|
|
|
|
return nil |
|
|
|
|
|
|
|
|
type SendVarType struct { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
type SendVarOp struct{} |
|
|
|
|
|
|
|
|
func (t *SendVarType) InitNode(node *Node) { |
|
|
|
|
|
dag.NodeDeclareInputValue(node, 1) |
|
|
|
|
|
dag.NodeNewOutputValue(node, VarProps{}) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
func (t *SendVarOp) GenerateOp(op *Node, blder *PlanBuilder) error { |
|
|
|
|
|
toAgt := op.OutputValues[0].Toes[0].Env.(*AgentEnv) |
|
|
|
|
|
|
|
|
func (t *SendVarType) GenerateOp(op *Node, blder *exec.PlanBuilder) error { |
|
|
|
|
|
toAgt := op.OutputValues[0].Toes[0].Node.Env.Worker.(*AgentWorker) |
|
|
addOpByEnv(&ops.SendVar{ |
|
|
addOpByEnv(&ops.SendVar{ |
|
|
Input: op.InputValues[0].Var, |
|
|
|
|
|
Send: op.OutputValues[0].Var, |
|
|
|
|
|
|
|
|
Input: op.InputValues[0].Props.Var, |
|
|
|
|
|
Send: op.OutputValues[0].Props.Var, |
|
|
Node: toAgt.Node, |
|
|
Node: toAgt.Node, |
|
|
}, op.Env, blder) |
|
|
}, op.Env, blder) |
|
|
return nil |
|
|
return nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
type GetVarOp struct{} |
|
|
|
|
|
|
|
|
func (t *SendVarType) String(node *Node) string { |
|
|
|
|
|
return fmt.Sprintf("SendVar[]%v%v", formatStreamIO(node), formatValueIO(node)) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
type GetStreamType struct { |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
func (t *GetVarOp) GenerateOp(op *Node, blder *PlanBuilder) error { |
|
|
|
|
|
fromAgt := op.InputValues[0].From.Env.(*AgentEnv) |
|
|
|
|
|
|
|
|
func (t *GetStreamType) InitNode(node *Node) { |
|
|
|
|
|
dag.NodeDeclareInputStream(node, 1) |
|
|
|
|
|
dag.NodeNewOutputValue(node, VarProps{}) |
|
|
|
|
|
dag.NodeNewOutputStream(node, VarProps{}) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (t *GetStreamType) GenerateOp(op *Node, blder *exec.PlanBuilder) error { |
|
|
|
|
|
fromAgt := op.InputStreams[0].From.Node.Env.Worker.(*AgentWorker) |
|
|
|
|
|
addOpByEnv(&ops.GetStream{ |
|
|
|
|
|
Signal: op.OutputValues[0].Props.Var.(*ioswitch.SignalVar), |
|
|
|
|
|
Output: op.OutputStreams[0].Props.Var.(*ioswitch.StreamVar), |
|
|
|
|
|
Target: op.InputStreams[0].Props.Var.(*ioswitch.StreamVar), |
|
|
|
|
|
Node: fromAgt.Node, |
|
|
|
|
|
}, op.Env, blder) |
|
|
|
|
|
return nil |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (t *GetStreamType) String(node *Node) string { |
|
|
|
|
|
return fmt.Sprintf("GetStream[]%v%v", formatStreamIO(node), formatValueIO(node)) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
type GetVaType struct { |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (t *GetVaType) InitNode(node *Node) { |
|
|
|
|
|
dag.NodeDeclareInputValue(node, 1) |
|
|
|
|
|
dag.NodeNewOutputValue(node, VarProps{}) |
|
|
|
|
|
dag.NodeNewOutputValue(node, VarProps{}) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (t *GetVaType) GenerateOp(op *Node, blder *exec.PlanBuilder) error { |
|
|
|
|
|
fromAgt := op.InputValues[0].From.Node.Env.Worker.(*AgentWorker) |
|
|
addOpByEnv(&ops.GetVar{ |
|
|
addOpByEnv(&ops.GetVar{ |
|
|
Signal: op.OutputValues[0].Var.(*ioswitch.SignalVar), |
|
|
|
|
|
Output: op.OutputValues[1].Var, |
|
|
|
|
|
Get: op.InputValues[0].Var, |
|
|
|
|
|
|
|
|
Signal: op.OutputValues[0].Props.Var.(*ioswitch.SignalVar), |
|
|
|
|
|
Output: op.OutputValues[1].Props.Var, |
|
|
|
|
|
Target: op.InputValues[0].Props.Var, |
|
|
Node: fromAgt.Node, |
|
|
Node: fromAgt.Node, |
|
|
}, op.Env, blder) |
|
|
}, op.Env, blder) |
|
|
return nil |
|
|
return nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (t *GetVaType) String(node *Node) string { |
|
|
|
|
|
return fmt.Sprintf("GetVar[]%v%v", formatStreamIO(node), formatValueIO(node)) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
type RangeType struct { |
|
|
type RangeType struct { |
|
|
Range Range |
|
|
Range Range |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (t *RangeType) GenerateOp(op *Node, blder *PlanBuilder) error { |
|
|
|
|
|
|
|
|
func (t *RangeType) InitNode(node *Node) { |
|
|
|
|
|
dag.NodeDeclareInputStream(node, 1) |
|
|
|
|
|
dag.NodeNewOutputStream(node, VarProps{}) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (t *RangeType) GenerateOp(op *Node, blder *exec.PlanBuilder) error { |
|
|
addOpByEnv(&ops.Range{ |
|
|
addOpByEnv(&ops.Range{ |
|
|
Input: op.InputStreams[0].Var, |
|
|
|
|
|
Output: op.OutputStreams[0].Var, |
|
|
|
|
|
|
|
|
Input: op.InputStreams[0].Props.Var.(*ioswitch.StreamVar), |
|
|
|
|
|
Output: op.OutputStreams[0].Props.Var.(*ioswitch.StreamVar), |
|
|
Offset: t.Range.Offset, |
|
|
Offset: t.Range.Offset, |
|
|
Length: t.Range.Length, |
|
|
Length: t.Range.Length, |
|
|
}, op.Env, blder) |
|
|
}, op.Env, blder) |
|
|
return nil |
|
|
return nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
type HoldUntilOp struct { |
|
|
|
|
|
|
|
|
func (t *RangeType) String(node *Node) string { |
|
|
|
|
|
return fmt.Sprintf("Range[%v+%v]%v%v", t.Range.Offset, t.Range.Length, formatStreamIO(node), formatValueIO(node)) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (t *HoldUntilOp) GenerateOp(op *Node, blder *PlanBuilder) error { |
|
|
|
|
|
|
|
|
type HoldUntilType struct { |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (t *HoldUntilType) InitNode(node *Node) { |
|
|
|
|
|
dag.NodeDeclareInputValue(node, 1) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (t *HoldUntilType) GenerateOp(op *Node, blder *exec.PlanBuilder) error { |
|
|
o := &ops.HoldUntil{ |
|
|
o := &ops.HoldUntil{ |
|
|
Waits: []*ioswitch.SignalVar{op.InputValues[0].Var.(*ioswitch.SignalVar)}, |
|
|
|
|
|
|
|
|
Waits: []*ioswitch.SignalVar{op.InputValues[0].Props.Var.(*ioswitch.SignalVar)}, |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
for i := 0; i < len(op.OutputValues); i++ { |
|
|
for i := 0; i < len(op.OutputValues); i++ { |
|
|
o.Holds = append(o.Holds, op.InputValues[i+1].Var) |
|
|
|
|
|
o.Emits = append(o.Emits, op.OutputValues[i].Var) |
|
|
|
|
|
|
|
|
o.Holds = append(o.Holds, op.InputValues[i+1].Props.Var) |
|
|
|
|
|
o.Emits = append(o.Emits, op.OutputValues[i].Props.Var) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
for i := 0; i < len(op.OutputStreams); i++ { |
|
|
for i := 0; i < len(op.OutputStreams); i++ { |
|
|
o.Holds = append(o.Holds, op.InputStreams[i].Var) |
|
|
|
|
|
o.Emits = append(o.Emits, op.OutputStreams[i].Var) |
|
|
|
|
|
|
|
|
o.Holds = append(o.Holds, op.InputStreams[i].Props.Var) |
|
|
|
|
|
o.Emits = append(o.Emits, op.OutputStreams[i].Props.Var) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
addOpByEnv(o, op.Env, blder) |
|
|
addOpByEnv(o, op.Env, blder) |
|
|
return nil |
|
|
return nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func addOpByEnv(op ioswitch.Op, env OpEnv, blder *PlanBuilder) { |
|
|
|
|
|
switch env := env.(type) { |
|
|
|
|
|
case *AgentEnv: |
|
|
|
|
|
blder.AtAgent(env.Node).AddOp(op) |
|
|
|
|
|
case *ExecutorEnv: |
|
|
|
|
|
|
|
|
func (t *HoldUntilType) String(node *Node) string { |
|
|
|
|
|
return fmt.Sprintf("HoldUntil[]%v%v", formatStreamIO(node), formatValueIO(node)) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func addOpByEnv(op ioswitch.Op, env dag.NodeEnv, blder *exec.PlanBuilder) { |
|
|
|
|
|
switch env.Type { |
|
|
|
|
|
case dag.EnvWorker: |
|
|
|
|
|
blder.AtAgent(env.Worker.(*AgentWorker).Node).AddOp(op) |
|
|
|
|
|
case dag.EnvExecutor: |
|
|
blder.AtExecutor().AddOp(op) |
|
|
blder.AtExecutor().AddOp(op) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func formatStreamIO(node *Node) string { |
|
|
|
|
|
is := "" |
|
|
|
|
|
for i, in := range node.InputStreams { |
|
|
|
|
|
if i > 0 { |
|
|
|
|
|
is += "," |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if in == nil { |
|
|
|
|
|
is += "." |
|
|
|
|
|
} else { |
|
|
|
|
|
is += fmt.Sprintf("%v", in.ID) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
os := "" |
|
|
|
|
|
for i, out := range node.OutputStreams { |
|
|
|
|
|
if i > 0 { |
|
|
|
|
|
os += "," |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if out == nil { |
|
|
|
|
|
os += "." |
|
|
|
|
|
} else { |
|
|
|
|
|
os += fmt.Sprintf("%v", out.ID) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if is == "" && os == "" { |
|
|
|
|
|
return "" |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return fmt.Sprintf("S{%s>%s}", is, os) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func formatValueIO(node *Node) string { |
|
|
|
|
|
is := "" |
|
|
|
|
|
for i, in := range node.InputValues { |
|
|
|
|
|
if i > 0 { |
|
|
|
|
|
is += "," |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if in == nil { |
|
|
|
|
|
is += "." |
|
|
|
|
|
} else { |
|
|
|
|
|
is += fmt.Sprintf("%v", in.ID) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
os := "" |
|
|
|
|
|
for i, out := range node.OutputValues { |
|
|
|
|
|
if i > 0 { |
|
|
|
|
|
os += "," |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if out == nil { |
|
|
|
|
|
os += "." |
|
|
|
|
|
} else { |
|
|
|
|
|
os += fmt.Sprintf("%v", out.ID) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if is == "" && os == "" { |
|
|
|
|
|
return "" |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return fmt.Sprintf("V{%s>%s}", is, os) |
|
|
|
|
|
} |