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

46 lines
1.1 KiB

  1. package erasure_coding
  2. import (
  3. "github.com/chrislusf/seaweedfs/weed/pb/master_pb"
  4. "github.com/chrislusf/seaweedfs/weed/storage/needle"
  5. )
  6. // data structure used in master
  7. type EcVolumeInfo struct {
  8. VolumeId needle.VolumeId
  9. Collection string
  10. shardIds uint16 // use bits to indicate the shard id
  11. }
  12. func (ecInfo *EcVolumeInfo) AddShardId(id ShardId) {
  13. ecInfo.shardIds |= (1 << id)
  14. }
  15. func (ecInfo *EcVolumeInfo) RemoveShardId(id ShardId) {
  16. ecInfo.shardIds &^= (1 << id)
  17. }
  18. func (ecInfo *EcVolumeInfo) HasShardId(id ShardId) bool {
  19. return ecInfo.shardIds&(1<<id) > 0
  20. }
  21. func (ecInfo *EcVolumeInfo) ShardIds() (ret []ShardId) {
  22. for i := ShardId(0); i < DataShardsCount+ParityShardsCount; i++ {
  23. if ecInfo.HasShardId(i) {
  24. ret = append(ret, i)
  25. }
  26. }
  27. return
  28. }
  29. func (ecInfo *EcVolumeInfo) ToVolumeEcShardInformationMessage() (ret []*master_pb.VolumeEcShardInformationMessage) {
  30. for _, shard := range ecInfo.ShardIds() {
  31. ret = append(ret, &master_pb.VolumeEcShardInformationMessage{
  32. Id: uint32(ecInfo.VolumeId),
  33. EcIndex: uint32(shard),
  34. Collection: ecInfo.Collection,
  35. })
  36. }
  37. return
  38. }