Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Creating a pluggable interface for Table config tuner (#6255)
* Creating a pluggable interface for indexing config resolution * Adding a simple auto tune indexing config resolver * Adding ability to deregister indexing config resolver * Enabling dynamically registered TableConfigTuner methods * - Adding a TableConfigTuner interface - Adding a Tuner annotation type for auto-discovering such tuners * Bug fix in TunerConfig. Adding serde test for TunerConfig
- Loading branch information
Showing
14 changed files
with
508 additions
and
3 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
...-common/src/main/java/org/apache/pinot/common/config/tuner/NoOpTableTableConfigTuner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.pinot.common.config.tuner; | ||
|
||
import org.apache.pinot.spi.config.table.TableConfig; | ||
import org.apache.pinot.spi.config.table.TunerConfig; | ||
import org.apache.pinot.spi.config.table.tuner.TableConfigTuner; | ||
import org.apache.pinot.spi.config.table.tuner.Tuner; | ||
import org.apache.pinot.spi.data.Schema; | ||
|
||
|
||
@Tuner(name = "noopConfigTuner") | ||
public class NoOpTableTableConfigTuner implements TableConfigTuner { | ||
@Override | ||
public void init(TunerConfig props, Schema schema) { | ||
} | ||
|
||
@Override | ||
public TableConfig apply(TableConfig initialConfig) { | ||
return initialConfig; | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
pinot-common/src/main/java/org/apache/pinot/common/config/tuner/RealTimeAutoIndexTuner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.pinot.common.config.tuner; | ||
|
||
import org.apache.pinot.spi.config.table.IndexingConfig; | ||
import org.apache.pinot.spi.config.table.TableConfig; | ||
import org.apache.pinot.spi.config.table.TunerConfig; | ||
import org.apache.pinot.spi.config.table.tuner.TableConfigTuner; | ||
import org.apache.pinot.spi.config.table.tuner.Tuner; | ||
import org.apache.pinot.spi.data.Schema; | ||
|
||
|
||
/** | ||
* Used to auto-tune the table indexing config. It takes the original table | ||
* config, table schema and adds the following to indexing config: | ||
* - Inverted indices for all dimensions | ||
* - No dictionary index for all metrics | ||
*/ | ||
@Tuner(name = "realtimeAutoIndexTuner") | ||
public class RealTimeAutoIndexTuner implements TableConfigTuner { | ||
private Schema _schema; | ||
|
||
@Override | ||
public void init(TunerConfig props, Schema schema) { | ||
_schema = schema; | ||
} | ||
|
||
@Override | ||
public TableConfig apply(TableConfig initialConfig) { | ||
IndexingConfig initialIndexingConfig = initialConfig.getIndexingConfig(); | ||
initialIndexingConfig.setInvertedIndexColumns(_schema.getDimensionNames()); | ||
initialIndexingConfig.setNoDictionaryColumns(_schema.getMetricNames()); | ||
return initialConfig; | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
...t-common/src/main/java/org/apache/pinot/common/config/tuner/TableConfigTunerRegistry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.pinot.common.config.tuner; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import org.apache.pinot.spi.config.table.tuner.TableConfigTuner; | ||
import org.apache.pinot.spi.config.table.tuner.Tuner; | ||
import org.reflections.Reflections; | ||
import org.reflections.scanners.ResourcesScanner; | ||
import org.reflections.scanners.SubTypesScanner; | ||
import org.reflections.scanners.TypeAnnotationsScanner; | ||
import org.reflections.util.ClasspathHelper; | ||
import org.reflections.util.ConfigurationBuilder; | ||
import org.reflections.util.FilterBuilder; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
|
||
/** | ||
* Helper class to dynamically register all annotated {@link Tuner} methods | ||
*/ | ||
public class TableConfigTunerRegistry { | ||
private TableConfigTunerRegistry() { | ||
} | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(TableConfigTunerRegistry.class); | ||
private static final Map<String, TableConfigTuner> _configTunerMap = new HashMap<>(); | ||
|
||
static { | ||
Reflections reflections = new Reflections( | ||
new ConfigurationBuilder().setUrls(ClasspathHelper.forPackage("org.apache.pinot")) | ||
.filterInputsBy(new FilterBuilder.Include(".*\\.tuner\\..*")) | ||
.setScanners(new ResourcesScanner(), new TypeAnnotationsScanner(), new SubTypesScanner())); | ||
Set<Class<?>> classes = reflections.getTypesAnnotatedWith(Tuner.class); | ||
classes.forEach(tunerClass -> { | ||
Tuner tunerAnnotation = tunerClass.getAnnotation(Tuner.class); | ||
if (tunerAnnotation.enabled()) { | ||
if (tunerAnnotation.name().isEmpty()) { | ||
LOGGER.error("Cannot register an unnamed config tuner for annotation {} ", tunerAnnotation.toString()); | ||
} else { | ||
String tunerName = tunerAnnotation.name(); | ||
TableConfigTuner tuner; | ||
try { | ||
tuner = (TableConfigTuner) tunerClass.newInstance(); | ||
_configTunerMap.putIfAbsent(tunerName, tuner); | ||
} catch (Exception e) { | ||
LOGGER.error(String.format("Unable to register tuner %s . Cannot instantiate.", tunerName), e); | ||
} | ||
} | ||
} | ||
}); | ||
LOGGER.info("Initialized TableConfigTunerRegistry with {} tuners: {}", _configTunerMap.size(), | ||
_configTunerMap.keySet()); | ||
} | ||
|
||
public static TableConfigTuner getTuner(String name) { | ||
return _configTunerMap.get(name); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
...common/src/test/java/org/apache/pinot/common/config/tuner/RealTimeAutoIndexTunerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.pinot.common.config.tuner; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Properties; | ||
import org.apache.pinot.spi.config.table.IndexingConfig; | ||
import org.apache.pinot.spi.config.table.TableConfig; | ||
import org.apache.pinot.spi.config.table.TableType; | ||
import org.apache.pinot.spi.config.table.TunerConfig; | ||
import org.apache.pinot.spi.config.table.tuner.TableConfigTuner; | ||
import org.apache.pinot.spi.data.FieldSpec; | ||
import org.apache.pinot.spi.data.Schema; | ||
import org.apache.pinot.spi.utils.builder.TableConfigBuilder; | ||
import org.testng.Assert; | ||
import org.testng.annotations.BeforeClass; | ||
import org.testng.annotations.Test; | ||
|
||
|
||
public class RealTimeAutoIndexTunerTest { | ||
|
||
private static final String TABLE_NAME = "test_table"; | ||
private static final String TUNER_NAME = "realtimeAutoIndexTuner"; | ||
private TunerConfig _tunerConfig; | ||
private Schema schema; | ||
private String dimensionColumns[] = {"col1", "col2"}; | ||
private String metricColumns[] = {"count"}; | ||
|
||
@BeforeClass | ||
public void setup() { | ||
schema = new Schema.SchemaBuilder().setSchemaName(TABLE_NAME) | ||
.addSingleValueDimension(dimensionColumns[0], FieldSpec.DataType.STRING) | ||
.addSingleValueDimension(dimensionColumns[1], FieldSpec.DataType.STRING) | ||
.addMetric(metricColumns[0], FieldSpec.DataType.INT).build(); | ||
Map<String, String> props = new HashMap<>(); | ||
_tunerConfig = new TunerConfig(TUNER_NAME, props); | ||
} | ||
|
||
@Test | ||
public void testTuner() { | ||
TableConfig tableConfig = | ||
new TableConfigBuilder(TableType.OFFLINE).setTableName("test").setTunerConfig(_tunerConfig).build(); | ||
TableConfigTuner tuner = TableConfigTunerRegistry.getTuner(TUNER_NAME); | ||
tuner.init(_tunerConfig, schema); | ||
TableConfig result = tuner.apply(tableConfig); | ||
|
||
IndexingConfig newConfig = result.getIndexingConfig(); | ||
List<String> invertedIndexColumns = newConfig.getInvertedIndexColumns(); | ||
Assert.assertTrue(invertedIndexColumns.size() == 2); | ||
for (int i = 0; i < dimensionColumns.length; i++) { | ||
Assert.assertTrue(invertedIndexColumns.contains(dimensionColumns[i])); | ||
} | ||
|
||
List<String> noDictionaryColumns = newConfig.getNoDictionaryColumns(); | ||
Assert.assertTrue(noDictionaryColumns.size() == 1); | ||
Assert.assertEquals(noDictionaryColumns.get(0), metricColumns[0]); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
pinot-common/src/test/java/org/apache/pinot/common/config/tuner/TunerRegistryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.pinot.common.config.tuner; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import org.apache.pinot.spi.config.table.TableConfig; | ||
import org.apache.pinot.spi.config.table.TableType; | ||
import org.apache.pinot.spi.config.table.TunerConfig; | ||
import org.apache.pinot.spi.config.table.tuner.TableConfigTuner; | ||
import org.apache.pinot.spi.data.Schema; | ||
import org.apache.pinot.spi.utils.builder.TableConfigBuilder; | ||
import org.testng.Assert; | ||
import org.testng.annotations.BeforeClass; | ||
import org.testng.annotations.Test; | ||
|
||
|
||
public class TunerRegistryTest { | ||
|
||
private static final String TUNER_NAME = "noopConfigTuner"; | ||
private static TunerConfig _tunerConfig; | ||
|
||
@BeforeClass | ||
public void setup() { | ||
Map<String, String> props = new HashMap<>(); | ||
_tunerConfig = new TunerConfig(TUNER_NAME, props); | ||
} | ||
|
||
@Test | ||
public void testNoOpTableConfigTuner() { | ||
Schema schema = new Schema.SchemaBuilder().build(); | ||
TableConfig tableConfig = | ||
new TableConfigBuilder(TableType.OFFLINE).setTableName("test").setTunerConfig(_tunerConfig).build(); | ||
TableConfigTuner tuner = TableConfigTunerRegistry.getTuner(TUNER_NAME); | ||
tuner.init(_tunerConfig, schema); | ||
TableConfig result = tuner.apply(tableConfig); | ||
Assert.assertEquals(result, tableConfig); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.