This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch branch-4.2
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-4.2 by this push:
new b437dc3f30b branch-4.2: [fix](fe) Align spill session variables with
backend limits #70876 (#70959)
b437dc3f30b is described below
commit b437dc3f30bc4d237825cfaf101359138b12949b
Author: Jerry Hu <[email protected]>
AuthorDate: Wed Nov 25 08:47:13 2026 +0800
branch-4.2: [fix](fe) Align spill session variables with backend limits
#70876 (#70959)
### What problem does this PR solve?
Issue Number: None
Related PR: #70876
Backport of #70876 to `branch-4.2`, cherry-picked from public commit
`567cfa2694f5a5327e812b423672c61c5ed7efd9`.
FE initializes the aggregation spill sink threshold to 64 GiB instead of
64 MiB, so BE silently caps it at 4 GiB. FE also retains out-of-range
values for six spill settings, making displayed and persisted settings
differ from their effective BE values.
### Changes
- Correct the compiled aggregation sink default to 64 MiB.
- Normalize the following settings at FE assignment and restoration
boundaries, covering SESSION/GLOBAL, hints and restoration, forwarding,
image JSON, job maps, and journal replay. Preserve numeric parse errors,
absent-key behavior, and unrelated variables.
| 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 |
- Retain `branch-4.2`'s `VariableMgr.VarAttr` annotations and bilingual
descriptions, share its integer-normalization entry point, and enable
forwarding for both spill partition-count settings. Adapt the added
tests to the branch's existing context and JUnit conventions.
- Clarify that the aggregation threshold controls proactive spilling
after aggregation starts spilling, not the initial spill trigger or
query memory limit. The sort-merge setting derives merge fan-in rather
than imposing a hard memory limit.
- Include the complete spill boundary and persistence/forwarding
coverage from the source change. BE algorithms, Thrift fields, and
absent-field fallbacks are unchanged.
### Compatibility and behavior
FE now displays and persists the bounded values used by BE. For these
six settings, 0 and -1 retain their previous BE-effective lower-bound
behavior. Historical 64 GiB aggregation values normalize to 4 GiB,
preserving their previous effective threshold.
The corrected 64 MiB compiled default applies without a restored GLOBAL
override or after explicit `SET
spill_aggregation_sink_mem_limit_bytes=DEFAULT`. New and reset
connections still inherit GLOBAL settings. The lower default may change
memory-revocation and spill-I/O frequency; explicitly setting this
variable to `4294967296` retains the previous effective threshold.
### Testing
Local validation on `branch-4.2`:
- `DISABLE_JAVA_CHECK_STYLE=OFF FE_MAVEN_THREADS=16 bash build.sh --fe
-j 16`: passed; 0 Checkstyle violations across 16 modules.
- `bash run-fe-ut.sh --run
org.apache.doris.qe.SessionVariableSpillContractTest,org.apache.doris.qe.VariableMgrTest`:
54 tests passed, with no failures, errors, or skips.
- `bash build.sh --be -j 48`: Release build passed.
- `bash run-regression-test.sh --conf "$REG_CONF" --run -d
query_p0/session_variable -s test_spill_session_variable_ranges
-parallel 1`: passed on an isolated local FE/BE cluster; all 78
expected-output sections matched.
- `bash run-regression-test.sh --conf "$REG_CONF" --run -d spill_p0 -s
aggregate_spill -parallel 1`: passed on the same cluster as a
compatibility smoke test, not a threshold-performance test.
- `git diff --check`: passed for the complete committed diff.
`REG_CONF` denotes the isolated local regression configuration. BE unit
tests, full CI, mixed-version upgrades, S3 validation, and
spill-workload performance testing were not run.
### Release note
Correct the compiled aggregation spill sink threshold to 64 MiB and
align FE storage/display of six spill settings with existing BE bounds.
Saved aggregation values retain their prior effective threshold, and
restored GLOBAL settings remain authoritative for new connections.
### Check List (For Author)
- [x] Unit tests
- [x] Regression tests
- Behavior changed: Yes, as described above.
- Documentation needed: Yes, the session-variable reference should
reflect the ranges and corrected aggregation default; documentation is
not included in this backport.
### AI Disclosure
- Tool: Codex
- Generated: Code, tests, and this description.
- 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 | 43 ++++
.../test_spill_session_variable_ranges.out | 234 +++++++++++++++++++++
.../test_spill_session_variable_ranges.groovy | 51 +++++
6 files changed, 605 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 2ec4aeb26c1..1f02528bca6 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
@@ -3582,13 +3582,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)
@@ -3599,12 +3604,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,
@@ -3614,10 +3624,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。",
@@ -3626,11 +3640,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)
@@ -6218,7 +6234,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()));
@@ -6272,7 +6288,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())));
@@ -6295,12 +6312,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 03337be1fe3..ccee72fe650 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
@@ -274,14 +274,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 f5f0241e639..30e408b27af 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
@@ -112,6 +112,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]