Skip to content

Commit d0785de

Browse files
authored
MB-61890 - Introducing config for zap layer (#2066)
- Currently there isn't a concept of config at the zap layer and whatever storage level configurations present (at various points of index lifetime) are global variables. This forces all indexes' segments to use same values irrespective of how heavy indexes are. - The PR introduces `segmentConfig` that can be used to pass index specific config values for the zap level. This would help in the future to perform any index specific tuning at the zap level. - This involves extending the existing interface's Merge, Open and New APIs. - The `segmentConfig` is something that's constructed by parsing the `scorch.config` and persisted in the index_meta.json file.
1 parent 74cb8d1 commit d0785de

File tree

6 files changed

+39
-29
lines changed

6 files changed

+39
-29
lines changed

go.mod

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ require (
1919
github.com/blevesearch/stempel v0.2.0
2020
github.com/blevesearch/upsidedown_store_api v1.0.2
2121
github.com/blevesearch/vellum v1.2.0
22-
github.com/blevesearch/zapx/v11 v11.4.2
23-
github.com/blevesearch/zapx/v12 v12.4.2
24-
github.com/blevesearch/zapx/v13 v13.4.2
25-
github.com/blevesearch/zapx/v14 v14.4.2
26-
github.com/blevesearch/zapx/v15 v15.4.2
27-
github.com/blevesearch/zapx/v16 v16.3.0
28-
github.com/blevesearch/zapx/v17 v17.0.1
22+
github.com/blevesearch/zapx/v11 v11.4.3
23+
github.com/blevesearch/zapx/v12 v12.4.3
24+
github.com/blevesearch/zapx/v13 v13.4.3
25+
github.com/blevesearch/zapx/v14 v14.4.3
26+
github.com/blevesearch/zapx/v15 v15.4.3
27+
github.com/blevesearch/zapx/v16 v16.3.1
28+
github.com/blevesearch/zapx/v17 v17.0.2-0.20260204210735-148661f2ddf6
2929
github.com/couchbase/moss v0.2.0
3030
github.com/spf13/cobra v1.10.2
3131
go.etcd.io/bbolt v1.4.0

go.sum

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,20 @@ github.com/blevesearch/upsidedown_store_api v1.0.2 h1:U53Q6YoWEARVLd1OYNc9kvhBMG
3333
github.com/blevesearch/upsidedown_store_api v1.0.2/go.mod h1:M01mh3Gpfy56Ps/UXHjEO/knbqyQ1Oamg8If49gRwrQ=
3434
github.com/blevesearch/vellum v1.2.0 h1:xkDiOEsHc2t3Cp0NsNZZ36pvc130sCzcGKOPMzXe+e0=
3535
github.com/blevesearch/vellum v1.2.0/go.mod h1:uEcfBJz7mAOf0Kvq6qoEKQQkLODBF46SINYNkZNae4k=
36-
github.com/blevesearch/zapx/v11 v11.4.2 h1:l46SV+b0gFN+Rw3wUI1YdMWdSAVhskYuvxlcgpQFljs=
37-
github.com/blevesearch/zapx/v11 v11.4.2/go.mod h1:4gdeyy9oGa/lLa6D34R9daXNUvfMPZqUYjPwiLmekwc=
38-
github.com/blevesearch/zapx/v12 v12.4.2 h1:fzRbhllQmEMUuAQ7zBuMvKRlcPA5ESTgWlDEoB9uQNE=
39-
github.com/blevesearch/zapx/v12 v12.4.2/go.mod h1:TdFmr7afSz1hFh/SIBCCZvcLfzYvievIH6aEISCte58=
40-
github.com/blevesearch/zapx/v13 v13.4.2 h1:46PIZCO/ZuKZYgxI8Y7lOJqX3Irkc3N8W82QTK3MVks=
41-
github.com/blevesearch/zapx/v13 v13.4.2/go.mod h1:knK8z2NdQHlb5ot/uj8wuvOq5PhDGjNYQQy0QDnopZk=
42-
github.com/blevesearch/zapx/v14 v14.4.2 h1:2SGHakVKd+TrtEqpfeq8X+So5PShQ5nW6GNxT7fWYz0=
43-
github.com/blevesearch/zapx/v14 v14.4.2/go.mod h1:rz0XNb/OZSMjNorufDGSpFpjoFKhXmppH9Hi7a877D8=
44-
github.com/blevesearch/zapx/v15 v15.4.2 h1:sWxpDE0QQOTjyxYbAVjt3+0ieu8NCE0fDRaFxEsp31k=
45-
github.com/blevesearch/zapx/v15 v15.4.2/go.mod h1:1pssev/59FsuWcgSnTa0OeEpOzmhtmr/0/11H0Z8+Nw=
46-
github.com/blevesearch/zapx/v16 v16.3.0 h1:hF6VlN15E9CB40RMPyqOIhlDw1OOo9RItumhKMQktxw=
47-
github.com/blevesearch/zapx/v16 v16.3.0/go.mod h1:zCFjv7McXWm1C8rROL+3mUoD5WYe2RKsZP3ufqcYpLY=
48-
github.com/blevesearch/zapx/v17 v17.0.1 h1:kdojyNDiC4abVvsSwequvqYTBuLEXoG3c0UKyxe1+GM=
49-
github.com/blevesearch/zapx/v17 v17.0.1/go.mod h1:gvr+JMDB9XvQUkT+CaYJhY7aMlez5EmXbkzOBCVyc7U=
36+
github.com/blevesearch/zapx/v11 v11.4.3 h1:PTZOO5loKpHC/x/GzmPZNa9cw7GZIQxd5qRjwij9tHY=
37+
github.com/blevesearch/zapx/v11 v11.4.3/go.mod h1:4gdeyy9oGa/lLa6D34R9daXNUvfMPZqUYjPwiLmekwc=
38+
github.com/blevesearch/zapx/v12 v12.4.3 h1:eElXvAaAX4m04t//CGBQAtHNPA+Q6A1hHZVrN3LSFYo=
39+
github.com/blevesearch/zapx/v12 v12.4.3/go.mod h1:TdFmr7afSz1hFh/SIBCCZvcLfzYvievIH6aEISCte58=
40+
github.com/blevesearch/zapx/v13 v13.4.3 h1:qsdhRhaSpVnqDFlRiH9vG5+KJ+dE7KAW9WyZz/KXAiE=
41+
github.com/blevesearch/zapx/v13 v13.4.3/go.mod h1:knK8z2NdQHlb5ot/uj8wuvOq5PhDGjNYQQy0QDnopZk=
42+
github.com/blevesearch/zapx/v14 v14.4.3 h1:GY4Hecx0C6UTmiNC2pKdeA2rOKiLR5/rwpU9WR51dgM=
43+
github.com/blevesearch/zapx/v14 v14.4.3/go.mod h1:rz0XNb/OZSMjNorufDGSpFpjoFKhXmppH9Hi7a877D8=
44+
github.com/blevesearch/zapx/v15 v15.4.3 h1:iJiMJOHrz216jyO6lS0m9RTCEkprUnzvqAI2lc/0/CU=
45+
github.com/blevesearch/zapx/v15 v15.4.3/go.mod h1:1pssev/59FsuWcgSnTa0OeEpOzmhtmr/0/11H0Z8+Nw=
46+
github.com/blevesearch/zapx/v16 v16.3.1 h1:ERxZUSC9UcuKggCQ6b3y4sTkyL4WnGOWuopzglR874g=
47+
github.com/blevesearch/zapx/v16 v16.3.1/go.mod h1:zCFjv7McXWm1C8rROL+3mUoD5WYe2RKsZP3ufqcYpLY=
48+
github.com/blevesearch/zapx/v17 v17.0.2-0.20260204210735-148661f2ddf6 h1:eqJh5al0dcPq6VsY6C+G4kva5BBffzMG+sN/SWg2/Eg=
49+
github.com/blevesearch/zapx/v17 v17.0.2-0.20260204210735-148661f2ddf6/go.mod h1:gvr+JMDB9XvQUkT+CaYJhY7aMlez5EmXbkzOBCVyc7U=
5050
github.com/couchbase/ghistogram v0.1.0 h1:b95QcQTCzjTUocDXp/uMgSNQi8oj1tGwnJ4bODWZnps=
5151
github.com/couchbase/ghistogram v0.1.0/go.mod h1:s1Jhy76zqfEecpNWJfWUiKZookAFaiGOEoyzgHt9i7k=
5252
github.com/couchbase/moss v0.2.0 h1:VCYrMzFwEryyhRSeI+/b3tRBSeTpi/8gn5Kf6dxqn+o=

index/scorch/merge.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -372,8 +372,8 @@ func (s *Scorch) planMergeAtSnapshot(ctx context.Context,
372372

373373
atomic.AddUint64(&s.stats.TotFileMergeZapBeg, 1)
374374
prevBytesReadTotal := cumulateBytesRead(segmentsToMerge)
375-
newDocNums, _, err := s.segPlugin.Merge(segmentsToMerge, docsToDrop, path,
376-
cw.cancelCh, s)
375+
newDocNums, _, err := s.segPlugin.MergeUsing(segmentsToMerge, docsToDrop, path,
376+
cw.cancelCh, s, s.segmentConfig)
377377
atomic.AddUint64(&s.stats.TotFileMergeZapEnd, 1)
378378

379379
fileMergeZapTime := uint64(time.Since(fileMergeZapStartTime))
@@ -391,7 +391,7 @@ func (s *Scorch) planMergeAtSnapshot(ctx context.Context,
391391
return fmt.Errorf("merging failed: %v", err)
392392
}
393393

394-
seg, err = s.segPlugin.Open(path)
394+
seg, err = s.segPlugin.OpenUsing(path, s.segmentConfig)
395395
if err != nil {
396396
s.unmarkIneligibleForRemoval(filename)
397397
atomic.AddUint64(&s.stats.TotFileMergePlanTasksErr, 1)
@@ -540,7 +540,7 @@ func (s *Scorch) mergeAndPersistInMemorySegments(snapshot *IndexSnapshot,
540540
// the newly merged segment is already flushed out to disk, just needs
541541
// to be opened using mmap.
542542
newDocIDs, _, err :=
543-
s.segPlugin.Merge(segsBatch, dropsBatch, path, s.closeCh, s)
543+
s.segPlugin.MergeUsing(segsBatch, dropsBatch, path, s.closeCh, s, s.segmentConfig)
544544
if err != nil {
545545
em.Lock()
546546
errs = append(errs, err)
@@ -555,7 +555,7 @@ func (s *Scorch) mergeAndPersistInMemorySegments(snapshot *IndexSnapshot,
555555
s.markIneligibleForRemoval(filename)
556556
newMergedSegmentIDs[id] = newSegmentID
557557
newDocIDsSet[id] = newDocIDs
558-
newMergedSegments[id], err = s.segPlugin.Open(path)
558+
newMergedSegments[id], err = s.segPlugin.OpenUsing(path, s.segmentConfig)
559559
if err != nil {
560560
em.Lock()
561561
errs = append(errs, err)

index/scorch/persister.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,7 @@ func (s *Scorch) persistSnapshotDirect(snapshot *IndexSnapshot, exclude map[uint
804804
}
805805
}()
806806
for segmentID, path := range newSegmentPaths {
807-
newSegments[segmentID], err = s.segPlugin.Open(path)
807+
newSegments[segmentID], err = s.segPlugin.OpenUsing(path, s.segmentConfig)
808808
if err != nil {
809809
return fmt.Errorf("error opening new segment at %s, %v", path, err)
810810
}
@@ -1016,7 +1016,7 @@ func (s *Scorch) loadSegment(segmentBucket *bolt.Bucket) (*SegmentSnapshot, erro
10161016
return nil, fmt.Errorf("segment path missing")
10171017
}
10181018
segmentPath := s.path + string(os.PathSeparator) + string(pathBytes)
1019-
seg, err := s.segPlugin.Open(segmentPath)
1019+
seg, err := s.segPlugin.OpenUsing(segmentPath, s.segmentConfig)
10201020
if err != nil {
10211021
return nil, fmt.Errorf("error opening bolt segment: %v", err)
10221022
}

index/scorch/scorch.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ type Scorch struct {
4545
readOnly bool
4646
version uint8
4747
config map[string]interface{}
48+
segmentConfig map[string]interface{}
4849
analysisQueue *index.AnalysisQueue
4950
path string
5051

@@ -154,6 +155,7 @@ func NewScorch(storeName string,
154155
forceMergeRequestCh: make(chan *mergerCtrl, 1),
155156
segPlugin: defaultSegmentPlugin,
156157
copyScheduled: map[string]int{},
158+
segmentConfig: make(map[string]interface{}),
157159
}
158160

159161
forcedSegmentType, forcedSegmentVersion, err := configForceSegmentTypeVersion(config)
@@ -497,7 +499,7 @@ func (s *Scorch) Batch(batch *index.Batch) (err error) {
497499
stats := newFieldStats()
498500

499501
if len(analysisResults) > 0 {
500-
newSegment, bufBytes, err = s.segPlugin.New(analysisResults)
502+
newSegment, bufBytes, err = s.segPlugin.NewUsing(analysisResults, s.segmentConfig)
501503
if err != nil {
502504
return err
503505
}

index/scorch/segment_plugin.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,14 @@ type SegmentPlugin interface {
4646
// New takes a set of Documents and turns them into a new Segment
4747
New(results []index.Document) (segment.Segment, uint64, error)
4848

49+
NewUsing(results []index.Document, config map[string]interface{}) (segment.Segment, uint64, error)
50+
4951
// Open attempts to open the file at the specified path and
5052
// return the corresponding Segment
5153
Open(path string) (segment.Segment, error)
5254

55+
OpenUsing(path string, config map[string]interface{}) (segment.Segment, error)
56+
5357
// Merge takes a set of Segments, and creates a new segment on disk at
5458
// the specified path.
5559
// Drops is a set of bitmaps (one for each segment) indicating which
@@ -67,6 +71,10 @@ type SegmentPlugin interface {
6771
Merge(segments []segment.Segment, drops []*roaring.Bitmap, path string,
6872
closeCh chan struct{}, s segment.StatsReporter) (
6973
[][]uint64, uint64, error)
74+
75+
MergeUsing(segments []segment.Segment, drops []*roaring.Bitmap, path string,
76+
closeCh chan struct{}, s segment.StatsReporter, config map[string]interface{}) (
77+
[][]uint64, uint64, error)
7078
}
7179

7280
var supportedSegmentPlugins map[string]map[uint32]SegmentPlugin

0 commit comments

Comments
 (0)