diff options
author | Jon Bratseth <bratseth@oath.com> | 2018-09-11 13:37:59 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@oath.com> | 2018-09-11 13:37:59 +0200 |
commit | 812511539b5ae0146623867229eb297b530a6d35 (patch) | |
tree | 72e4111b4da1b17375c887bf89e04fd74c574c82 /config-model/src/main/java/com/yahoo | |
parent | 7b280eec0f27ff793c6467d00784d89fdbe977d3 (diff) |
Only store large constants under global models
Diffstat (limited to 'config-model/src/main/java/com/yahoo')
-rw-r--r-- | config-model/src/main/java/com/yahoo/searchdefinition/expressiontransforms/ConvertedModel.java | 36 |
1 files changed, 26 insertions, 10 deletions
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/expressiontransforms/ConvertedModel.java b/config-model/src/main/java/com/yahoo/searchdefinition/expressiontransforms/ConvertedModel.java index 852972803f3..050a5226324 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/expressiontransforms/ConvertedModel.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/expressiontransforms/ConvertedModel.java @@ -240,9 +240,12 @@ public class ConvertedModel { profile.addConstant(constantName, asValue(constantValue)); } - private static void transformLargeConstant(ModelStore store, RankProfile profile, QueryProfileRegistry queryProfiles, - Set<String> constantsReplacedByMacros, - String constantName, Tensor constantValue) { + private static void transformLargeConstant(ModelStore store, + RankProfile profile, + QueryProfileRegistry queryProfiles, + Set<String> constantsReplacedByMacros, + String constantName, + Tensor constantValue) { RankProfile.Macro macroOverridingConstant = profile.getMacros().get(constantName); if (macroOverridingConstant != null) { TensorType macroType = macroOverridingConstant.getRankingExpression().type(profile.typeContext(queryProfiles)); @@ -255,7 +258,7 @@ public class ConvertedModel { Path constantPath = store.writeLargeConstant(constantName, constantValue); if ( ! profile.rankingConstants().asMap().containsKey(constantName)) { profile.rankingConstants().add(new RankingConstant(constantName, constantValue.type(), - constantPath.toString())); + constantPath.toString())); } } } @@ -612,8 +615,12 @@ public class ConvertedModel { .writeFile(new StringReader(name + ":" + constant.type() + ":" + correct(constantPath))); // Write content explicitly as a file on the file system as this is distributed using file distribution - createIfNeeded(constantsPath); - IOUtils.writeFile(application.getFileReference(constantPath), TypedBinaryFormat.encode(constant)); + // - but only if this is a global model to avoid writing the same constants for each rank profile + // where they are used + if (modelFiles.modelName.isGlobal()) { + createIfNeeded(constantsPath); + IOUtils.writeFile(application.getFileReference(constantPath), TypedBinaryFormat.encode(constant)); + } return correct(constantPath); } @@ -683,9 +690,13 @@ public class ConvertedModel { return ApplicationPackage.MODELS_GENERATED_REPLICATED_DIR.append(modelName.fullName()); } - /** Files stored below this path will not be replicated in zookeeper */ - public Path storedModelPath() { - return ApplicationPackage.MODELS_GENERATED_DIR.append(modelName.fullName()); + /** + * Files stored below this path will not be replicated in zookeeper. + * Large constants are only stored under the global (not rank-profile-specific) + * path to avoid storing the same large constant multiple times. + */ + public Path storedGlobalModelPath() { + return ApplicationPackage.MODELS_GENERATED_DIR.append(modelName.localName()); } public Path expressionPath(String name) { @@ -702,7 +713,7 @@ public class ConvertedModel { /** Path to the large (ranking) constants directory */ public Path largeConstantsContentPath() { - return storedModelPath().append("constants"); + return storedGlobalModelPath().append("constants"); } /** Path to the large (ranking) constants directory */ @@ -790,10 +801,15 @@ public class ConvertedModel { this.fullName = (namespace != null ? namespace + "." : "") + name; } + /** Returns true if the local name of this is not in a namespace */ + public boolean isGlobal() { return namespace == null; } + + /** Returns the namespace, or null if this is global */ public String namespace() { return namespace; } public String localName() { return name; } public String fullName() { return fullName; } + @Override public boolean equals(Object o) { if (o == this) return true; |