Skip to content

Commit

Permalink
wip: making v16 as default zap plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Thejas-bhat committed Dec 4, 2023
1 parent 74e5007 commit 2f3cd09
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 16 deletions.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,5 @@ require (
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
golang.org/x/sys v0.13.0 // indirect
)

replace github.com/blevesearch/zapx/v16 => ../zapx
20 changes: 10 additions & 10 deletions index/scorch/segment_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ import (
"github.com/blevesearch/bleve/v2/geo"
segment "github.com/blevesearch/scorch_segment_api/v2"

zapv11 "github.com/blevesearch/zapx/v11"
zapv12 "github.com/blevesearch/zapx/v12"
zapv13 "github.com/blevesearch/zapx/v13"
zapv14 "github.com/blevesearch/zapx/v14"
zapv15 "github.com/blevesearch/zapx/v15"
zapv16 "github.com/blevesearch/zapx/v16"
)

Expand Down Expand Up @@ -75,11 +70,6 @@ var defaultSegmentPlugin SegmentPlugin
func init() {
ResetSegmentPlugins()
RegisterSegmentPlugin(&zapv16.ZapPlugin{}, true)
RegisterSegmentPlugin(&zapv15.ZapPlugin{}, false)
RegisterSegmentPlugin(&zapv14.ZapPlugin{}, false)
RegisterSegmentPlugin(&zapv13.ZapPlugin{}, false)
RegisterSegmentPlugin(&zapv12.ZapPlugin{}, false)
RegisterSegmentPlugin(&zapv11.ZapPlugin{}, false)
}

func ResetSegmentPlugins() {
Expand Down Expand Up @@ -112,6 +102,16 @@ func SupportedSegmentTypeVersions(typ string) (rv []uint32) {

func chooseSegmentPlugin(forcedSegmentType string,
forcedSegmentVersion uint32) (SegmentPlugin, error) {
// TBD: zap v16 can support the older file formats as well, however
// it breaks the TestForceVersion unit test in scorch_test.go
// commenting the code below to avoid any breakages.
//
// v16 and above are able to handle upgrade scenarios, so no need to load
// the force load the older plugins
if defaultSegmentPlugin.Version() >= 16 {
return defaultSegmentPlugin, nil
}

if versions, ok := supportedSegmentPlugins[forcedSegmentType]; ok {
if segPlugin, ok := versions[uint32(forcedSegmentVersion)]; ok {
return segPlugin, nil
Expand Down
75 changes: 69 additions & 6 deletions index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,69 @@ func checkStatsOnIndexedBatch(indexPath string, indexMapping mapping.IndexMappin
return statValError
}

func TestIndexSectionsUpgrade(t *testing.T) {
tmpIndexPath := createTmpIndexPath(t)
defer cleanupTmpIndexPath(t, tmpIndexPath)

indexMapping := NewIndexMapping()
indexMapping.TypeField = "type"
indexMapping.DefaultAnalyzer = "en"
documentMapping := NewDocumentMapping()
indexMapping.AddDocumentMapping("hotel", documentMapping)
indexMapping.StoreDynamic = false
indexMapping.DocValuesDynamic = false
contentFieldMapping := NewTextFieldMapping()
contentFieldMapping.IncludeInAll = false

reviewsMapping := NewDocumentMapping()
reviewsMapping.AddFieldMappingsAt("content", contentFieldMapping)
documentMapping.AddSubDocumentMapping("reviews", reviewsMapping)

typeFieldMapping := NewTextFieldMapping()
typeFieldMapping.Store = false
typeFieldMapping.DocValues = true
documentMapping.AddFieldMappingsAt("type", typeFieldMapping)

config := map[string]interface{}{
"forceSegmentVersion": 11,
"forceSegmentType": "zap",
}

idx, err := NewUsing(tmpIndexPath, indexMapping, Config.DefaultIndexType, Config.DefaultMemKVStore, config)
if err != nil {
t.Fatal(err)
}

defer func() {
err := idx.Close()
if err != nil {
t.Fatal(err)
}
}()

batch, err := getBatchFromData(idx, "sample-data.json")
if err != nil {
t.Fatalf("failed to form a batch")
}
err = idx.Batch(batch)
if err != nil {
t.Fatalf("failed to index batch %v\n", err)
}
typeFacet := NewFacetRequest("type", 2)
query := NewQueryStringQuery("united")

searchRequest := NewSearchRequestOptions(query, int(10), 0, true)
searchRequest.AddFacet("types", typeFacet)
res, err := idx.Search(searchRequest)
if err != nil {
t.Error(err)
}

if res.Facets["types"].Total != 9 {
t.Errorf("expected count for types facets is 9 got %v", res.Facets["types"].Total)
}
}

/*
func TestBytesWritten(t *testing.T) {
tmpIndexPath := createTmpIndexPath(t)
Expand Down Expand Up @@ -402,8 +465,8 @@ func TestBytesRead(t *testing.T) {
}
stats, _ := idx.StatsMap()["index"].(map[string]interface{})
prevBytesRead, _ := stats["num_bytes_read_at_query_time"].(uint64)
if prevBytesRead != 21631 && res.Cost == prevBytesRead {
t.Fatalf("expected bytes read for query string 21631, got %v",
if prevBytesRead != 21639 && res.Cost == prevBytesRead {
t.Fatalf("expected bytes read for query string 21639, got %v",
prevBytesRead)
}
Expand Down Expand Up @@ -554,8 +617,8 @@ func TestBytesReadStored(t *testing.T) {
stats, _ := idx.StatsMap()["index"].(map[string]interface{})
bytesRead, _ := stats["num_bytes_read_at_query_time"].(uint64)
if bytesRead != 11493 && bytesRead == res.Cost {
t.Fatalf("expected the bytes read stat to be around 11493, got %v", bytesRead)
if bytesRead != 11501 && bytesRead == res.Cost {
t.Fatalf("expected the bytes read stat to be around 11501, got %v", bytesRead)
}
prevBytesRead := bytesRead
Expand Down Expand Up @@ -625,8 +688,8 @@ func TestBytesReadStored(t *testing.T) {
stats, _ = idx1.StatsMap()["index"].(map[string]interface{})
bytesRead, _ = stats["num_bytes_read_at_query_time"].(uint64)
if bytesRead != 3679 && bytesRead == res.Cost {
t.Fatalf("expected the bytes read stat to be around 3679, got %v", bytesRead)
if bytesRead != 3687 && bytesRead == res.Cost {
t.Fatalf("expected the bytes read stat to be around 3687, got %v", bytesRead)
}
prevBytesRead = bytesRead
Expand Down

0 comments on commit 2f3cd09

Please sign in to comment.