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.

fromto.go 4.9 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. package ioswitch2
  2. import (
  3. "gitlink.org.cn/cloudream/common/utils/math2"
  4. "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/ioswitch/exec"
  5. stgtypes "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/types"
  6. jcstypes "gitlink.org.cn/cloudream/jcs-pub/common/types"
  7. )
  8. type From interface {
  9. GetStreamIndex() StreamIndex
  10. }
  11. type To interface {
  12. // To所需要的文件流的范围。具体含义与DataIndex有关系:
  13. // 如果DataIndex == -1,则表示在整个文件的范围。
  14. // 如果DataIndex >= 0,则表示在文件的某个分片的范围。
  15. GetRange() math2.Range
  16. GetStreamIndex() StreamIndex
  17. }
  18. const (
  19. // 未处理的完整文件流
  20. StreamIndexRaw = iota
  21. // EC编码的某一块的流
  22. StreamIndexEC
  23. // 分段编码的某一段的流
  24. StreamIndexSegment
  25. )
  26. type StreamIndex struct {
  27. Type int
  28. Index int
  29. }
  30. func RawStream() StreamIndex {
  31. return StreamIndex{
  32. Type: StreamIndexRaw,
  33. }
  34. }
  35. func ECStream(index int) StreamIndex {
  36. return StreamIndex{
  37. Type: StreamIndexEC,
  38. Index: index,
  39. }
  40. }
  41. func SegmentStream(index int) StreamIndex {
  42. return StreamIndex{
  43. Type: StreamIndexSegment,
  44. Index: index,
  45. }
  46. }
  47. func (s StreamIndex) IsRaw() bool {
  48. return s.Type == StreamIndexRaw
  49. }
  50. func (s StreamIndex) IsEC() bool {
  51. return s.Type == StreamIndexEC
  52. }
  53. func (s StreamIndex) IsSegment() bool {
  54. return s.Type == StreamIndexSegment
  55. }
  56. type FromTos []FromTo
  57. type FromTo struct {
  58. // 如果输入或者输出用到了EC编码的流,则需要提供EC参数。
  59. ECParam *jcstypes.ECRedundancy
  60. // 同上
  61. SegmentParam *jcstypes.SegmentRedundancy
  62. Froms []From
  63. Toes []To
  64. // 用于识别不同的统计信息对应的上下文
  65. StatsCtx string
  66. }
  67. func NewFromTo() FromTo {
  68. return FromTo{}
  69. }
  70. func (ft *FromTo) AddFrom(from From) *FromTo {
  71. ft.Froms = append(ft.Froms, from)
  72. return ft
  73. }
  74. func (ft *FromTo) AddTo(to To) *FromTo {
  75. ft.Toes = append(ft.Toes, to)
  76. return ft
  77. }
  78. type FromDriver struct {
  79. Handle *exec.DriverWriteStream
  80. StreamIndex StreamIndex
  81. }
  82. func NewFromDriver(strIdx StreamIndex) (*FromDriver, *exec.DriverWriteStream) {
  83. handle := &exec.DriverWriteStream{
  84. RangeHint: &math2.Range{},
  85. }
  86. return &FromDriver{
  87. Handle: handle,
  88. StreamIndex: strIdx,
  89. }, handle
  90. }
  91. func (f *FromDriver) GetStreamIndex() StreamIndex {
  92. return f.StreamIndex
  93. }
  94. type FromShardStore struct {
  95. FileHash jcstypes.FileHash
  96. UserSpace jcstypes.UserSpaceDetail
  97. StreamIndex StreamIndex
  98. }
  99. func NewFromShardstore(fileHash jcstypes.FileHash, space jcstypes.UserSpaceDetail, strIdx StreamIndex) *FromShardStore {
  100. return &FromShardStore{
  101. FileHash: fileHash,
  102. UserSpace: space,
  103. StreamIndex: strIdx,
  104. }
  105. }
  106. func (f *FromShardStore) GetStreamIndex() StreamIndex {
  107. return f.StreamIndex
  108. }
  109. type FromBaseStore struct {
  110. UserSpace jcstypes.UserSpaceDetail
  111. Path jcstypes.JPath
  112. }
  113. func NewFromBaseStore(space jcstypes.UserSpaceDetail, path jcstypes.JPath) *FromBaseStore {
  114. return &FromBaseStore{
  115. UserSpace: space,
  116. Path: path,
  117. }
  118. }
  119. func (f *FromBaseStore) GetStreamIndex() StreamIndex {
  120. return StreamIndex{
  121. Type: StreamIndexRaw,
  122. }
  123. }
  124. type ToDriver struct {
  125. Handle *exec.DriverReadStream
  126. StreamIndex StreamIndex
  127. Range math2.Range
  128. }
  129. func NewToDriver(strIdx StreamIndex) (*ToDriver, *exec.DriverReadStream) {
  130. str := exec.DriverReadStream{}
  131. return &ToDriver{
  132. Handle: &str,
  133. StreamIndex: strIdx,
  134. }, &str
  135. }
  136. func NewToDriverWithRange(strIdx StreamIndex, rng math2.Range) (*ToDriver, *exec.DriverReadStream) {
  137. str := exec.DriverReadStream{}
  138. return &ToDriver{
  139. Handle: &str,
  140. StreamIndex: strIdx,
  141. Range: rng,
  142. }, &str
  143. }
  144. func (t *ToDriver) GetStreamIndex() StreamIndex {
  145. return t.StreamIndex
  146. }
  147. func (t *ToDriver) GetRange() math2.Range {
  148. return t.Range
  149. }
  150. type ToShardStore struct {
  151. UserSpace jcstypes.UserSpaceDetail
  152. StreamIndex StreamIndex
  153. Range math2.Range
  154. ResultStoreKey string
  155. }
  156. func NewToShardStore(space jcstypes.UserSpaceDetail, strIdx StreamIndex, retStoreKey string) *ToShardStore {
  157. return &ToShardStore{
  158. UserSpace: space,
  159. StreamIndex: strIdx,
  160. ResultStoreKey: retStoreKey,
  161. }
  162. }
  163. func (t *ToShardStore) WithRange(rng math2.Range) *ToShardStore {
  164. t.Range = rng
  165. return t
  166. }
  167. func (t *ToShardStore) GetStreamIndex() StreamIndex {
  168. return t.StreamIndex
  169. }
  170. func (t *ToShardStore) GetRange() math2.Range {
  171. return t.Range
  172. }
  173. type ToBaseStore struct {
  174. UserSpace jcstypes.UserSpaceDetail
  175. ObjectPath jcstypes.JPath
  176. Option stgtypes.WriteOption
  177. Range math2.Range
  178. }
  179. func NewToBaseStore(space jcstypes.UserSpaceDetail, objectPath jcstypes.JPath) *ToBaseStore {
  180. return &ToBaseStore{
  181. UserSpace: space,
  182. ObjectPath: objectPath,
  183. }
  184. }
  185. func (t *ToBaseStore) WithRange(rng math2.Range) *ToBaseStore {
  186. t.Range = rng
  187. return t
  188. }
  189. func (t *ToBaseStore) GetStreamIndex() StreamIndex {
  190. return StreamIndex{
  191. Type: StreamIndexRaw,
  192. }
  193. }
  194. func (t *ToBaseStore) GetRange() math2.Range {
  195. return t.Range
  196. }

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