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.

55 lines
1.7 KiB

7 years ago
7 years ago
  1. package operation
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "net/url"
  6. "github.com/chrislusf/seaweedfs/weed/glog"
  7. . "github.com/chrislusf/seaweedfs/weed/storage/types"
  8. "github.com/chrislusf/seaweedfs/weed/util"
  9. )
  10. type SyncVolumeResponse struct {
  11. Replication string `json:"Replication,omitempty"`
  12. Ttl string `json:"Ttl,omitempty"`
  13. TailOffset uint64 `json:"TailOffset,omitempty"`
  14. CompactRevision uint16 `json:"CompactRevision,omitempty"`
  15. IdxFileSize uint64 `json:"IdxFileSize,omitempty"`
  16. Error string `json:"error,omitempty"`
  17. }
  18. func GetVolumeSyncStatus(server string, vid string) (*SyncVolumeResponse, error) {
  19. values := make(url.Values)
  20. values.Add("volume", vid)
  21. jsonBlob, err := util.Post("http://"+server+"/admin/sync/status", values)
  22. glog.V(2).Info("sync volume result :", string(jsonBlob))
  23. if err != nil {
  24. return nil, err
  25. }
  26. var ret SyncVolumeResponse
  27. err = json.Unmarshal(jsonBlob, &ret)
  28. if err != nil {
  29. return nil, err
  30. }
  31. if ret.Error != "" {
  32. return nil, fmt.Errorf("Volume %s get sync status error: %s", vid, ret.Error)
  33. }
  34. return &ret, nil
  35. }
  36. func GetVolumeIdxEntries(server string, vid string, eachEntryFn func(key NeedleId, offset Offset, size uint32)) error {
  37. values := make(url.Values)
  38. values.Add("volume", vid)
  39. line := make([]byte, NeedleEntrySize)
  40. err := util.GetBufferStream("http://"+server+"/admin/sync/index", values, line, func(bytes []byte) {
  41. key := BytesToNeedleId(line[:NeedleIdSize])
  42. offset := BytesToOffset(line[NeedleIdSize : NeedleIdSize+OffsetSize])
  43. size := util.BytesToUint32(line[NeedleIdSize+OffsetSize : NeedleIdSize+OffsetSize+SizeSize])
  44. eachEntryFn(key, offset, size)
  45. })
  46. if err != nil {
  47. return err
  48. }
  49. return nil
  50. }