-
Notifications
You must be signed in to change notification settings - Fork 453
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
[dbnode] Add ability to force repair regardless namespace has option set and add compare only repair type #3550
Merged
robskillington
merged 8 commits into
master
from
r/add-repair-force-and-compare-only-flags
Jun 10, 2021
Merged
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
99fb33e
[dbnode] Add ability to force repair regardless namespace has option …
robskillington eb0f019
Add integration test
robskillington 4e834a3
Fix license header
robskillington aa71b60
Fix mockgen and comment without fullstop
robskillington e309841
Fix tests
robskillington 91ad7f3
Fix lint
robskillington 70793f7
Merge branch 'master' into r/add-repair-force-and-compare-only-flags
robskillington 843dd77
Fix final unit test
robskillington 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
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
210 changes: 210 additions & 0 deletions
210
src/dbnode/integration/repair_force_only_compare_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,210 @@ | ||
// +build integration | ||
|
||
// Copyright (c) 2021 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 ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/require" | ||
"github.com/uber-go/tally" | ||
|
||
"github.com/m3db/m3/src/dbnode/integration/generate" | ||
"github.com/m3db/m3/src/dbnode/namespace" | ||
"github.com/m3db/m3/src/dbnode/retention" | ||
"github.com/m3db/m3/src/dbnode/storage/repair" | ||
xtest "github.com/m3db/m3/src/x/test" | ||
xtime "github.com/m3db/m3/src/x/time" | ||
) | ||
|
||
func TestRepairForceAndOnlyCompare(t *testing.T) { | ||
if testing.Short() { | ||
t.SkipNow() | ||
} | ||
|
||
var ( | ||
// Test both disjoint and shared series repair. | ||
genRepairData = genRepairDatafn(func(now xtime.UnixNano, blockSize time.Duration) ( | ||
node0Data generate.SeriesBlocksByStart, | ||
node1Data generate.SeriesBlocksByStart, | ||
node2Data generate.SeriesBlocksByStart, | ||
allData generate.SeriesBlocksByStart, | ||
) { | ||
currBlockStart := now.Truncate(blockSize) | ||
node0Data = generate.BlocksByStart([]generate.BlockConfig{ | ||
{IDs: []string{"foo"}, NumPoints: 90, Start: currBlockStart.Add(-4 * blockSize)}, | ||
{IDs: []string{"foo", "baz"}, NumPoints: 90, Start: currBlockStart.Add(-3 * blockSize)}, | ||
}) | ||
node1Data = generate.BlocksByStart([]generate.BlockConfig{ | ||
{IDs: []string{"bar"}, NumPoints: 90, Start: currBlockStart.Add(-4 * blockSize)}, | ||
{IDs: []string{"foo", "baz"}, NumPoints: 90, Start: currBlockStart.Add(-3 * blockSize)}, | ||
}) | ||
|
||
allData = make(map[xtime.UnixNano]generate.SeriesBlock) | ||
for start, data := range node0Data { | ||
for _, series := range data { | ||
allData[start] = append(allData[start], series) | ||
} | ||
} | ||
for start, data := range node1Data { | ||
for _, series := range data { | ||
allData[start] = append(allData[start], series) | ||
} | ||
} | ||
for start, data := range node2Data { | ||
for _, series := range data { | ||
allData[start] = append(allData[start], series) | ||
} | ||
} | ||
|
||
return node0Data, node1Data, node2Data, allData | ||
}) | ||
) | ||
|
||
// Test setups. | ||
log := xtest.NewLogger(t) | ||
retentionOpts := retention.NewOptions(). | ||
SetRetentionPeriod(20 * time.Hour). | ||
SetBlockSize(2 * time.Hour). | ||
SetBufferPast(10 * time.Minute). | ||
SetBufferFuture(2 * time.Minute) | ||
nsOpts := namespace.NewOptions(). | ||
// Test needing to force enable repairs. | ||
SetRepairEnabled(false). | ||
SetRetentionOptions(retentionOpts) | ||
namesp, err := namespace.NewMetadata(testNamespaces[0], nsOpts) | ||
require.NoError(t, err) | ||
opts := NewTestOptions(t). | ||
SetNamespaces([]namespace.Metadata{namesp}). | ||
// Use TChannel clients for writing / reading because we want to target individual nodes at a time | ||
// and not write/read all nodes in the cluster. | ||
SetUseTChannelClientForWriting(true). | ||
SetUseTChannelClientForReading(true) | ||
|
||
setupOpts := []BootstrappableTestSetupOptions{ | ||
{ | ||
DisablePeersBootstrapper: true, | ||
EnableRepairs: true, | ||
// Test forcing repair of type compare only repair. | ||
ForceRepairs: true, | ||
RepairType: repair.OnlyCompareRepair, | ||
}, | ||
{ | ||
DisablePeersBootstrapper: true, | ||
EnableRepairs: true, | ||
// Test forcing repair of type compare only repair. | ||
ForceRepairs: true, | ||
RepairType: repair.OnlyCompareRepair, | ||
}, | ||
{ | ||
DisablePeersBootstrapper: true, | ||
EnableRepairs: true, | ||
// Test forcing repair of type compare only repair. | ||
ForceRepairs: true, | ||
RepairType: repair.OnlyCompareRepair, | ||
}, | ||
} | ||
setups, closeFn := NewDefaultBootstrappableTestSetups(t, opts, setupOpts) | ||
defer closeFn() | ||
|
||
// Ensure that the current time is set such that the previous block is flushable. | ||
blockSize := retentionOpts.BlockSize() | ||
now := setups[0].NowFn()().Truncate(blockSize).Add(retentionOpts.BufferPast()).Add(time.Second) | ||
for _, setup := range setups { | ||
setup.SetNowFn(now) | ||
} | ||
|
||
node0Data, node1Data, node2Data, _ := genRepairData(now, blockSize) | ||
if node0Data != nil { | ||
require.NoError(t, writeTestDataToDisk(namesp, setups[0], node0Data, 0)) | ||
} | ||
if node1Data != nil { | ||
require.NoError(t, writeTestDataToDisk(namesp, setups[1], node1Data, 0)) | ||
} | ||
if node2Data != nil { | ||
require.NoError(t, writeTestDataToDisk(namesp, setups[2], node2Data, 0)) | ||
} | ||
|
||
// Start the servers with filesystem bootstrappers. | ||
setups.parallel(func(s TestSetup) { | ||
if err := s.StartServer(); err != nil { | ||
panic(err) | ||
} | ||
}) | ||
log.Debug("servers are now up") | ||
|
||
// Stop the servers. | ||
defer func() { | ||
setups.parallel(func(s TestSetup) { | ||
require.NoError(t, s.StopServer()) | ||
}) | ||
log.Debug("servers are now down") | ||
}() | ||
|
||
// Wait for repairs to occur at least once per node. | ||
log.Debug("waiting for repairs to run") | ||
var runSuccessPerNodeCounters []tally.CounterSnapshot | ||
require.True(t, waitUntil(func() bool { | ||
var successCounters []tally.CounterSnapshot | ||
for _, setup := range setups { | ||
scope := setup.Scope() | ||
for _, v := range scope.Snapshot().Counters() { | ||
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. nit: can also use |
||
if v.Name() != "repair.run" { | ||
continue | ||
} | ||
repairType, ok := v.Tags()["repair_type"] | ||
if !ok || repairType != "only_compare" { | ||
continue | ||
} | ||
if v.Value() > 0 { | ||
successCounters = append(successCounters, v) | ||
break | ||
} | ||
} | ||
} | ||
|
||
// Check if all counters are success. | ||
successAll := len(successCounters) == len(setups) | ||
if successAll { | ||
runSuccessPerNodeCounters = successCounters | ||
return true | ||
} | ||
return false | ||
}, 60*time.Second)) | ||
|
||
// Verify that the repair runs only ran comparisons without repairing data. | ||
log.Debug("verifying repairs that ran") | ||
require.Equal(t, len(setups), len(runSuccessPerNodeCounters), | ||
"unexpected number of successful nodes ran repairs") | ||
for _, counter := range runSuccessPerNodeCounters { | ||
repairType, ok := counter.Tags()["repair_type"] | ||
require.True(t, ok) | ||
require.Equal(t, "only_compare", repairType) | ||
require.True(t, counter.Value() > 0) | ||
} | ||
|
||
// Verify data did not change (repair type is compare only). | ||
verifySeriesMaps(t, setups[0], namesp.ID(), node0Data) | ||
verifySeriesMaps(t, setups[1], namesp.ID(), node1Data) | ||
verifySeriesMaps(t, setups[2], namesp.ID(), node2Data) | ||
} |
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
Oops, something went wrong.
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.
nit: change to
ForceEnabled
for context?