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.

shard_store.go 2.6 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. package pubshards
  2. import (
  3. "context"
  4. "fmt"
  5. stgglb "gitlink.org.cn/cloudream/jcs-pub/common/globals"
  6. hubrpc "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/rpc/hub"
  7. stgtypes "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/types"
  8. jcstypes "gitlink.org.cn/cloudream/jcs-pub/common/types"
  9. )
  10. type ShardStore struct {
  11. detail *jcstypes.UserSpaceDetail
  12. stgType *jcstypes.PubShardsType
  13. hubCli *hubrpc.Client
  14. }
  15. func NewShardStore(detail *jcstypes.UserSpaceDetail, stgType *jcstypes.PubShardsType) (*ShardStore, error) {
  16. if stgglb.StandaloneMode {
  17. return nil, fmt.Errorf("pub shards only support online mode")
  18. }
  19. return &ShardStore{
  20. detail: detail,
  21. stgType: stgType,
  22. }, nil
  23. }
  24. func (s *ShardStore) Start(ch *stgtypes.StorageEventChan) {
  25. s.hubCli = stgglb.HubRPCPool.GetByID(s.stgType.MasterHub)
  26. }
  27. func (s *ShardStore) Stop() {
  28. if s.hubCli != nil {
  29. s.hubCli.Release()
  30. s.hubCli = nil
  31. }
  32. }
  33. func (s *ShardStore) Store(path jcstypes.JPath, hash jcstypes.FileHash, size int64) (stgtypes.FileInfo, error) {
  34. resp, cerr := s.hubCli.PubShardsStore(context.Background(), &hubrpc.PubShardsStore{
  35. PubShardsID: s.stgType.PubShardsID,
  36. Password: s.stgType.Password,
  37. Path: path,
  38. Hash: hash,
  39. Size: size,
  40. })
  41. if cerr != nil {
  42. return stgtypes.FileInfo{}, cerr.ToError()
  43. }
  44. return resp.Info, nil
  45. }
  46. func (s *ShardStore) Info(hash jcstypes.FileHash) (stgtypes.FileInfo, error) {
  47. resp, cerr := s.hubCli.PubShardsInfo(context.Background(), &hubrpc.PubShardsInfo{
  48. PubShardsID: s.stgType.PubShardsID,
  49. Password: s.stgType.Password,
  50. FileHash: hash,
  51. })
  52. if cerr != nil {
  53. return stgtypes.FileInfo{}, cerr.ToError()
  54. }
  55. return resp.Info, nil
  56. }
  57. func (s *ShardStore) ListAll() ([]stgtypes.FileInfo, error) {
  58. resp, cerr := s.hubCli.PubShardsListAll(context.Background(), &hubrpc.PubShardsListAll{
  59. PubShardsID: s.stgType.PubShardsID,
  60. Password: s.stgType.Password,
  61. })
  62. if cerr != nil {
  63. return nil, cerr.ToError()
  64. }
  65. return resp.Infos, nil
  66. }
  67. func (s *ShardStore) GC(avaiables []jcstypes.FileHash) error {
  68. _, cerr := s.hubCli.PubShardsGC(context.Background(), &hubrpc.PubShardsGC{
  69. PubShardsID: s.stgType.PubShardsID,
  70. Password: s.stgType.Password,
  71. FileHashes: avaiables,
  72. })
  73. if cerr != nil {
  74. return cerr.ToError()
  75. }
  76. return nil
  77. }
  78. func (s *ShardStore) Stats() stgtypes.ShardStoreStats {
  79. resp, cerr := s.hubCli.PubShardsStats(context.Background(), &hubrpc.PubShardsStats{
  80. PubShardsID: s.stgType.PubShardsID,
  81. Password: s.stgType.Password,
  82. })
  83. if cerr != nil {
  84. return stgtypes.ShardStoreStats{}
  85. }
  86. return resp.Stats
  87. }

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