Skip to content

Commit

Permalink
Fix interpreting scorch config: "FieldTFRCacheThreshold"
Browse files Browse the repository at this point in the history
+ This threshold can be used to toggle recycling of TermFieldReaders
  on/off.
+ Couchbase users will have the ability to provide this setting within
  a JSON payload, which when interpreted into a map[string]interface{}
  will need to be interpreted as a `float64`.
+ Should library users set it as `int` we'll honor that setting as well.
  • Loading branch information
abhinavdangeti committed Dec 17, 2024
1 parent be61628 commit 650046f
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions index/scorch/snapshot_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down Expand Up @@ -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
Expand All @@ -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)
}
Expand Down

0 comments on commit 650046f

Please sign in to comment.