|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- package ops2
-
- import (
- "fmt"
-
- "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/ioswitch/dag"
- "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/ioswitch/exec"
- "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/pool"
- stgtypes "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/types"
- jcstypes "gitlink.org.cn/cloudream/jcs-pub/common/types"
- )
-
- func init() {
- exec.UseOp[*GetShardHTTPRequest]()
- exec.UseVarValue[*HTTPRequestValue]()
- }
-
- // 旁路Http读取
- type GetShardHTTPRequest struct {
- UserSpace jcstypes.UserSpaceDetail
- FileHash jcstypes.FileHash
- Output exec.VarID
- }
-
- type HTTPRequestValue struct {
- stgtypes.HTTPRequest
- }
-
- func (v *HTTPRequestValue) Clone() exec.VarValue {
- return &HTTPRequestValue{
- HTTPRequest: v.HTTPRequest,
- }
- }
-
- func (o *GetShardHTTPRequest) Execute(ctx *exec.ExecContext, e *exec.Executor) error {
- stgPool, err := exec.GetValueByType[*pool.Pool](ctx)
- if err != nil {
- return err
- }
-
- shardStore, err := stgPool.GetShardStore(&o.UserSpace)
- if err != nil {
- return err
- }
-
- br, ok := shardStore.(stgtypes.HTTPShardRead)
- if !ok {
- return fmt.Errorf("shard store %v not support bypass read", o.UserSpace)
- }
-
- req, err := br.MakeHTTPReadRequest(o.FileHash)
- if err != nil {
- return err
- }
-
- e.PutVar(o.Output, &HTTPRequestValue{HTTPRequest: req})
- return nil
- }
-
- func (o *GetShardHTTPRequest) String() string {
- return fmt.Sprintf("GetShardHTTPRequest[UserSpace:%v] FileHash: %v, Output: %v", o.UserSpace, o.FileHash, o.Output)
- }
-
- // 旁路Http读取
- type GetShardHTTPRequestNode struct {
- dag.NodeBase
- UserSpace jcstypes.UserSpaceDetail
- FileHash jcstypes.FileHash
- }
-
- func (b *GraphNodeBuilder) NewGetShardHTTPRequest(userSpace jcstypes.UserSpaceDetail, fileHash jcstypes.FileHash) *GetShardHTTPRequestNode {
- node := &GetShardHTTPRequestNode{
- UserSpace: userSpace,
- FileHash: fileHash,
- }
- b.AddNode(node)
-
- node.OutputValues().Init(node, 1)
- return node
- }
-
- func (n *GetShardHTTPRequestNode) HTTPRequestVar() dag.ValueOutputSlot {
- return dag.ValueOutputSlot{
- Node: n,
- Index: 0,
- }
- }
-
- func (n *GetShardHTTPRequestNode) GenerateOp() (exec.Op, error) {
- return &GetShardHTTPRequest{
- UserSpace: n.UserSpace,
- FileHash: n.FileHash,
- Output: n.HTTPRequestVar().Var().VarID,
- }, nil
- }
|