volume_grpc_read_all.go 979 B

123456789101112131415161718192021222324252627282930313233343536
  1. package weed_server
  2. import (
  3. "fmt"
  4. "github.com/seaweedfs/seaweedfs/weed/pb/volume_server_pb"
  5. "github.com/seaweedfs/seaweedfs/weed/storage"
  6. "github.com/seaweedfs/seaweedfs/weed/storage/needle"
  7. )
  8. func (vs *VolumeServer) ReadAllNeedles(req *volume_server_pb.ReadAllNeedlesRequest, stream volume_server_pb.VolumeServer_ReadAllNeedlesServer) (err error) {
  9. for _, vid := range req.VolumeIds {
  10. if err := vs.streamReadOneVolume(needle.VolumeId(vid), stream, err); err != nil {
  11. return err
  12. }
  13. }
  14. return nil
  15. }
  16. func (vs *VolumeServer) streamReadOneVolume(vid needle.VolumeId, stream volume_server_pb.VolumeServer_ReadAllNeedlesServer, err error) error {
  17. v := vs.store.GetVolume(vid)
  18. if v == nil {
  19. return fmt.Errorf("not found volume id %d", vid)
  20. }
  21. scanner := &storage.VolumeFileScanner4ReadAll{
  22. Stream: stream,
  23. V: v,
  24. }
  25. offset := int64(v.SuperBlock.BlockSize())
  26. err = storage.ScanVolumeFileFrom(v.Version(), v.DataBackend, offset, scanner)
  27. return err
  28. }