You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

s2s.go 3.4 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. package parser
  2. import (
  3. "gitlink.org.cn/cloudream/storage/common/pkgs/ioswitch2"
  4. "gitlink.org.cn/cloudream/storage/common/pkgs/ioswitch2/ops2"
  5. "gitlink.org.cn/cloudream/storage/common/pkgs/storage/factory"
  6. )
  7. // 将直接从一个存储服务传到另一个存储服务的过程换成S2S传输
  8. func useS2STransfer(ctx *ParseContext) {
  9. // S2S传输暂不支持只传文件的一部分
  10. if ctx.StreamRange.Offset != 0 || ctx.StreamRange.Length != nil {
  11. return
  12. }
  13. for fr, frNode := range ctx.FromNodes {
  14. fromShard, ok := fr.(*ioswitch2.FromShardstore)
  15. if !ok {
  16. continue
  17. }
  18. s2s, err := factory.GetBuilder(fromShard.Storage).CreateS2STransfer()
  19. if err != nil {
  20. continue
  21. }
  22. // 此输出流的所有目的地都要能支持S2S传输
  23. outVar := frNode.Output().Var()
  24. if outVar.Dst.Len() == 0 {
  25. continue
  26. }
  27. failed := false
  28. var toShards []*ops2.ShardWriteNode
  29. // var toShareds []*ops2.SharedLoadNode
  30. loop:
  31. for i := 0; i < outVar.Dst.Len(); i++ {
  32. dstNode := outVar.Dst.Get(i)
  33. switch dstNode := dstNode.(type) {
  34. case *ops2.ShardWriteNode:
  35. if !s2s.CanTransfer(dstNode.Storage) {
  36. failed = true
  37. break
  38. }
  39. toShards = append(toShards, dstNode)
  40. /* TODO 暂不支持共享存储服务
  41. case *ops2.SharedLoadNode:
  42. if !s2s.CanTransfer(to.Storage) {
  43. failed = true
  44. break
  45. }
  46. toShareds = append(toShareds, to)
  47. */
  48. default:
  49. failed = true
  50. break loop
  51. }
  52. }
  53. if failed {
  54. continue
  55. }
  56. for _, toShard := range toShards {
  57. s2sNode := ctx.DAG.NewS2STransfer(fromShard.Storage, toShard.Storage)
  58. // 直传指令在目的地Hub上执行
  59. s2sNode.Env().CopyFrom(toShard.Env())
  60. // 先获取文件路径,送到S2S节点
  61. brNode := ctx.DAG.NewBypassFromShardStore(fromShard.Storage.Storage.StorageID, fromShard.FileHash)
  62. brNode.Env().CopyFrom(frNode.Env())
  63. brNode.FilePathVar().ToSlot(s2sNode.SrcPathSlot())
  64. // 传输结果通知目的节点
  65. to := toShard.To.(*ioswitch2.ToShardStore)
  66. bwNode := ctx.DAG.NewBypassToShardStore(toShard.Storage.Storage.StorageID, to.FileHashStoreKey)
  67. bwNode.Env().CopyFrom(toShard.Env())
  68. s2sNode.BypassFileInfoVar().ToSlot(bwNode.BypassFileInfoSlot())
  69. bwNode.BypassCallbackVar().ToSlot(s2sNode.BypassCallbackSlot())
  70. // 从计划中删除目标节点
  71. ctx.DAG.RemoveNode(toShard)
  72. delete(ctx.ToNodes, toShard.To)
  73. }
  74. /*
  75. for _, toShared := range toShareds {
  76. s2sNode := ctx.DAG.NewS2STransfer(fromShard.Storage, toShared.Storage)
  77. // 直传指令在目的地Hub上执行
  78. s2sNode.Env().CopyFrom(toShared.Env())
  79. // 先获取文件路径,送到S2S节点
  80. brNode := ctx.DAG.NewBypassFromShardStore(fromShard.Storage.Storage.StorageID, fromShard.FileHash)
  81. brNode.Env().CopyFrom(toShared.Env())
  82. brNode.FilePathVar().ToSlot(s2sNode.SrcPathSlot())
  83. // 传输结果通知目的节点
  84. to := toShared.To.(*ioswitch2.LoadToShared)
  85. bwNode := ctx.DAG.NewBypassToShardStore(toShard.Storage.Storage.StorageID, to.FileHashStoreKey)
  86. bwNode.Env().CopyFrom(toShard.Env())
  87. s2sNode.BypassFileInfoVar().ToSlot(bwNode.BypassFileInfoSlot())
  88. bwNode.BypassCallbackVar().ToSlot(s2sNode.BypassCallbackSlot())
  89. // 从计划中删除目标节点
  90. ctx.DAG.RemoveNode(toShared)
  91. delete(ctx.ToNodes, toShared.To)
  92. }
  93. */
  94. // 从计划中删除源节点
  95. ctx.DAG.RemoveNode(frNode)
  96. delete(ctx.FromNodes, fr)
  97. }
  98. }

本项目旨在将云际存储公共基础设施化,使个人及企业可低门槛使用高效的云际存储服务(安装开箱即用云际存储客户端即可,无需关注其他组件的部署),同时支持用户灵活便捷定制云际存储的功能细节。