Skip to content

Commit

Permalink
addressing review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Bharathwaj G <[email protected]>
  • Loading branch information
bharath-techie committed Jun 25, 2024
1 parent 6371916 commit 680875e
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 44 deletions.
9 changes: 6 additions & 3 deletions server/src/main/java/org/opensearch/index/IndexModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ public Iterator<Setting<?>> settings() {
private final BooleanSupplier allowExpensiveQueries;
private final Map<String, IndexStorePlugin.RecoveryStateFactory> recoveryStateFactories;
private final FileCache fileCache;
private final CompositeIndexSettings compositeIndexSettings;

/**
* Construct the index module for the index with the specified index settings. The index module contains extension points for plugins
Expand All @@ -331,7 +332,8 @@ public IndexModule(
final BooleanSupplier allowExpensiveQueries,
final IndexNameExpressionResolver expressionResolver,
final Map<String, IndexStorePlugin.RecoveryStateFactory> recoveryStateFactories,
final FileCache fileCache
final FileCache fileCache,
final CompositeIndexSettings compositeIndexSettings
) {
this.indexSettings = indexSettings;
this.analysisRegistry = analysisRegistry;
Expand All @@ -344,6 +346,7 @@ public IndexModule(
this.expressionResolver = expressionResolver;
this.recoveryStateFactories = recoveryStateFactories;
this.fileCache = fileCache;
this.compositeIndexSettings = compositeIndexSettings;
}

public IndexModule(
Expand All @@ -365,6 +368,7 @@ public IndexModule(
allowExpensiveQueries,
expressionResolver,
recoveryStateFactories,
null,
null
);
}
Expand Down Expand Up @@ -680,8 +684,7 @@ public IndexService newIndexService(
BiFunction<IndexSettings, ShardRouting, TranslogFactory> translogFactorySupplier,
Supplier<TimeValue> clusterDefaultRefreshIntervalSupplier,
RecoverySettings recoverySettings,
RemoteStoreSettings remoteStoreSettings,
CompositeIndexSettings compositeIndexSettings
RemoteStoreSettings remoteStoreSettings
) throws IOException {
final IndexEventListener eventListener = freeze();
Function<IndexService, CheckedFunction<DirectoryReader, DirectoryReader, IOException>> readerWrapperFactory = indexReaderWrapper
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,4 @@ private void starTreeIndexCreationEnabled(boolean value) {
public boolean isStarTreeIndexCreationEnabled() {
return starTreeIndexCreationEnabled;
}

/**
* Utility to provide a {@link CompositeIndexSettings} instance containing all defaults
*/
public static class DefaultCompositeIndexSettings {
private DefaultCompositeIndexSettings() {}

public static final CompositeIndexSettings INSTANCE = new CompositeIndexSettings(
Settings.EMPTY,
new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import org.opensearch.index.compositeindex.datacube.Dimension;
import org.opensearch.index.compositeindex.datacube.Metric;
import org.opensearch.index.compositeindex.datacube.startree.StarTreeIndexSettings;
import org.opensearch.index.mapper.CompositeDataCubeFieldType;
import org.opensearch.index.mapper.CompositeMappedFieldType;
import org.opensearch.index.mapper.MappedFieldType;
import org.opensearch.index.mapper.MapperService;
Expand Down Expand Up @@ -57,9 +56,7 @@ private static void validateStarTreeMappings(
IndexSettings indexSettings
) {
Set<CompositeMappedFieldType> compositeFieldTypes = mapperService.getCompositeFieldTypes();
if (mapperService.getCompositeFieldTypes().size() > StarTreeIndexSettings.STAR_TREE_MAX_FIELDS_SETTING.get(
indexSettings.getSettings()
)) {
if (compositeFieldTypes.size() > StarTreeIndexSettings.STAR_TREE_MAX_FIELDS_SETTING.get(indexSettings.getSettings())) {
throw new IllegalArgumentException(
String.format(
Locale.ROOT,
Expand All @@ -70,7 +67,7 @@ private static void validateStarTreeMappings(
}
for (CompositeMappedFieldType compositeFieldType : compositeFieldTypes) {
if (!(compositeFieldType instanceof StarTreeMapper.StarTreeFieldType)) {
return;
continue;

Check warning on line 70 in server/src/main/java/org/opensearch/index/compositeindex/CompositeIndexValidator.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/index/compositeindex/CompositeIndexValidator.java#L70

Added line #L70 was not covered by tests
}
if (!compositeIndexSettings.isStarTreeIndexCreationEnabled()) {
throw new IllegalArgumentException(
Expand All @@ -81,15 +78,15 @@ private static void validateStarTreeMappings(
)
);
}
CompositeDataCubeFieldType dataCubeFieldType = (CompositeDataCubeFieldType) compositeFieldType;
StarTreeMapper.StarTreeFieldType dataCubeFieldType = (StarTreeMapper.StarTreeFieldType) compositeFieldType;
for (Dimension dim : dataCubeFieldType.getDimensions()) {
MappedFieldType ft = mapperService.fieldType(dim.getField());
if (ft == null) {
throw new IllegalArgumentException(
String.format(Locale.ROOT, "unknown dimension field [%s] as part of star tree field", dim.getField())

Check warning on line 86 in server/src/main/java/org/opensearch/index/compositeindex/CompositeIndexValidator.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/index/compositeindex/CompositeIndexValidator.java#L85-L86

Added lines #L85 - L86 were not covered by tests
);
}
if (!ft.isAggregatable()) {
if (ft.isAggregatable() == false) {
throw new IllegalArgumentException(
String.format(
Locale.ROOT,
Expand All @@ -107,7 +104,7 @@ private static void validateStarTreeMappings(
String.format(Locale.ROOT, "unknown metric field [%s] as part of star tree field", metric.getField())

Check warning on line 104 in server/src/main/java/org/opensearch/index/compositeindex/CompositeIndexValidator.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/index/compositeindex/CompositeIndexValidator.java#L103-L104

Added lines #L103 - L104 were not covered by tests
);
}
if (!ft.isAggregatable()) {
if (ft.isAggregatable() == false) {
throw new IllegalArgumentException(
String.format(
Locale.ROOT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
import org.opensearch.core.xcontent.XContentBuilder;

import java.io.IOException;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;

/**
Expand All @@ -27,10 +27,10 @@
public class StarTreeFieldConfiguration implements ToXContent {

private final AtomicInteger maxLeafDocs = new AtomicInteger();
private final List<String> skipStarNodeCreationInDims;
private final Set<String> skipStarNodeCreationInDims;
private final StarTreeBuildMode buildMode;

public StarTreeFieldConfiguration(int maxLeafDocs, List<String> skipStarNodeCreationInDims, StarTreeBuildMode buildMode) {
public StarTreeFieldConfiguration(int maxLeafDocs, Set<String> skipStarNodeCreationInDims, StarTreeBuildMode buildMode) {
this.maxLeafDocs.set(maxLeafDocs);
this.skipStarNodeCreationInDims = skipStarNodeCreationInDims;
this.buildMode = buildMode;
Expand Down Expand Up @@ -87,7 +87,7 @@ public StarTreeBuildMode getBuildMode() {
return buildMode;
}

public List<String> getSkipStarNodeCreationInDims() {
public Set<String> getSkipStarNodeCreationInDims() {
return skipStarNodeCreationInDims;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.opensearch.search.lookup.SearchLookup;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
Expand Down Expand Up @@ -83,8 +82,8 @@ public static class Builder extends ParametrizedFieldMapper.Builder {
);
}
paramMap.remove(MAX_LEAF_DOCS);
List<String> skipStarInDims = Arrays.asList(
XContentMapValues.nodeStringArrayValue(paramMap.getOrDefault(SKIP_STAR_NODE_IN_DIMS, new ArrayList<String>()))
Set<String> skipStarInDims = new LinkedHashSet<>(
List.of(XContentMapValues.nodeStringArrayValue(paramMap.getOrDefault(SKIP_STAR_NODE_IN_DIMS, new ArrayList<String>())))
);
paramMap.remove(SKIP_STAR_NODE_IN_DIMS);
StarTreeFieldConfiguration.StarTreeBuildMode buildMode = StarTreeFieldConfiguration.StarTreeBuildMode.fromTypeName(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -944,7 +944,8 @@ private synchronized IndexService createIndexService(
() -> allowExpensiveQueries,
indexNameExpressionResolver,
recoveryStateFactories,
fileCache
fileCache,
compositeIndexSettings
);
for (IndexingOperationListener operationListener : indexingOperationListeners) {
indexModule.addIndexOperationListener(operationListener);
Expand Down Expand Up @@ -974,8 +975,7 @@ private synchronized IndexService createIndexService(
translogFactorySupplier,
this::getClusterDefaultRefreshInterval,
this.recoverySettings,
this.remoteStoreSettings,
this.compositeIndexSettings
this.remoteStoreSettings
);
}

Expand Down Expand Up @@ -1036,7 +1036,8 @@ public synchronized MapperService createIndexMapperService(IndexMetadata indexMe
() -> allowExpensiveQueries,
indexNameExpressionResolver,
recoveryStateFactories,
fileCache
fileCache,
compositeIndexSettings
);
pluginsService.onIndexModule(indexModule);
return indexModule.newIndexMapperService(xContentRegistry, mapperRegistry, scriptService);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@
import org.opensearch.index.cache.query.DisabledQueryCache;
import org.opensearch.index.cache.query.IndexQueryCache;
import org.opensearch.index.cache.query.QueryCache;
import org.opensearch.index.compositeindex.CompositeIndexSettings;
import org.opensearch.index.engine.Engine;
import org.opensearch.index.engine.EngineConfigFactory;
import org.opensearch.index.engine.InternalEngineFactory;
Expand Down Expand Up @@ -265,8 +264,7 @@ private IndexService newIndexService(IndexModule module) throws IOException {
translogFactorySupplier,
() -> IndexSettings.DEFAULT_REFRESH_INTERVAL,
DefaultRecoverySettings.INSTANCE,
DefaultRemoteStoreSettings.INSTANCE,
CompositeIndexSettings.DefaultCompositeIndexSettings.INSTANCE
DefaultRemoteStoreSettings.INSTANCE
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ public void testValidCompositeIndex() {
StarTreeFieldConfiguration.StarTreeBuildMode.OFF_HEAP,
starTreeFieldType.getStarTreeConfig().getBuildMode()
);
assertEquals(Collections.emptyList(), starTreeFieldType.getStarTreeConfig().getSkipStarNodeCreationInDims());
assertEquals(Collections.emptySet(), starTreeFieldType.getStarTreeConfig().getSkipStarNodeCreationInDims());
}
}
}
Expand Down Expand Up @@ -311,7 +311,7 @@ public void testUpdateIndexWhenMappingIsSame() {
StarTreeFieldConfiguration.StarTreeBuildMode.OFF_HEAP,
starTreeFieldType.getStarTreeConfig().getBuildMode()
);
assertEquals(Collections.emptyList(), starTreeFieldType.getStarTreeConfig().getSkipStarNodeCreationInDims());
assertEquals(Collections.emptySet(), starTreeFieldType.getStarTreeConfig().getSkipStarNodeCreationInDims());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

Expand Down Expand Up @@ -61,7 +62,10 @@ public void testValidStarTree() throws IOException {
assertEquals(expectedMetrics, starTreeFieldType.getMetrics().get(0).getMetrics());
assertEquals(100, starTreeFieldType.getStarTreeConfig().maxLeafDocs());
assertEquals(StarTreeFieldConfiguration.StarTreeBuildMode.ON_HEAP, starTreeFieldType.getStarTreeConfig().getBuildMode());
assertEquals(Arrays.asList("@timestamp", "status"), starTreeFieldType.getStarTreeConfig().getSkipStarNodeCreationInDims());
assertEquals(
new HashSet<>(Arrays.asList("@timestamp", "status")),
starTreeFieldType.getStarTreeConfig().getSkipStarNodeCreationInDims()
);
}
}

Expand Down Expand Up @@ -90,7 +94,7 @@ public void testValidStarTreeDefaults() throws IOException {
assertEquals(expectedMetrics, starTreeFieldType.getMetrics().get(0).getMetrics());
assertEquals(10000, starTreeFieldType.getStarTreeConfig().maxLeafDocs());
assertEquals(StarTreeFieldConfiguration.StarTreeBuildMode.OFF_HEAP, starTreeFieldType.getStarTreeConfig().getBuildMode());
assertEquals(Collections.emptyList(), starTreeFieldType.getStarTreeConfig().getSkipStarNodeCreationInDims());
assertEquals(Collections.emptySet(), starTreeFieldType.getStarTreeConfig().getSkipStarNodeCreationInDims());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@
import org.opensearch.index.SegmentReplicationPressureService;
import org.opensearch.index.SegmentReplicationStatsTracker;
import org.opensearch.index.analysis.AnalysisRegistry;
import org.opensearch.index.compositeindex.CompositeIndexSettings;
import org.opensearch.index.remote.RemoteStorePressureService;
import org.opensearch.index.remote.RemoteStoreStatsTrackerFactory;
import org.opensearch.index.seqno.GlobalCheckpointSyncAction;
Expand Down Expand Up @@ -2079,8 +2078,7 @@ public void onFailure(final Exception e) {
new RemoteStoreStatsTrackerFactory(clusterService, settings),
DefaultRecoverySettings.INSTANCE,
new CacheModule(new ArrayList<>(), settings).getCacheService(),
DefaultRemoteStoreSettings.INSTANCE,
CompositeIndexSettings.DefaultCompositeIndexSettings.INSTANCE
DefaultRemoteStoreSettings.INSTANCE
);
final RecoverySettings recoverySettings = new RecoverySettings(settings, clusterSettings);
snapshotShardsService = new SnapshotShardsService(
Expand Down

0 comments on commit 680875e

Please sign in to comment.