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

MB-61890 - Introducing config at zap layer #256

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion build.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func persistStoredFieldValues(fieldID int,
func InitSegmentBase(mem []byte, memCRC uint32, chunkMode uint32,
fieldsMap map[string]uint16, fieldsInv []string, numDocs uint64,
storedIndexOffset uint64, dictLocs []uint64,
sectionsIndexOffset uint64) (*SegmentBase, error) {
sectionsIndexOffset uint64, config map[string]interface{}) (*SegmentBase, error) {
sb := &SegmentBase{
mem: mem,
memCRC: memCRC,
Expand All @@ -175,6 +175,7 @@ func InitSegmentBase(mem []byte, memCRC uint32, chunkMode uint32,
dictLocs: dictLocs,
fieldFSTs: make(map[uint16]*vellum.FST),
vecIndexCache: newVectorIndexCache(),
config: config,
}
sb.updateSize()

Expand Down
10 changes: 5 additions & 5 deletions build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,28 +48,28 @@ func buildTestSegment() (*SegmentBase, uint64, error) {
doc,
}

seg, size, err := zapPlugin.newWithChunkMode(results, DefaultChunkMode)
seg, size, err := zapPlugin.newWithChunkMode(results, DefaultChunkMode, nil)
return seg.(*SegmentBase), size, err
}

func buildTestSegmentMulti() (*SegmentBase, uint64, error) {
results := buildTestAnalysisResultsMulti()

seg, size, err := zapPlugin.newWithChunkMode(results, DefaultChunkMode)
seg, size, err := zapPlugin.newWithChunkMode(results, DefaultChunkMode, nil)
return seg.(*SegmentBase), size, err
}

func buildTestSegmentMultiWithChunkFactor(chunkFactor uint32) (*SegmentBase, uint64, error) {
results := buildTestAnalysisResultsMulti()

seg, size, err := zapPlugin.newWithChunkMode(results, chunkFactor)
seg, size, err := zapPlugin.newWithChunkMode(results, chunkFactor, nil)
return seg.(*SegmentBase), size, err
}

func buildTestSegmentMultiWithDifferentFields(includeDocA, includeDocB bool) (*SegmentBase, uint64, error) {
results := buildTestAnalysisResultsMultiWithDifferentFields(includeDocA, includeDocB)

seg, size, err := zapPlugin.newWithChunkMode(results, DefaultChunkMode)
seg, size, err := zapPlugin.newWithChunkMode(results, DefaultChunkMode, nil)
return seg.(*SegmentBase), size, err
}

Expand Down Expand Up @@ -152,7 +152,7 @@ func buildTestSegmentWithDefaultFieldMapping(chunkFactor uint32) (
doc,
}

sb, _, err := zapPlugin.newWithChunkMode(results, chunkFactor)
sb, _, err := zapPlugin.newWithChunkMode(results, chunkFactor, nil)

return sb.(*SegmentBase), fields, err
}
2 changes: 1 addition & 1 deletion dict_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func buildTestSegmentForDict() (*SegmentBase, uint64, error) {
doc,
}

seg, size, err := zapPlugin.newWithChunkMode(results, 1024)
seg, size, err := zapPlugin.newWithChunkMode(results, 1024, nil)
return seg.(*SegmentBase), size, err
}

Expand Down
14 changes: 13 additions & 1 deletion merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,21 @@ const docDropped = math.MaxUint64 // sentinel docNum to represent a deleted doc
// Merge takes a slice of segments and bit masks describing which
// documents may be dropped, and creates a new segment containing the
// remaining data. This new segment is built at the specified path.
func (*ZapPlugin) Merge(segments []seg.Segment, drops []*roaring.Bitmap, path string,
func (z *ZapPlugin) Merge(segments []seg.Segment, drops []*roaring.Bitmap, path string,
closeCh chan struct{}, s seg.StatsReporter) (
[][]uint64, uint64, error) {
return z.merge(segments, drops, path, closeCh, s, nil)
}

func (z *ZapPlugin) MergeEx(segments []seg.Segment, drops []*roaring.Bitmap, path string,
closeCh chan struct{}, s seg.StatsReporter, config map[string]interface{}) (
[][]uint64, uint64, error) {
return z.merge(segments, drops, path, closeCh, s, config)
}

func (*ZapPlugin) merge(segments []seg.Segment, drops []*roaring.Bitmap, path string,
closeCh chan struct{}, s seg.StatsReporter, config map[string]interface{}) (
[][]uint64, uint64, error) {
segmentBases := make([]*SegmentBase, len(segments))
for segmenti, segment := range segments {
switch segmentx := segment.(type) {
Expand Down
4 changes: 2 additions & 2 deletions merge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func testMergeWithEmptySegments(t *testing.T, before bool, numEmptySegments int)

_ = os.RemoveAll("/tmp/" + fname)

emptySegment, _, err := zapPlugin.newWithChunkMode([]index.Document{}, 1024)
emptySegment, _, err := zapPlugin.newWithChunkMode([]index.Document{}, 1024, nil)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -644,7 +644,7 @@ func buildTestSegmentMultiHelper(docIds []string) (*SegmentBase, uint64, error)
doc2,
}

seg, size, err := zapPlugin.newWithChunkMode(results, 1024)
seg, size, err := zapPlugin.newWithChunkMode(results, 1024, nil)
return seg.(*SegmentBase), size, err
}

Expand Down
11 changes: 8 additions & 3 deletions new.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,16 @@ var ValidateDocFields = func(field index.Field) error {
// New creates an in-memory zap-encoded SegmentBase from a set of Documents
func (z *ZapPlugin) New(results []index.Document) (
segment.Segment, uint64, error) {
return z.newWithChunkMode(results, DefaultChunkMode)
return z.newWithChunkMode(results, DefaultChunkMode, nil)
}

func (z *ZapPlugin) NewEx(results []index.Document, config map[string]interface{}) (
segment.Segment, uint64, error) {
return z.newWithChunkMode(results, DefaultChunkMode, config)
}

func (*ZapPlugin) newWithChunkMode(results []index.Document,
chunkMode uint32) (segment.Segment, uint64, error) {
chunkMode uint32, config map[string]interface{}) (segment.Segment, uint64, error) {
s := interimPool.Get().(*interim)

var br bytes.Buffer
Expand All @@ -73,7 +78,7 @@ func (*ZapPlugin) newWithChunkMode(results []index.Document,

sb, err := InitSegmentBase(br.Bytes(), s.w.Sum32(), chunkMode,
s.FieldsMap, s.FieldsInv, uint64(len(results)),
storedIndexOffset, dictOffsets, sectionsIndexOffset)
storedIndexOffset, dictOffsets, sectionsIndexOffset, config)

// get the bytes written before the interim's reset() call
// write it to the newly formed segment base.
Expand Down
15 changes: 14 additions & 1 deletion segment.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,18 @@ func init() {
reflectStaticSizeSegmentBase = int(unsafe.Sizeof(sb))
}

// OpenEx returns a zap impl of a segment which tracks some config values during
// the its lifetime.
func (z *ZapPlugin) OpenEx(path string, config map[string]interface{}) (segment.Segment, error) {
return z.open(path, config)
}

// Open returns a zap impl of a segment
func (*ZapPlugin) Open(path string) (segment.Segment, error) {
func (z *ZapPlugin) Open(path string) (segment.Segment, error) {
return z.open(path, nil)
}

func (*ZapPlugin) open(path string, config map[string]interface{}) (segment.Segment, error) {
f, err := os.Open(path)
if err != nil {
return nil, err
Expand All @@ -57,6 +67,7 @@ func (*ZapPlugin) Open(path string) (segment.Segment, error) {
fieldFSTs: make(map[uint16]*vellum.FST),
vecIndexCache: newVectorIndexCache(),
fieldDvReaders: make([]map[uint16]*docValueReader, len(segmentSections)),
config: config,
},
f: f,
mm: mm,
Expand Down Expand Up @@ -108,6 +119,8 @@ type SegmentBase struct {
bytesRead uint64
bytesWritten uint64

config map[string]interface{} // config for the segment

m sync.Mutex
fieldFSTs map[uint16]*vellum.FST

Expand Down
Loading