Skip to content

Commit

Permalink
Added lease duration option
Browse files Browse the repository at this point in the history
  • Loading branch information
jmsadair committed Jul 25, 2023
1 parent 0eaed5e commit 1562d7f
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ const (
minMaxEntriesPerRPC = 50
maxMaxEntriesPerRPC = 500
defaultMaxEntriesPerRPC = 100

minLeaseDuration = time.Duration(25 * time.Millisecond)
maxLeaseDuration = time.Duration(1000 * time.Millisecond)
defaultLeaseDuration = time.Duration(300 * time.Millisecond)
)

// Logger supports logging messages at the debug, info, warn, error, and fatal level.
Expand Down Expand Up @@ -66,6 +70,9 @@ type options struct {
// an AppendEntries RPC.
maxEntriesPerRPC int

// The duration that a lease remains valid upon renewal.
leaseDuration time.Duration

// A logger for debugging and important events.
logger Logger
}
Expand Down Expand Up @@ -107,6 +114,21 @@ func WithMaxEntriesPerRPC(maxEntriesPerRPC int) Option {
}
}

// WithLeaseDuration sets the duration for which a lease remains valid upon
// renewal. A longer lease duration generally corresponds to higher performance
// of read-only operations but increases the likelihood that stale data is read.
// Likewise, a shorter lease duration corresponds to lesser performance of read-only
// operations but decreases the likelihood of stale data being read.
func WithLeaseDuration(leaseDuration time.Duration) Option {
return func(options *options) error {
if leaseDuration < minLeaseDuration || leaseDuration > maxLeaseDuration {
return errors.New("lease duration is invalid")
}
options.leaseDuration = leaseDuration
return nil
}
}

// WithLogger sets the logger used by the Raft server.
func WithLogger(logger Logger) Option {
return func(options *options) error {
Expand Down

0 comments on commit 1562d7f

Please sign in to comment.