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.

51 lines
1.2 KiB

6 years ago
6 years ago
6 years ago
6 years ago
  1. package topology
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "github.com/chrislusf/raft"
  6. "github.com/chrislusf/seaweedfs/weed/glog"
  7. "github.com/chrislusf/seaweedfs/weed/storage/needle"
  8. hashicorpRaft "github.com/hashicorp/raft"
  9. )
  10. type MaxVolumeIdCommand struct {
  11. MaxVolumeId needle.VolumeId `json:"maxVolumeId"`
  12. }
  13. func NewMaxVolumeIdCommand(value needle.VolumeId) *MaxVolumeIdCommand {
  14. return &MaxVolumeIdCommand{
  15. MaxVolumeId: value,
  16. }
  17. }
  18. func (c *MaxVolumeIdCommand) CommandName() string {
  19. return "MaxVolumeId"
  20. }
  21. // deprecatedCommandApply represents the old interface to apply a command to the server.
  22. func (c *MaxVolumeIdCommand) Apply(server raft.Server) (interface{}, error) {
  23. topo := server.Context().(*Topology)
  24. before := topo.GetMaxVolumeId()
  25. topo.UpAdjustMaxVolumeId(c.MaxVolumeId)
  26. glog.V(1).Infoln("max volume id", before, "==>", topo.GetMaxVolumeId())
  27. return nil, nil
  28. }
  29. func (s *MaxVolumeIdCommand) Persist(sink hashicorpRaft.SnapshotSink) error {
  30. b, err := json.Marshal(s)
  31. if err != nil {
  32. return fmt.Errorf("marshal: %v", err)
  33. }
  34. _, err = sink.Write(b)
  35. if err != nil {
  36. sink.Cancel()
  37. return fmt.Errorf("sink.Write(): %v", err)
  38. }
  39. return sink.Close()
  40. }
  41. func (s *MaxVolumeIdCommand) Release() {
  42. }