|
@ -101,13 +101,18 @@ func (s *Store) ReadEcShardNeedle(ctx context.Context, vid needle.VolumeId, n *n |
|
|
return 0, err |
|
|
return 0, err |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
bytes, err := s.readEcShardIntervals(ctx, vid, localEcVolume, intervals) |
|
|
|
|
|
|
|
|
glog.V(4).Infof("read ec volume %d offset %d size %d intervals:%+v", vid, offset.ToAcutalOffset(), size, intervals) |
|
|
|
|
|
|
|
|
|
|
|
// TODO need to read the version
|
|
|
|
|
|
version := needle.CurrentVersion |
|
|
|
|
|
|
|
|
|
|
|
// TODO the interval size should be the actual size
|
|
|
|
|
|
|
|
|
|
|
|
bytes, err := s.readEcShardIntervals(ctx, vid, localEcVolume, version, intervals) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
return 0, fmt.Errorf("ReadEcShardIntervals: %v", err) |
|
|
return 0, fmt.Errorf("ReadEcShardIntervals: %v", err) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
version := needle.CurrentVersion |
|
|
|
|
|
|
|
|
|
|
|
err = n.ReadBytes(bytes, offset.ToAcutalOffset(), size, version) |
|
|
err = n.ReadBytes(bytes, offset.ToAcutalOffset(), size, version) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
return 0, fmt.Errorf("readbytes: %v", err) |
|
|
return 0, fmt.Errorf("readbytes: %v", err) |
|
@ -119,14 +124,14 @@ func (s *Store) ReadEcShardNeedle(ctx context.Context, vid needle.VolumeId, n *n |
|
|
return 0, fmt.Errorf("ec shard %d not found", vid) |
|
|
return 0, fmt.Errorf("ec shard %d not found", vid) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (s *Store) readEcShardIntervals(ctx context.Context, vid needle.VolumeId, ecVolume *erasure_coding.EcVolume, intervals []erasure_coding.Interval) (data []byte, err error) { |
|
|
|
|
|
|
|
|
func (s *Store) readEcShardIntervals(ctx context.Context, vid needle.VolumeId, ecVolume *erasure_coding.EcVolume, version needle.Version, intervals []erasure_coding.Interval) (data []byte, err error) { |
|
|
|
|
|
|
|
|
if err = s.cachedLookupEcShardLocations(ctx, ecVolume); err != nil { |
|
|
if err = s.cachedLookupEcShardLocations(ctx, ecVolume); err != nil { |
|
|
return nil, fmt.Errorf("failed to locate shard via master grpc %s: %v", s.MasterAddress, err) |
|
|
return nil, fmt.Errorf("failed to locate shard via master grpc %s: %v", s.MasterAddress, err) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
for i, interval := range intervals { |
|
|
for i, interval := range intervals { |
|
|
if d, e := s.readOneEcShardInterval(ctx, ecVolume, interval); e != nil { |
|
|
|
|
|
|
|
|
if d, e := s.readOneEcShardInterval(ctx, ecVolume, version, interval); e != nil { |
|
|
return nil, e |
|
|
return nil, e |
|
|
} else { |
|
|
} else { |
|
|
if i == 0 { |
|
|
if i == 0 { |
|
@ -139,11 +144,13 @@ func (s *Store) readEcShardIntervals(ctx context.Context, vid needle.VolumeId, e |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (s *Store) readOneEcShardInterval(ctx context.Context, ecVolume *erasure_coding.EcVolume, interval erasure_coding.Interval) (data []byte, err error) { |
|
|
|
|
|
|
|
|
func (s *Store) readOneEcShardInterval(ctx context.Context, ecVolume *erasure_coding.EcVolume, version needle.Version, interval erasure_coding.Interval) (data []byte, err error) { |
|
|
shardId, actualOffset := interval.ToShardIdAndOffset(erasure_coding.ErasureCodingLargeBlockSize, erasure_coding.ErasureCodingSmallBlockSize) |
|
|
shardId, actualOffset := interval.ToShardIdAndOffset(erasure_coding.ErasureCodingLargeBlockSize, erasure_coding.ErasureCodingSmallBlockSize) |
|
|
data = make([]byte, interval.Size) |
|
|
|
|
|
|
|
|
data = make([]byte, int(needle.GetActualSize(interval.Size, version))) |
|
|
if shard, found := ecVolume.FindEcVolumeShard(shardId); found { |
|
|
if shard, found := ecVolume.FindEcVolumeShard(shardId); found { |
|
|
|
|
|
glog.V(3).Infof("read local ec shard %d.%d", ecVolume.VolumeId, shardId) |
|
|
if _, err = shard.ReadAt(data, actualOffset); err != nil { |
|
|
if _, err = shard.ReadAt(data, actualOffset); err != nil { |
|
|
|
|
|
glog.V(0).Infof("read local ec shard %d.%d: %v", ecVolume.VolumeId, shardId, err) |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |
|
@ -153,6 +160,7 @@ func (s *Store) readOneEcShardInterval(ctx context.Context, ecVolume *erasure_co |
|
|
if !found || len(sourceDataNodes) == 0 { |
|
|
if !found || len(sourceDataNodes) == 0 { |
|
|
return nil, fmt.Errorf("failed to find ec shard %d.%d", ecVolume.VolumeId, shardId) |
|
|
return nil, fmt.Errorf("failed to find ec shard %d.%d", ecVolume.VolumeId, shardId) |
|
|
} |
|
|
} |
|
|
|
|
|
glog.V(3).Infof("read remote ec shard %d.%d from %s", ecVolume.VolumeId, shardId, sourceDataNodes[0]) |
|
|
_, err = s.readOneRemoteEcShardInterval(ctx, sourceDataNodes[0], ecVolume.VolumeId, shardId, data, actualOffset) |
|
|
_, err = s.readOneRemoteEcShardInterval(ctx, sourceDataNodes[0], ecVolume.VolumeId, shardId, data, actualOffset) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
glog.V(1).Infof("failed to read from %s for ec shard %d.%d : %v", sourceDataNodes[0], ecVolume.VolumeId, shardId, err) |
|
|
glog.V(1).Infof("failed to read from %s for ec shard %d.%d : %v", sourceDataNodes[0], ecVolume.VolumeId, shardId, err) |
|
@ -168,8 +176,7 @@ func (s *Store) cachedLookupEcShardLocations(ctx context.Context, ecVolume *eras |
|
|
return nil |
|
|
return nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
ecVolume.ShardLocationsLock.Lock() |
|
|
|
|
|
defer ecVolume.ShardLocationsLock.Unlock() |
|
|
|
|
|
|
|
|
glog.V(3).Infof("lookup and cache ec volume %d locations", ecVolume.VolumeId) |
|
|
|
|
|
|
|
|
err = operation.WithMasterServerClient(s.MasterAddress, s.grpcDialOption, func(masterClient master_pb.SeaweedClient) error { |
|
|
err = operation.WithMasterServerClient(s.MasterAddress, s.grpcDialOption, func(masterClient master_pb.SeaweedClient) error { |
|
|
req := &master_pb.LookupEcVolumeRequest{ |
|
|
req := &master_pb.LookupEcVolumeRequest{ |
|
@ -183,7 +190,7 @@ func (s *Store) cachedLookupEcShardLocations(ctx context.Context, ecVolume *eras |
|
|
ecVolume.ShardLocationsLock.Lock() |
|
|
ecVolume.ShardLocationsLock.Lock() |
|
|
for _, shardIdLocations := range resp.ShardIdLocations { |
|
|
for _, shardIdLocations := range resp.ShardIdLocations { |
|
|
shardId := erasure_coding.ShardId(shardIdLocations.ShardId) |
|
|
shardId := erasure_coding.ShardId(shardIdLocations.ShardId) |
|
|
ecVolume.ShardLocations[shardId] = nil |
|
|
|
|
|
|
|
|
delete(ecVolume.ShardLocations, shardId) |
|
|
for _, loc := range shardIdLocations.Locations { |
|
|
for _, loc := range shardIdLocations.Locations { |
|
|
ecVolume.ShardLocations[shardId] = append(ecVolume.ShardLocations[shardId], loc.Url) |
|
|
ecVolume.ShardLocations[shardId] = append(ecVolume.ShardLocations[shardId], loc.Url) |
|
|
} |
|
|
} |
|
|