durable

package
v0.0.0-...-fd5963e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 13, 2019 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultStateConfig = StateConfig{
	Config:             raft.DefaultConfig,
	TransportConfig:    raft.DefaultTransportConfig,
	RPCTransportConfig: raftrpc.DefaultRPCTransportConfig,
	StorageConfig:      raftfs.DefaultStorageConfig,
}

DefaultStateConfig includes default values for the state handler.

Functions

This section is empty.

Types

type ChecksumRequestCmd

type ChecksumRequestCmd struct {
}

ChecksumRequestCmd asks the master to compute a checksum of its state.

type ChecksumRes

type ChecksumRes struct {
	Index    uint64 // Index of the ChecksumRequestCmd itself
	Checksum uint32 // Computed checksum
}

ChecksumRes is the result of a ChecksumRequestCmd.

type ChecksumVerifyCmd

type ChecksumVerifyCmd struct {
	Index    uint64 // Index of the corresponding ChecksumRequestCommand
	Checksum uint32 // Checksum to verify
}

ChecksumVerifyCmd asks the master to compare the checksum it saved with this checksum. The index is provided so that we can skip the check if the master didn't apply the corresponding ChecksumRequestCmd (e.g. if it restored from a snapshot right after that command).

type Command

type Command struct {
	Cmd interface{}
}

Command wraps pre-defined command types to be proposed to Raft.

type NewPartitionCmd

type NewPartitionCmd struct {
	CuratorID core.CuratorID
}

NewPartitionCmd assigns a new partition to a curator.

type NewPartitionRes

type NewPartitionRes struct {
	PartitionID core.PartitionID
	Err         core.Error
}

NewPartitionRes is the result of a committed NewPartitionCmd.

type RegisterCuratorCmd

type RegisterCuratorCmd struct {
}

RegisterCuratorCmd registers a new curator.

type RegisterTractserverCmd

type RegisterTractserverCmd struct {
}

RegisterTractserverCmd registers a new tractserver.

type SetReadOnlyModeCmd

type SetReadOnlyModeCmd struct {
	ReadOnly bool
}

SetReadOnlyModeCmd changes the read-only mode of the master. Use this during upgrades to prevent introducing corruption from differing implementations of raft commands.

type State

type State struct {
	// List of curators managing the assigned partitions.
	//
	// Note that we are currently assuming that:
	// 1. CuratorIDs never go away and
	// 2. CuratorIDs are never reused.
	//
	// Curators own metadata, and to lose a curator replica group entirely
	// would be a disaster that we would have to recover from by determining
	// which blobIDs were not managed by a curator. In this case, we might
	// as well use the same CuratorID. Also, we can change this decision later.
	//
	// The slice is indexed by the partition IDs and stores curator IDs.
	// Note that valid partition and curator IDs start from 1 and thus we
	// reserve the first spot. This layout optimizes the lookup from blob
	// (partition) to curator with O(1) cost but has O(n) cost for returning
	// the list of partitions owned by a given curator. An alternative is to
	// store the reversed mapping from curators to list of partitions, which
	// works best for the second query. We opt for this design because the
	// first query happens much more frequently than the second.
	Partitions []core.CuratorID

	// The next curator ID we assign.
	NextCuratorID core.CuratorID

	// The next tractserver ID we assign.
	NextTractserverID core.TractserverID

	// Are we currently read-only?
	ReadOnly bool
}

State is the durable state that can only be mutated by Raft. There is no need to maintain a lock as Raft is responsible for serializing commands.

The types don't really have to be Exported but we use Gob which requires it. NOTE: Don't forget to update State.checksum if any change is made to State.

type StateConfig

type StateConfig struct {
	raft.Config                `json:"Config"`            // Parameters for Raft core.
	raft.TransportConfig       `json:"TransportConfig"`   // Parameters for Raft transport.
	raftrpc.RPCTransportConfig `json:"RPCTransporConfig"` // Parameters for Raft RPC transport.
	raftfs.StorageConfig       `json:"StorageConfig"`     // Parameters for Raft storage.

	// The callback for newly elected leader. This function, if not-nil, is called
	// synchronously by Raft when a member becomes the leader of the replication group.
	OnLeader func()
}

StateConfig encapsulates the parameters needed for creating a StateHandler.

type StateHandler

type StateHandler struct {
	// contains filtered or unexported fields
}

StateHandler exports an API that allows clients to easily query and mutate the durable state managed by Raft.

func NewStateHandler

func NewStateHandler(cfg *StateConfig, raft *raft.Raft) *StateHandler

NewStateHandler creates a handler for manipulating persistent state.

func (*StateHandler) AddNode

func (h *StateHandler) AddNode(node string) error

AddNode addes a node to the cluster.

func (*StateHandler) Apply

func (h *StateHandler) Apply(ent raft.Entry) interface{}

Apply implements raft.FSM.

func (*StateHandler) ConsistencyCheck

func (h *StateHandler) ConsistencyCheck() core.Error

ConsistencyCheck runs one round of consistency checking.

func (*StateHandler) GetClusterMembers

func (h *StateHandler) GetClusterMembers() []string

GetClusterMembers return current members in the Raft cluster.

func (*StateHandler) GetMembership

func (h *StateHandler) GetMembership() []string

GetMembership gets the current membership of the cluster.

func (*StateHandler) GetPartitions

func (h *StateHandler) GetPartitions(curatorID core.CuratorID) ([]core.PartitionID, core.Error)

GetPartitions returns the partition assignment for the given curator, or zero for all.

func (*StateHandler) GetTerm

func (h *StateHandler) GetTerm() uint64

GetTerm returns current Raft term.

func (*StateHandler) ID

func (h *StateHandler) ID() string

ID returns the Raft ID of the node.

func (*StateHandler) IsLeader

func (h *StateHandler) IsLeader() bool

IsLeader returns whether it is the leader in the replication group.

func (*StateHandler) LeaderID

func (h *StateHandler) LeaderID() string

LeaderID returns the Raft ID of the leader.

func (*StateHandler) Lookup

Lookup returns the ID of the curator replication group that is responsible for a partition.

func (*StateHandler) NewPartition

func (h *StateHandler) NewPartition(curatorID core.CuratorID, term uint64) (core.PartitionID, core.Error)

NewPartition assigns a new partition to a curator.

func (*StateHandler) OnLeadershipChange

func (h *StateHandler) OnLeadershipChange(b bool, term uint64, leader string)

OnLeadershipChange implements raft.FSM. When a master becomes the leader, it starts to track the heartbeats of curators. When a leader steps down, it stops watching for such heartbeats.

func (*StateHandler) OnMembershipChange

func (h *StateHandler) OnMembershipChange(membership raft.Membership)

OnMembershipChange is called to notify current members in a Raft cluster.

func (*StateHandler) ProposeInitialMembership

func (h *StateHandler) ProposeInitialMembership(members []string) error

ProposeInitialMembership proposes an initial membership for the cluster.

func (*StateHandler) ReadOnlyMode

func (h *StateHandler) ReadOnlyMode() (bool, core.Error)

ReadOnlyMode gets the current state of read-only mode.

func (*StateHandler) RegisterCurator

func (h *StateHandler) RegisterCurator(term uint64) (core.CuratorID, core.Error)

RegisterCurator registers a new curator. A curator ID is generated and persisted.

func (*StateHandler) RegisterTractserver

func (h *StateHandler) RegisterTractserver(term uint64) (core.TractserverID, core.Error)

RegisterTractserver registers a new tractserver. A tractserver ID is generated and persisted.

func (*StateHandler) RemoveNode

func (h *StateHandler) RemoveNode(node string) error

RemoveNode removes a node from the cluster.

func (*StateHandler) SetOnLeader

func (h *StateHandler) SetOnLeader(f func())

SetOnLeader sets the callback that Raft calls when it becomes the leader. Must be called before StateHandler.Start is invoked.

func (*StateHandler) SetReadOnlyMode

func (h *StateHandler) SetReadOnlyMode(mode bool) core.Error

SetReadOnlyMode changes the read-only mode of the master.

func (*StateHandler) Snapshot

func (h *StateHandler) Snapshot() (raft.Snapshoter, error)

Snapshot implements raft.FSM.

func (*StateHandler) SnapshotRestore

func (h *StateHandler) SnapshotRestore(reader io.Reader, lastIndex, lastTerm uint64)

SnapshotRestore implements raft.FSM.

func (*StateHandler) Start

func (h *StateHandler) Start()

Start starts the Raft instance.

func (*StateHandler) ValidateCuratorID

func (h *StateHandler) ValidateCuratorID(curatorID core.CuratorID) core.Error

ValidateCuratorID returns core.NoError if the given curator id is valid.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL