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.7 kB

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

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