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.

61 lines
1.7 KiB

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