-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Be consistent with how we report init status. #10498
Merged
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ff1b5b4
Be consistent with how we report init status.
ncabatoff 2dff344
Make half-joined raft peers consider storage to be initialized.
ncabatoff b0ed12a
Merge branch 'master' into consistent-init-status-apis
ncabatoff 76b9068
Make half-joined raft peers that have been unsealed but haven't finis…
ncabatoff 7ec7708
Raft retry join fails unless we revert to the old behaviour for Initi…
ncabatoff 1a6bd82
Add changelog.
ncabatoff 91afe70
Remove unneeded param to joinFunc.
ncabatoff File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
```release-note:bug | ||
core: Make all APIs that report init status consistent, and make them report | ||
initialized=true when a Raft join is in progress. | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -875,3 +875,104 @@ func BenchmarkRaft_SingleNode(b *testing.B) { | |
|
||
b.Run("256b", func(b *testing.B) { bench(b, 25) }) | ||
} | ||
|
||
func TestRaft_Join_InitStatus(t *testing.T) { | ||
t.Parallel() | ||
var conf vault.CoreConfig | ||
var opts = vault.TestClusterOptions{HandlerFunc: vaulthttp.Handler} | ||
teststorage.RaftBackendSetup(&conf, &opts) | ||
opts.SetupFunc = nil | ||
cluster := vault.NewTestCluster(t, &conf, &opts) | ||
cluster.Start() | ||
defer cluster.Cleanup() | ||
|
||
addressProvider := &testhelpers.TestRaftServerAddressProvider{Cluster: cluster} | ||
|
||
leaderCore := cluster.Cores[0] | ||
leaderAPI := leaderCore.Client.Address() | ||
atomic.StoreUint32(&vault.TestingUpdateClusterAddr, 1) | ||
|
||
// Seal the leader so we can install an address provider | ||
{ | ||
testhelpers.EnsureCoreSealed(t, leaderCore) | ||
leaderCore.UnderlyingRawStorage.(*raft.RaftBackend).SetServerAddressProvider(addressProvider) | ||
cluster.UnsealCore(t, leaderCore) | ||
vault.TestWaitActive(t, leaderCore.Core) | ||
} | ||
|
||
joinFunc := func(client *api.Client, addClientCerts bool) { | ||
req := &api.RaftJoinRequest{ | ||
LeaderAPIAddr: leaderAPI, | ||
LeaderCACert: string(cluster.CACertPEM), | ||
} | ||
if addClientCerts { | ||
req.LeaderClientCert = string(cluster.CACertPEM) | ||
req.LeaderClientKey = string(cluster.CAKeyPEM) | ||
} | ||
resp, err := client.Sys().RaftJoin(req) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if !resp.Joined { | ||
t.Fatalf("failed to join raft cluster") | ||
} | ||
} | ||
|
||
verifyInitStatus := func(coreIdx int, expected bool) { | ||
t.Helper() | ||
client := cluster.Cores[coreIdx].Client | ||
|
||
initialized, err := client.Sys().InitStatus() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if initialized != expected { | ||
t.Errorf("core %d: expected init=%v, sys/init returned %v", coreIdx, expected, initialized) | ||
} | ||
|
||
status, err := client.Sys().SealStatus() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if status.Initialized != expected { | ||
t.Errorf("core %d: expected init=%v, sys/seal-status returned %v", coreIdx, expected, status.Initialized) | ||
} | ||
|
||
health, err := client.Sys().Health() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if health.Initialized != expected { | ||
t.Errorf("core %d: expected init=%v, sys/health returned %v", coreIdx, expected, health.Initialized) | ||
} | ||
} | ||
|
||
for i := range cluster.Cores { | ||
verifyInitStatus(i, i < 1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
} | ||
|
||
joinFunc(cluster.Cores[1].Client, false) | ||
for i, core := range cluster.Cores { | ||
verifyInitStatus(i, i < 2) | ||
if i == 1 { | ||
cluster.UnsealCore(t, core) | ||
verifyInitStatus(i, true) | ||
} | ||
} | ||
|
||
joinFunc(cluster.Cores[2].Client, false) | ||
for i, core := range cluster.Cores { | ||
verifyInitStatus(i, true) | ||
vishalnayak marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if i == 2 { | ||
cluster.UnsealCore(t, core) | ||
verifyInitStatus(i, true) | ||
} | ||
} | ||
|
||
testhelpers.WaitForActiveNodeAndStandbys(t, cluster) | ||
for i := range cluster.Cores { | ||
verifyInitStatus(i, true) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May be the join function can do away with the
addClientCerts
logic as we are only setting it to false.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call.