Repository: milvus-io/milvus
File: internal/querycoordv2/task/utils.go (Go)

Code before:
					Key:   common.MmapEnabledKey,
					Value: strconv.FormatBool(structMmapEnabled),
				})
			} else if exist {
				field.TypeParams = append(field.TypeParams, &commonpb.KeyValuePair{
					Key:   common.MmapEnabledKey,
					Value: strconv.FormatBool(collectionMmapEnabled),
				})
			}
		}
	}
	return schema
}

// autoWarmupForNonPKIsolationCollection checks if autoWarmupForNonPKIsolationCollection should be applied for a collection.
// Returns true when the AutoWarmupForNonPKIsolationCollection config is enabled AND the collection
// does NOT have partition key isolation.
func autoWarmupForNonPKIsolationCollection(collectionProperties []*commonpb.KeyValuePair) bool {
	if !paramtable.Get().QueryNodeCfg.AutoWarmupForNonPKIsolationCollection.GetAsBool() {
		return false
	}
	isPKI, isError := common.IsPartitionKeyIsolationKvEnabled(collectionProperties...)
	if isError != nil {
		// if error, regarding as non partition key isolation collection, so autowarmup is true
		log.Warn("failed to parse partition key isolation, regarding as non partition key isolation collection")
		return true
	}
	return !isPKI
}

// applyCollectionWarmupSetting applies collection-level warmup setting to all fields
// and propagates struct-level warmup to nested fields.
// Priority: field-level > struct-level > collection-level > autoWarmupForNonPKIsolationCollection (scalar only)
// Collection-level granular keys: warmup.scalarField, warmup.vectorField
func applyCollectionWarmupSetting(schema *schemapb.CollectionSchema,
	collectionProperties []*commonpb.KeyValuePair,
) *schemapb.CollectionSchema {
	// Get collection-level granular warmup policies
	scalarFieldWarmup, scalarFieldExist := common.GetWarmupPolicyByKey(common.WarmupScalarFieldKey, collectionProperties...)
	vectorFieldWarmup, vectorFieldExist := common.GetWarmupPolicyByKey(common.WarmupVectorFieldKey, collectionProperties...)
	autoWarmup := autoWarmupForNonPKIsolationCollection(collectionProperties)

	// Apply collection-level warmup to regular fields
	for _, field := range schema.GetFields() {
		// field-level warmup setting has higher priority, skip if field already has warmup setting
		if common.FieldHasWarmupKey(schema, field.GetFieldID()) {
			continue
		}

		isVector := typeutil.IsVectorType(field.GetDataType())
		if isVector && vectorFieldExist {

Review comment (bug):
This is fail-open — a malformed PKI value (e.g. `"abc"`) would cause `ParseBool` to error, silently enabling sync warmup for all affected collections and increasing load latency. Should be `return false` (fail-closed), and add `zap.Error(isError)` to the log for debuggability.

Code after:
				field.TypeParams = append(field.TypeParams, &commonpb.KeyValuePair{
					Key:   common.MmapEnabledKey,
					Value: strconv.FormatBool(structMmapEnabled),
				})
			} else if exist {
				field.TypeParams = append(field.TypeParams, &commonpb.KeyValuePair{
					Key:   common.MmapEnabledKey,
					Value: strconv.FormatBool(collectionMmapEnabled),
				})
			}
		}
	}
	return schema
}

// autoWarmupForNonPKIsolationCollection checks if autoWarmupForNonPKIsolationCollection should be applied for a collection.
// Returns true when the AutoWarmupForNonPKIsolationCollection config is enabled AND the collection
// does NOT have partition key isolation.
func autoWarmupForNonPKIsolationCollection(collectionProperties []*commonpb.KeyValuePair) bool {
	if !paramtable.Get().QueryCoordCfg.AutoWarmupForNonPKIsolationCollection.GetAsBool() {
		return false
	}
	isPKI, isError := common.IsPartitionKeyIsolationKvEnabled(collectionProperties...)
	if isError != nil {
		log.Warn("failed to parse partition key isolation, autowarmup is disabled", zap.Error(isError))
		return false
	}
	if !isPKI {
		log.Info("collection is not partition key isolated and autowarmup is enabled, force scalar field/index and vector index warmup to sync")
	}
	return !isPKI
}

// applyCollectionWarmupSetting applies collection-level warmup setting to all fields
// and propagates struct-level warmup to nested fields.
// Priority: field-level > struct-level > collection-level > autoWarmupForNonPKIsolationCollection (scalar only)
// Collection-level granular keys: warmup.scalarField, warmup.vectorField
func applyCollectionWarmupSetting(schema *schemapb.CollectionSchema,
	collectionProperties []*commonpb.KeyValuePair,
) *schemapb.CollectionSchema {
	// Get collection-level granular warmup policies
	scalarFieldWarmup, scalarFieldExist := common.GetWarmupPolicyByKey(common.WarmupScalarFieldKey, collectionProperties...)
	vectorFieldWarmup, vectorFieldExist := common.GetWarmupPolicyByKey(common.WarmupVectorFieldKey, collectionProperties...)
	autoWarmup := autoWarmupForNonPKIsolationCollection(collectionProperties)

	// Apply collection-level warmup to regular fields
	for _, field := range schema.GetFields() {
		// field-level warmup setting has higher priority, skip if field already has warmup setting
		if common.FieldHasWarmupKey(schema, field.GetFieldID()) {
			continue
		}