Hi team, our OFFLINE ingestion job occasionally ru...
# troubleshooting
z
Hi team, our OFFLINE ingestion job occasionally runs into OOM when generating JSON index. 🧵
Copy code
2025-02-20 19:50:49,541 ERROR [main] org.apache.hadoop.mapred.YarnChild: Error running child : java.lang.OutOfMemoryError: Java heap space
	at java.base/java.util.TreeMap.addEntry(TreeMap.java:800)
	at java.base/java.util.TreeMap.put(TreeMap.java:863)
	at java.base/java.util.TreeMap.put(TreeMap.java:569)
	at org.apache.pinot.segment.local.segment.creator.impl.inv.json.BaseJsonIndexCreator.addToPostingList(BaseJsonIndexCreator.java:125)
	at org.apache.pinot.segment.local.segment.creator.impl.inv.json.BaseJsonIndexCreator.addFlattenedRecords(BaseJsonIndexCreator.java:112)
	at org.apache.pinot.segment.local.segment.creator.impl.inv.json.OffHeapJsonIndexCreator.addFlattenedRecords(OffHeapJsonIndexCreator.java:83)
	at org.apache.pinot.segment.local.segment.creator.impl.inv.json.BaseJsonIndexCreator.add(BaseJsonIndexCreator.java:94)
	at org.apache.pinot.segment.spi.index.creator.JsonIndexCreator.add(JsonIndexCreator.java:36)
Looking at
OffHeapJsonIndexCreator
, it has a defined
Copy code
FLUSH_THRESHOLD = 100_000
Wondering if there is a way(or are you open) to config the threshold to a smaller size to mitigate this OOM issue?
Although it tries to use off-heap memory, I suspect the 100_000 records still unfortunately results in
OutOfMemoryError: Java heap space
b
Hi. While offheap json index flushes every 100k original records, it might actually be processing millions of flattened records. If disableCrossArrayUnnest=false (default), arrays are unnested so e.g. if there are two arrays with 10 elements, there will be 100 flattened documents. You might be able to work around the issue by setting disableCrossArrayUnnest=true . See https://docs.pinot.apache.org/basics/indexing/json-index for details . I think FLUSH_THRESHOLD should be configurable rather than a fixed smaller value/
z
Thanks for the tip Bolek. We have disabled it and also excluded array and set max levels to 1. But our problem is some of our values are extremely long strings like 2000+ characters.
I have also tried set
maxValueLength
to 512 but
that is after adding to postingList
b
Hmm, I think it should rather be during flattening . See following code: JsonUtils:382
Copy code
private static List<Map<String, String>> flatten(JsonNode node, JsonIndexConfig jsonIndexConfig, int level,
    String path, boolean includePathMatched, JsonSchemaTreeNode indexPathNode) {
  // Null
  if (node.isNull() || node.isMissingNode() || indexPathNode == null) {
    return Collections.emptyList();
  }

  // Value
  if (node.isValueNode()) {
    String valueAsText = node.asText();
    int maxValueLength = jsonIndexConfig.getMaxValueLength();
    if (0 < maxValueLength && maxValueLength < valueAsText.length()) {
      valueAsText = SKIPPED_VALUE_REPLACEMENT;
    }
    return Collections.singletonList(Collections.singletonMap(VALUE_KEY, valueAsText));
  }
Note that it applies to value nodes only (and not whole json document) and then replaces value with "$SKIPPED$", that means index still receives key=$SKIPPED$ entry.
z
hmm good point. so it should have helped then
I can try to reduce it further to verify
b
If you still get OOM then it might be a good idea to enable heap dump on OOM and then check Json index creator's memory. If only some values are 2k chars long then maxValueLength should do the trick. OTOH If most values are that long then indexing 100k docs can take a lot of memory for keys alone.