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.

45 lines
1.4 KiB

7 years ago
  1. package operation
  2. import (
  3. "context"
  4. "github.com/chrislusf/seaweedfs/weed/pb/volume_server_pb"
  5. . "github.com/chrislusf/seaweedfs/weed/storage/types"
  6. "github.com/chrislusf/seaweedfs/weed/util"
  7. )
  8. func GetVolumeSyncStatus(server string, vid uint32) (resp *volume_server_pb.VolumeSyncStatusResponse, err error) {
  9. WithVolumeServerClient(server, func(client volume_server_pb.VolumeServerClient) error {
  10. resp, err = client.VolumeSyncStatus(context.Background(), &volume_server_pb.VolumeSyncStatusRequest{
  11. VolumdId: vid,
  12. })
  13. return nil
  14. })
  15. return
  16. }
  17. func GetVolumeIdxEntries(server string, vid uint32, eachEntryFn func(key NeedleId, offset Offset, size uint32)) error {
  18. return WithVolumeServerClient(server, func(client volume_server_pb.VolumeServerClient) error {
  19. resp, err := client.VolumeSyncIndex(context.Background(), &volume_server_pb.VolumeSyncIndexRequest{
  20. VolumdId: vid,
  21. })
  22. if err != nil {
  23. return err
  24. }
  25. dataSize := len(resp.IndexFileContent)
  26. for idx := 0; idx+NeedleEntrySize <= dataSize; idx += NeedleEntrySize {
  27. line := resp.IndexFileContent[idx : idx+NeedleEntrySize]
  28. key := BytesToNeedleId(line[:NeedleIdSize])
  29. offset := BytesToOffset(line[NeedleIdSize : NeedleIdSize+OffsetSize])
  30. size := util.BytesToUint32(line[NeedleIdSize+OffsetSize : NeedleIdSize+OffsetSize+SizeSize])
  31. eachEntryFn(key, offset, size)
  32. }
  33. return nil
  34. })
  35. }