Skip to content

Commit

Permalink
[17449] Introduces a locking mechanism over variables (#18207)
Browse files Browse the repository at this point in the history
It includes the work over the state store, the PRC server, the HTTP server, the go API package and the CLI's  command. To read more on the actuall functionality, refer to the RFCs [NMD-178] Locking with Nomad Variables and [NMD-179] Leader election using locking mechanism for the Autoscaler.
  • Loading branch information
Juanadelacuesta authored Sep 21, 2023
1 parent 86d2cdc commit 72acaf6
Show file tree
Hide file tree
Showing 40 changed files with 6,410 additions and 975 deletions.
3 changes: 3 additions & 0 deletions .changelog/18520.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvement
vars: Added a locking feature for Nomad Variables
```
39 changes: 39 additions & 0 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"errors"
"fmt"
"io"
"math"
"net"
"net/http"
"net/url"
Expand Down Expand Up @@ -200,6 +201,10 @@ type Config struct {
TLSConfig *TLSConfig

Headers http.Header

// retryOptions holds the configuration necessary to perform retries
// on put calls.
retryOptions *retryOptions
}

// ClientConfig copies the configuration with a new client address, region, and
Expand Down Expand Up @@ -578,6 +583,40 @@ func (c *Client) SetSecretID(secretID string) {
c.config.SecretID = secretID
}

func (c *Client) configureRetries(ro *retryOptions) {

c.config.retryOptions = &retryOptions{
maxRetries: defaultNumberOfRetries,
maxBackoffDelay: defaultMaxBackoffDelay,
delayBase: defaultDelayTimeBase,
}

if ro.delayBase != 0 {
c.config.retryOptions.delayBase = ro.delayBase
}

if ro.maxRetries != defaultNumberOfRetries {
c.config.retryOptions.maxRetries = ro.maxRetries
}

if ro.maxBackoffDelay != 0 {
c.config.retryOptions.maxBackoffDelay = ro.maxBackoffDelay
}

if ro.maxToLastCall != 0 {
c.config.retryOptions.maxToLastCall = ro.maxToLastCall
}

if ro.fixedDelay != 0 {
c.config.retryOptions.fixedDelay = ro.fixedDelay
}

// Ensure that a big attempt number or a big delayBase number will not cause
// a negative delay by overflowing the delay increase.
c.config.retryOptions.maxValidAttempt = int64(math.Log2(float64(math.MaxInt64 /
c.config.retryOptions.delayBase.Nanoseconds())))
}

// request is used to help build up a request
type request struct {
config *Config
Expand Down
Loading

0 comments on commit 72acaf6

Please sign in to comment.