Skip to content

Commit dc1107f

Browse files
committed
2026_update1
1 parent 10f96ac commit dc1107f

File tree

7 files changed

+429
-16
lines changed

7 files changed

+429
-16
lines changed
Lines changed: 323 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,323 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package org.apache.doris.catalog;
19+
20+
import org.apache.doris.common.Config;
21+
import org.apache.doris.common.util.DebugPointUtil;
22+
import org.apache.doris.thrift.TStorageMedium;
23+
24+
import org.apache.logging.log4j.Level;
25+
import org.apache.logging.log4j.LogManager;
26+
import org.apache.logging.log4j.core.LoggerContext;
27+
import org.apache.logging.log4j.core.config.Configuration;
28+
import org.apache.logging.log4j.core.config.LoggerConfig;
29+
import org.junit.After;
30+
import org.junit.Assert;
31+
import org.junit.Before;
32+
import org.junit.Test;
33+
34+
/**
35+
* Unit tests for DiskInfo class, focusing on exceedLimit() method
36+
* and debug point functionality for storage medium capacity checks.
37+
*/
38+
public class DiskInfoTest {
39+
40+
@Before
41+
public void setUp() {
42+
// Enable debug points for testing
43+
Config.enable_debug_points = true;
44+
45+
// Set DEBUG level for DiskInfo logger to cover debug log statements
46+
LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
47+
Configuration config = ctx.getConfiguration();
48+
LoggerConfig loggerConfig = config.getLoggerConfig("org.apache.doris.catalog.DiskInfo");
49+
if (loggerConfig.getName().equals("org.apache.doris.catalog.DiskInfo")) {
50+
loggerConfig.setLevel(Level.DEBUG);
51+
} else {
52+
// Create new logger config if it doesn't exist
53+
LoggerConfig newLoggerConfig = new LoggerConfig("org.apache.doris.catalog.DiskInfo", Level.DEBUG, true);
54+
config.addLogger("org.apache.doris.catalog.DiskInfo", newLoggerConfig);
55+
}
56+
ctx.updateLoggers();
57+
58+
// Set test-friendly config values
59+
// Note: We directly set values without saving originals because
60+
// in unit test environment Config may not be fully initialized
61+
Config.storage_min_left_capacity_bytes = 100L * 1024 * 1024; // 100MB
62+
Config.storage_high_watermark_usage_percent = 85;
63+
Config.storage_flood_stage_left_capacity_bytes = 50L * 1024 * 1024; // 50MB
64+
Config.storage_flood_stage_usage_percent = 95;
65+
66+
// Clear any existing debug points
67+
DebugPointUtil.clearDebugPoints();
68+
}
69+
70+
@After
71+
public void tearDown() {
72+
// Restore logger level to INFO
73+
LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
74+
Configuration config = ctx.getConfiguration();
75+
LoggerConfig loggerConfig = config.getLoggerConfig("org.apache.doris.catalog.DiskInfo");
76+
if (loggerConfig.getName().equals("org.apache.doris.catalog.DiskInfo")) {
77+
loggerConfig.setLevel(Level.INFO);
78+
ctx.updateLoggers();
79+
}
80+
81+
// Disable debug points
82+
Config.enable_debug_points = false;
83+
84+
// Reset config values to reasonable defaults
85+
Config.storage_min_left_capacity_bytes = 2L * 1024 * 1024 * 1024; // 2GB (default)
86+
Config.storage_high_watermark_usage_percent = 85; // default
87+
Config.storage_flood_stage_left_capacity_bytes = 1L * 1024 * 1024 * 1024; // 1GB (default)
88+
Config.storage_flood_stage_usage_percent = 95; // default
89+
90+
// Clear all debug points
91+
DebugPointUtil.clearDebugPoints();
92+
}
93+
94+
/**
95+
* Test basic capacity check without debug points
96+
*/
97+
@Test
98+
public void testBasicCapacityCheck() {
99+
// Case 1: Disk has enough capacity
100+
DiskInfo diskInfo = new DiskInfo("/data/disk1");
101+
diskInfo.setTotalCapacityB(1024L * 1024 * 1024); // 1GB
102+
diskInfo.setAvailableCapacityB(500L * 1024 * 1024); // 500MB available
103+
diskInfo.setStorageMedium(TStorageMedium.HDD);
104+
105+
Assert.assertFalse("Disk with 500MB available should not exceed limit",
106+
diskInfo.exceedLimit(false));
107+
108+
// Case 2: Disk exceeds capacity limit (low available space)
109+
diskInfo.setAvailableCapacityB(50L * 1024 * 1024); // 50MB available (< 100MB min)
110+
Assert.assertTrue("Disk with only 50MB available should exceed limit",
111+
diskInfo.exceedLimit(false));
112+
113+
// Case 3: Disk exceeds capacity limit (high usage percentage)
114+
diskInfo.setAvailableCapacityB(100L * 1024 * 1024); // 100MB available
115+
diskInfo.setTotalCapacityB(500L * 1024 * 1024); // 500MB total (80% used)
116+
Assert.assertFalse("Disk with 80% usage should not exceed 85% limit",
117+
diskInfo.exceedLimit(false));
118+
119+
diskInfo.setAvailableCapacityB(50L * 1024 * 1024); // 50MB available (90% used)
120+
Assert.assertTrue("Disk with 90% usage should exceed 85% limit",
121+
diskInfo.exceedLimit(false));
122+
}
123+
124+
/**
125+
* Test flood stage capacity check
126+
*/
127+
@Test
128+
public void testFloodStageCheck() {
129+
DiskInfo diskInfo = new DiskInfo("/data/disk1");
130+
diskInfo.setTotalCapacityB(1024L * 1024 * 1024); // 1GB
131+
diskInfo.setStorageMedium(TStorageMedium.HDD);
132+
133+
// Flood stage uses AND condition (both must be true)
134+
// Case 1: Low space but not high percentage -> should not exceed
135+
// 40MB available (< 50MB), but 984MB/1024MB = 96% used is still high
136+
diskInfo.setAvailableCapacityB(40L * 1024 * 1024); // 40MB available (< 50MB flood stage)
137+
// Used = Total - Available = 1024MB - 40MB = 984MB (96% > 95%)
138+
// This WILL exceed because both conditions are met!
139+
Assert.assertTrue("Low space AND high percentage -> should exceed",
140+
diskInfo.exceedLimit(true));
141+
142+
// Case 2: High percentage but enough space -> should not exceed
143+
diskInfo.setAvailableCapacityB(100L * 1024 * 1024); // 100MB available (> 50MB)
144+
// Used = 1024MB - 100MB = 924MB (90% < 95%)
145+
Assert.assertFalse("High percentage but enough space -> should not exceed",
146+
diskInfo.exceedLimit(true));
147+
148+
// Case 3: Low percentage but not enough space -> should not exceed
149+
diskInfo.setTotalCapacityB(500L * 1024 * 1024); // 500MB total
150+
diskInfo.setAvailableCapacityB(40L * 1024 * 1024); // 40MB available (< 50MB)
151+
// Used = 500MB - 40MB = 460MB (92% < 95%)
152+
Assert.assertFalse("Low space but low percentage -> should not exceed",
153+
diskInfo.exceedLimit(true));
154+
155+
// Case 4: Both conditions met -> should exceed
156+
diskInfo.setTotalCapacityB(1024L * 1024 * 1024); // 1GB
157+
diskInfo.setAvailableCapacityB(30L * 1024 * 1024); // 30MB available (< 50MB)
158+
// Used = 1024MB - 30MB = 994MB (97% > 95%)
159+
Assert.assertTrue("Flood stage with both conditions should exceed",
160+
diskInfo.exceedLimit(true));
161+
}
162+
163+
/**
164+
* Test debug point: DiskInfo.exceedLimit.ssd.alwaysTrue
165+
* Forces SSD disks to report as exceed limit
166+
*/
167+
@Test
168+
public void testDebugPointSsdAlwaysTrue() {
169+
DiskInfo diskInfo = new DiskInfo("/data/ssd1");
170+
diskInfo.setTotalCapacityB(1024L * 1024 * 1024); // 1GB
171+
diskInfo.setAvailableCapacityB(500L * 1024 * 1024); // 500MB available (plenty)
172+
diskInfo.setStorageMedium(TStorageMedium.SSD);
173+
174+
// Without debug point - should not exceed
175+
Assert.assertFalse("SSD with plenty space should not exceed",
176+
diskInfo.exceedLimit(false));
177+
178+
// Enable debug point
179+
DebugPointUtil.addDebugPoint("DiskInfo.exceedLimit.ssd.alwaysTrue");
180+
181+
// With debug point - should always exceed
182+
Assert.assertTrue("SSD with debug point should always exceed",
183+
diskInfo.exceedLimit(false));
184+
185+
// HDD should not be affected
186+
diskInfo.setStorageMedium(TStorageMedium.HDD);
187+
Assert.assertFalse("HDD should not be affected by SSD debug point",
188+
diskInfo.exceedLimit(false));
189+
190+
// Clear debug point
191+
DebugPointUtil.clearDebugPoints();
192+
}
193+
194+
/**
195+
* Test debug point: DiskInfo.exceedLimit.ssd.alwaysFalse
196+
* Forces SSD disks to report as available
197+
*/
198+
@Test
199+
public void testDebugPointSsdAlwaysFalse() {
200+
DiskInfo diskInfo = new DiskInfo("/data/ssd1");
201+
diskInfo.setTotalCapacityB(1024L * 1024 * 1024); // 1GB
202+
diskInfo.setAvailableCapacityB(50L * 1024 * 1024); // 50MB available (low)
203+
diskInfo.setStorageMedium(TStorageMedium.SSD);
204+
205+
// Without debug point - should exceed
206+
Assert.assertTrue("SSD with low space should exceed",
207+
diskInfo.exceedLimit(false));
208+
209+
// Enable debug point
210+
DebugPointUtil.addDebugPoint("DiskInfo.exceedLimit.ssd.alwaysFalse");
211+
212+
// With debug point - should never exceed
213+
Assert.assertFalse("SSD with debug point should never exceed",
214+
diskInfo.exceedLimit(false));
215+
216+
// HDD should not be affected
217+
diskInfo.setStorageMedium(TStorageMedium.HDD);
218+
Assert.assertTrue("HDD should not be affected by SSD debug point",
219+
diskInfo.exceedLimit(false));
220+
221+
// Clear debug point
222+
DebugPointUtil.clearDebugPoints();
223+
}
224+
225+
/**
226+
* Test debug point: DiskInfo.exceedLimit.hdd.alwaysTrue
227+
* Forces HDD disks to report as exceed limit
228+
*/
229+
@Test
230+
public void testDebugPointHddAlwaysTrue() {
231+
DiskInfo diskInfo = new DiskInfo("/data/hdd1");
232+
diskInfo.setTotalCapacityB(1024L * 1024 * 1024); // 1GB
233+
diskInfo.setAvailableCapacityB(500L * 1024 * 1024); // 500MB available (plenty)
234+
diskInfo.setStorageMedium(TStorageMedium.HDD);
235+
236+
// Without debug point - should not exceed
237+
Assert.assertFalse("HDD with plenty space should not exceed",
238+
diskInfo.exceedLimit(false));
239+
240+
// Enable debug point
241+
DebugPointUtil.addDebugPoint("DiskInfo.exceedLimit.hdd.alwaysTrue");
242+
243+
// With debug point - should always exceed
244+
Assert.assertTrue("HDD with debug point should always exceed",
245+
diskInfo.exceedLimit(false));
246+
247+
// SSD should not be affected
248+
diskInfo.setStorageMedium(TStorageMedium.SSD);
249+
Assert.assertFalse("SSD should not be affected by HDD debug point",
250+
diskInfo.exceedLimit(false));
251+
252+
// Clear debug point
253+
DebugPointUtil.clearDebugPoints();
254+
}
255+
256+
/**
257+
* Test debug point: DiskInfo.exceedLimit.hdd.alwaysFalse
258+
* Forces HDD disks to report as available
259+
*/
260+
@Test
261+
public void testDebugPointHddAlwaysFalse() {
262+
DiskInfo diskInfo = new DiskInfo("/data/hdd1");
263+
diskInfo.setTotalCapacityB(1024L * 1024 * 1024); // 1GB
264+
diskInfo.setAvailableCapacityB(50L * 1024 * 1024); // 50MB available (low)
265+
diskInfo.setStorageMedium(TStorageMedium.HDD);
266+
267+
// Without debug point - should exceed
268+
Assert.assertTrue("HDD with low space should exceed",
269+
diskInfo.exceedLimit(false));
270+
271+
// Enable debug point
272+
DebugPointUtil.addDebugPoint("DiskInfo.exceedLimit.hdd.alwaysFalse");
273+
274+
// With debug point - should never exceed
275+
Assert.assertFalse("HDD with debug point should never exceed",
276+
diskInfo.exceedLimit(false));
277+
278+
// SSD should not be affected
279+
diskInfo.setStorageMedium(TStorageMedium.SSD);
280+
Assert.assertTrue("SSD should not be affected by HDD debug point",
281+
diskInfo.exceedLimit(false));
282+
283+
// Clear debug point
284+
DebugPointUtil.clearDebugPoints();
285+
}
286+
287+
/**
288+
* Test multiple debug points interaction
289+
*/
290+
@Test
291+
public void testMultipleDebugPoints() {
292+
DiskInfo ssdDisk = new DiskInfo("/data/ssd1");
293+
ssdDisk.setTotalCapacityB(1024L * 1024 * 1024);
294+
ssdDisk.setAvailableCapacityB(500L * 1024 * 1024);
295+
ssdDisk.setStorageMedium(TStorageMedium.SSD);
296+
297+
DiskInfo hddDisk = new DiskInfo("/data/hdd1");
298+
hddDisk.setTotalCapacityB(1024L * 1024 * 1024);
299+
hddDisk.setAvailableCapacityB(500L * 1024 * 1024);
300+
hddDisk.setStorageMedium(TStorageMedium.HDD);
301+
302+
// Enable both alwaysTrue debug points
303+
DebugPointUtil.addDebugPoint("DiskInfo.exceedLimit.ssd.alwaysTrue");
304+
DebugPointUtil.addDebugPoint("DiskInfo.exceedLimit.hdd.alwaysTrue");
305+
306+
// Both should report exceed limit
307+
Assert.assertTrue("SSD should exceed with debug point", ssdDisk.exceedLimit(false));
308+
Assert.assertTrue("HDD should exceed with debug point", hddDisk.exceedLimit(false));
309+
310+
// Clear and set alwaysFalse for both
311+
DebugPointUtil.clearDebugPoints();
312+
DebugPointUtil.addDebugPoint("DiskInfo.exceedLimit.ssd.alwaysFalse");
313+
DebugPointUtil.addDebugPoint("DiskInfo.exceedLimit.hdd.alwaysFalse");
314+
315+
// Both should report available
316+
Assert.assertFalse("SSD should not exceed with debug point", ssdDisk.exceedLimit(false));
317+
Assert.assertFalse("HDD should not exceed with debug point", hddDisk.exceedLimit(false));
318+
319+
// Clear debug points
320+
DebugPointUtil.clearDebugPoints();
321+
}
322+
}
323+

regression-test/suites/backup_restore/test_backup_restore_advanced_scenarios.groovy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ suite("test_backup_restore_advanced_scenarios", "backup_restore") {
7878
`id` INT,
7979
`value` STRING
8080
)
81+
UNIQUE KEY(`id`)
8182
DISTRIBUTED BY HASH(`id`) BUCKETS 2
8283
PROPERTIES ("replication_num" = "1")
8384
"""

0 commit comments

Comments
 (0)