volume_read_all.go 1016 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package storage
  2. import (
  3. "github.com/chrislusf/seaweedfs/weed/pb/volume_server_pb"
  4. "github.com/chrislusf/seaweedfs/weed/storage/needle"
  5. "github.com/chrislusf/seaweedfs/weed/storage/super_block"
  6. )
  7. type VolumeFileScanner4ReadAll struct {
  8. Stream volume_server_pb.VolumeServer_ReadAllNeedlesServer
  9. V *Volume
  10. }
  11. func (scanner *VolumeFileScanner4ReadAll) VisitSuperBlock(superBlock super_block.SuperBlock) error {
  12. return nil
  13. }
  14. func (scanner *VolumeFileScanner4ReadAll) ReadNeedleBody() bool {
  15. return true
  16. }
  17. func (scanner *VolumeFileScanner4ReadAll) VisitNeedle(n *needle.Needle, offset int64, needleHeader, needleBody []byte) error {
  18. nv, ok := scanner.V.nm.Get(n.Id)
  19. if !ok {
  20. return nil
  21. }
  22. if nv.Offset.ToActualOffset() != offset {
  23. return nil
  24. }
  25. sendErr := scanner.Stream.Send(&volume_server_pb.ReadAllNeedlesResponse{
  26. VolumeId: uint32(scanner.V.Id),
  27. NeedleId: uint64(n.Id),
  28. Cookie: uint32(n.Cookie),
  29. NeedleBlob: n.Data,
  30. })
  31. if sendErr != nil {
  32. return sendErr
  33. }
  34. return nil
  35. }