-
Notifications
You must be signed in to change notification settings - Fork 454
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix data race in FST Segment reads (#938)
- Loading branch information
Showing
5 changed files
with
138 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright (c) 2018 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 proptest | ||
|
||
import "github.com/m3db/m3/src/m3ninx/util" | ||
|
||
var ( | ||
lotsTestDocuments = util.MustReadDocs("../../util/testdata/node_exporter.json", 2000) | ||
) |
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,102 @@ | ||
// Copyright (c) 2018 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 proptest | ||
|
||
import ( | ||
"math/rand" | ||
"os" | ||
"sync" | ||
"testing" | ||
"time" | ||
|
||
"github.com/m3db/m3/src/m3ninx/index" | ||
"github.com/m3db/m3/src/m3ninx/index/segment/fst" | ||
"github.com/m3db/m3/src/m3ninx/search" | ||
"github.com/m3db/m3/src/m3ninx/search/executor" | ||
|
||
"github.com/leanovate/gopter" | ||
"github.com/leanovate/gopter/prop" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestConcurrentQueries(t *testing.T) { | ||
parameters := gopter.DefaultTestParameters() | ||
seed := time.Now().UnixNano() | ||
parameters.MinSuccessfulTests = 100 | ||
parameters.MaxSize = 20 | ||
parameters.Rng = rand.New(rand.NewSource(seed)) | ||
properties := gopter.NewProperties(parameters) | ||
|
||
simpleSeg := newTestMemSegment(t, lotsTestDocuments) | ||
simpleReader, err := simpleSeg.Reader() | ||
require.NoError(t, err) | ||
simpleExec := executor.NewExecutor([]index.Reader{simpleReader}) | ||
|
||
fstSeg := fst.ToTestSegment(t, simpleSeg, fstOptions) | ||
fstReader, err := fstSeg.Reader() | ||
require.NoError(t, err) | ||
fstExec := executor.NewExecutor([]index.Reader{fstReader}) | ||
|
||
properties.Property("Any concurrent queries segments does not affect fst segments", prop.ForAll( | ||
func(q search.Query) (bool, error) { | ||
dOrg, err := simpleExec.Execute(q) | ||
require.NoError(t, err) | ||
matchedDocs, err := collectDocs(dOrg) | ||
require.NoError(t, err) | ||
docMatcher, err := newDocumentIteratorMatcher(matchedDocs...) | ||
require.NoError(t, err) | ||
|
||
var ( | ||
wg sync.WaitGroup | ||
errLock sync.Mutex | ||
matchErr error | ||
) | ||
wg.Add(2) | ||
|
||
for i := 0; i < 2; i++ { | ||
go func() { | ||
defer wg.Done() | ||
fstDocs, err := fstExec.Execute(q) | ||
require.NoError(t, err) | ||
if err := docMatcher.Matches(fstDocs); err != nil { | ||
errLock.Lock() | ||
matchErr = err | ||
errLock.Unlock() | ||
} | ||
}() | ||
} | ||
wg.Wait() | ||
errLock.Lock() | ||
defer errLock.Unlock() | ||
if matchErr != nil { | ||
return false, matchErr | ||
} | ||
|
||
return true, nil | ||
}, | ||
genQuery(lotsTestDocuments), | ||
)) | ||
|
||
reporter := gopter.NewFormatedReporter(true, 160, os.Stdout) | ||
if !properties.Run(reporter) { | ||
t.Errorf("failed with initial seed: %d", seed) | ||
} | ||
} |
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