0
0

Merge pull request #623 from mschoch/fix-race-518

fix data race in doc id search
This commit is contained in:
Marty Schoch 2017-08-08 08:17:03 -04:00 committed by GitHub
commit 82a101aedd

View File

@ -190,15 +190,18 @@ func newUpsideDownCouchDocIDReader(indexReader *IndexReader) (*UpsideDownCouchDo
} }
func newUpsideDownCouchDocIDReaderOnly(indexReader *IndexReader, ids []string) (*UpsideDownCouchDocIDReader, error) { func newUpsideDownCouchDocIDReaderOnly(indexReader *IndexReader, ids []string) (*UpsideDownCouchDocIDReader, error) {
// we don't actually own the list of ids, so if before we sort we must copy
idsCopy := make([]string, len(ids))
copy(idsCopy, ids)
// ensure ids are sorted // ensure ids are sorted
sort.Strings(ids) sort.Strings(idsCopy)
startBytes := []byte{0x0} startBytes := []byte{0x0}
if len(ids) > 0 { if len(idsCopy) > 0 {
startBytes = []byte(ids[0]) startBytes = []byte(idsCopy[0])
} }
endBytes := []byte{0xff} endBytes := []byte{0xff}
if len(ids) > 0 { if len(idsCopy) > 0 {
endBytes = incrementBytes([]byte(ids[len(ids)-1])) endBytes = incrementBytes([]byte(idsCopy[len(idsCopy)-1]))
} }
bisr := NewBackIndexRow(startBytes, nil, nil) bisr := NewBackIndexRow(startBytes, nil, nil)
bier := NewBackIndexRow(endBytes, nil, nil) bier := NewBackIndexRow(endBytes, nil, nil)
@ -207,7 +210,7 @@ func newUpsideDownCouchDocIDReaderOnly(indexReader *IndexReader, ids []string) (
return &UpsideDownCouchDocIDReader{ return &UpsideDownCouchDocIDReader{
indexReader: indexReader, indexReader: indexReader,
iterator: it, iterator: it,
only: ids, only: idsCopy,
onlyMode: true, onlyMode: true,
}, nil }, nil
} }