mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2025-10-21 13:48:51 +08:00
ec shard info can be queried via VolumeList()
This commit is contained in:
@@ -10,9 +10,11 @@ import (
|
||||
"github.com/chrislusf/seaweedfs/weed/storage/needle"
|
||||
)
|
||||
|
||||
type ShardId uint8
|
||||
|
||||
type EcVolumeShard struct {
|
||||
VolumeId needle.VolumeId
|
||||
ShardId uint8
|
||||
ShardId ShardId
|
||||
Collection string
|
||||
dir string
|
||||
ecdFile *os.File
|
||||
@@ -22,7 +24,7 @@ type EcVolumeShards []*EcVolumeShard
|
||||
|
||||
func NewEcVolumeShard(dirname string, collection string, id needle.VolumeId, shardId int) (v *EcVolumeShard, e error) {
|
||||
|
||||
v = &EcVolumeShard{dir: dirname, Collection: collection, VolumeId: id, ShardId: uint8(shardId)}
|
||||
v = &EcVolumeShard{dir: dirname, Collection: collection, VolumeId: id, ShardId: ShardId(shardId)}
|
||||
|
||||
baseFileName := v.FileName()
|
||||
if v.ecxFile, e = os.OpenFile(baseFileName+".ecx", os.O_RDONLY, 0644); e != nil {
|
||||
|
46
weed/storage/erasure_coding/ec_volume_info.go
Normal file
46
weed/storage/erasure_coding/ec_volume_info.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package erasure_coding
|
||||
|
||||
import (
|
||||
"github.com/chrislusf/seaweedfs/weed/pb/master_pb"
|
||||
"github.com/chrislusf/seaweedfs/weed/storage/needle"
|
||||
)
|
||||
|
||||
// data structure used in master
|
||||
type EcVolumeInfo struct {
|
||||
VolumeId needle.VolumeId
|
||||
Collection string
|
||||
shardIds uint16 // use bits to indicate the shard id
|
||||
}
|
||||
|
||||
func (ecInfo *EcVolumeInfo) AddShardId(id ShardId) {
|
||||
ecInfo.shardIds |= (1 << id)
|
||||
}
|
||||
|
||||
func (ecInfo *EcVolumeInfo) RemoveShardId(id ShardId) {
|
||||
ecInfo.shardIds &^= (1 << id)
|
||||
}
|
||||
|
||||
func (ecInfo *EcVolumeInfo) HasShardId(id ShardId) bool {
|
||||
return ecInfo.shardIds&(1<<id) > 0
|
||||
}
|
||||
|
||||
func (ecInfo *EcVolumeInfo) ShardIds() (ret []ShardId) {
|
||||
for i := ShardId(0); i < DataShardsCount+ParityShardsCount; i++ {
|
||||
if ecInfo.HasShardId(i) {
|
||||
ret = append(ret, i)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (ecInfo *EcVolumeInfo) ToVolumeEcShardInformationMessage() (ret []*master_pb.VolumeEcShardInformationMessage) {
|
||||
for _, shard := range ecInfo.ShardIds() {
|
||||
ret = append(ret, &master_pb.VolumeEcShardInformationMessage{
|
||||
Id: uint32(ecInfo.VolumeId),
|
||||
EcIndex: uint32(shard),
|
||||
Collection: ecInfo.Collection,
|
||||
})
|
||||
|
||||
}
|
||||
return
|
||||
}
|
Reference in New Issue
Block a user