volume_read_all.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package storage
  2. import (
  3. "github.com/seaweedfs/seaweedfs/weed/pb/volume_server_pb"
  4. "github.com/seaweedfs/seaweedfs/weed/storage/needle"
  5. "github.com/seaweedfs/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. NeedleBlobCompressed: n.IsCompressed(),
  31. LastModified: n.LastModified,
  32. Crc: n.Checksum.Value(),
  33. Name: n.Name,
  34. Mime: n.Mime,
  35. })
  36. if sendErr != nil {
  37. return sendErr
  38. }
  39. return nil
  40. }