You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.7 KiB

7 years ago
  1. package operation
  2. import (
  3. "context"
  4. "fmt"
  5. "io"
  6. "time"
  7. "github.com/chrislusf/seaweedfs/weed/pb/volume_server_pb"
  8. . "github.com/chrislusf/seaweedfs/weed/storage/types"
  9. "github.com/chrislusf/seaweedfs/weed/util"
  10. )
  11. func GetVolumeSyncStatus(server string, vid uint32) (resp *volume_server_pb.VolumeSyncStatusResponse, err error) {
  12. WithVolumeServerClient(server, func(client volume_server_pb.VolumeServerClient) error {
  13. ctx, cancel := context.WithTimeout(context.Background(), time.Duration(5*time.Second))
  14. defer cancel()
  15. resp, err = client.VolumeSyncStatus(ctx, &volume_server_pb.VolumeSyncStatusRequest{
  16. VolumdId: vid,
  17. })
  18. return nil
  19. })
  20. return
  21. }
  22. func GetVolumeIdxEntries(server string, vid uint32, eachEntryFn func(key NeedleId, offset Offset, size uint32)) error {
  23. return WithVolumeServerClient(server, func(client volume_server_pb.VolumeServerClient) error {
  24. stream, err := client.VolumeSyncIndex(context.Background(), &volume_server_pb.VolumeSyncIndexRequest{
  25. VolumdId: vid,
  26. })
  27. if err != nil {
  28. return err
  29. }
  30. var indexFileContent []byte
  31. for {
  32. resp, err := stream.Recv()
  33. if err == io.EOF {
  34. break
  35. }
  36. if err != nil {
  37. return fmt.Errorf("read index entries: %v", err)
  38. }
  39. indexFileContent = append(indexFileContent, resp.IndexFileContent...)
  40. }
  41. dataSize := len(indexFileContent)
  42. for idx := 0; idx+NeedleEntrySize <= dataSize; idx += NeedleEntrySize {
  43. line := indexFileContent[idx : idx+NeedleEntrySize]
  44. key := BytesToNeedleId(line[:NeedleIdSize])
  45. offset := BytesToOffset(line[NeedleIdSize : NeedleIdSize+OffsetSize])
  46. size := util.BytesToUint32(line[NeedleIdSize+OffsetSize : NeedleIdSize+OffsetSize+SizeSize])
  47. eachEntryFn(key, offset, size)
  48. }
  49. return nil
  50. })
  51. }