diff --git a/index/scorch/snapshot_index.go b/index/scorch/snapshot_index.go index 79840a41f..bec7a0d33 100644 --- a/index/scorch/snapshot_index.go +++ b/index/scorch/snapshot_index.go @@ -59,7 +59,7 @@ var reflectStaticSizeIndexSnapshot int // This threshold can be overwritten by users at the library level by changing the // exported variable, or at the index level by setting the FieldTFRCacheThreshold // in the kvConfig. -var DefaultFieldTFRCacheThreshold uint64 = 10 +var DefaultFieldTFRCacheThreshold int = 10 func init() { var is interface{} = IndexSnapshot{} @@ -640,10 +640,18 @@ func (is *IndexSnapshot) allocTermFieldReaderDicts(field string) (tfr *IndexSnap } } -func (is *IndexSnapshot) getFieldTFRCacheThreshold() uint64 { +func (is *IndexSnapshot) getFieldTFRCacheThreshold() int { if is.parent.config != nil { - if _, ok := is.parent.config["FieldTFRCacheThreshold"]; ok { - return is.parent.config["FieldTFRCacheThreshold"].(uint64) + if _, exists := is.parent.config["FieldTFRCacheThreshold"]; exists { + val := is.parent.config["FieldTFRCacheThreshold"] + if x, ok := val.(float64); ok { + // JSON unmarshal-ed into a map[string]interface{} will default + // to float64 for numbers, so we need to check for float64 first. + return int(x) + } else if x, ok := val.(int); ok { + // If library users provided an int in the config, we'll honor it. + return x + } } } return DefaultFieldTFRCacheThreshold @@ -670,7 +678,7 @@ func (is *IndexSnapshot) recycleTermFieldReader(tfr *IndexSnapshotTermFieldReade if is.fieldTFRs == nil { is.fieldTFRs = map[string][]*IndexSnapshotTermFieldReader{} } - if uint64(len(is.fieldTFRs[tfr.field])) < is.getFieldTFRCacheThreshold() { + if len(is.fieldTFRs[tfr.field]) < is.getFieldTFRCacheThreshold() { tfr.bytesRead = 0 is.fieldTFRs[tfr.field] = append(is.fieldTFRs[tfr.field], tfr) }