This is an automated email from the ASF dual-hosted git repository.
xiangfu0 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pinot.git
The following commit(s) were added to refs/heads/master by this push:
new 4355e8ed5f3 Make the realtime multi-value limit configurable (#20279)
4355e8ed5f3 is described below
commit 4355e8ed5f3811fea67aa64dc635b85fd361eeb4
Author: Xiang Fu <[email protected]>
AuthorDate: Tue Nov 17 11:28:10 2026 -0800
Make the realtime multi-value limit configurable (#20279)
To reproduce, set maxNumMultiValues to 4096 on a realtime multi-value
column and ingest a row with 4096 values. Pinot previously rejected the row at
1000.
Use explicit limits in batch builds and fall back to byte-based sizing when
a legacy raw chunk exceeds the writer or codec limit.
---
.../indexsegment/mutable/MutableSegmentImpl.java | 5 +
.../forward/FixedByteMVMutableForwardIndex.java | 14 +--
.../segment/creator/impl/BaseSegmentCreator.java | 11 +++
.../fwd/MultiValueFixedByteRawIndexCreator.java | 33 ++++++-
.../segment/index/forward/ForwardIndexType.java | 28 +++++-
...bleSegmentImplNumMultiValuesValidationTest.java | 71 +++++++++++++++
.../converter/RealtimeSegmentConverterTest.java | 51 +++++++++++
.../impl/SegmentColumnarIndexCreatorTest.java | 101 +++++++++++++++++++++
.../FixedByteMVMutableForwardIndexTest.java | 19 ++++
.../segment/spi/index/ForwardIndexConfig.java | 42 ++++++++-
10 files changed, 357 insertions(+), 18 deletions(-)
diff --git
a/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/indexsegment/mutable/MutableSegmentImpl.java
b/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/indexsegment/mutable/MutableSegmentImpl.java
index 618147bb59a..8341d1d80b0 100644
---
a/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/indexsegment/mutable/MutableSegmentImpl.java
+++
b/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/indexsegment/mutable/MutableSegmentImpl.java
@@ -348,6 +348,11 @@ public class MutableSegmentImpl implements MutableSegment {
if (vectorIndexConfig.isEnabled()) {
// A vector column holds one value per dimension, which may exceed the
default cap
contextBuilder.withMaxNumMultiValues(vectorIndexConfig.getVectorDimension());
+ } else if (!fieldSpec.isSingleValueField()) {
+ Integer maxNumMultiValues =
indexConfigs.getConfig(StandardIndexes.forward()).getMaxNumMultiValues();
+ if (maxNumMultiValues != null) {
+ contextBuilder.withMaxNumMultiValues(maxNumMultiValues);
+ }
}
MutableIndexContext context = contextBuilder.build();
diff --git
a/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/realtime/impl/forward/FixedByteMVMutableForwardIndex.java
b/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/realtime/impl/forward/FixedByteMVMutableForwardIndex.java
index 2c69ab7c657..8ee7400e5ef 100644
---
a/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/realtime/impl/forward/FixedByteMVMutableForwardIndex.java
+++
b/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/realtime/impl/forward/FixedByteMVMutableForwardIndex.java
@@ -25,6 +25,7 @@ import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import
org.apache.pinot.segment.local.io.reader.impl.FixedByteSingleValueMultiColReader;
import
org.apache.pinot.segment.local.io.writer.impl.FixedByteSingleValueMultiColWriter;
+import org.apache.pinot.segment.spi.index.ForwardIndexConfig;
import org.apache.pinot.segment.spi.index.mutable.MutableForwardIndex;
import org.apache.pinot.segment.spi.memory.PinotDataBuffer;
import org.apache.pinot.segment.spi.memory.PinotDataBufferMemoryManager;
@@ -96,9 +97,6 @@ public class FixedByteMVMutableForwardIndex implements
MutableForwardIndex {
private static final int SIZE_OF_INT = 4;
private static final int NUM_COLS_IN_HEADER = 3;
- private static final int INCREMENT_PERCENTAGE = 100;
- //Increments the Initial size by 100% of initial capacity every time we runs
out of capacity
-
// Conservative figure to not breach 2GB size limit for immutable index
private final static int DEFAULT_THRESHOLD_FOR_NUM_OF_VALUES_PER_COLUMN =
450_000_000;
@@ -147,9 +145,11 @@ public class FixedByteMVMutableForwardIndex implements
MutableForwardIndex {
_headerSize = numRowsPerChunk * SIZE_OF_INT * NUM_COLS_IN_HEADER;
addHeaderBuffer();
- int initialCapacity = Math.max(maxNumMultiValues, numRowsPerChunk *
avgNumMultiValues);
+ // Size for expected data at creation. Larger allowed entries only need
more space when they arrive.
+ int initialCapacity = Math.max(Math.min(maxNumMultiValues,
ForwardIndexConfig.DEFAULT_MAX_NUM_MULTI_VALUES),
+ numRowsPerChunk * avgNumMultiValues);
addDataBuffer(initialCapacity);
- _incrementalCapacity = Math.max(maxNumMultiValues, (int) ((double)
initialCapacity * INCREMENT_PERCENTAGE / 100));
+ _incrementalCapacity = initialCapacity;
}
private void addHeaderBuffer() {
@@ -207,8 +207,8 @@ public class FixedByteMVMutableForwardIndex implements
MutableForwardIndex {
"Row %s has %s multi-values, exceeding the maximum of %s", row,
numValues, _maxNumMultiValues);
_numValues += numValues;
int newStartIndex = _prevRowStartIndex + _prevRowLength;
- if (newStartIndex + numValues > _currentCapacity) {
- addDataBuffer(_incrementalCapacity);
+ if (numValues > _currentCapacity - newStartIndex) {
+ addDataBuffer(Math.max(_incrementalCapacity, numValues));
_prevRowStartIndex = 0;
_prevRowLength = 0;
newStartIndex = 0;
diff --git
a/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/creator/impl/BaseSegmentCreator.java
b/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/creator/impl/BaseSegmentCreator.java
index 21791dee355..a1ad60590ae 100644
---
a/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/creator/impl/BaseSegmentCreator.java
+++
b/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/creator/impl/BaseSegmentCreator.java
@@ -162,6 +162,17 @@ public abstract class BaseSegmentCreator implements
SegmentCreator {
ColumnStatistics columnStatistics = _columnStatisticsMap.get(columnName);
Preconditions.checkNotNull(columnStatistics, "Missing column statistics
for column: %s", columnName);
+ // Consuming segments have already used the effective limit, which can be
set by a consuming tier override.
+ if (!_config.isRealtimeConversion() && !fieldSpec.isSingleValueField()) {
+ Integer maxNumMultiValues =
originalConfig.getConfig(StandardIndexes.forward()).getMaxNumMultiValues();
+ if (maxNumMultiValues != null &&
!originalConfig.getConfig(StandardIndexes.vector()).isEnabled()) {
+ int numValues = columnStatistics.getMaxNumberOfMultiValues();
+ Preconditions.checkState(numValues <= maxNumMultiValues,
+ "Number of values: %s in MV column: %s exceeds the maximum
allowed: %s", numValues, columnName,
+ maxNumMultiValues);
+ }
+ }
+
boolean dictEnabledColumn = createDictionaryForColumn(columnStatistics,
_config, fieldSpec);
if (originalConfig.getConfig(StandardIndexes.inverted()).isEnabled()) {
Preconditions.checkState(dictEnabledColumn,
diff --git
a/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/creator/impl/fwd/MultiValueFixedByteRawIndexCreator.java
b/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/creator/impl/fwd/MultiValueFixedByteRawIndexCreator.java
index 8667ed66f5a..ac0529eeeec 100644
---
a/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/creator/impl/fwd/MultiValueFixedByteRawIndexCreator.java
+++
b/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/creator/impl/fwd/MultiValueFixedByteRawIndexCreator.java
@@ -20,6 +20,7 @@ package
org.apache.pinot.segment.local.segment.creator.impl.fwd;
import java.io.File;
import java.io.IOException;
+import org.apache.pinot.segment.local.io.compression.ChunkCompressorFactory;
import
org.apache.pinot.segment.local.io.writer.impl.VarByteChunkForwardIndexWriter;
import
org.apache.pinot.segment.local.io.writer.impl.VarByteChunkForwardIndexWriterV4;
import
org.apache.pinot.segment.local.io.writer.impl.VarByteChunkForwardIndexWriterV5;
@@ -27,6 +28,7 @@ import
org.apache.pinot.segment.local.io.writer.impl.VarByteChunkForwardIndexWri
import org.apache.pinot.segment.local.io.writer.impl.VarByteChunkWriter;
import org.apache.pinot.segment.spi.V1Constants.Indexes;
import org.apache.pinot.segment.spi.compression.ChunkCompressionType;
+import org.apache.pinot.segment.spi.compression.ChunkCompressor;
import org.apache.pinot.segment.spi.index.ForwardIndexConfig;
import org.apache.pinot.spi.data.FieldSpec.DataType;
@@ -34,6 +36,8 @@ import org.apache.pinot.spi.data.FieldSpec.DataType;
/// Raw (non-dictionary-encoded) forward index creator for multi-value column
of fixed length data type (INT, LONG,
/// FLOAT, DOUBLE).
public class MultiValueFixedByteRawIndexCreator implements
CompressionStatsTrackingForwardIndexCreator {
+ // At this size even DELTA's expansion of 32-bit values to 64-bit
differences fits before and after LZ4.
+ private static final int SAFE_LEGACY_CHUNK_SIZE_BYTES = 1_000_000_000;
private final VarByteChunkWriter _indexWriter;
private final DataType _valueType;
@@ -48,8 +52,8 @@ public class MultiValueFixedByteRawIndexCreator implements
CompressionStatsTrack
/// @param valueType Type of the values
/// @param deriveNumDocsPerChunk true if writer should auto-derive the
number of rows per chunk
/// @param writerVersion writer format version
- /// @param targetMaxChunkSizeBytes target max chunk size in bytes,
applicable only for V4 or when
- /// deriveNumDocsPerChunk is true
+ /// @param targetMaxChunkSizeBytes target max chunk size in bytes, used by
V4 and later and for byte-based
+ /// sizing of legacy chunks
public MultiValueFixedByteRawIndexCreator(File baseIndexDir,
ChunkCompressionType compressionType, String column,
int totalDocs, DataType valueType, int maxNumberOfMultiValueElements,
boolean deriveNumDocsPerChunk,
int writerVersion, int targetMaxChunkSizeBytes, int targetDocsPerChunk)
@@ -74,8 +78,14 @@ public class MultiValueFixedByteRawIndexCreator implements
CompressionStatsTrack
if (writerVersion < VarByteChunkForwardIndexWriterV4.VERSION) {
// Store the length followed by the values
int totalMaxLength = Integer.BYTES + (maxNumberOfMultiValueElements *
valueType.getStoredType().size());
- int numDocsPerChunk = deriveNumDocsPerChunk ?
Math.max(targetMaxChunkSizeBytes / (totalMaxLength
- +
VarByteChunkForwardIndexWriter.CHUNK_HEADER_ENTRY_ROW_OFFSET_SIZE), 1) :
targetDocsPerChunk;
+ long bytesPerDoc = (long) totalMaxLength +
VarByteChunkForwardIndexWriter.CHUNK_HEADER_ENTRY_ROW_OFFSET_SIZE;
+ int numDocsPerChunk = deriveNumDocsPerChunk
+ ? Math.max((int) (targetMaxChunkSizeBytes / bytesPerDoc), 1)
+ : targetDocsPerChunk;
+ if (!fitsLegacyChunk(bytesPerDoc * numDocsPerChunk, compressionType)) {
+ int fallbackChunkSize = Math.min(targetMaxChunkSizeBytes,
SAFE_LEGACY_CHUNK_SIZE_BYTES);
+ numDocsPerChunk = Math.max((int) (fallbackChunkSize / bytesPerDoc), 1);
+ }
_indexWriter =
new VarByteChunkForwardIndexWriter(indexFile, compressionType,
totalDocs, numDocsPerChunk, totalMaxLength,
writerVersion);
@@ -104,6 +114,21 @@ public class MultiValueFixedByteRawIndexCreator implements
CompressionStatsTrack
_chunkCompressionType = compressionType;
}
+ private static boolean fitsLegacyChunk(long chunkSize, ChunkCompressionType
compressionType)
+ throws IOException {
+ if (chunkSize > Integer.MAX_VALUE) {
+ return false;
+ }
+ if (chunkSize <= SAFE_LEGACY_CHUNK_SIZE_BYTES || compressionType ==
ChunkCompressionType.PASS_THROUGH) {
+ return true;
+ }
+ try (ChunkCompressor compressor =
ChunkCompressorFactory.getCompressor(compressionType)) {
+ return compressor.maxCompressedSize((int) chunkSize) > 0;
+ } catch (IllegalArgumentException e) {
+ return false;
+ }
+ }
+
@Override
public boolean isDictionaryEncoded() {
return false;
diff --git
a/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/forward/ForwardIndexType.java
b/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/forward/ForwardIndexType.java
index 77bfcb34d6d..bd5948fcbe4 100644
---
a/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/forward/ForwardIndexType.java
+++
b/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/forward/ForwardIndexType.java
@@ -250,13 +250,16 @@ public class ForwardIndexType extends
AbstractIndexType<ForwardIndexConfig, Forw
JsonNode forwardIndexNode =
fieldConfig.getIndexes().get(INDEX_DISPLAY_NAME);
- // `forwardIndexDisabled` short-circuits everything else.
+ // The ingestion limit still applies when forward-index creation is
disabled.
Map<String, String> properties = fieldConfig.getProperties();
if (properties != null && isDisabled(properties)) {
JsonNode codecSpecNode = forwardIndexNode != null ?
forwardIndexNode.get("codecSpec") : null;
Preconditions.checkState(codecSpecNode == null ||
codecSpecNode.isNull(),
"codecSpec cannot be configured when the forward index is
disabled for column: %s", column);
- result.put(column, ForwardIndexConfig.getDisabled());
+ result.put(column, new
ForwardIndexConfig.Builder(FieldConfig.EncodingType.DICTIONARY)
+ .withDisabled(true)
+
.withMaxNumMultiValues(resolveMaxNumMultiValues(forwardIndexNode, properties,
column))
+ .build());
continue;
}
@@ -299,6 +302,10 @@ public class ForwardIndexType extends
AbstractIndexType<ForwardIndexConfig, Forw
if ((innerCodecNode == null || innerCodecNode.isNull()) && fcCodec
!= null) {
configNode.put("compressionCodec", fcCodec.name());
}
+ Integer maxNumMultiValues =
resolveMaxNumMultiValues(forwardIndexNode, properties, column);
+ if (maxNumMultiValues != null) {
+ configNode.put(ForwardIndexConfig.MAX_NUM_MULTI_VALUES,
maxNumMultiValues);
+ }
try {
result.put(column, JsonUtils.jsonNodeToObject(configNode,
ForwardIndexConfig.class));
} catch (IOException e) {
@@ -324,13 +331,28 @@ public class ForwardIndexType extends
AbstractIndexType<ForwardIndexConfig, Forw
props.getOrDefault(FieldConfig.FORWARD_INDEX_DISABLED,
FieldConfig.DEFAULT_FORWARD_INDEX_DISABLED));
}
+ @Nullable
+ private static Integer resolveMaxNumMultiValues(@Nullable JsonNode
forwardIndexNode,
+ @Nullable Map<String, String> properties, String column) {
+ JsonNode maxNumMultiValues =
+ forwardIndexNode != null ?
forwardIndexNode.get(ForwardIndexConfig.MAX_NUM_MULTI_VALUES) : null;
+ if (maxNumMultiValues != null && !maxNumMultiValues.isNull()) {
+ Preconditions.checkArgument(maxNumMultiValues.isIntegralNumber() &&
maxNumMultiValues.canConvertToInt(),
+ "%s must be an integer for column: %s",
ForwardIndexConfig.MAX_NUM_MULTI_VALUES, column);
+ return maxNumMultiValues.intValue();
+ }
+ String legacyMax = properties != null ?
properties.get(ForwardIndexConfig.MAX_NUM_MULTI_VALUES) : null;
+ return legacyMax != null ? Integer.valueOf(legacyMax) : null;
+ }
+
private ForwardIndexConfig createConfigFromFieldConfig(FieldConfig
fieldConfig,
FieldConfig.EncodingType resolvedEncodingType) {
ForwardIndexConfig.Builder builder = new
ForwardIndexConfig.Builder(resolvedEncodingType)
.withCompressionCodec(fieldConfig.getCompressionCodec());
Map<String, String> properties = fieldConfig.getProperties();
if (properties != null) {
- builder.withLegacyProperties(properties);
+ builder.withLegacyProperties(properties)
+ .withMaxNumMultiValues(resolveMaxNumMultiValues(null, properties,
fieldConfig.getName()));
}
return builder.build();
}
diff --git
a/pinot-segment-local/src/test/java/org/apache/pinot/segment/local/indexsegment/mutable/MutableSegmentImplNumMultiValuesValidationTest.java
b/pinot-segment-local/src/test/java/org/apache/pinot/segment/local/indexsegment/mutable/MutableSegmentImplNumMultiValuesValidationTest.java
index a802aee6404..e2f889932a2 100644
---
a/pinot-segment-local/src/test/java/org/apache/pinot/segment/local/indexsegment/mutable/MutableSegmentImplNumMultiValuesValidationTest.java
+++
b/pinot-segment-local/src/test/java/org/apache/pinot/segment/local/indexsegment/mutable/MutableSegmentImplNumMultiValuesValidationTest.java
@@ -18,25 +18,36 @@
*/
package org.apache.pinot.segment.local.indexsegment.mutable;
+import java.io.File;
+import java.nio.file.Files;
+import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.stream.IntStream;
+import org.apache.commons.io.FileUtils;
+import org.apache.pinot.common.metadata.segment.SegmentZKMetadata;
import org.apache.pinot.common.partition.function.ModuloPartitionFunction;
import org.apache.pinot.segment.local.PinotBuffersAfterClassCheckRule;
import org.apache.pinot.segment.local.data.manager.TableDataManager;
import org.apache.pinot.segment.local.dedup.DedupContext;
import org.apache.pinot.segment.local.dedup.DedupRecordInfo;
import org.apache.pinot.segment.local.dedup.PartitionDedupMetadataManager;
+import org.apache.pinot.segment.local.io.writer.impl.DirectMemoryManager;
+import org.apache.pinot.segment.local.realtime.impl.RealtimeSegmentConfig;
+import
org.apache.pinot.segment.local.realtime.impl.RealtimeSegmentStatsHistory;
import
org.apache.pinot.segment.local.realtime.impl.forward.FixedByteMVMutableForwardIndex;
import
org.apache.pinot.segment.local.realtime.impl.invertedindex.RealtimeLuceneTextIndexSearcherPool;
import org.apache.pinot.segment.local.upsert.PartitionUpsertMetadataManager;
import org.apache.pinot.segment.local.upsert.RecordInfo;
import org.apache.pinot.segment.local.upsert.TableUpsertMetadataManager;
import org.apache.pinot.segment.local.upsert.TableUpsertMetadataManagerFactory;
+import org.apache.pinot.segment.local.utils.TableConfigUtils;
import org.apache.pinot.segment.spi.datasource.DataSource;
import org.apache.pinot.segment.spi.index.creator.VectorIndexConfig;
import org.apache.pinot.segment.spi.index.reader.Dictionary;
+import org.apache.pinot.spi.config.table.FieldConfig;
import org.apache.pinot.spi.config.table.TableConfig;
import org.apache.pinot.spi.config.table.TableType;
import org.apache.pinot.spi.config.table.UpsertConfig;
@@ -45,6 +56,7 @@ import org.apache.pinot.spi.data.Schema;
import org.apache.pinot.spi.data.readers.GenericRow;
import org.apache.pinot.spi.data.readers.PrimaryKey;
import org.apache.pinot.spi.env.PinotConfiguration;
+import org.apache.pinot.spi.utils.JsonUtils;
import org.apache.pinot.spi.utils.builder.TableConfigBuilder;
import org.roaringbitmap.buffer.ImmutableRoaringBitmap;
import org.testng.annotations.BeforeClass;
@@ -106,6 +118,65 @@ public class
MutableSegmentImplNumMultiValuesValidationTest implements PinotBuff
}
}
+ @DataProvider(name = "multiValueLimitConfigFormats")
+ private static Object[][] multiValueLimitConfigFormats() {
+ return new Object[][]{{false}, {true}};
+ }
+
+ @Test(dataProvider = "multiValueLimitConfigFormats")
+ public void testConfiguredMultiValueLimit(boolean convertConfig)
+ throws Exception {
+ int configuredLimit = 4096;
+ String tableName = "configuredNumMultiValues";
+ String segmentName = tableName + "__0__0__123456";
+ Schema schema = new Schema.SchemaBuilder().setSchemaName(tableName)
+ .addMultiValueDimension(MV_COLUMN, DataType.STRING)
+ .build();
+ FieldConfig fieldConfig = new FieldConfig.Builder(MV_COLUMN)
+ .withProperties(Map.of("maxNumMultiValues",
Integer.toString(configuredLimit)))
+ .withIndexes(JsonUtils.objectToJsonNode(Map.of("forward",
Map.of("encodingType", "DICTIONARY"))))
+ .build();
+ TableConfig tableConfig = new
TableConfigBuilder(TableType.REALTIME).setTableName(tableName)
+ .setFieldConfigList(new ArrayList<>(List.of(fieldConfig)))
+ .build();
+ if (convertConfig) {
+ tableConfig =
TableConfigUtils.createTableConfigFromOldFormat(tableConfig, schema);
+ }
+ File tempDir = Files.createTempDirectory(tableName).toFile();
+ try {
+ RealtimeSegmentConfig segmentConfig = new
RealtimeSegmentConfig.Builder(tableConfig, schema)
+ .setTableNameWithType(tableConfig.getTableName())
+ .setSegmentName(segmentName)
+ .setStreamName(tableName)
+ .setSchema(schema)
+ .setCapacity(10)
+ .setAvgNumMultiValues(2)
+ .setSegmentZKMetadata(new SegmentZKMetadata(segmentName))
+ .setMemoryManager(new DirectMemoryManager(segmentName))
+ .setStatsHistory(RealtimeSegmentStatsHistory.deserializeFrom(new
File(tempDir, "stats")))
+ .setConsumerDir(tempDir.getAbsolutePath())
+ .build();
+ MutableSegmentImpl mutableSegment = new
MutableSegmentImpl(segmentConfig, null);
+ try {
+ String[] valuesAtLimit = IntStream.range(0,
configuredLimit).mapToObj(i -> "url-" + i).toArray(String[]::new);
+ mutableSegment.index(createRow(valuesAtLimit), null);
+ assertEquals((Object[]) mutableSegment.getValue(0, MV_COLUMN),
valuesAtLimit);
+
+ String[] aboveLimit =
+ IntStream.rangeClosed(0, configuredLimit).mapToObj(i -> "cve-" +
i).toArray(String[]::new);
+ IllegalStateException exception =
+ expectThrows(IllegalStateException.class, () ->
mutableSegment.index(createRow(aboveLimit), null));
+ assertTrue(exception.getMessage().contains("exceeds the maximum
allowed: " + configuredLimit),
+ exception.getMessage());
+ assertEquals(mutableSegment.getNumDocsIndexed(), 1);
+ } finally {
+ mutableSegment.destroy();
+ }
+ } finally {
+ FileUtils.deleteDirectory(tempDir);
+ }
+ }
+
@Test
public void testAcceptVectorDimensionAboveDefaultMultiValueLimit()
throws Exception {
diff --git
a/pinot-segment-local/src/test/java/org/apache/pinot/segment/local/realtime/converter/RealtimeSegmentConverterTest.java
b/pinot-segment-local/src/test/java/org/apache/pinot/segment/local/realtime/converter/RealtimeSegmentConverterTest.java
index 5f8e7d851c5..6a6434265ec 100644
---
a/pinot-segment-local/src/test/java/org/apache/pinot/segment/local/realtime/converter/RealtimeSegmentConverterTest.java
+++
b/pinot-segment-local/src/test/java/org/apache/pinot/segment/local/realtime/converter/RealtimeSegmentConverterTest.java
@@ -566,6 +566,57 @@ public class RealtimeSegmentConverterTest implements
PinotBuffersAfterMethodChec
}
}
+ @Test
+ public void testLegacyRawMultiValueChunkFitsWhenSealing()
+ throws Exception {
+ String tableName = "legacyRawMultiValueChunk";
+ String segmentName = tableName + "__0__0__123456";
+ File tmpDir = new File(TMP_DIR, tableName);
+ FileUtils.forceMkdir(tmpDir);
+ Schema schema = new Schema.SchemaBuilder().setSchemaName(tableName)
+ .addMultiValueDimension("values", DataType.LONG)
+ .addDateTime("ts", DataType.LONG, "1:MILLISECONDS:EPOCH",
"1:MILLISECONDS")
+ .build();
+ int maxNumMultiValues = 65_536;
+ FieldConfig fieldConfig = new
FieldConfig.Builder("values").withEncodingType(FieldConfig.EncodingType.RAW)
+ .withIndexes(JsonUtils.objectToJsonNode(Map.of("forward",
Map.of("rawIndexWriterVersion", 3,
+ "targetDocsPerChunk", 4096, "maxNumMultiValues",
maxNumMultiValues))))
+ .build();
+ TableConfig tableConfig = new
TableConfigBuilder(TableType.REALTIME).setTableName(tableName)
+
.setTimeColumnName("ts").setFieldConfigList(List.of(fieldConfig)).build();
+ RealtimeSegmentConfig segmentConfig = new
RealtimeSegmentConfig.Builder(tableConfig, schema)
+
.setTableNameWithType(tableConfig.getTableName()).setSegmentName(segmentName).setStreamName(tableName)
+
.setSchema(schema).setTimeColumnName("ts").setCapacity(10).setAvgNumMultiValues(2)
+
.setSegmentZKMetadata(getSegmentZKMetadata(segmentName)).setOffHeap(true)
+ .setMemoryManager(new DirectMemoryManager(segmentName))
+ .setStatsHistory(RealtimeSegmentStatsHistory.deserializeFrom(new
File(tmpDir, "stats")))
+ .setConsumerDir(new File(tmpDir, "consumer").getAbsolutePath())
+ .build();
+ MutableSegmentImpl mutableSegment = new MutableSegmentImpl(segmentConfig,
null);
+ try {
+ Long[] values = new Long[maxNumMultiValues];
+ Arrays.setAll(values, i -> (long) i);
+ GenericRow row = new GenericRow();
+ row.putValue("ts", 1793750400000L);
+ row.putValue("values", values);
+ mutableSegment.index(row, null);
+
+ File outputDir = new File(tmpDir, "output");
+ RealtimeSegmentConverter converter = new
RealtimeSegmentConverter(mutableSegment, new SegmentZKPropsConfig(),
+ outputDir.getAbsolutePath(), schema, tableConfig.getTableName(),
tableConfig, segmentName, false);
+ converter.build(SegmentVersion.v3);
+ ImmutableSegment immutable = ImmutableSegmentLoader.load(new
File(outputDir, segmentName),
+ new IndexLoadingConfig(tableConfig, schema));
+ try {
+ assertEquals((Object[]) immutable.getRecord(0, new
GenericRow()).getValue("values"), values);
+ } finally {
+ immutable.destroy();
+ }
+ } finally {
+ mutableSegment.destroy();
+ }
+ }
+
private void testSegment(List<GenericRow> rows, File indexDir,
TableConfig tableConfig, SegmentMetadataImpl segmentMetadata)
throws IOException, ConfigurationException {
diff --git
a/pinot-segment-local/src/test/java/org/apache/pinot/segment/local/segment/creator/impl/SegmentColumnarIndexCreatorTest.java
b/pinot-segment-local/src/test/java/org/apache/pinot/segment/local/segment/creator/impl/SegmentColumnarIndexCreatorTest.java
index d7a22d532bd..65a7319af47 100644
---
a/pinot-segment-local/src/test/java/org/apache/pinot/segment/local/segment/creator/impl/SegmentColumnarIndexCreatorTest.java
+++
b/pinot-segment-local/src/test/java/org/apache/pinot/segment/local/segment/creator/impl/SegmentColumnarIndexCreatorTest.java
@@ -21,30 +21,39 @@ package org.apache.pinot.segment.local.segment.creator.impl;
import java.io.File;
import java.io.IOException;
import java.util.List;
+import java.util.Map;
+import java.util.stream.IntStream;
import org.apache.commons.configuration2.PropertiesConfiguration;
import org.apache.commons.io.FileUtils;
import org.apache.pinot.segment.local.PinotBuffersAfterClassCheckRule;
import
org.apache.pinot.segment.local.indexsegment.immutable.ImmutableSegmentLoader;
import org.apache.pinot.segment.local.segment.readers.GenericRowRecordReader;
+import
org.apache.pinot.segment.local.segment.readers.PinotSegmentColumnReaderFactory;
+import org.apache.pinot.segment.spi.ImmutableSegment;
import org.apache.pinot.segment.spi.IndexSegment;
import org.apache.pinot.segment.spi.SegmentMetadata;
import org.apache.pinot.segment.spi.V1Constants.MetadataKeys.Column;
import org.apache.pinot.segment.spi.creator.SegmentGeneratorConfig;
+import org.apache.pinot.spi.config.table.FieldConfig;
+import org.apache.pinot.spi.config.table.FieldConfig.EncodingType;
import org.apache.pinot.spi.config.table.TableConfig;
import org.apache.pinot.spi.config.table.TableType;
import org.apache.pinot.spi.data.FieldSpec.DataType;
import org.apache.pinot.spi.data.Schema;
import org.apache.pinot.spi.data.readers.GenericRow;
import org.apache.pinot.spi.env.CommonsConfigurationUtils;
+import org.apache.pinot.spi.utils.JsonUtils;
import org.apache.pinot.spi.utils.ReadMode;
import org.apache.pinot.spi.utils.builder.TableConfigBuilder;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
+import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.expectThrows;
public class SegmentColumnarIndexCreatorTest implements
PinotBuffersAfterClassCheckRule {
@@ -95,6 +104,98 @@ public class SegmentColumnarIndexCreatorTest implements
PinotBuffersAfterClassCh
assertEquals(withTZ, withoutTZ);
}
+ @DataProvider
+ public Object[][] forwardIndexEncodings() {
+ return new Object[][]{{EncodingType.DICTIONARY}, {EncodingType.RAW}};
+ }
+
+ @Test(dataProvider = "forwardIndexEncodings")
+ public void testExplicitMultiValueLimit(EncodingType encoding)
+ throws Exception {
+ int limit = 4;
+ Schema schema = new
Schema.SchemaBuilder().addMultiValueDimension(COLUMN_NAME,
DataType.LONG).build();
+ FieldConfig fieldConfig = new
FieldConfig.Builder(COLUMN_NAME).withEncodingType(encoding).build();
+ FieldConfig limitedFieldConfig =
+ new
FieldConfig.Builder(fieldConfig).withProperties(Map.of("maxNumMultiValues",
String.valueOf(limit))).build();
+ TableConfigBuilder tableConfigBuilder = new
TableConfigBuilder(TableType.OFFLINE).setTableName("test");
+ TableConfig limitedTableConfig =
tableConfigBuilder.setFieldConfigList(List.of(limitedFieldConfig)).build();
+ TableConfig unlimitedTableConfig =
tableConfigBuilder.setFieldConfigList(List.of(fieldConfig)).build();
+
+ SegmentGeneratorConfig limitedConfig = new
SegmentGeneratorConfig(limitedTableConfig, schema);
+ limitedConfig.setOutDir(new File(TEMP_DIR,
encoding.name()).getAbsolutePath());
+ limitedConfig.setSegmentName("atLimit");
+ buildMultiValueSegment(limitedConfig, limit);
+ ImmutableSegment segment =
+ ImmutableSegmentLoader.load(new File(limitedConfig.getOutDir(),
"atLimit"), ReadMode.heap);
+ try {
+
assertEquals(segment.getSegmentMetadata().getColumnMetadataFor(COLUMN_NAME).getMaxNumberOfMultiValues(),
limit);
+
assertEquals(segment.getDataSource(COLUMN_NAME).getForwardIndex().isDictionaryEncoded(),
+ encoding == EncodingType.DICTIONARY);
+ } finally {
+ segment.destroy();
+ }
+
+ limitedConfig.setSegmentName("overLimit");
+ String error = "Number of values: 5 in MV column: " + COLUMN_NAME + "
exceeds the maximum allowed: " + limit;
+ assertEquals(expectThrows(IllegalStateException.class, () ->
buildMultiValueSegment(limitedConfig, limit + 1))
+ .getMessage(), error);
+
+ SegmentGeneratorConfig unlimitedConfig = new
SegmentGeneratorConfig(unlimitedTableConfig, schema);
+ unlimitedConfig.setOutDir(limitedConfig.getOutDir());
+ unlimitedConfig.setSegmentName("unlimited");
+ buildMultiValueSegment(unlimitedConfig, 1001);
+ ImmutableSegment sourceSegment =
+ ImmutableSegmentLoader.load(new File(unlimitedConfig.getOutDir(),
"unlimited"), ReadMode.heap);
+ try (PinotSegmentColumnReaderFactory factory = new
PinotSegmentColumnReaderFactory(sourceSegment)) {
+
assertEquals(sourceSegment.getSegmentMetadata().getColumnMetadataFor(COLUMN_NAME).getMaxNumberOfMultiValues(),
+ 1001);
+ limitedConfig.setSegmentName("overLimitColumnar");
+ SegmentIndexCreationDriverImpl driver = new
SegmentIndexCreationDriverImpl();
+ driver.init(limitedConfig, factory);
+ assertEquals(expectThrows(IllegalStateException.class,
driver::build).getMessage(),
+ "Number of values: 1001 in MV column: " + COLUMN_NAME + " exceeds
the maximum allowed: " + limit);
+ } finally {
+ sourceSegment.destroy();
+ }
+ }
+
+ @Test
+ public void testExplicitMultiValueLimitWithDisabledForwardIndex()
+ throws Exception {
+ Schema schema = new
Schema.SchemaBuilder().addMultiValueDimension(COLUMN_NAME,
DataType.LONG).build();
+ FieldConfig fieldConfig = new FieldConfig.Builder(COLUMN_NAME)
+ .withProperties(Map.of(FieldConfig.FORWARD_INDEX_DISABLED, "true",
"maxNumMultiValues", "4"))
+ .build();
+ TableConfigBuilder tableConfigBuilder = new
TableConfigBuilder(TableType.OFFLINE).setTableName("test");
+ TableConfig tableConfig =
tableConfigBuilder.setFieldConfigList(List.of(fieldConfig)).build();
+ String outDir = new File(TEMP_DIR,
"disabledForwardIndex").getAbsolutePath();
+ SegmentGeneratorConfig config = new SegmentGeneratorConfig(tableConfig,
schema);
+ config.setOutDir(outDir);
+ config.setSegmentName("overLegacyLimit");
+ assertEquals(expectThrows(IllegalStateException.class, () ->
buildMultiValueSegment(config, 5)).getMessage(),
+ "Number of values: 5 in MV column: " + COLUMN_NAME + " exceeds the
maximum allowed: 4");
+
+ FieldConfig modernFieldConfig = new FieldConfig.Builder(fieldConfig)
+
.withIndexes(JsonUtils.stringToJsonNode("{\"forward\":{\"maxNumMultiValues\":5}}"))
+ .build();
+ TableConfig modernTableConfig =
tableConfigBuilder.setFieldConfigList(List.of(modernFieldConfig)).build();
+ SegmentGeneratorConfig modernConfig = new
SegmentGeneratorConfig(modernTableConfig, schema);
+ modernConfig.setOutDir(outDir);
+ modernConfig.setSegmentName("overModernLimit");
+ assertEquals(expectThrows(IllegalStateException.class, () ->
buildMultiValueSegment(modernConfig, 6)).getMessage(),
+ "Number of values: 6 in MV column: " + COLUMN_NAME + " exceeds the
maximum allowed: 5");
+ }
+
+ private static void buildMultiValueSegment(SegmentGeneratorConfig config,
int numValues)
+ throws Exception {
+ Object[] values = IntStream.range(0,
numValues).asLongStream().boxed().toArray();
+ GenericRow row = new GenericRow();
+ row.putValue(COLUMN_NAME, values);
+ SegmentIndexCreationDriverImpl driver = new
SegmentIndexCreationDriverImpl();
+ driver.init(config, new GenericRowRecordReader(List.of(row)));
+ driver.build();
+ }
+
private static long getStartTimeInSegmentMetadata(String testDateTimeFormat,
String testDateTime)
throws Exception {
String timeColumn = "foo";
diff --git
a/pinot-segment-local/src/test/java/org/apache/pinot/segment/local/segment/index/forward/mutable/FixedByteMVMutableForwardIndexTest.java
b/pinot-segment-local/src/test/java/org/apache/pinot/segment/local/segment/index/forward/mutable/FixedByteMVMutableForwardIndexTest.java
index ac6a9ca95b5..4b40fe164c3 100644
---
a/pinot-segment-local/src/test/java/org/apache/pinot/segment/local/segment/index/forward/mutable/FixedByteMVMutableForwardIndexTest.java
+++
b/pinot-segment-local/src/test/java/org/apache/pinot/segment/local/segment/index/forward/mutable/FixedByteMVMutableForwardIndexTest.java
@@ -32,6 +32,9 @@ import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
+
public class FixedByteMVMutableForwardIndexTest implements
PinotBuffersAfterClassCheckRule {
private PinotDataBufferMemoryManager _memoryManager;
@@ -104,6 +107,22 @@ public class FixedByteMVMutableForwardIndexTest implements
PinotBuffersAfterClas
}
}
+ @Test
+ public void testLargeLimitDoesNotPreallocateLargeBuffer()
+ throws IOException {
+ int maxNumMultiValues = 4096;
+ try (PinotDataBufferMemoryManager memoryManager = new
DirectMemoryManager("largeLimit");
+ FixedByteMVMutableForwardIndex index =
+ new FixedByteMVMutableForwardIndex(maxNumMultiValues, 2, 10,
Integer.BYTES, memoryManager, "largeLimit",
+ false, FieldSpec.DataType.INT)) {
+ assertTrue(memoryManager.getTotalAllocatedBytes() < (long)
maxNumMultiValues * Integer.BYTES);
+ int[] values = new int[maxNumMultiValues];
+ Arrays.fill(values, 42);
+ index.setIntMV(0, values);
+ assertEquals(index.getIntMV(0), values);
+ }
+ }
+
public void testIntArray(final long seed, boolean isDictionaryEncoded)
throws IOException {
FixedByteMVMutableForwardIndex readerWriter;
diff --git
a/pinot-segment-spi/src/main/java/org/apache/pinot/segment/spi/index/ForwardIndexConfig.java
b/pinot-segment-spi/src/main/java/org/apache/pinot/segment/spi/index/ForwardIndexConfig.java
index 0899e808d73..cb9798d8c6e 100644
---
a/pinot-segment-spi/src/main/java/org/apache/pinot/segment/spi/index/ForwardIndexConfig.java
+++
b/pinot-segment-spi/src/main/java/org/apache/pinot/segment/spi/index/ForwardIndexConfig.java
@@ -20,6 +20,7 @@ package org.apache.pinot.segment.spi.index;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.Preconditions;
import java.util.Arrays;
@@ -40,11 +41,14 @@ import org.apache.pinot.spi.utils.DataSizeUtils;
public class ForwardIndexConfig extends IndexConfig {
- // TODO: Make the maximum number of multi-values configurable, and also
enforce it when creating the immutable forward
- // index, which currently accepts any number of values per entry.
+ public static final String MAX_NUM_MULTI_VALUES = "maxNumMultiValues";
+
/// Default maximum number of values in a single multi-value entry of the
mutable forward index.
public static final int DEFAULT_MAX_NUM_MULTI_VALUES = 1000;
+ // Bound one fixed-width raw entry to about 1 MiB even with 16-byte values.
+ private static final int MAX_SUPPORTED_NUM_MULTI_VALUES = 65_536;
+
private static int _defaultRawIndexWriterVersion = 4;
private static String _defaultTargetMaxChunkSize = "1MB";
private static int _defaultTargetMaxChunkSizeBytes = 1024 * 1024;
@@ -179,6 +183,8 @@ public class ForwardIndexConfig extends IndexConfig {
private final String _targetMaxChunkSize;
private final int _targetMaxChunkSizeBytes;
private final int _targetDocsPerChunk;
+ @Nullable
+ private final Integer _maxNumMultiValues;
@Nullable
private final ChunkCompressionType _chunkCompressionType;
@@ -198,6 +204,7 @@ public class ForwardIndexConfig extends IndexConfig {
@JsonProperty("rawIndexWriterVersion") @Nullable Integer
rawIndexWriterVersion,
@JsonProperty("targetMaxChunkSize") @Nullable String targetMaxChunkSize,
@JsonProperty("targetDocsPerChunk") @Nullable Integer targetDocsPerChunk,
+ @JsonProperty(MAX_NUM_MULTI_VALUES) @Nullable Integer maxNumMultiValues,
@JsonProperty("configs") @Nullable Map<String, Object> configs) {
super(disabled);
// Backward-compat for legacy JSON that lacks `encodingType`: default to
DICTIONARY (matches the historical
@@ -218,6 +225,11 @@ public class ForwardIndexConfig extends IndexConfig {
_targetMaxChunkSizeBytes =
targetMaxChunkSize == null ? _defaultTargetMaxChunkSizeBytes : (int)
DataSizeUtils.toBytes(targetMaxChunkSize);
_targetDocsPerChunk = targetDocsPerChunk == null ?
_defaultTargetDocsPerChunk : targetDocsPerChunk;
+ Preconditions.checkArgument(
+ maxNumMultiValues == null || (maxNumMultiValues > 0 &&
maxNumMultiValues <= MAX_SUPPORTED_NUM_MULTI_VALUES),
+ "%s must be between 1 and %s, found: %s", MAX_NUM_MULTI_VALUES,
MAX_SUPPORTED_NUM_MULTI_VALUES,
+ maxNumMultiValues);
+ _maxNumMultiValues = maxNumMultiValues;
_configs = configs != null ? configs : new HashMap<>();
if (_compressionCodec != null) {
_chunkCompressionType = toChunkCompressionType(_compressionCodec);
@@ -300,6 +312,18 @@ public class ForwardIndexConfig extends IndexConfig {
return _targetDocsPerChunk;
}
+ /// Optional per-row limit (1–65,536) for a multi-value column. Vector
indexes use their configured dimension.
+ /// If omitted, realtime ingestion uses [#DEFAULT_MAX_NUM_MULTI_VALUES] and
batch builds have no limit from
+ /// this setting.
+ /// Set a string in `fieldConfigList[].properties.maxNumMultiValues` or an
integer in
+ /// `fieldConfigList[].indexes.forward.maxNumMultiValues`. Pinot reads the
limit when creating a consuming segment.
+ /// Upgrade consuming replicas and batch builders to a build that supports
this setting before enabling it.
+ @JsonInclude(JsonInclude.Include.NON_NULL)
+ @Nullable
+ public Integer getMaxNumMultiValues() {
+ return _maxNumMultiValues;
+ }
+
@JsonIgnore
public int getTargetMaxChunkSizeBytes() {
return _targetMaxChunkSizeBytes;
@@ -345,13 +369,14 @@ public class ForwardIndexConfig extends IndexConfig {
&& _rawIndexWriterVersion == that._rawIndexWriterVersion
&& Objects.equals(_targetMaxChunkSize, that._targetMaxChunkSize)
&& _targetDocsPerChunk == that._targetDocsPerChunk
+ && Objects.equals(_maxNumMultiValues, that._maxNumMultiValues)
&& _encodingType == that._encodingType;
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), _compressionCodec, _codecSpec,
_deriveNumDocsPerChunk, _rawIndexWriterVersion,
- _targetMaxChunkSize, _targetDocsPerChunk, _encodingType);
+ _targetMaxChunkSize, _targetDocsPerChunk, _maxNumMultiValues,
_encodingType);
}
public static class Builder {
@@ -365,6 +390,8 @@ public class ForwardIndexConfig extends IndexConfig {
private int _rawIndexWriterVersion = _defaultRawIndexWriterVersion;
private String _targetMaxChunkSize = _defaultTargetMaxChunkSize;
private int _targetDocsPerChunk = _defaultTargetDocsPerChunk;
+ @Nullable
+ private Integer _maxNumMultiValues;
private Map<String, Object> _configs = new HashMap<>();
/// Constructs a builder with the given forward-index encoding. Callers
should pass `FieldConfig.getEncodingType()`
@@ -389,6 +416,7 @@ public class ForwardIndexConfig extends IndexConfig {
_rawIndexWriterVersion = other._rawIndexWriterVersion;
_targetMaxChunkSize = other._targetMaxChunkSize;
_targetDocsPerChunk = other._targetDocsPerChunk;
+ _maxNumMultiValues = other._maxNumMultiValues;
_configs = other._configs;
}
@@ -438,6 +466,11 @@ public class ForwardIndexConfig extends IndexConfig {
return this;
}
+ public Builder withMaxNumMultiValues(@Nullable Integer maxNumMultiValues) {
+ _maxNumMultiValues = maxNumMultiValues;
+ return this;
+ }
+
@Deprecated
public Builder withCompressionType(ChunkCompressionType
chunkCompressionType) {
if (chunkCompressionType == null) {
@@ -500,7 +533,8 @@ public class ForwardIndexConfig extends IndexConfig {
public ForwardIndexConfig build() {
return new ForwardIndexConfig(_disabled, _encodingType,
_compressionCodec, null, null, _codecSpec,
- _deriveNumDocsPerChunk, _rawIndexWriterVersion, _targetMaxChunkSize,
_targetDocsPerChunk, _configs);
+ _deriveNumDocsPerChunk, _rawIndexWriterVersion, _targetMaxChunkSize,
_targetDocsPerChunk,
+ _maxNumMultiValues, _configs);
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]