cluster_commands.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package topology
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. hashicorpRaft "github.com/hashicorp/raft"
  6. "github.com/seaweedfs/raft"
  7. "github.com/seaweedfs/seaweedfs/weed/glog"
  8. "github.com/seaweedfs/seaweedfs/weed/storage/needle"
  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. }