Skip to content

Commit 289e64a

Browse files
committed
MB-57888: Added unit tests covering all update paths
- Few changes to the deleted fields logic to accommodate edge cases - Added deletion logic to vector paths - Tweaked deletion logic in index path
1 parent 5e53bf7 commit 289e64a

File tree

4 files changed

+2535
-11
lines changed

4 files changed

+2535
-11
lines changed

index/scorch/optimize_knn.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,15 @@ func (o *OptimizeVR) Finish() error {
8585
wg.Done()
8686
}()
8787
for field, vrs := range o.vrs {
88-
vecIndex, err := segment.InterpretVectorIndex(field,
89-
o.requiresFiltering, origSeg.deleted)
88+
var vecIndex segment_api.VectorIndex
89+
var err error
90+
if info, ok := o.snapshot.updatedFields[field]; ok && info.All || info.Index {
91+
vecIndex, err = segment.InterpretVectorIndex("",
92+
o.requiresFiltering, origSeg.deleted)
93+
} else {
94+
vecIndex, err = segment.InterpretVectorIndex(field,
95+
o.requiresFiltering, origSeg.deleted)
96+
}
9097
if err != nil {
9198
errorsM.Lock()
9299
errors = append(errors, err)

index/scorch/snapshot_index.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@ func (is *IndexSnapshot) TermFieldReader(ctx context.Context, term []byte, field
623623
// Skip fields that are supposed to have no indexing
624624
if info, ok := is.updatedFields[field]; ok &&
625625
(info.Index || info.All) {
626-
dict = nil
626+
dict, err = s.segment.Dictionary("")
627627
} else {
628628
dict, err = s.segment.Dictionary(field)
629629
}

index_update.go

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,17 @@ func DeletedFields(ori, upd *mapping.IndexMappingImpl) (map[string]*index.FieldI
104104
if !info.All && !info.Index && !info.DocValues && !info.Store {
105105
delete(fieldInfo, name)
106106
}
107+
if info.All {
108+
if upd.IndexDynamic {
109+
return nil, fmt.Errorf("Mapping cannot be removed when index dynamic is true")
110+
}
111+
if upd.StoreDynamic {
112+
return nil, fmt.Errorf("Mapping cannot be removed when store dynamic is true")
113+
}
114+
if upd.DocValuesDynamic {
115+
return nil, fmt.Errorf("Mapping cannot be removed when docvalues dynamic is true")
116+
}
117+
}
107118
}
108119
return fieldInfo, nil
109120
}
@@ -112,7 +123,7 @@ func compareMappings(ori, upd *mapping.IndexMappingImpl) (*defaultInfo, error) {
112123
rv := &defaultInfo{}
113124

114125
if ori.TypeField != upd.TypeField &&
115-
len(ori.TypeMapping) != 0 || len(upd.TypeMapping) != 0 {
126+
(len(ori.TypeMapping) != 0 || len(upd.TypeMapping) != 0) {
116127
return nil, fmt.Errorf("type field cannot be changed when type mappings are present")
117128
}
118129

@@ -264,7 +275,7 @@ func addFieldInfo(fInfo map[string]*index.FieldInfo, ori, upd *pathInfo, default
264275
if err != nil {
265276
return err
266277
}
267-
err = validateFieldInfo(info, updated, fInfo, ori)
278+
err = validateFieldInfo(info, updated, fInfo, ori, oriFMapInfo)
268279
if err != nil {
269280
return err
270281
}
@@ -285,7 +296,7 @@ func addFieldInfo(fInfo map[string]*index.FieldInfo, ori, upd *pathInfo, default
285296
if err != nil {
286297
return err
287298
}
288-
err = validateFieldInfo(info, updated, fInfo, ori)
299+
err = validateFieldInfo(info, updated, fInfo, ori, oriFMapInfo)
289300
if err != nil {
290301
return err
291302
}
@@ -395,7 +406,7 @@ func compareFieldMapping(original, updated *mapping.FieldMapping, defaultChanges
395406
}
396407
}
397408

398-
if rv.All || rv.Index || rv.Store {
409+
if rv.All || rv.Index || rv.Store || rv.DocValues {
399410
return rv, true, nil
400411
}
401412
return rv, false, nil
@@ -404,13 +415,21 @@ func compareFieldMapping(original, updated *mapping.FieldMapping, defaultChanges
404415
// After identifying changes, validate against the existing changes incase of duplicate fields.
405416
// In such a situation, any conflicting changes found will abort the update process
406417
func validateFieldInfo(newInfo *index.FieldInfo, updated bool, fInfo map[string]*index.FieldInfo,
407-
ori *pathInfo) error {
418+
ori *pathInfo, oriFMapInfo *fieldMapInfo) error {
408419

409420
var name string
410-
if ori.fieldMapInfo[0].parent.parentPath == "" {
411-
name = ori.fieldMapInfo[0].fieldMapping.Name
421+
if oriFMapInfo.parent.parentPath == "" {
422+
if oriFMapInfo.fieldMapping.Name == "" {
423+
name = oriFMapInfo.parent.path
424+
} else {
425+
name = oriFMapInfo.fieldMapping.Name
426+
}
412427
} else {
413-
name = ori.fieldMapInfo[0].parent.parentPath + "." + ori.fieldMapInfo[0].fieldMapping.Name
428+
if oriFMapInfo.fieldMapping.Name == "" {
429+
name = oriFMapInfo.parent.parentPath + "." + oriFMapInfo.parent.path
430+
} else {
431+
name = oriFMapInfo.parent.parentPath + "." + oriFMapInfo.fieldMapping.Name
432+
}
414433
}
415434
if updated {
416435
if ori.dynamic {

0 commit comments

Comments
 (0)