Skip to content
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

index out of range when visiting stored fields #123

Open
enex opened this issue Jun 27, 2022 · 4 comments
Open

index out of range when visiting stored fields #123

enex opened this issue Jun 27, 2022 · 4 comments

Comments

@enex
Copy link

enex commented Jun 27, 2022

since the update to ice v2 I get the following error:

panic: runtime error: index out of range [76] with length 18

goroutine 88 [running]:
github.com/blugelabs/ice/v2.(*Segment).visitDocument(0xc003618300, 0xc00964a640, 0x2a7b9ca0?, 0xc0135d2190)
        $GOPATH/pkg/mod/github.com/blugelabs/ice/v2@v2.0.1/segment.go:223 +0x307
github.com/blugelabs/ice/v2.(*Segment).VisitStoredFields(0xc01358b350?, 0x2e?, 0x2f?)
        $GOPATH/pkg/mod/github.com/blugelabs/ice/v2@v2.0.1/segment.go:190 +0xab
github.com/blugelabs/bluge/index.(*segmentSnapshot).VisitDocument(...)
        $GOPATH/pkg/mod/github.com/blugelabs/bluge@v0.2.1/index/segment.go:61
github.com/blugelabs/bluge/index.(*Snapshot).VisitStoredFields(0xc0013cf700?, 0xc004d43330?, 0xc00964b300?)
        $GOPATH/pkg/mod/github.com/blugelabs/bluge@v0.2.1/index/snapshot.go:307 +0x146
github.com/blugelabs/bluge/search.(*DocumentMatch).VisitStoredFields(...)
        $GOPATH/pkg/mod/github.com/blugelabs/bluge@v0.2.1/search/search.go:134
my-path/notes.(*BlugeIndex).buildBlugeRequestToFindNote.func1(0xc004d432c0)
        /Users/simonvetter/Projekte/clye/go-server/cmd/notes/notes/bluge.go:452 +0x16f
my-path/utils.(*CustomScoreSearcher).Next(0xc004f5e408, 0xc013581ac0?)
        /Users/simonvetter/Projekte/clye/go-server/cmd/notes/utils/custom.go:40 +0x48
github.com/blugelabs/bluge/search/collector.(*TopNCollector).Collect(0xc0074f82d0, {0x1cf81b0, 0xc0025ea000}, 0xc0074f82d0?, {0x2762db8?, 0xc004f5e408?})
        $GOPATH/pkg/mod/github.com/blugelabs/bluge@v0.2.1/search/collector/topn.go:168 +0x60a
github.com/blugelabs/bluge.(*Reader).Search(0xc004ee4280, {0x1cf81b0, 0xc0025ea000}, {0x1cf8488, 0xc000f7dd80})
        $GOPATH/pkg/mod/github.com/blugelabs/bluge@v0.2.1/reader.go:79 +0x286

Am I doing something wrong? Should there be an additional check?

@FZambia
Copy link

FZambia commented Jun 27, 2022

@enex hello! Do you get this all the time? Is there a reproducer? Have you re-created your indexes from scratch or trying to use existing index with new version?

@enex
Copy link
Author

enex commented Jun 28, 2022

I recreated the index with the new version (using the old immediately fails). It always crashes after a few batches. I am currently trying to create a simple example that behaves the same

@FZambia
Copy link

FZambia commented Jun 30, 2022

I reproduced similar panic by stressing our tests too. Though in my case it was originating from different path (from merger). But I think the root cause may be the same.

panic: runtime error: index out of range [63] with length 8

goroutine 397 [running]:
github.com/blugelabs/ice/v2.(*Segment).visitDocument(0xc002ba0180, 0xc002c20bc0, 0xc000040280?, 0xc000dc94e0)
	/Users/fz/go/pkg/mod/github.com/blugelabs/ice/v2@v2.0.1/segment.go:223 +0x307
github.com/blugelabs/ice/v2.mergeStoredAndRemapSegment(0xc002ba0180, 0x0, {0xc000040240, 0x7, 0xc002b7f788?}, 0x4c6b1bc?, 0xc000dc96b8, {0x0, 0x0, 0x0}, ...)
	/Users/fz/go/pkg/mod/github.com/blugelabs/ice/v2@v2.0.1/merge.go:724 +0x20b
github.com/blugelabs/ice/v2.mergeStoredAndRemap({0xc0005934a0, 0x2, 0x8?}, {0xc000593490, 0x2, 0xc002b7f830?}, 0xc00287b380?, {0xc000232a80, 0x8, 0x8}, ...)
	/Users/fz/go/pkg/mod/github.com/blugelabs/ice/v2@v2.0.1/merge.go:674 +0x528
github.com/blugelabs/ice/v2.mergeToWriter({0xc0005934a0, 0x2, 0x2}, {0xc000593490, 0x2, 0x2}, 0x5934a0?, 0x0?, 0xc002d00000?)
	/Users/fz/go/pkg/mod/github.com/blugelabs/ice/v2@v2.0.1/merge.go:130 +0x212
github.com/blugelabs/ice/v2.mergeSegmentBasesWriter({0xc0005934a0, 0x2, 0x2}, {0xc000593490, 0x2, 0x2}, {0x548bd40?, 0xc002c20b80}, 0x401, 0xc0028b00c0)
	/Users/fz/go/pkg/mod/github.com/blugelabs/ice/v2@v2.0.1/merge.go:96 +0xfd
github.com/blugelabs/ice/v2.merge({0xc001df0320, 0x2, 0x4c7f471?}, {0xc000593490, 0x2, 0x2}, {0x548bd40, 0xc002c20b80}, 0xc00023b500?)
	/Users/fz/go/pkg/mod/github.com/blugelabs/ice/v2@v2.0.1/merge.go:85 +0xba
github.com/blugelabs/ice/v2.(*Merger).WriteTo(0xc000302780, {0x548bd80?, 0xc00023b500?}, 0xc002bbff00?)
	/Users/fz/go/pkg/mod/github.com/blugelabs/ice/v2@v2.0.1/merge.go:48 +0x14d
github.com/blugelabs/bluge/index.(*InMemoryDirectory).Persist(0xc00287ce20, {0x50bc904, 0x4}, 0xc000593490?, {0xc5ef9e0, 0xc000302780}, 0x100000?)
	/Users/fz/go/pkg/mod/github.com/blugelabs/bluge@v0.2.1/index/directory_mem.go:75 +0xfa
github.com/blugelabs/bluge/index.(*Writer).merge(0xc002880480, {0xc001df0320?, 0xc000302730?, 0x404df13?}, {0xc000593490?, 0x38?, 0x8?}, 0x1?)
	/Users/fz/go/pkg/mod/github.com/blugelabs/bluge@v0.2.1/index/merge.go:368 +0xb5
github.com/blugelabs/blu

Moreover, with v0.2.1 I am observing occasional CRC check failed errors (when calling DocumentMatch.VisitStoredFields method). The error comes from ZSTD https://github.com/klauspost/compress/blob/v1.15.2/zstd/zstd.go#L90:

	// ErrCRCMismatch is returned if CRC mismatches.
	ErrCRCMismatch = errors.New("CRC check failed")

We are using in-memory index. With Bluge v0.1.9 both problems are not reproducing.

@FZambia
Copy link

FZambia commented Jun 30, 2022

Found a test case that reproduces both panics (most of the time it fails on my machine with one of the panics mentioned above). Maybe it's possible to simplify it further.

func TestPanic(t *testing.T) {
	indexWriter, err := OpenWriter(InMemoryOnlyConfig())
	if err != nil {
		t.Fatal(err)
	}

	batch := NewBatch()
	for i := 0; i < 1000; i++ {
		doc := NewDocument("a" + strconv.Itoa(i)).
			AddField(NewKeywordField("location", "/a").Aggregatable().StoreValue())
		batch.Update(doc.ID(), doc)
	}
	err = indexWriter.Batch(batch)
	if err != nil {
		t.Error(err)
	}

	batch.Reset()
	for i := 0; i < 1000; i++ {
		doc := NewDocument("a" + strconv.Itoa(i+1000))
		batch.Update(doc.ID(), doc)
	}
	err = indexWriter.Batch(batch)
	if err != nil {
		t.Error(err)
	}

	indexReader, err := indexWriter.Reader()
	if err != nil {
		t.Fatalf("error getting reader: %v", err)
	}
	defer func() { _ = indexReader.Close() }()

	req := NewAllMatches(NewPrefixQuery("/a").SetField("location"))
	documentMatchIterator, err := indexReader.Search(context.Background(), req)
	if err != nil {
		t.Fatalf("error search: %v", err)
	}

	match, err := documentMatchIterator.Next()
	for err == nil && match != nil {
		err = match.VisitStoredFields(func(field string, value []byte) bool {
			return true
		})
		match, err = documentMatchIterator.Next()
	}
	if err != nil {
		t.Fatalf("error iterating: %v", err)
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants