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.

54 lines
1.5 KiB

  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/util"
  8. )
  9. type SyncVolumeResponse struct {
  10. Replication string `json:"Replication,omitempty"`
  11. Ttl string `json:"Ttl,omitempty"`
  12. TailOffset uint64 `json:"TailOffset,omitempty"`
  13. CompactRevision uint16 `json:"CompactRevision,omitempty"`
  14. IdxFileSize uint64 `json:"IdxFileSize,omitempty"`
  15. Error string `json:"error,omitempty"`
  16. }
  17. func GetVolumeSyncStatus(server string, vid string) (*SyncVolumeResponse, error) {
  18. values := make(url.Values)
  19. values.Add("volume", vid)
  20. jsonBlob, err := util.Post("http://"+server+"/admin/sync/status", values)
  21. glog.V(2).Info("sync volume result :", string(jsonBlob))
  22. if err != nil {
  23. return nil, err
  24. }
  25. var ret SyncVolumeResponse
  26. err = json.Unmarshal(jsonBlob, &ret)
  27. if err != nil {
  28. return nil, err
  29. }
  30. if ret.Error != "" {
  31. return nil, fmt.Errorf("Volume %s get sync status error: %s", vid, ret.Error)
  32. }
  33. return &ret, nil
  34. }
  35. func GetVolumeIdxEntries(server string, vid string, eachEntryFn func(key uint64, offset, size uint32)) error {
  36. values := make(url.Values)
  37. values.Add("volume", vid)
  38. line := make([]byte, 16)
  39. err := util.GetBufferStream("http://"+server+"/admin/sync/index", values, line, func(bytes []byte) {
  40. key := util.BytesToUint64(bytes[:8])
  41. offset := util.BytesToUint32(bytes[8:12])
  42. size := util.BytesToUint32(bytes[12:16])
  43. eachEntryFn(key, offset, size)
  44. })
  45. if err != nil {
  46. return err
  47. }
  48. return nil
  49. }