You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@asterixdb.apache.org by mb...@apache.org on 2026/09/27 12:03:44 UTC
(asterixdb) branch master updated: [NO ISSUE][STO] Cap flush leaf size on all columns
This is an automated email from the ASF dual-hosted git repository.
asf-gitbox-commits pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/asterixdb.git
The following commit(s) were added to refs/heads/master by this push:
new 0acebe2ecc [NO ISSUE][STO] Cap flush leaf size on all columns
0acebe2ecc is described below
commit 0acebe2eccbad1c12850b783d8d7fb5bafeb6418
Author: Ritik Raj <ra...@gmail.com>
AuthorDate: Thu Sep 24 12:26:01 2026 +0530
[NO ISSUE][STO] Cap flush leaf size on all columns
- user model changes: no
- storage format changes: no
- interface changes: no
A flushed or loaded mega leaf node was bounded by the max leaf node size
only through the length of its string values, on the assumption that
numerics encode compactly. Plain-encoded numerics do not: a record
holding a 384-dimension array of doubles filled leaves to several times
the configured size, and every reader pinning such a leaf holds that
many buffer cache pages. Bound the leaf by the encoded size of every
non-key value instead, so well-encoded columns still pack densely.
Ext-ref: MB-74142
Co-Authored-By: Claude Opus 5.5 (1M context) <no...@anthropic.com>
Change-Id: Ie17f53db5b716b105b3a5e7d6259dbcc10ce2d9b
Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/21880
Tested-by: Jenkins <je...@fulliautomatix.ics.uci.edu>
Reviewed-by: Murtadha Hubail <mh...@apache.org>
---
.../operation/lsm/flush/ColumnTransformer.java | 24 ++---
.../lsm/flush/FlushColumnTupleWriter.java | 6 +-
.../column/test/bytes/FlushLeafSizeLimitTest.java | 101 +++++++++++++++++++++
3 files changed, 117 insertions(+), 14 deletions(-)
diff --git a/asterixdb/asterix-column/src/main/java/org/apache/asterix/column/operation/lsm/flush/ColumnTransformer.java b/asterixdb/asterix-column/src/main/java/org/apache/asterix/column/operation/lsm/flush/ColumnTransformer.java
index d146872fa5..d976165776 100644
--- a/asterixdb/asterix-column/src/main/java/org/apache/asterix/column/operation/lsm/flush/ColumnTransformer.java
+++ b/asterixdb/asterix-column/src/main/java/org/apache/asterix/column/operation/lsm/flush/ColumnTransformer.java
@@ -47,11 +47,12 @@ public class ColumnTransformer implements ILazyVisitablePointableVisitor<Abstrac
private AbstractSchemaNestedNode currentParent;
private int primaryKeysLength;
/**
- * Hack-alert! This tracks the total length of all strings (as they're not as encodable as numerics)
- * The total length can be used by {@link FlushColumnTupleWriter} to stop writing tuples to the current mega
- * leaf node to avoid having a single column that spans to megabytes of pages.
+ * Estimated encoded size of all non-key values in the current batch, used by {@link FlushColumnTupleWriter} to
+ * stop writing tuples to the current mega leaf node before it exceeds the max leaf node size. The encoded size
+ * (not the raw value length) is tracked so that well-encoded columns (e.g., delta-packed integers) do not cut
+ * leaves short, while poorly-encoded ones (e.g., plain doubles of an embedding array) are not ignored.
*/
- private int stringLengths;
+ private int valuesEstimatedSize;
private int currentBatchVersion;
public ColumnTransformer(FlushColumnMetadata columnMetadata, ObjectSchemaNode root, BitSet presentColumnsIndexes) {
@@ -59,16 +60,16 @@ public class ColumnTransformer implements ILazyVisitablePointableVisitor<Abstrac
this.root = root;
this.presentColumnsIndexes = presentColumnsIndexes;
nonTaggedValue = new VoidPointable();
- stringLengths = 0;
+ valuesEstimatedSize = 0;
currentBatchVersion = 1;
}
- public int getStringLengths() {
- return stringLengths;
+ public int getValuesEstimatedSize() {
+ return valuesEstimatedSize;
}
- public void resetStringLengths() {
- stringLengths = 0;
+ public void resetValuesEstimatedSize() {
+ valuesEstimatedSize = 0;
currentBatchVersion++;
}
@@ -204,6 +205,7 @@ public class ColumnTransformer implements ILazyVisitablePointableVisitor<Abstrac
PrimitiveSchemaNode node = (PrimitiveSchemaNode) arg;
presentColumnsIndexes.set(node.getColumnIndex());
IColumnValuesWriter writer = columnMetadata.getWriter(node.getColumnIndex());
+ int sizeBeforeWrite = writer.getEstimatedSize();
if (valueTypeTag == ATypeTag.MISSING) {
writer.writeLevel(columnMetadata.getLevel());
} else if (valueTypeTag == ATypeTag.NULL) {
@@ -217,8 +219,8 @@ public class ColumnTransformer implements ILazyVisitablePointableVisitor<Abstrac
}
if (node.isPrimaryKey()) {
primaryKeysLength += writer.getEstimatedSize();
- } else if (node.getTypeTag() == ATypeTag.STRING) {
- stringLengths += pointable.getLength();
+ } else {
+ valuesEstimatedSize += writer.getEstimatedSize() - sizeBeforeWrite;
}
columnMetadata.exitNode(arg);
return null;
diff --git a/asterixdb/asterix-column/src/main/java/org/apache/asterix/column/operation/lsm/flush/FlushColumnTupleWriter.java b/asterixdb/asterix-column/src/main/java/org/apache/asterix/column/operation/lsm/flush/FlushColumnTupleWriter.java
index 27765c0508..925b9d2cb8 100644
--- a/asterixdb/asterix-column/src/main/java/org/apache/asterix/column/operation/lsm/flush/FlushColumnTupleWriter.java
+++ b/asterixdb/asterix-column/src/main/java/org/apache/asterix/column/operation/lsm/flush/FlushColumnTupleWriter.java
@@ -134,11 +134,11 @@ public class FlushColumnTupleWriter extends AbstractColumnTupleWriter {
/**
* TODO a better approach should be adopted
*
- * @return the configured max number of tuples or zero if strings exceeded the maximum size
+ * @return the configured max number of tuples or zero if the written values exceeded the maximum size
*/
@Override
public final int getMaxNumberOfTuples() {
- if (transformer.getStringLengths() >= maxLeafNodeSize) {
+ if (transformer.getValuesEstimatedSize() >= maxLeafNodeSize) {
return 0;
}
return maxNumberOfTuples;
@@ -261,7 +261,7 @@ public class FlushColumnTupleWriter extends AbstractColumnTupleWriter {
@Override
public void reset() {
- transformer.resetStringLengths();
+ transformer.resetValuesEstimatedSize();
transformerForCurrentTuple.reset();
presentColumnsIndexes.clear();
}
diff --git a/asterixdb/asterix-column/src/test/java/org/apache/asterix/column/test/bytes/FlushLeafSizeLimitTest.java b/asterixdb/asterix-column/src/test/java/org/apache/asterix/column/test/bytes/FlushLeafSizeLimitTest.java
new file mode 100644
index 0000000000..a55e28f198
--- /dev/null
+++ b/asterixdb/asterix-column/src/test/java/org/apache/asterix/column/test/bytes/FlushLeafSizeLimitTest.java
@@ -0,0 +1,101 @@
+/*
+ * 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.asterix.column.test.bytes;
+
+import java.io.ByteArrayInputStream;
+import java.nio.charset.StandardCharsets;
+import java.util.Collections;
+
+import org.apache.asterix.column.common.buffer.DummyBufferCache;
+import org.apache.asterix.column.common.buffer.TestWriteMultiPageOp;
+import org.apache.asterix.column.common.row.DummyLSMBTreeTupleReference;
+import org.apache.asterix.column.operation.lsm.flush.FlushColumnMetadata;
+import org.apache.asterix.column.operation.lsm.flush.FlushColumnTupleWriter;
+import org.apache.asterix.column.values.IColumnValuesWriterFactory;
+import org.apache.asterix.column.values.writer.ColumnValuesWriterFactory;
+import org.apache.asterix.external.parser.ADMDataParser;
+import org.apache.asterix.om.pointables.base.DefaultOpenFieldType;
+import org.apache.commons.lang3.mutable.Mutable;
+import org.apache.commons.lang3.mutable.MutableObject;
+import org.apache.hyracks.data.std.util.ArrayBackedValueStorage;
+import org.apache.hyracks.storage.am.lsm.btree.column.api.IColumnWriteMultiPageOp;
+import org.apache.hyracks.storage.am.lsm.btree.column.cloud.buffercache.write.DefaultColumnWriteContext;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * The max leaf node size must bound every column, not only strings: a numeric array (e.g., an embedding) is stored
+ * with a plain encoding and would otherwise grow a mega leaf node far beyond the configured size.
+ */
+public class FlushLeafSizeLimitTest {
+ private static final int PAGE_SIZE = 4 * 1024;
+ private static final int MAX_NUMBER_OF_TUPLES = 1000;
+ private static final int MAX_LEAF_NODE_SIZE = 64 * 1024;
+ private static final int EMBEDDING_DIMENSION = 384;
+
+ @Test
+ public void numericArrayBoundsLeafSize() throws Exception {
+ DummyBufferCache bufferCache = new DummyBufferCache(PAGE_SIZE);
+ int fileId = bufferCache.createFile();
+ Mutable<IColumnWriteMultiPageOp> multiPageOpRef = new MutableObject<>();
+ IColumnValuesWriterFactory writerFactory = new ColumnValuesWriterFactory(multiPageOpRef);
+ FlushColumnMetadata columnMetadata = new FlushColumnMetadata(DefaultOpenFieldType.NESTED_OPEN_RECORD_TYPE, null,
+ Collections.emptyList(), null, writerFactory, multiPageOpRef);
+ columnMetadata.init(new TestWriteMultiPageOp(bufferCache, fileId));
+ FlushColumnTupleWriter writer = new FlushColumnTupleWriter(columnMetadata, PAGE_SIZE, MAX_NUMBER_OF_TUPLES,
+ 0.15, MAX_LEAF_NODE_SIZE, DefaultColumnWriteContext.INSTANCE);
+
+ ADMDataParser parser = new ADMDataParser(DefaultOpenFieldType.NESTED_OPEN_RECORD_TYPE, true);
+ DummyLSMBTreeTupleReference tuple = new DummyLSMBTreeTupleReference();
+ // 384 doubles are ~3KB per record, so the leaf must fill up within ~21 records rather than 1000
+ int tupleCount = 0;
+ try {
+ while (writer.getMaxNumberOfTuples() > tupleCount) {
+ ArrayBackedValueStorage record = new ArrayBackedValueStorage();
+ parser.setInputStream(new ByteArrayInputStream(createRecord(tupleCount)));
+ Assert.assertTrue(parser.parse(record.getDataOutput()));
+ tuple.set(record);
+ writer.writeTuple(tuple);
+ tupleCount++;
+ }
+ } finally {
+ writer.close();
+ }
+
+ int bytesPerRecord = EMBEDDING_DIMENSION * Double.BYTES;
+ int expectedTupleCount = MAX_LEAF_NODE_SIZE / bytesPerRecord;
+ Assert.assertTrue("Leaf size limit ignored numeric values, wrote " + tupleCount + " tuples",
+ tupleCount <= expectedTupleCount + 1);
+ Assert.assertTrue("Leaf size limit tripped too early, wrote " + tupleCount + " tuples",
+ tupleCount >= expectedTupleCount / 2);
+ }
+
+ private static byte[] createRecord(int id) {
+ StringBuilder builder = new StringBuilder();
+ builder.append("{\"id\": ").append(id).append(", \"emb\": [");
+ for (int i = 0; i < EMBEDDING_DIMENSION; i++) {
+ if (i > 0) {
+ builder.append(", ");
+ }
+ builder.append(String.format("%.6f", Math.sin(id + i * 0.001)));
+ }
+ builder.append("]}");
+ return builder.toString().getBytes(StandardCharsets.UTF_8);
+ }
+}