Skip to content

Commit d400235

Browse files
committed
Fix log flooding for engine deprecation notice (#2495)
Signed-off-by: Kunal Kotwani <[email protected]>
1 parent 872caa4 commit d400235

File tree

4 files changed

+19
-31
lines changed

4 files changed

+19
-31
lines changed

src/main/java/org/opensearch/knn/index/engine/EngineResolver.java

+18-6
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,19 @@
55

66
package org.opensearch.knn.index.engine;
77

8+
import org.apache.logging.log4j.LogManager;
9+
import org.apache.logging.log4j.Logger;
810
import org.opensearch.knn.index.mapper.CompressionLevel;
911
import org.opensearch.knn.index.mapper.Mode;
1012

13+
import static org.opensearch.knn.index.engine.KNNEngine.DEPRECATED_ENGINES;
14+
1115
/**
1216
* Figures out what {@link KNNEngine} to use based on configuration details
1317
*/
1418
public final class EngineResolver {
1519

20+
private static Logger logger = LogManager.getLogger(EngineResolver.class);
1621
public static final EngineResolver INSTANCE = new EngineResolver();
1722

1823
private EngineResolver() {}
@@ -32,31 +37,38 @@ public KNNEngine resolveEngine(
3237
) {
3338
// User configuration gets precedence
3439
if (knnMethodContext != null && knnMethodContext.isEngineConfigured()) {
35-
return knnMethodContext.getKnnEngine();
40+
return logAndReturnEngine(knnMethodContext.getKnnEngine());
3641
}
3742

3843
// Faiss is the only engine that supports training, so we default to faiss here for now
3944
if (requiresTraining) {
40-
return KNNEngine.FAISS;
45+
return logAndReturnEngine(KNNEngine.FAISS);
4146
}
4247

4348
Mode mode = knnMethodConfigContext.getMode();
4449
CompressionLevel compressionLevel = knnMethodConfigContext.getCompressionLevel();
4550
// If both mode and compression are not specified, we can just default
4651
if (Mode.isConfigured(mode) == false && CompressionLevel.isConfigured(compressionLevel) == false) {
47-
return KNNEngine.DEFAULT;
52+
return logAndReturnEngine(KNNEngine.DEFAULT);
4853
}
4954

5055
// For 1x, we need to default to faiss if mode is provided and use nmslib otherwise
5156
if (CompressionLevel.isConfigured(compressionLevel) == false || compressionLevel == CompressionLevel.x1) {
52-
return mode == Mode.ON_DISK ? KNNEngine.FAISS : KNNEngine.NMSLIB;
57+
return logAndReturnEngine(mode == Mode.ON_DISK ? KNNEngine.FAISS : KNNEngine.NMSLIB);
5358
}
5459

5560
// Lucene is only engine that supports 4x - so we have to default to it here.
5661
if (compressionLevel == CompressionLevel.x4) {
57-
return KNNEngine.LUCENE;
62+
return logAndReturnEngine(KNNEngine.LUCENE);
5863
}
5964

60-
return KNNEngine.FAISS;
65+
return logAndReturnEngine(KNNEngine.FAISS);
66+
}
67+
68+
private KNNEngine logAndReturnEngine(KNNEngine knnEngine) {
69+
if (DEPRECATED_ENGINES.contains(knnEngine)) {
70+
logger.warn("[Deprecation] {} engine is deprecated and will be removed in a future release.", knnEngine);
71+
}
72+
return knnEngine;
6173
}
6274
}

src/main/java/org/opensearch/knn/index/engine/KNNEngine.java

+1-9
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
package org.opensearch.knn.index.engine;
77

88
import com.google.common.collect.ImmutableSet;
9-
import org.apache.logging.log4j.LogManager;
10-
import org.apache.logging.log4j.Logger;
119
import org.opensearch.common.ValidationException;
1210
import org.opensearch.knn.index.SpaceType;
1311
import org.opensearch.knn.index.engine.faiss.Faiss;
@@ -37,7 +35,7 @@ public enum KNNEngine implements KNNLibrary {
3735
private static final Set<KNNEngine> CUSTOM_SEGMENT_FILE_ENGINES = ImmutableSet.of(KNNEngine.NMSLIB, KNNEngine.FAISS);
3836
private static final Set<KNNEngine> ENGINES_SUPPORTING_FILTERS = ImmutableSet.of(KNNEngine.LUCENE, KNNEngine.FAISS);
3937
public static final Set<KNNEngine> ENGINES_SUPPORTING_RADIAL_SEARCH = ImmutableSet.of(KNNEngine.LUCENE, KNNEngine.FAISS);
40-
private static Logger logger = LogManager.getLogger(KNNEngine.class);
38+
public static final Set<KNNEngine> DEPRECATED_ENGINES = ImmutableSet.of(KNNEngine.NMSLIB);
4139

4240
private static Map<KNNEngine, Integer> MAX_DIMENSIONS_BY_ENGINE = Map.of(
4341
KNNEngine.NMSLIB,
@@ -70,9 +68,6 @@ public enum KNNEngine implements KNNLibrary {
7068
*/
7169
public static KNNEngine getEngine(String name) {
7270
if (NMSLIB.getName().equalsIgnoreCase(name)) {
73-
logger.warn(
74-
"[Deprecation] nmslib engine is deprecated and will be removed in a future release. Please use Faiss or Lucene engine instead."
75-
);
7671
return NMSLIB;
7772
}
7873

@@ -95,9 +90,6 @@ public static KNNEngine getEngine(String name) {
9590
*/
9691
public static KNNEngine getEngineNameFromPath(String path) {
9792
if (path.endsWith(KNNEngine.NMSLIB.getExtension()) || path.endsWith(KNNEngine.NMSLIB.getCompoundExtension())) {
98-
logger.warn(
99-
"[Deprecation] nmslib engine is deprecated and will be removed in a future release. Please use Faiss or Lucene engine instead."
100-
);
10193
return KNNEngine.NMSLIB;
10294
}
10395

src/main/java/org/opensearch/knn/index/engine/nmslib/NmslibMethodResolver.java

-6
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55

66
package org.opensearch.knn.index.engine.nmslib;
77

8-
import org.apache.logging.log4j.LogManager;
9-
import org.apache.logging.log4j.Logger;
108
import org.opensearch.common.ValidationException;
119
import org.opensearch.knn.index.SpaceType;
1210
import org.opensearch.knn.index.engine.AbstractMethodResolver;
@@ -33,7 +31,6 @@
3331
public class NmslibMethodResolver extends AbstractMethodResolver {
3432

3533
private static final Set<CompressionLevel> SUPPORTED_COMPRESSION_LEVELS = Set.of(CompressionLevel.x1);
36-
private static Logger logger = LogManager.getLogger(NmslibMethodResolver.class);
3734

3835
@Override
3936
public ResolvedMethodContext resolveMethod(
@@ -42,9 +39,6 @@ public ResolvedMethodContext resolveMethod(
4239
boolean shouldRequireTraining,
4340
final SpaceType spaceType
4441
) {
45-
logger.warn(
46-
"[Deprecation] nmslib engine is deprecated and will be removed in a future release. Please use Faiss or Lucene engine instead."
47-
);
4842
validateConfig(knnMethodConfigContext, shouldRequireTraining);
4943
KNNMethodContext resolvedKNNMethodContext = initResolvedKNNMethodContext(
5044
knnMethodContext,

src/main/java/org/opensearch/knn/jni/JNIService.java

-10
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
package org.opensearch.knn.jni;
1313

1414
import org.apache.commons.lang.ArrayUtils;
15-
import org.apache.logging.log4j.LogManager;
16-
import org.apache.logging.log4j.Logger;
1715
import org.opensearch.common.Nullable;
1816
import org.opensearch.knn.common.KNNConstants;
1917
import org.opensearch.knn.index.engine.KNNEngine;
@@ -30,8 +28,6 @@
3028
*/
3129
public class JNIService {
3230

33-
private static Logger logger = LogManager.getLogger(JNIService.class);
34-
3531
/**
3632
* Initialize an index for the native library. Takes in numDocs to
3733
* allocate the correct amount of memory.
@@ -142,9 +138,6 @@ public static void createIndex(
142138
KNNEngine knnEngine
143139
) {
144140
if (KNNEngine.NMSLIB == knnEngine) {
145-
logger.warn(
146-
"[Deprecation] nmslib engine is deprecated and will be removed in a future release. Please use Faiss or Lucene engine instead."
147-
);
148141
NmslibService.createIndex(ids, vectorsAddress, dim, output, parameters);
149142
return;
150143
}
@@ -209,9 +202,6 @@ public static long loadIndex(IndexInputWithBuffer readStream, Map<String, Object
209202
return FaissService.loadIndexWithStream(readStream);
210203
}
211204
} else if (KNNEngine.NMSLIB == knnEngine) {
212-
logger.warn(
213-
"[Deprecation] nmslib engine is deprecated and will be removed in a future release. Please use Faiss or Lucene engine instead."
214-
);
215205
return NmslibService.loadIndexWithStream(readStream, parameters);
216206
}
217207

0 commit comments

Comments
 (0)