This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch branch-4.1
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-4.1 by this push:
new f92adba6131 branch-4.1: [fix](fe) Align spill session variables with
backend limits #70876 (#70944)
f92adba6131 is described below
commit f92adba6131aac559238c76420952625e65624b9
Author: Jerry Hu <[email protected]>
AuthorDate: Sun Nov 29 18:36:11 2026 +0800
branch-4.1: [fix](fe) Align spill session variables with backend limits
#70876 (#70944)
### What problem does this PR solve?
Issue Number: None
Related PR: #70876 (backport to `branch-4.1`)
Problem Summary:
FE initializes `spill_aggregation_sink_mem_limit_bytes` to 64 GiB
instead of the protocol default of 64 MiB, so BE silently caps the value
at 4 GiB. Six spill settings can also retain out-of-range values in FE,
making the displayed, forwarded and persisted settings differ from the
values used during execution.
This backport corrects the compiled aggregation default and normalizes
FE values to the bounds already enforced by BE. It does not change BE
spill algorithms, Thrift fields or absent-field fallbacks.
### Changes
- Correct `SessionVariable.spillAggregationSinkMemLimitBytes` from 64
GiB to 64 MiB.
- Share int/long normalization between `VariableMgr` assignment and
`SessionVariable` reads. This covers SESSION/GLOBAL assignment, hints
and restoration, forwarded variables, image/JSON reads, job maps and
GLOBAL journal replay.
- Retain `branch-4.1`'s bilingual `VariableMgr.VarAttr` metadata and
existing APIs; enable forwarding for the aggregation and hash-join
partition settings.
- Document the effective ranges and clarify that the aggregation
threshold applies after aggregation starts spilling. The sort merge
budget derives merge fan-in; it is not a hard memory limit.
- Add boundary/default, invalid-number, forwarding and persistence
coverage, plus a SQL regression with expected output.
### Configuration and compatibility
| Variable | Inclusive range | Compiled default |
|---|---|---|
| `spill_hash_join_partition_count` | [2, 32] | 4 |
| `spill_aggregation_partition_count` | [2, 32] | 4 |
| `spill_repartition_max_depth` | [1, 128] | 8 |
| `spill_buffer_size_bytes` | [1 MiB, 256 MiB] | 8 MiB |
| `spill_aggregation_sink_mem_limit_bytes` | [1 MiB, 4 GiB] | 64 MiB |
| `spill_sort_merge_mem_limit_bytes` | [1 MiB, 4 GiB] | 64 MiB |
Only the aggregation compiled default changes. Parseable out-of-range
values are clamped to the nearest bound, including the existing
BE-effective lower-bound behavior of 0 and -1. Non-integer values and
numeric overflow still fail; unrelated variables are unchanged.
Historical 64 GiB aggregation values normalize to 4 GiB, preserving
their previous effective threshold rather than replacing them with 64
MiB. Restored GLOBAL settings remain authoritative for new connections.
The 64 MiB compiled default applies without a GLOBAL override, or after
an explicit `SET spill_aggregation_sink_mem_limit_bytes=DEFAULT` in the
session.
This threshold is neither the initial spill trigger nor the query memory
limit. The lower default may change proactive memory revocation and
spill I/O frequency; explicitly setting
`spill_aggregation_sink_mem_limit_bytes=4294967296` retains the previous
effective threshold.
### Testing
Local validation of the `branch-4.1` backport:
- `timeout 2400 bash run-fe-ut.sh --run
org.apache.doris.qe.SessionVariableSpillContractTest,org.apache.doris.qe.VariableMgrTest,org.apache.doris.qe.RuntimeFilterTypeHelperTest`:
61 tests passed, zero failures/errors/skips.
- `timeout 2400 bash build.sh --fe -j 16`: passed, including Checkstyle
with zero violations.
- `timeout 3600 bash build.sh --be -j 32`: Release build passed.
- `timeout 1500 ./run-regression-test.sh --conf "$REG_CONF" --run -d
query_p0/session_variable -s test_spill_session_variable_ranges`:
passed, comparing all 78 output sections against the unchanged expected
output from #70876.
- `timeout 900 ./run-regression-test.sh --conf "$REG_CONF" --run -d
spill_p0 -s aggregate_spill`: passed as a compatibility smoke test, not
a threshold-performance test.
- `git diff --check`: passed for the complete backport diff.
`REG_CONF` was an isolated local regression configuration. The
native-only regression cluster used `enable_java_support=false`; Java
UDF/connector paths were not exercised. Full CI, BE unit tests,
mixed-version upgrades, S3 and spill workload performance were not run.
### Release note
Correct the compiled aggregation spill sink threshold to 64 MiB and make
six spill settings display and persist the bounded values used by BE.
Previously saved aggregation values retain their prior effective
behavior.
### Check List (For Author)
- Test:
- [x] Regression test
- [x] Unit Test
- Behavior changed:
- [x] Yes. FE stores normalized spill values and uses the corrected
aggregation compiled default; see compatibility details above.
- Does this need documentation?
- [x] Yes. The session-variable reference should reflect the ranges and
corrected aggregation default; no website documentation change is
included here.
### AI Disclosure
- Tool: Codex
- Generated: Backport adaptations and this description; source
code/tests originated in #70876.
- Human review: No human review is claimed.
---
.../java/org/apache/doris/qe/SessionVariable.java | 82 ++++++--
.../main/java/org/apache/doris/qe/VariableMgr.java | 8 +-
.../doris/qe/SessionVariableSpillContractTest.java | 215 +++++++++++++++++++
.../java/org/apache/doris/qe/VariableMgrTest.java | 49 +++++
.../test_spill_session_variable_ranges.out | 234 +++++++++++++++++++++
.../test_spill_session_variable_ranges.groovy | 51 +++++
6 files changed, 611 insertions(+), 28 deletions(-)
diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java
b/fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java
index 660c8f6964b..0e7622fcf60 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java
@@ -3482,13 +3482,18 @@ public class SessionVariable implements Serializable,
Writable {
@VariableMgr.VarAttr(name = SPILL_BUFFER_SIZE_BYTES, fuzzy = true,
needForward = true,
description = {"落盘时写 block 的最大大小(字节)。如果一个 block
超过该阈值,会按此大小拆分后再写入磁盘。"
- + "同时也控制 merge sort 阶段每个文件的读 buffer 大小。默认 8MB。",
+ + "同时也控制 merge sort 阶段每个文件的读 buffer 大小。默认 8 MiB。范围为 [1
MiB, 256 MiB],"
+ + "超出范围的值会限制到最近的边界。",
"Maximum block size for spill writes (in bytes). Blocks larger
than this threshold are "
+ "split before writing to disk. Also controls per-file
read buffer size during merge sort. "
- + "Default is 8MB."})
+ + "Default is 8 MiB. Range is [1 MiB, 256 MiB]; "
+ + "out-of-range values are clamped to the nearest bound."})
public long spillBufferSizeBytes = 8L * 1024L * 1024L;
- @VariableMgr.VarAttr(name = SPILL_AGGREGATION_PARTITION_COUNT, fuzzy =
true)
+ @VariableMgr.VarAttr(name = SPILL_AGGREGATION_PARTITION_COUNT, needForward
= true, fuzzy = true,
+ description = {"聚合落盘的分区数。默认 4。范围为 [2, 32],超出范围的值会限制到最近的边界。",
+ "Number of partitions for aggregation spill. Default is 4.
Range is [2, 32]; "
+ + "out-of-range values are clamped to the nearest bound."})
public int spillAggregationPartitionCount = 4;
@VariableMgr.VarAttr(name = LOW_MEMORY_MODE_BUFFER_LIMIT, fuzzy = false)
@@ -3499,12 +3504,17 @@ public class SessionVariable implements Serializable,
Writable {
@VariableMgr.VarAttr(name = SPILL_STREAMING_AGG_MEM_LIMIT, fuzzy = false)
public long spillStreamingAggMemLimit = 268435456; //256MB
- @VariableMgr.VarAttr(name = SPILL_HASH_JOIN_PARTITION_COUNT, fuzzy = true)
+ @VariableMgr.VarAttr(name = SPILL_HASH_JOIN_PARTITION_COUNT, needForward =
true, fuzzy = true,
+ description = {"哈希连接落盘的分区数。默认 4。范围为 [2, 32],超出范围的值会限制到最近的边界。",
+ "Number of partitions for hash join spill. Default is 4. Range
is [2, 32]; "
+ + "out-of-range values are clamped to the nearest bound."})
public int spillHashJoinPartitionCount = 4;
@VariableMgr.VarAttr(name = SPILL_REPARTITION_MAX_DEPTH, fuzzy = true,
needForward = true,
- description = {"重分区的最大递归深度,超过该深度不再继续重分区,\n默认值为 8",
- "Maximum depth for repartition recursion. When exceeded,
repartitioning will stop. Default is 8."})
+ description = {"重分区的最大递归深度,超过该深度不再继续重分区。默认 8。范围为 [1, 128],"
+ + "超出范围的值会限制到最近的边界。",
+ "Maximum depth for repartition recursion. When exceeded,
repartitioning will stop. Default "
+ + "is 8. Range is [1, 128]; out-of-range values are
clamped to the nearest bound."})
public int spillRepartitionMaxDepth = 8;
@VariableMgr.VarAttr(name = SPILL_JOIN_BUILD_SINK_MEM_LIMIT_BYTES, fuzzy =
true, needForward = true,
@@ -3514,10 +3524,14 @@ public class SessionVariable implements Serializable,
Writable {
public long spillJoinBuildSinkMemLimitBytes = 64L * 1024L * 1024L;
@VariableMgr.VarAttr(name = SPILL_AGGREGATION_SINK_MEM_LIMIT_BYTES, fuzzy
= true, needForward = true,
- description = {"一旦触发 spill 后,aggregation sink 的 revocable memory
超过该阈值就主动落盘(字节)。默认 64MB。",
- "After spill is triggered, aggregation sink will proactively
spill when revocable memory "
- + "exceeds this threshold (in bytes). Default is 64GB."})
- public long spillAggregationSinkMemLimitBytes = 64L * 1024L * 1024L *
1024L;
+ description = {"聚合开始落盘后,sink 的可回收内存达到该阈值就主动落盘(字节)。"
+ + "此值不是查询内存限制或首次落盘的触发阈值。默认 64 MiB。范围为 [1 MiB, 4 GiB],"
+ + "超出范围的值会限制到最近的边界。",
+ "After aggregation starts spilling, the sink proactively
spills when revocable memory "
+ + "reaches this threshold (in bytes), not a query memory
limit or the initial spill trigger. "
+ + "Default is 64 MiB. Range is [1 MiB, 4 GiB]; "
+ + "out-of-range values are clamped to the nearest bound."})
+ public long spillAggregationSinkMemLimitBytes = 64L * 1024L * 1024L;
@VariableMgr.VarAttr(name = SPILL_SORT_SINK_MEM_LIMIT_BYTES, fuzzy = true,
needForward = true,
description = {"一旦触发 spill 后,sort sink 的 revocable memory
超过该阈值就主动落盘(字节)。默认 64MB。",
@@ -3526,11 +3540,13 @@ public class SessionVariable implements Serializable,
Writable {
public long spillSortSinkMemLimitBytes = 64L * 1024L * 1024L;
@VariableMgr.VarAttr(name = SPILL_SORT_MERGE_MEM_LIMIT_BYTES, fuzzy =
true, needForward = true,
- description = {"一旦触发 spill 后,sort merge 阶段可用的总内存大小(字节)。"
- + "该值除以 spill_buffer_size_bytes 即为可并行读取合并的文件数。默认 64MB。",
- "After spill is triggered, total memory budget for the sort
merge phase (in bytes). "
- + "Divided by spill_buffer_size_bytes gives the number of
files that can be merged "
- + "in parallel. Default is 64MB."})
+ description = {"用于确定落盘排序归并路数的预算(字节),不是内存硬限制。查询排序每次最多归并 "
+ + "max(8, floor(预算 / spill_buffer_size_bytes)) 个文件。默认 64
MiB。"
+ + "范围为 [1 MiB, 4 GiB],超出范围的值会限制到最近的边界。",
+ "Budget used to derive spill sort merge fan-in (in bytes), not
a hard memory limit. "
+ + "Query sort merges up to max(8, floor(budget /
spill_buffer_size_bytes)) files at a time. "
+ + "Default is 64 MiB. Range is [1 MiB, 4 GiB]; "
+ + "out-of-range values are clamped to the nearest bound."})
public long spillSortMergeMemLimitBytes = 64L * 1024L * 1024L;
@VariableMgr.VarAttr(name = SPILL_REVOCABLE_MEMORY_HIGH_WATERMARK_PERCENT,
fuzzy = true)
@@ -6076,7 +6092,7 @@ public class SessionVariable implements Serializable,
Writable {
field.set(this, normalizeIntValue(attr.name(),
root.get(attr.name()).toString()));
break;
case "long":
- field.set(this, (Long) root.get(attr.name()));
+ field.set(this, normalizeLongValue(attr.name(), (Long)
root.get(attr.name())));
break;
case "float":
field.set(this, root.get(attr.name()));
@@ -6130,7 +6146,8 @@ public class SessionVariable implements Serializable,
Writable {
field.set(this, normalizeIntValue(attr.name(),
sessionVarMap.get(attr.name())));
break;
case "long":
- field.set(this,
Long.valueOf(sessionVarMap.get(attr.name())));
+ field.set(this, normalizeLongValue(attr.name(),
+
Long.parseLong(sessionVarMap.get(attr.name()))));
break;
case "float":
field.set(this,
Float.valueOf(sessionVarMap.get(attr.name())));
@@ -6153,12 +6170,33 @@ public class SessionVariable implements Serializable,
Writable {
}
}
- private static int normalizeIntValue(String name, String value) {
- int intValue = Integer.valueOf(value);
- if (RUNTIME_FILTER_TYPE.equalsIgnoreCase(name)) {
- return (int)
RuntimeFilterTypeHelper.normalizeDeprecatedRuntimeFilterTypes(intValue);
+ static int normalizeIntValue(String name, String value) {
+ int intValue = Integer.parseInt(value);
+ switch (name.toLowerCase(Locale.ROOT)) {
+ case RUNTIME_FILTER_TYPE:
+ return (int)
RuntimeFilterTypeHelper.normalizeDeprecatedRuntimeFilterTypes(intValue);
+ // Match the spill ranges enforced by RuntimeState getters.
+ case SPILL_HASH_JOIN_PARTITION_COUNT:
+ case SPILL_AGGREGATION_PARTITION_COUNT:
+ return Math.max(2, Math.min(intValue, 32));
+ case SPILL_REPARTITION_MAX_DEPTH:
+ return Math.max(1, Math.min(intValue, 128));
+ default:
+ return intValue;
+ }
+ }
+
+ static long normalizeLongValue(String name, long value) {
+ // Match the spill ranges enforced by RuntimeState getters.
+ switch (name.toLowerCase(Locale.ROOT)) {
+ case SPILL_BUFFER_SIZE_BYTES:
+ return Math.max(1024L * 1024, Math.min(value, 256L * 1024 *
1024));
+ case SPILL_AGGREGATION_SINK_MEM_LIMIT_BYTES:
+ case SPILL_SORT_MERGE_MEM_LIMIT_BYTES:
+ return Math.max(1024L * 1024, Math.min(value, 4L * 1024 * 1024
* 1024));
+ default:
+ return value;
}
- return intValue;
}
/**
diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/VariableMgr.java
b/fe/fe-core/src/main/java/org/apache/doris/qe/VariableMgr.java
index e3f6eb151be..a5cf8dd8b05 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/qe/VariableMgr.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/qe/VariableMgr.java
@@ -260,14 +260,10 @@ public class VariableMgr {
field.setShort(obj, Short.parseShort(value));
break;
case "int":
- int intValue = Integer.parseInt(value);
- if
(SessionVariable.RUNTIME_FILTER_TYPE.equalsIgnoreCase(name)) {
- intValue = (int)
RuntimeFilterTypeHelper.normalizeDeprecatedRuntimeFilterTypes(intValue);
- }
- field.setInt(obj, intValue);
+ field.setInt(obj, SessionVariable.normalizeIntValue(name,
value));
break;
case "long":
- field.setLong(obj, Long.parseLong(value));
+ field.setLong(obj, SessionVariable.normalizeLongValue(name,
Long.parseLong(value)));
break;
case "float":
field.setFloat(obj, Float.parseFloat(value));
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/qe/SessionVariableSpillContractTest.java
b/fe/fe-core/src/test/java/org/apache/doris/qe/SessionVariableSpillContractTest.java
new file mode 100644
index 00000000000..8c4b766b522
--- /dev/null
+++
b/fe/fe-core/src/test/java/org/apache/doris/qe/SessionVariableSpillContractTest.java
@@ -0,0 +1,215 @@
+// 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.doris.qe;
+
+import org.apache.doris.analysis.SetType;
+import org.apache.doris.analysis.SetVar;
+import org.apache.doris.analysis.StringLiteral;
+import org.apache.doris.common.DdlException;
+import org.apache.doris.common.io.Text;
+import org.apache.doris.persist.GlobalVarPersistInfo;
+import org.apache.doris.thrift.TQueryOptions;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.util.Collections;
+import java.util.Map;
+import java.util.stream.Stream;
+
+class SessionVariableSpillContractTest {
+ private static final long MIB = 1024L * 1024;
+ private static final long GIB = 1024L * MIB;
+
+ private static Stream<Arguments> ranges() {
+ // Variable, minimum, interior value, maximum, default.
+ return Stream.of(
+ Arguments.of(SessionVariable.SPILL_HASH_JOIN_PARTITION_COUNT,
2L, 5L, 32L, 4L),
+
Arguments.of(SessionVariable.SPILL_AGGREGATION_PARTITION_COUNT, 2L, 5L, 32L,
4L),
+ Arguments.of(SessionVariable.SPILL_REPARTITION_MAX_DEPTH, 1L,
5L, 128L, 8L),
+ Arguments.of(SessionVariable.SPILL_BUFFER_SIZE_BYTES, MIB, 2 *
MIB, 256 * MIB, 8 * MIB),
+
Arguments.of(SessionVariable.SPILL_AGGREGATION_SINK_MEM_LIMIT_BYTES, MIB, 2 *
MIB, 4 * GIB, 64 * MIB),
+ Arguments.of(SessionVariable.SPILL_SORT_MERGE_MEM_LIMIT_BYTES,
MIB, 2 * MIB, 4 * GIB, 64 * MIB));
+ }
+
+ @Test
+ void aggregationDefaultAgreesWithProtocolDefault() {
+ SessionVariable session = new SessionVariable();
+ Assertions.assertEquals(64 * MIB,
session.spillAggregationSinkMemLimitBytes);
+ Assertions.assertEquals(new
TQueryOptions().getSpillAggregationSinkMemLimitBytes(),
+ session.toThrift().getSpillAggregationSinkMemLimitBytes());
+
Assertions.assertTrue(session.toThrift().isSetSpillAggregationSinkMemLimitBytes());
+ }
+
+ @ParameterizedTest(name = "{0}")
+ @MethodSource("ranges")
+ void defaultsAndReset(String name, long min, long interior, long max, long
defaultValue) throws Exception {
+ SessionVariable session = new SessionVariable();
+ assertStoredValue(session, name, defaultValue);
+ set(session, name, interior);
+ VariableMgr.setVar(session, new SetVar(SetType.SESSION, name, null));
+ assertStoredValue(session, name, defaultValue);
+ }
+
+ @ParameterizedTest(name = "{0}")
+ @MethodSource("ranges")
+ void setStoresAndForwardsEffectiveValue(String name, long min, long
interior, long max, long defaultValue)
+ throws Exception {
+ long[][] samples = {{min - 1, min}, {min, min}, {interior, interior},
{max, max},
+ {max + 1, max}, {0, min}, {-1, min}};
+ SessionVariable session = new SessionVariable();
+ for (long[] sample : samples) {
+ set(session, name, sample[0]);
+ assertStoredValue(session, name, sample[1]);
+ SessionVariable forwarded = new SessionVariable();
+
forwarded.setForwardedSessionVariables(session.getForwardVariables());
+ assertStoredValue(forwarded, name, sample[1]);
+ }
+ }
+
+ @ParameterizedTest(name = "{0}")
+ @MethodSource("ranges")
+ void historicalReadPathsAndHintRestoration(String name, long min, long
interior, long max, long defaultValue)
+ throws Exception {
+ long[][] samples = {{max + 1, max}, {0, min}, {-1, min}};
+ for (long[] sample : samples) {
+ Map<String, String> raw = Collections.singletonMap(name,
Long.toString(sample[0]));
+ SessionVariable fromJson = new SessionVariable();
+ fromJson.readFromJson("{\"" + name + "\":" + sample[0] + "}");
+ assertRestoredValue(fromJson, name, interior, sample[1]);
+
+ SessionVariable fromMap = new SessionVariable();
+ fromMap.readFromMap(raw);
+ assertRestoredValue(fromMap, name, interior, sample[1]);
+
+ SessionVariable forwarded = new SessionVariable();
+ forwarded.setForwardedSessionVariables(raw);
+ assertRestoredValue(forwarded, name, interior, sample[1]);
+ }
+ }
+
+ @Test
+ void historicalAggregationDefaultKeepsItsEffectiveValue() throws Exception
{
+ String name = SessionVariable.SPILL_AGGREGATION_SINK_MEM_LIMIT_BYTES;
+ Map<String, String> raw = Collections.singletonMap(name,
Long.toString(64 * GIB));
+ SessionVariable fromJson = new SessionVariable();
+ fromJson.readFromJson("{\"" + name + "\":" + 64 * GIB + "}");
+ assertRestoredValue(fromJson, name, 64 * MIB, 4 * GIB);
+ SessionVariable fromMap = new SessionVariable();
+ fromMap.readFromMap(raw);
+ assertRestoredValue(fromMap, name, 64 * MIB, 4 * GIB);
+ SessionVariable forwarded = new SessionVariable();
+ forwarded.setForwardedSessionVariables(raw);
+ assertRestoredValue(forwarded, name, 64 * MIB, 4 * GIB);
+ }
+
+ @ParameterizedTest(name = "{0}")
+ @MethodSource("ranges")
+ void absentKeysPreserveExistingValue(String name, long min, long interior,
long max, long defaultValue)
+ throws Exception {
+ SessionVariable session = new SessionVariable();
+ set(session, name, interior);
+ session.readFromJson("{}");
+ session.readFromMap(Collections.emptyMap());
+ session.setForwardedSessionVariables(Collections.emptyMap());
+ assertStoredValue(session, name, interior);
+ }
+
+ @ParameterizedTest(name = "{0}")
+ @MethodSource("ranges")
+ void invalidNumbersStillFailWithoutChangingValue(String name, long min,
long interior, long max, long defaultValue)
+ throws Exception {
+ SessionVariable session = new SessionVariable();
+ set(session, name, interior);
+ boolean isInt = VariableMgr.getVarContext(name).getField().getType()
== int.class;
+ String overflow = isInt ? "2147483648" : "9223372036854775808";
+ for (String invalid : new String[] {"not_an_integer", "1.5",
overflow}) {
+ Assertions.assertThrows(DdlException.class, () ->
VariableMgr.setVar(session,
+ new SetVar(SetType.SESSION, name, new
StringLiteral(invalid))), name);
+ assertStoredValue(session, name, interior);
+ }
+ set(session, name, isInt ? Integer.MIN_VALUE : Long.MIN_VALUE);
+ assertStoredValue(session, name, min);
+ set(session, name, isInt ? Integer.MAX_VALUE : Long.MAX_VALUE);
+ assertStoredValue(session, name, max);
+ }
+
+ @Test
+ void historicalGlobalEditLogNormalizesBeforeNewSessions() throws Exception
{
+ SessionVariable defaults = VariableMgr.getDefaultSessionVariable();
+ long aggregationBefore = defaults.spillAggregationSinkMemLimitBytes;
+ int partitionBefore = defaults.spillAggregationPartitionCount;
+ try {
+ ByteArrayOutputStream bytes = new ByteArrayOutputStream();
+ Text.writeString(new DataOutputStream(bytes),
"{\"spill_aggregation_sink_mem_limit_bytes\":68719476736,"
+ + "\"spill_aggregation_partition_count\":64}");
+ GlobalVarPersistInfo info = GlobalVarPersistInfo.read(
+ new DataInputStream(new
ByteArrayInputStream(bytes.toByteArray())));
+ VariableMgr.replayGlobalVariableV2(info, false);
+ SessionVariable session = VariableMgr.newSessionVariable();
+ assertStoredValue(session,
SessionVariable.SPILL_AGGREGATION_SINK_MEM_LIMIT_BYTES, 4 * GIB);
+ assertStoredValue(session,
SessionVariable.SPILL_AGGREGATION_PARTITION_COUNT, 32);
+ } finally {
+ defaults.spillAggregationSinkMemLimitBytes = aggregationBefore;
+ defaults.spillAggregationPartitionCount = partitionBefore;
+ }
+ }
+
+ @Test
+ void unrelatedLongVariablesAreNotNormalized() throws Exception {
+ SessionVariable session = new SessionVariable();
+ String name = SessionVariable.SPILL_JOIN_BUILD_SINK_MEM_LIMIT_BYTES;
+ set(session, name, 64 * GIB);
+ assertStoredValue(session, name, 64 * GIB);
+ session.readFromJson("{\"" + name + "\":0}");
+ assertStoredValue(session, name, 0);
+ session.readFromMap(Collections.singletonMap(name, "-1"));
+ assertStoredValue(session, name, -1);
+ }
+
+ private static void set(SessionVariable session, String name, long value)
throws DdlException {
+ VariableMgr.setVar(session, new SetVar(SetType.SESSION, name, new
StringLiteral(Long.toString(value))));
+ }
+
+ private static void assertStoredValue(SessionVariable session, String
name, long expected) throws Exception {
+ Assertions.assertEquals(expected,
+ ((Number)
VariableMgr.getVarContext(name).getField().get(session)).longValue(), name);
+ Assertions.assertEquals(expected, ((Number)
session.toJson().get(name)).longValue(), name);
+ TQueryOptions options = session.toThrift();
+ TQueryOptions._Fields field = TQueryOptions._Fields.findByName(name);
+ Assertions.assertTrue(options.isSet(field), name);
+ Assertions.assertEquals(expected, ((Number)
options.getFieldValue(field)).longValue(), name);
+ Assertions.assertEquals(Long.toString(expected),
session.getForwardVariables().get(name), name);
+ }
+
+ private static void assertRestoredValue(SessionVariable session, String
name, long temporary, long expected)
+ throws Exception {
+ assertStoredValue(session, name, expected);
+ Assertions.assertTrue(session.setVarOnce(name,
Long.toString(temporary)), name);
+ assertStoredValue(session, name, temporary);
+ VariableMgr.revertSessionValue(session);
+ assertStoredValue(session, name, expected);
+ }
+}
diff --git a/fe/fe-core/src/test/java/org/apache/doris/qe/VariableMgrTest.java
b/fe/fe-core/src/test/java/org/apache/doris/qe/VariableMgrTest.java
index 5219437fdc1..f23f032b264 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/qe/VariableMgrTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/qe/VariableMgrTest.java
@@ -35,9 +35,11 @@ import
org.apache.doris.nereids.trees.plans.commands.CreateDatabaseCommand;
import org.apache.doris.nereids.trees.plans.commands.SetOptionsCommand;
import org.apache.doris.nereids.trees.plans.logical.LogicalPlan;
import org.apache.doris.nereids.types.BigIntType;
+import org.apache.doris.persist.GlobalVarPersistInfo;
import org.apache.doris.thrift.TQueryOptions;
import org.apache.doris.utframe.UtFrameUtils;
+import com.google.common.collect.Lists;
import org.apache.commons.io.FileUtils;
import org.junit.After;
import org.junit.Assert;
@@ -45,6 +47,10 @@ import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
import java.io.File;
import java.util.UUID;
@@ -104,6 +110,49 @@ public class VariableMgrTest {
Assert.assertEquals(7890,
VariableMgr.newSessionVariable().getMaxExecMemByte());
}
+ @Test
+ public void testGlobalSpillVariablesPersistNormalizedValues() throws
Exception {
+ String[][] samples = {
+ {SessionVariable.SPILL_AGGREGATION_SINK_MEM_LIMIT_BYTES,
"68719476736", "4294967296"},
+ {SessionVariable.SPILL_HASH_JOIN_PARTITION_COUNT, "64", "32"},
+ {SessionVariable.SPILL_AGGREGATION_PARTITION_COUNT, "1", "2"},
+ {SessionVariable.SPILL_REPARTITION_MAX_DEPTH, "256", "128"},
+ {SessionVariable.SPILL_BUFFER_SIZE_BYTES, "1024", "1048576"},
+ {SessionVariable.SPILL_SORT_MERGE_MEM_LIMIT_BYTES,
"8589934592", "4294967296"}
+ };
+ for (String[] sample : samples) {
+ String name = sample[0];
+ String originalGlobal = VariableMgr.getVarContext(name).getField()
+ .get(VariableMgr.getDefaultSessionVariable()).toString();
+ String originalSession = VariableMgr.getVarContext(name).getField()
+ .get(ctx.getSessionVariable()).toString();
+ try {
+ SetOptionsCommand stmt = (SetOptionsCommand)
UtFrameUtils.parseStmt(
+ "set global " + name + "=" + sample[1], ctx);
+ stmt.run(ctx, null);
+ Assertions.assertEquals(sample[2],
VariableMgr.getVarContext(name).getField()
+ .get(VariableMgr.newSessionVariable()).toString());
+ Assertions.assertEquals(sample[2],
VariableMgr.getVarContext(name).getField()
+ .get(ctx.getSessionVariable()).toString());
+
+ GlobalVarPersistInfo info = new GlobalVarPersistInfo(
+ VariableMgr.getDefaultSessionVariable(),
Lists.newArrayList(name));
+ ByteArrayOutputStream bytes = new ByteArrayOutputStream();
+ info.write(new DataOutputStream(bytes));
+ GlobalVarPersistInfo restored = GlobalVarPersistInfo.read(
+ new DataInputStream(new
ByteArrayInputStream(bytes.toByteArray())));
+ SessionVariable fromLog = new SessionVariable();
+ fromLog.readFromJson(restored.getPersistJsonString());
+ Assertions.assertEquals(sample[2],
VariableMgr.getVarContext(name).getField().get(fromLog).toString());
+ } finally {
+ VariableMgr.setVar(ctx.getSessionVariable(),
+ new SetVar(SetType.GLOBAL, name, new
StringLiteral(originalGlobal)));
+ VariableMgr.setVar(ctx.getSessionVariable(),
+ new SetVar(SetType.SESSION, name, new
StringLiteral(originalSession)));
+ }
+ }
+ }
+
@Test(expected = DdlException.class)
public void testReadOnly() throws DdlException {
// Set global variable
diff --git
a/regression-test/data/query_p0/session_variable/test_spill_session_variable_ranges.out
b/regression-test/data/query_p0/session_variable/test_spill_session_variable_ranges.out
new file mode 100644
index 00000000000..376626bcbfc
--- /dev/null
+++
b/regression-test/data/query_p0/session_variable/test_spill_session_variable_ranges.out
@@ -0,0 +1,234 @@
+-- This file is automatically generated. You should know what you did if you
want to edit this
+-- !spill_hash_join_partition_count_0 --
+2
+
+-- !spill_hash_join_partition_count_1 --
+2
+
+-- !spill_hash_join_partition_count_2 --
+5
+
+-- !spill_hash_join_partition_count_3 --
+32
+
+-- !spill_hash_join_partition_count_4 --
+32
+
+-- !spill_hash_join_partition_count_5 --
+2
+
+-- !spill_hash_join_partition_count_6 --
+2
+
+-- !spill_hash_join_partition_count_7 --
+32
+
+-- !spill_hash_join_partition_count_show --
+spill_hash_join_partition_count 32 4 1
+
+-- !spill_hash_join_partition_count_hint --
+32
+
+-- !spill_hash_join_partition_count_restored --
+5
+
+-- !spill_hash_join_partition_count_unchanged_after_invalid --
+5
+
+-- !spill_hash_join_partition_count_default --
+4
+
+-- !spill_aggregation_partition_count_0 --
+2
+
+-- !spill_aggregation_partition_count_1 --
+2
+
+-- !spill_aggregation_partition_count_2 --
+5
+
+-- !spill_aggregation_partition_count_3 --
+32
+
+-- !spill_aggregation_partition_count_4 --
+32
+
+-- !spill_aggregation_partition_count_5 --
+2
+
+-- !spill_aggregation_partition_count_6 --
+2
+
+-- !spill_aggregation_partition_count_7 --
+32
+
+-- !spill_aggregation_partition_count_show --
+spill_aggregation_partition_count 32 4 1
+
+-- !spill_aggregation_partition_count_hint --
+32
+
+-- !spill_aggregation_partition_count_restored --
+5
+
+-- !spill_aggregation_partition_count_unchanged_after_invalid --
+5
+
+-- !spill_aggregation_partition_count_default --
+4
+
+-- !spill_repartition_max_depth_0 --
+1
+
+-- !spill_repartition_max_depth_1 --
+1
+
+-- !spill_repartition_max_depth_2 --
+5
+
+-- !spill_repartition_max_depth_3 --
+128
+
+-- !spill_repartition_max_depth_4 --
+128
+
+-- !spill_repartition_max_depth_5 --
+1
+
+-- !spill_repartition_max_depth_6 --
+1
+
+-- !spill_repartition_max_depth_7 --
+128
+
+-- !spill_repartition_max_depth_show --
+spill_repartition_max_depth 128 8 1
+
+-- !spill_repartition_max_depth_hint --
+128
+
+-- !spill_repartition_max_depth_restored --
+5
+
+-- !spill_repartition_max_depth_unchanged_after_invalid --
+5
+
+-- !spill_repartition_max_depth_default --
+8
+
+-- !spill_buffer_size_bytes_0 --
+1048576
+
+-- !spill_buffer_size_bytes_1 --
+1048576
+
+-- !spill_buffer_size_bytes_2 --
+2097152
+
+-- !spill_buffer_size_bytes_3 --
+268435456
+
+-- !spill_buffer_size_bytes_4 --
+268435456
+
+-- !spill_buffer_size_bytes_5 --
+1048576
+
+-- !spill_buffer_size_bytes_6 --
+1048576
+
+-- !spill_buffer_size_bytes_7 --
+1048576
+
+-- !spill_buffer_size_bytes_show --
+spill_buffer_size_bytes 1048576 8388608 1
+
+-- !spill_buffer_size_bytes_hint --
+1048576
+
+-- !spill_buffer_size_bytes_restored --
+2097152
+
+-- !spill_buffer_size_bytes_unchanged_after_invalid --
+2097152
+
+-- !spill_buffer_size_bytes_default --
+8388608
+
+-- !spill_aggregation_sink_mem_limit_bytes_0 --
+1048576
+
+-- !spill_aggregation_sink_mem_limit_bytes_1 --
+1048576
+
+-- !spill_aggregation_sink_mem_limit_bytes_2 --
+2097152
+
+-- !spill_aggregation_sink_mem_limit_bytes_3 --
+4294967296
+
+-- !spill_aggregation_sink_mem_limit_bytes_4 --
+4294967296
+
+-- !spill_aggregation_sink_mem_limit_bytes_5 --
+1048576
+
+-- !spill_aggregation_sink_mem_limit_bytes_6 --
+1048576
+
+-- !spill_aggregation_sink_mem_limit_bytes_7 --
+4294967296
+
+-- !spill_aggregation_sink_mem_limit_bytes_show --
+spill_aggregation_sink_mem_limit_bytes 4294967296 67108864 1
+
+-- !spill_aggregation_sink_mem_limit_bytes_hint --
+4294967296
+
+-- !spill_aggregation_sink_mem_limit_bytes_restored --
+2097152
+
+-- !spill_aggregation_sink_mem_limit_bytes_unchanged_after_invalid --
+2097152
+
+-- !spill_aggregation_sink_mem_limit_bytes_default --
+67108864
+
+-- !spill_sort_merge_mem_limit_bytes_0 --
+1048576
+
+-- !spill_sort_merge_mem_limit_bytes_1 --
+1048576
+
+-- !spill_sort_merge_mem_limit_bytes_2 --
+2097152
+
+-- !spill_sort_merge_mem_limit_bytes_3 --
+4294967296
+
+-- !spill_sort_merge_mem_limit_bytes_4 --
+4294967296
+
+-- !spill_sort_merge_mem_limit_bytes_5 --
+1048576
+
+-- !spill_sort_merge_mem_limit_bytes_6 --
+1048576
+
+-- !spill_sort_merge_mem_limit_bytes_7 --
+4294967296
+
+-- !spill_sort_merge_mem_limit_bytes_show --
+spill_sort_merge_mem_limit_bytes 4294967296 67108864 1
+
+-- !spill_sort_merge_mem_limit_bytes_hint --
+4294967296
+
+-- !spill_sort_merge_mem_limit_bytes_restored --
+2097152
+
+-- !spill_sort_merge_mem_limit_bytes_unchanged_after_invalid --
+2097152
+
+-- !spill_sort_merge_mem_limit_bytes_default --
+67108864
diff --git
a/regression-test/suites/query_p0/session_variable/test_spill_session_variable_ranges.groovy
b/regression-test/suites/query_p0/session_variable/test_spill_session_variable_ranges.groovy
new file mode 100644
index 00000000000..b26b4bbbb2c
--- /dev/null
+++
b/regression-test/suites/query_p0/session_variable/test_spill_session_variable_ranges.groovy
@@ -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.
+
+suite("test_spill_session_variable_ranges", "p0") {
+ // Variable, minimum, interior value, maximum, historical out-of-range
value.
+ def ranges = [
+ ["spill_hash_join_partition_count", 2L, 5L, 32L, 64L],
+ ["spill_aggregation_partition_count", 2L, 5L, 32L, 64L],
+ ["spill_repartition_max_depth", 1L, 5L, 128L, 256L],
+ ["spill_buffer_size_bytes", 1048576L, 2097152L, 268435456L, 1024L],
+ ["spill_aggregation_sink_mem_limit_bytes", 1048576L, 2097152L,
4294967296L, 68719476736L],
+ ["spill_sort_merge_mem_limit_bytes", 1048576L, 2097152L, 4294967296L,
8589934592L]
+ ]
+ ranges.each { bounds ->
+ def (variable, minimum, interior, maximum, historical) = bounds
+ def saved = sql("SHOW VARIABLES LIKE '${variable}'")[0][1]
+ try {
+ [minimum - 1, minimum, interior, maximum, maximum + 1, 0L, -1L,
historical].eachWithIndex { value, index ->
+ sql "SET SESSION ${variable}=${value}"
+ "order_qt_${variable}_${index}"("SELECT @@${variable}")
+ }
+ "order_qt_${variable}_show"("SHOW VARIABLES LIKE '${variable}'")
+ sql "SET SESSION ${variable}=${interior}"
+ "order_qt_${variable}_hint"("SELECT /*+
SET_VAR(${variable}=${historical}) */ @@${variable}")
+ "order_qt_${variable}_restored"("SELECT @@${variable}")
+ test {
+ sql "SET SESSION ${variable}='not_an_integer'"
+ exception "Incorrect argument type to variable '${variable}'"
+ }
+ "order_qt_${variable}_unchanged_after_invalid"("SELECT
@@${variable}")
+ sql "SET SESSION ${variable}=DEFAULT"
+ "order_qt_${variable}_default"("SELECT @@${variable}")
+ } finally {
+ sql "SET SESSION ${variable}=${saved}"
+ }
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]