Skip to content

Commit

Permalink
storage: rename replica application files and objects
Browse files Browse the repository at this point in the history
This isn't being squashed into the previous diff to keep the diffs there
more clear. The renames include:

Types:
`replicaApplier` -> `replicaStateMachine`
`cmdAppCtx`      -> `replicatedCmd`
`cmdAppCtxBuf`   -> `replicatedCmdBuf`

Files:
`replica_application_impl.go` -> `replica_application_state_machine.go`
`cmd_app_ctx.go`              -> `replica_application_cmd.go`
`cmd_app_ctx_buf.go`          -> `replica_application_cmd_buf.go`

Release note: None
  • Loading branch information
nvanbenschoten committed Aug 6, 2019
1 parent e9b6abf commit 54a2da7
Show file tree
Hide file tree
Showing 9 changed files with 355 additions and 311 deletions.
214 changes: 0 additions & 214 deletions pkg/storage/cmd_app_ctx_buf.go

This file was deleted.

4 changes: 2 additions & 2 deletions pkg/storage/replica.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,10 @@ type Replica struct {
stateLoader stateloader.StateLoader
// on-disk storage for sideloaded SSTables. nil when there's no ReplicaID.
sideloaded SideloadStorage
// stateMachine is used to apply committed raft entries.
stateMachine replicaStateMachine
// decoder is used to decode committed raft entries.
decoder replicaDecoder
// applier is used to apply committed raft entries.
applier replicaApplier
}

// Contains the lease history when enabled.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,26 @@ import (
"go.etcd.io/etcd/raft/raftpb"
)

// cmdAppCtx stores the state required to apply a single raft entry to a
// replica_application_*.go files provide concrete implementations of
// the interfaces defined in the storage/apply package:
//
// replica_application_state_machine.go -> apply.StateMachine
// replica_application_decoder.go -> apply.Decoder
// replica_application_cmd.go -> apply.Command (and variants)
// replica_application_cmd_buf.go -> apply.CommandIterator (and variants)
// replica_application_cmd_buf.go -> apply.CommandList (and variants)
//
// These allow Replica to interface with the storage/apply package.

// replicatedCmd stores the state required to apply a single raft entry to a
// replica. The state is accumulated in stages which occur in apply.Task. From
// a high level, the command is decoded from a committed raft entry, then if it
// was proposed locally the proposal is populated from the replica's proposals
// map, then the command is staged into a replicaAppBatch by writing its update
// to the batch's engine.Batch and applying its "trivial" side-effects to the
// batch's view of ReplicaState. Then the batch is committed, the side-effects
// are applied and the local result is processed.
type cmdAppCtx struct {
type replicatedCmd struct {
ent *raftpb.Entry // the raft.Entry being applied
decodedRaftEntry // decoded from ent

Expand Down Expand Up @@ -73,38 +84,34 @@ type decodedConfChange struct {
ccCtx ConfChangeContext
}

// decode decodes the entry e into the cmdAppCtx.
func (c *cmdAppCtx) decode(ctx context.Context, e *raftpb.Entry) error {
// decode decodes the entry e into the replicatedCmd.
func (c *replicatedCmd) decode(ctx context.Context, e *raftpb.Entry) error {
c.ent = e
return c.decodedRaftEntry.decode(ctx, e)
}

func (d *decodedRaftEntry) replicatedResult() *storagepb.ReplicatedEvalResult {
return &d.raftCmd.ReplicatedEvalResult
}

// Index implements the apply.Command interface.
func (c *cmdAppCtx) Index() uint64 {
func (c *replicatedCmd) Index() uint64 {
return c.ent.Index
}

// IsTrivial implements the apply.Command interface.
func (c *cmdAppCtx) IsTrivial() bool {
func (c *replicatedCmd) IsTrivial() bool {
return isTrivial(c.replicatedResult())
}

// IsLocal implements the apply.Command interface.
func (c *cmdAppCtx) IsLocal() bool {
func (c *replicatedCmd) IsLocal() bool {
return c.proposal != nil
}

// Rejected implements the apply.CheckedCommand interface.
func (c *cmdAppCtx) Rejected() bool {
func (c *replicatedCmd) Rejected() bool {
return c.forcedErr != nil
}

// FinishAndAckOutcome implements the apply.AppliedCommand interface.
func (c *cmdAppCtx) FinishAndAckOutcome() error {
func (c *replicatedCmd) FinishAndAckOutcome() error {
if !c.IsLocal() {
return nil
}
Expand Down Expand Up @@ -158,3 +165,7 @@ func (d *decodedRaftEntry) decodeConfChangeEntry(e *raftpb.Entry) error {
d.idKey = storagebase.CmdIDKey(d.ccCtx.CommandID)
return nil
}

func (d *decodedRaftEntry) replicatedResult() *storagepb.ReplicatedEvalResult {
return &d.raftCmd.ReplicatedEvalResult
}
Loading

0 comments on commit 54a2da7

Please sign in to comment.