Skip to content

Commit

Permalink
Implement model cache flush when the cluster metadata is changed.
Browse files Browse the repository at this point in the history
  • Loading branch information
afoucret committed Apr 10, 2024
1 parent 19753c9 commit 82567c6
Showing 1 changed file with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.xpack.core.ml.action.GetTrainedModelsAction;
import org.elasticsearch.xpack.core.ml.inference.ModelAliasMetadata;
import org.elasticsearch.xpack.core.ml.inference.TrainedModelCacheMetadata;
import org.elasticsearch.xpack.core.ml.inference.TrainedModelConfig;
import org.elasticsearch.xpack.core.ml.inference.TrainedModelType;
import org.elasticsearch.xpack.core.ml.inference.trainedmodel.ClassificationConfig;
Expand Down Expand Up @@ -750,6 +751,12 @@ private void cacheEvictionListener(RemovalNotification<String, ModelAndConsumer>

@Override
public void clusterChanged(ClusterChangedEvent event) {
if (event.changedCustomMetadataSet().contains(TrainedModelCacheMetadata.NAME)) {
// Flush all models cache since we are detecting some changes.
logger.debug("Trained model cache invalidated on node [{}]", event.state().nodes().getLocalNodeId());
localModelCache.invalidateAll();
}

final boolean prefetchModels = event.state().nodes().getLocalNode().isIngestNode();
// If we are not prefetching models and there were no model alias changes, don't bother handling the changes
if ((prefetchModels == false)
Expand Down

0 comments on commit 82567c6

Please sign in to comment.