@@ -15,15 +15,16 @@ import (
1515)
1616
1717const (
18- // This is the current suggested max size of the data in a raft log entry.
19- // This is based on current architecture, default timing, etc. Clients can
18+ // SuggestedMaxDataSize of the data in a raft log entry, in bytes.
19+ //
20+ // The value is based on current architecture, default timing, etc. Clients can
2021 // ignore this value if they want as there is no actual hard checking
2122 // within the library. As the library is enhanced this value may change
2223 // over time to reflect current suggested maximums.
2324 //
24- // Increasing beyond this risks RPC IO taking too long and preventing
25- // timely heartbeat signals which are sent in serial in current transports,
26- // potentially causing leadership instability.
25+ // Applying log entries with data greater than this size risks RPC IO taking
26+ // too long and preventing timely heartbeat signals. These signals are sent in serial
27+ // in current transports, potentially causing leadership instability.
2728 SuggestedMaxDataSize = 512 * 1024
2829)
2930
@@ -146,8 +147,8 @@ type Raft struct {
146147 // the log/snapshot.
147148 configurations configurations
148149
149- // Holds a copy of the latest configuration which can be read
150- // independently from main loop.
150+ // Holds a copy of the latest configuration which can be read independently
151+ // of the main loop.
151152 latestConfiguration atomic.Value
152153
153154 // RPC chan comes from the transport layer
@@ -762,11 +763,11 @@ func (r *Raft) ApplyLog(log Log, timeout time.Duration) ApplyFuture {
762763 }
763764}
764765
765- // Barrier is used to issue a command that blocks until all preceeding
766+ // Barrier is used to issue a command that blocks until all preceding
766767// operations have been applied to the FSM. It can be used to ensure the
767768// FSM reflects all queued writes. An optional timeout can be provided to
768769// limit the amount of time we wait for the command to be started. This
769- // must be run on the leader or it will fail.
770+ // must be run on the leader, or it will fail.
770771func (r * Raft ) Barrier (timeout time.Duration ) Future {
771772 metrics .IncrCounter ([]string {"raft" , "barrier" }, 1 )
772773 var timer <- chan time.Time
@@ -775,11 +776,7 @@ func (r *Raft) Barrier(timeout time.Duration) Future {
775776 }
776777
777778 // Create a log future, no index or term yet
778- logFuture := & logFuture {
779- log : Log {
780- Type : LogBarrier ,
781- },
782- }
779+ logFuture := & logFuture {log : Log {Type : LogBarrier }}
783780 logFuture .init ()
784781
785782 select {
@@ -792,9 +789,9 @@ func (r *Raft) Barrier(timeout time.Duration) Future {
792789 }
793790}
794791
795- // VerifyLeader is used to ensure the current node is still
796- // the leader. This can be done to prevent stale reads when a
797- // new leader has potentially been elected .
792+ // VerifyLeader is used to ensure this peer is still the leader. It may be used
793+ // to prevent returning stale data from the FSM after the peer has lost
794+ // leadership .
798795func (r * Raft ) VerifyLeader () Future {
799796 metrics .IncrCounter ([]string {"raft" , "verify_leader" }, 1 )
800797 verifyFuture := & verifyFuture {}
@@ -817,8 +814,9 @@ func (r *Raft) GetConfiguration() ConfigurationFuture {
817814 return configReq
818815}
819816
820- // AddPeer (deprecated) is used to add a new peer into the cluster. This must be
821- // run on the leader or it will fail. Use AddVoter/AddNonvoter instead.
817+ // AddPeer to the cluster configuration. Must be run on the leader, or it will fail.
818+ //
819+ // Deprecated: Use AddVoter/AddNonvoter instead.
822820func (r * Raft ) AddPeer (peer ServerAddress ) Future {
823821 if r .protocolVersion > 2 {
824822 return errorFuture {ErrUnsupportedProtocol }
@@ -832,10 +830,11 @@ func (r *Raft) AddPeer(peer ServerAddress) Future {
832830 }, 0 )
833831}
834832
835- // RemovePeer (deprecated) is used to remove a peer from the cluster. If the
836- // current leader is being removed, it will cause a new election
837- // to occur. This must be run on the leader or it will fail.
838- // Use RemoveServer instead.
833+ // RemovePeer from the cluster configuration. If the current leader is being
834+ // removed, it will cause a new election to occur. Must be run on the leader,
835+ // or it will fail.
836+
837+ // Deprecated: Use RemoveServer instead.
839838func (r * Raft ) RemovePeer (peer ServerAddress ) Future {
840839 if r .protocolVersion > 2 {
841840 return errorFuture {ErrUnsupportedProtocol }
@@ -955,7 +954,7 @@ func (r *Raft) Snapshot() SnapshotFuture {
955954// Restore is used to manually force Raft to consume an external snapshot, such
956955// as if restoring from a backup. We will use the current Raft configuration,
957956// not the one from the snapshot, so that we can restore into a new cluster. We
958- // will also use the higher of the index of the snapshot, or the current index,
957+ // will also use the max of the index of the snapshot, or the current index,
959958// and then add 1 to that, so we force a new state with a hole in the Raft log,
960959// so that the snapshot will be sent to followers and used for any new joiners.
961960// This can only be run on the leader, and blocks until the restore is complete
@@ -1011,7 +1010,7 @@ func (r *Raft) Restore(meta *SnapshotMeta, reader io.Reader, timeout time.Durati
10111010 }
10121011}
10131012
1014- // State is used to return the current raft state .
1013+ // State returns the state of this raft peer .
10151014func (r * Raft ) State () RaftState {
10161015 return r .getState ()
10171016}
@@ -1151,7 +1150,7 @@ func (r *Raft) AppliedIndex() uint64 {
11511150// This can only be called from the leader, or it will fail. The leader will
11521151// stop accepting client requests, make sure the target server is up to date
11531152// and starts the transfer with a TimeoutNow message. This message has the same
1154- // effect as if the election timeout on the on the target server fires. Since
1153+ // effect as if the election timeout on the target server fires. Since
11551154// it is unlikely that another server is starting an election, it is very
11561155// likely that the target server is able to win the election. Note that raft
11571156// protocol version 3 is not sufficient to use LeadershipTransfer. A recent
0 commit comments