Skip to content

Commit

Permalink
primary role: add 'is-secondary' environment; precedence
Browse files Browse the repository at this point in the history
* add 'is-secondary' environment
* use it at proxy startup (bootstrap)
* from now on, (is-primary, is-secondary) environment always takes precedence
  - will override the primary recorded into local copy of the cluster map

Signed-off-by: Alex Aizman <[email protected]>
  • Loading branch information
alex-aizman committed Mar 26, 2024
1 parent 20d8ac7 commit b0538df
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
21 changes: 14 additions & 7 deletions ais/earlystart.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,18 @@ func (p *proxy) determineRole(loadedSmap *smapX) (pid string, primary bool) {
}
// parse env
envP := struct {
pid string
primary bool
pid string
primary bool
secondary bool
}{
pid: os.Getenv(env.AIS.PrimaryID),
primary: cos.IsParseBool(os.Getenv(env.AIS.IsPrimary)),
pid: os.Getenv(env.AIS.PrimaryID),
primary: cos.IsParseBool(os.Getenv(env.AIS.IsPrimary)),
secondary: cos.IsParseBool(os.Getenv(env.AIS.IsSecondary)),
}

if envP.primary && envP.secondary {
cos.ExitLogf("%s: both %s and %s cannot be true", p, env.AIS.IsPrimary, env.AIS.IsSecondary)
}
if envP.pid != "" && envP.primary && p.SID() != envP.pid {
cos.ExitLogf("%s: invalid combination of %s=true & %s=%s", p, env.AIS.IsPrimary, env.AIS.PrimaryID, envP.pid)
}
Expand All @@ -142,13 +147,15 @@ func (p *proxy) determineRole(loadedSmap *smapX) (pid string, primary bool) {
loadedSmap.Primary = primary
}
}

// NOTE: environment always takes precedence
if envP.pid != "" {
primary = envP.pid == p.SID()
pid = envP.pid
} else if loadedSmap != nil {
} else if envP.primary {
primary = true
} else if loadedSmap != nil && !envP.secondary {
primary = loadedSmap.isPrimary(p.si)
} else {
primary = envP.primary
}
return
}
Expand Down
16 changes: 9 additions & 7 deletions api/env/ais.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ package env

var (
AIS = struct {
Endpoint string
IsPrimary string
PrimaryID string
UseHTTPS string
Endpoint string
IsPrimary string
IsSecondary string
PrimaryID string
UseHTTPS string
// TLS: client side
Certificate string
CertKey string
Expand All @@ -33,9 +34,10 @@ var (
K8sNamespace string
}{
// the way to designate primary when cluster's starting up
Endpoint: "AIS_ENDPOINT",
IsPrimary: "AIS_IS_PRIMARY",
PrimaryID: "AIS_PRIMARY_ID",
Endpoint: "AIS_ENDPOINT",
IsPrimary: "AIS_IS_PRIMARY",
IsSecondary: "AIS_IS_SECONDARY",
PrimaryID: "AIS_PRIMARY_ID",

// false: HTTP transport, with all the TLS config (below) ignored
// true: HTTPS/TLS
Expand Down

0 comments on commit b0538df

Please sign in to comment.