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: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AddPartitionCommand

type AddPartitionCommand struct {
	ID core.PartitionID
}

AddPartitionCommand adds a partition to our state.

type AddPartitionResult

type AddPartitionResult struct {
	Err core.Error
}

AddPartitionResult is the result of an AddPartitionCommand.

type AllocateRSChunkIDsCommand

type AllocateRSChunkIDsCommand struct {
	N int
}

AllocateRSChunkIDsCommand asks the curator to allocate a contiguous range of RSChunkIDs.

type AllocateRSChunkIDsResult

type AllocateRSChunkIDsResult struct {
	Err core.Error
	ID  core.RSChunkID // the first id
}

AllocateRSChunkIDsResult is the result of an AllocateRSChunkIDsCommand.

type ChangeTractCommand

type ChangeTractCommand struct {
	// What tract are we changing?
	ID core.TractID

	// What is the new version of the tract?  The command only succeeds
	// if the existing version + 1 == NewVersion.  This is to allow only
	// one curator to succeed at bumping the version to any particular value.
	NewVersion int

	// What are the new hosts for this tract?
	NewHosts []core.TractserverID
}

ChangeTractCommand changes the replication group for a tract.

type ChecksumCommand

type ChecksumCommand struct {
	Start state.ChecksumPosition
	N     int
}

ChecksumCommand asks the curator to compute a partial checksum of its state.

type ChecksumResult

type ChecksumResult struct {
	Next     state.ChecksumPosition
	Checksum uint64
	Index    uint64
}

ChecksumResult is the result of a ChecksumCommand.

type Command

type Command struct {
	Cmd interface{}
}

Command is a command that is serialized and handed to the Raft algorithm. Gob requires a known type passed as an argument to serialize/deserialize, which is why we can't just pass the command.

type CommitRSChunkCommand

type CommitRSChunkCommand struct {
	// Base ID for the RS chunk.
	ID core.RSChunkID
	// The storage class that this chunk is encoded as.
	Storage core.StorageClass
	// The hosts that each piece is stored on, in order.
	Hosts []core.TractserverID
	// The layout of the data pieces.
	Data [][]state.EncodedTract
}

CommitRSChunkCommand asks the curator to store an RS chunk and also update the metadata for all tracts contained in that chunk to point to it.

type CreateBlobCommand

type CreateBlobCommand struct {
	// The desired replication factor of this blob.
	Repl int

	// Initial value for MTime and ATime.
	InitialTime int64

	// Expiry time.
	Expires int64

	// Initial storage hint.
	Hint core.StorageHint
}

CreateBlobCommand adds a blob.

type CreateBlobResult

type CreateBlobResult struct {
	// What's the ID?
	ID core.BlobID

	// Did anything go wrong during creation?  We can successfully issue a create
	// command but not have any BlobID space.
	Err core.Error
}

CreateBlobResult is a reply to a CreateBlobCommand.

type DeleteBlobCommand

type DeleteBlobCommand struct {
	ID core.BlobID

	// When should this blob be considered deleted?  We keep the metadata of blobs
	// around for some time period to allow for easy recovery from administrator error.
	When time.Time
}

DeleteBlobCommand deletes a blob.

type DeleteBlobResult

type DeleteBlobResult struct {
	// Was there an error in executing this command?
	Err core.Error
}

DeleteBlobResult is the result of a DeleteBlobCommand.

type ExtendBlobCommand

type ExtendBlobCommand struct {
	// What blob are we extending?
	ID core.BlobID

	// The tract key for the first new tract. New tracts have contigious
	// tract keys.
	FirstTractKey core.TractKey

	// Each Hosts[i] is a replication group for a new tract.
	Hosts [][]core.TractserverID
}

ExtendBlobCommand extends a blob, adding 'Tracts' to the blob 'ID'.

type ExtendBlobResult

type ExtendBlobResult struct {
	Err core.Error

	// What is the new number of tracts?
	NewSize int
}

ExtendBlobResult is the result of a blob extension.

type FinishDeleteCommand

type FinishDeleteCommand struct {
	Blobs []core.BlobID
}

FinishDeleteCommand finalizes the deletion of one or more blobs.

type ReadOnlyTxn

type ReadOnlyTxn struct {
	*state.Txn
	// contains filtered or unexported fields
}

ReadOnlyTxn represents a read-only transaction.

func (*ReadOnlyTxn) Commit

func (t *ReadOnlyTxn) Commit()

Commit the read-only transaction. It MUST be called when you are done with the transaction.

type SetMetadataCommand

type SetMetadataCommand struct {
	ID       core.BlobID
	Metadata core.BlobInfo
}

SetMetadataCommand changes metadata for a blob.

type SetReadOnlyModeCommand

type SetReadOnlyModeCommand struct {
	ReadOnly bool
}

SetReadOnlyModeCommand changes the read-only mode of the curator's state. This is used to prevent mutations during upgrades.

type SetRegistrationCommand

type SetRegistrationCommand struct {
	ID core.CuratorID
}

SetRegistrationCommand sets the flag indicating whether or not the curator has registered, and also sets its master-assigned ID.

type SetRegistrationResult

type SetRegistrationResult struct {
	ID core.CuratorID
}

SetRegistrationResult returns the registration. If a command is re-registering the curator, which is an unfortunate consequence of reading, contacting the master, and then writing, the first value wins.

type StateConfig

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

	DBDir string // The directory for DB file.

	// The callback that Raft calls when there is a leadership change.
	OnLeadershipChange func(bool)
}

StateConfig encapsulates the parameters needed for creating a ReplicatedState.

var DefaultStateConfig StateConfig

DefaultStateConfig includes default values for replicated state.

func (*StateConfig) GetStateDBPath

func (s *StateConfig) GetStateDBPath() string

GetStateDBPath returns the path of state database file.

func (*StateConfig) GetStateTempDBPath

func (s *StateConfig) GetStateTempDBPath() string

GetStateTempDBPath returns the path of state temporary database file.

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.

All methods which will change the state of the StateHandler must accept a term number for leader continuity check. Term number uniquely identified a continuous period of leadership, and users can ask StateHandler to propose changes if it's still the leader of the given term. If the term is 0, no leader continuity check will be performed.

func NewStateHandler

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

NewStateHandler creates a new StateHandler based on configuration 'cfg' and an raft instance 'raft'.

func (*StateHandler) AddNode

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

AddNode addes a node to the cluster.

func (*StateHandler) AddPartition

func (h *StateHandler) AddPartition(id core.PartitionID, term uint64) core.Error

AddPartition adds a partition to the set managed by this curator.

If a non-nil error is returned, the Raft algorithm encountered a non-fatal error. This is normal.

func (*StateHandler) AllocateRSChunkIDs

func (h *StateHandler) AllocateRSChunkIDs(n int, term uint64) (core.RSChunkID, core.Error)

AllocateRSChunkIDs allocates a contiguous range of n RSChunkIDs.

If there are no partitions available to allocate ids in, core.ErrGenBlobID will be returned.

Returns core.NoError on success, another core.Error otherwise (including expected Raft errors).

func (*StateHandler) Apply

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

Apply allows us to implement the raft.FSM interface. Note that raft.FSM will never issue two Apply calls in parallel.

func (*StateHandler) ChangeTract

func (h *StateHandler) ChangeTract(id core.TractID, newVersion int, hosts []core.TractserverID, term uint64) core.Error

ChangeTract changes the repl group of a tract.

func (*StateHandler) CheckForGarbage

func (h *StateHandler) CheckForGarbage(tsid core.TractserverID, tracts []core.TractID) ([]core.TractState, []core.TractID)

CheckForGarbage looks at all tracts in 'tracts', and verifies that 'tsid' is supposed to be hosting that tract. If the tractserver isn't supposed to host the tract, returns a core.TractState that indicates what version(s) of that tract can be safely garbage collected by any tractserver.

func (*StateHandler) CommitRSChunk

func (h *StateHandler) CommitRSChunk(id core.RSChunkID, cls core.StorageClass,
	hosts []core.TractserverID, data [][]state.EncodedTract, term uint64) core.Error

CommitRSChunk records a newly-encoded RSChunk and updates all the tracts that are included in the chunk to point to it.

func (*StateHandler) ConsistencyCheck

func (h *StateHandler) ConsistencyCheck(start state.ChecksumPosition, n int) (state.ChecksumPosition, core.Error)

ConsistencyCheck runs one round of consistency checking. Curators will compute a checksum of their state starting with `start` and containing n blobs (among other data). If successful, this will return the position that the next round should start at, and NoError. Otherwise it will return `start` and an error.

func (*StateHandler) CreateBlob

func (h *StateHandler) CreateBlob(repl int, now, expires int64, hint core.StorageHint, term uint64) (core.BlobID, core.Error)

CreateBlob creates a blob and returns its ID, or an error.

If there are no partitions available to create a blob in, core.ErrGenBlobID will be returned.

Returns core.NoError on success, another core.Error otherwise (including expected Raft errors).

func (*StateHandler) DeleteBlob

func (h *StateHandler) DeleteBlob(id core.BlobID, when time.Time, term uint64) core.Error

DeleteBlob deletes a blob.

Returns information about the just-deleted blob so the caller could clean up the tracts. Returns core.NoError on success, another core.Error otherwise (including expected Raft errors).

func (*StateHandler) ExtendBlob

func (h *StateHandler) ExtendBlob(id core.BlobID, firstTractKey core.TractKey, hosts [][]core.TractserverID) (int, core.Error)

ExtendBlob extends a blob.

Returns core.NoError on success, another core.Error otherwise (including expected Raft errors).

func (*StateHandler) FinishDelete

func (h *StateHandler) FinishDelete(blobs []core.BlobID) core.Error

FinishDelete permanently deletes blobs from the database.

func (*StateHandler) ForEachBlob

func (h *StateHandler) ForEachBlob(
	includeDeleted bool,
	bfunc func(core.BlobID, *fb.BlobF),
	inBetween func() bool)

ForEachBlob calls the given function for each blob in the database. If includeDeleted is true, deleted blobs will be included, otherwise they'll be skipped. The iteration will be split scross multiple transactions so that we don't hold a single transaction open for too long. That means the caller might not get a consistent view of the state! Since we're giving up on consistency anyway, this function does not do a read-verify. The function will be called serially so it does not have to serialize data structure access. The arguments passed to the function are not allowed to be modified. The inBetween function, if given, will be called in between each transaction. This may be used to do some work set up by the iteration function, without holding a transaction open. If the inBetween function returns false, iteration is aborted.

func (*StateHandler) ForEachRSChunk

func (h *StateHandler) ForEachRSChunk(cfunc func(core.RSChunkID, *fb.RSChunkF), inBetween func() bool)

ForEachRSChunk calls the given function for each RSChunk in the database. inBetween is as in ForEachBlob.

func (*StateHandler) ForEachTract

func (h *StateHandler) ForEachTract(tfunc func(core.TractID, *fb.TractF), inBetween func() bool)

ForEachTract calls the given function for each tract in non-deleted blobs. inBetween is as in ForEachBlob.

func (*StateHandler) GetClusterMembers

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

GetClusterMembers return current members in the Raft cluster.

func (*StateHandler) GetCuratorInfo

func (h *StateHandler) GetCuratorInfo() (id core.CuratorID, partitions []core.PartitionID, err core.Error)

GetCuratorInfo returns the registration status and owned partitions of this curator. This read is processed through the Raft layer as we do not want to doubly register a curator.

If a non-nil error is returned, the Raft algorithm encountered a non-fatal error. This is normal.

func (*StateHandler) GetCuratorInfoLocal

func (h *StateHandler) GetCuratorInfoLocal() (id core.CuratorID, partitionIDs []core.PartitionID)

GetCuratorInfoLocal returns the registration status and owned partitions of this curator. This read is processed locally without verifying if the state is still up-to-date. The read is processed locally because it's used for generating status page and we need to get this info on non-leader nodes as well.

func (*StateHandler) GetFreeSpace

func (h *StateHandler) GetFreeSpace() (uint64, core.Error)

GetFreeSpace returns the number of blobs can be created in the existing partitions. Error is returned if raft complaints.

func (*StateHandler) GetFreeSpaceLocal

func (h *StateHandler) GetFreeSpaceLocal() uint64

GetFreeSpaceLocal returns the number of blobs can be created in the existing partitions by reading local state. We use it to generate status pages for non-leader node.

func (*StateHandler) GetKnownTSIDs

func (h *StateHandler) GetKnownTSIDs() []core.TractserverID

GetKnownTSIDs returns all the known tractserver IDs in the database.

func (*StateHandler) GetMembership

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

GetMembership gets the current membership of the cluster.

func (*StateHandler) GetRSChunk

func (h *StateHandler) GetRSChunk(id core.RSChunkID) *fb.RSChunkF

GetRSChunk looks up one RSChunk.

func (*StateHandler) GetTerm

func (h *StateHandler) GetTerm() uint64

GetTerm returns current Raft term.

func (*StateHandler) GetTracts

func (h *StateHandler) GetTracts(id core.BlobID, start, end int) ([]core.TractInfo, core.StorageClass, core.Error)

GetTracts returns information about tracts in a blob.

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 true if this node is the leader currently, false otherwise. Note that this state can be stale.

func (*StateHandler) LeaderID

func (h *StateHandler) LeaderID() string

LeaderID returns the Raft ID of the leader.

func (*StateHandler) LinearizableReadOnlyTxn

func (h *StateHandler) LinearizableReadOnlyTxn() (*ReadOnlyTxn, core.Error)

LinearizableReadOnlyTxn returns a read-only transaction that access a snapshot of curator's current state. The transaction can only be used for read access, write access must be initiated by Raft.

NOTE: please release the transaction as soon as you are done with it. The read only transaction will capture a point-in-time snapshot of the state and data in the state can not be GC-ed until you release the transaction.

func (*StateHandler) ListBlobs

func (h *StateHandler) ListBlobs(partition core.PartitionID, start core.BlobKey) (keys []core.BlobKey, err core.Error)

ListBlobs returns a range of existing blob keys in one partition.

func (*StateHandler) LocalReadOnlyTxn

func (h *StateHandler) LocalReadOnlyTxn() *ReadOnlyTxn

LocalReadOnlyTxn returns a read-only transaction without verifying linearizability.

The transaction must be released as soon as you are done with it.

func (*StateHandler) OnLeadershipChange

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

OnLeadershipChange is called when our leadership status changes.

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 returns the current state of read-only mode.

func (*StateHandler) Register

func (h *StateHandler) Register(id core.CuratorID) (core.CuratorID, core.Error)

Register registers the curator with the Master-provided id 'id'.

If a non-nil error is returned, the Raft algorithm encountered a non-fatal error. This is normal.

func (*StateHandler) RemoveNode

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

RemoveNode removes a node from the cluster.

func (*StateHandler) SetLeadershipChange

func (h *StateHandler) SetLeadershipChange(f func(bool))

SetLeadershipChange sets the callback that Raft calls when there is a leadership change. Must be called before ReplicatedState.Start is invoked.

func (*StateHandler) SetMetadata

func (h *StateHandler) SetMetadata(id core.BlobID, md core.BlobInfo) core.Error

SetMetadata changes metadata for a blob.

func (*StateHandler) SetReadOnlyMode

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

SetReadOnlyMode changes the read-only mode in durable state. While set, no other commands that modify state will be accepted.

func (*StateHandler) Snapshot

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

Snapshot implements FSM.Snapshot.

func (*StateHandler) SnapshotRestore

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

SnapshotRestore implements raft.FSM. See comments of StateHandler.SnapshotSave for the format of snapshot file.

func (*StateHandler) Start

func (h *StateHandler) Start()

Start starts the raft instance.

func (*StateHandler) Stat

func (h *StateHandler) Stat(id core.BlobID) (core.BlobInfo, core.Error)

Stat stats a blob.

func (*StateHandler) SyncPartitions

func (h *StateHandler) SyncPartitions(partitions []core.PartitionID, term uint64) core.Error

SyncPartitions syncs this curator's partition assignment with that piggybacked in heartbeat reply.

If a non-nil error is returned, the Raft algorithm encountered a non-fatal error. This is normal.

func (*StateHandler) UndeleteBlob

func (h *StateHandler) UndeleteBlob(id core.BlobID, term uint64) core.Error

UndeleteBlob un-deletes a blob.

If the blob could be un-deleted, returns core.NoError. Otherwise, returns another blb error.

func (*StateHandler) UpdateRSHosts

func (h *StateHandler) UpdateRSHosts(id core.RSChunkID, hosts []core.TractserverID, term uint64) core.Error

UpdateRSHosts updates the record of hosts in an RS chunk.

func (*StateHandler) UpdateStorageClass

func (h *StateHandler) UpdateStorageClass(id core.BlobID, target core.StorageClass, term uint64) core.Error

UpdateStorageClass changes the storage class of a blob and removes metadata related to other storage classes.

func (*StateHandler) UpdateTimes

func (h *StateHandler) UpdateTimes(updates []state.UpdateTime) core.Error

UpdateTimes applies a batch of time updates to the state.

type SyncPartitionsCommand

type SyncPartitionsCommand struct {
	Partitions []core.PartitionID
}

SyncPartitionsCommand syncs partition assignment.

type SyncPartitionsResult

type SyncPartitionsResult struct {
	Err core.Error
}

SyncPartitionsResult is just a placeholder for consistency.

type UndeleteBlobCommand

type UndeleteBlobCommand struct {
	ID core.BlobID
}

UndeleteBlobCommand undeletes a blob.

type UndeleteBlobResult

type UndeleteBlobResult struct {
	Err core.Error
}

UndeleteBlobResult is the result of an UndeleteBlobCommand.

type UpdateRSHostsCommand

type UpdateRSHostsCommand struct {
	ID    core.RSChunkID
	Hosts []core.TractserverID
}

UpdateRSHostsCommand asks the curator to update its record of the hosts that a chunk is stored on.

type UpdateStorageClassCommand

type UpdateStorageClassCommand struct {
	ID      core.BlobID
	Storage core.StorageClass
}

UpdateStorageClassCommand asks the curator to update the storage class of a blob. All tracts of the blob must already be encoded with that storage class first, or this will fail. As part of this transaction, information in the tracts that apply to other storage classes will be removed. (E.g. changing storage class to RS_6_3 will delete replicated host and version for all tracts in the blob.)

type UpdateTimesCommand

type UpdateTimesCommand struct {
	Updates []state.UpdateTime
}

UpdateTimesCommand asks the curator to update blob mtimes/atimes in a batch.

type VerifyChecksumCommand

type VerifyChecksumCommand struct {
	Index    uint64
	Checksum uint64
}

VerifyChecksumCommand asks the curator to verify a previously-computed checksum.

Directories

Path Synopsis
fb

Jump to

Keyboard shortcuts

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