-
Notifications
You must be signed in to change notification settings - Fork 460
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[aggregator] Followers
CanLead
before the first flush is persisted (#…
…4169) * Have follower report CanLead if there are no flush times * Refactor out common integration test multiServerSetup
- Loading branch information
Showing
8 changed files
with
333 additions
and
282 deletions.
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
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
101 changes: 101 additions & 0 deletions
101
src/aggregator/integration/multi_server_follower_health_init_test.go
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,101 @@ | ||
//go:build integration | ||
// +build integration | ||
|
||
// Copyright (c) 2022 Uber Technologies, Inc. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
package integration | ||
|
||
import ( | ||
"sync" | ||
"sync/atomic" | ||
"testing" | ||
|
||
httpserver "github.com/m3db/m3/src/aggregator/server/http" | ||
xtest "github.com/m3db/m3/src/x/test" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestMultiServerFollowerHealthInit(t *testing.T) { | ||
if testing.Short() { | ||
t.SkipNow() | ||
} | ||
|
||
testParams := newTestServerSetups(t) | ||
servers := testParams.servers | ||
|
||
// Start the servers. | ||
log := xtest.NewLogger(t) | ||
log.Info("test forwarding pipeline") | ||
for i, server := range servers { | ||
require.NoError(t, server.startServer()) | ||
log.Sugar().Infof("server %d is now up", i) | ||
} | ||
|
||
// Stop the servers. | ||
for i, server := range servers { | ||
i := i | ||
server := server | ||
defer func() { | ||
require.NoError(t, server.stopServer()) | ||
log.Sugar().Infof("server %d is now down", i) | ||
}() | ||
} | ||
|
||
// Waiting for two leaders to come up. | ||
var ( | ||
leaders = make(map[int]struct{}) | ||
leaderCh = make(chan int, len(servers)/2) | ||
numLeaders int32 | ||
wg sync.WaitGroup | ||
) | ||
wg.Add(len(servers) / 2) | ||
for i, server := range servers { | ||
i, server := i, server | ||
go func() { | ||
if err := server.waitUntilLeader(); err == nil { | ||
res := int(atomic.AddInt32(&numLeaders, 1)) | ||
if res <= len(servers)/2 { | ||
leaderCh <- i | ||
wg.Done() | ||
} | ||
} | ||
}() | ||
} | ||
wg.Wait() | ||
close(leaderCh) | ||
|
||
for i := range leaderCh { | ||
leaders[i] = struct{}{} | ||
log.Sugar().Infof("server %d has become the leader", i) | ||
} | ||
log.Sugar().Infof("%d servers have become leaders", len(leaders)) | ||
|
||
for _, server := range servers { | ||
var resp httpserver.StatusResponse | ||
require.NoError(t, server.getStatusResponse(httpserver.StatusPath, &resp)) | ||
|
||
// No data has been written to the aggregators yet, but all servers (including the | ||
// followers) should be able to lead. | ||
assert.True(t, resp.Status.FlushStatus.CanLead) | ||
} | ||
} |
Oops, something went wrong.