|
| 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 | +import org.apache.doris.regression.suite.ClusterOptions |
| 19 | + |
| 20 | +// Verify that INSERT job statistics (ScannedRows, LoadBytes, etc.) shown in |
| 21 | +// SHOW LOAD are preserved after a FE restart. Before the fix, loadStatistic |
| 22 | +// was not serialized to the edit log, so all counters reset to 0 after restart. |
| 23 | +suite("test_insert_statistic_after_fe_restart", "docker") { |
| 24 | + def options = new ClusterOptions() |
| 25 | + options.setFeNum(1) |
| 26 | + docker(options) { |
| 27 | + def dbName = "test_insert_statistic_restart_db" |
| 28 | + def srcTbl = "src_tbl" |
| 29 | + def dstTbl = "dst_tbl" |
| 30 | + |
| 31 | + sql """DROP DATABASE IF EXISTS ${dbName}""" |
| 32 | + sql """CREATE DATABASE ${dbName}""" |
| 33 | + sql """USE ${dbName}""" |
| 34 | + |
| 35 | + sql """ |
| 36 | + CREATE TABLE ${srcTbl} ( |
| 37 | + k1 INT NULL, |
| 38 | + k2 VARCHAR(50) NULL |
| 39 | + ) ENGINE=OLAP |
| 40 | + DUPLICATE KEY(k1) |
| 41 | + DISTRIBUTED BY HASH(k1) BUCKETS 3 |
| 42 | + PROPERTIES ("replication_num" = "1") |
| 43 | + """ |
| 44 | + sql """ |
| 45 | + CREATE TABLE ${dstTbl} ( |
| 46 | + k1 INT NULL, |
| 47 | + k2 VARCHAR(50) NULL |
| 48 | + ) ENGINE=OLAP |
| 49 | + DUPLICATE KEY(k1) |
| 50 | + DISTRIBUTED BY HASH(k1) BUCKETS 3 |
| 51 | + PROPERTIES ("replication_num" = "1") |
| 52 | + """ |
| 53 | + |
| 54 | + // Insert enough rows so ScannedRows and LoadBytes are clearly non-zero |
| 55 | + sql """INSERT INTO ${srcTbl} SELECT number, concat('value_', number) |
| 56 | + FROM numbers('number'='1000')""" |
| 57 | + |
| 58 | + // insert into select — this creates the INSERT load job tracked by show load |
| 59 | + sql """INSERT INTO ${dstTbl} SELECT * FROM ${srcTbl}""" |
| 60 | + |
| 61 | + def result = sql """SHOW LOAD FROM ${dbName}""" |
| 62 | + assertEquals(1, result.size()) |
| 63 | + def jobDetailsBefore = parseJson(result[0][14]) |
| 64 | + logger.info("JobDetails before restart: ${result[0][14]}") |
| 65 | + |
| 66 | + assertTrue(jobDetailsBefore.ScannedRows > 0, |
| 67 | + "ScannedRows should be > 0 before restart, got ${jobDetailsBefore.ScannedRows}") |
| 68 | + assertTrue(jobDetailsBefore.LoadBytes > 0, |
| 69 | + "LoadBytes should be > 0 before restart, got ${jobDetailsBefore.LoadBytes}") |
| 70 | + |
| 71 | + // Restart FE and reconnect |
| 72 | + cluster.restartFrontends() |
| 73 | + sleep(30000) |
| 74 | + context.reconnectFe() |
| 75 | + |
| 76 | + sql """USE ${dbName}""" |
| 77 | + |
| 78 | + result = sql """SHOW LOAD FROM ${dbName}""" |
| 79 | + assertEquals(1, result.size()) |
| 80 | + def jobDetailsAfter = parseJson(result[0][14]) |
| 81 | + logger.info("JobDetails after restart: ${result[0][14]}") |
| 82 | + |
| 83 | + assertEquals(jobDetailsBefore.ScannedRows, jobDetailsAfter.ScannedRows, |
| 84 | + "ScannedRows changed after FE restart: before=${jobDetailsBefore.ScannedRows}, after=${jobDetailsAfter.ScannedRows}") |
| 85 | + assertEquals(jobDetailsBefore.LoadBytes, jobDetailsAfter.LoadBytes, |
| 86 | + "LoadBytes changed after FE restart: before=${jobDetailsBefore.LoadBytes}, after=${jobDetailsAfter.LoadBytes}") |
| 87 | + assertEquals(jobDetailsBefore.FileNumber, jobDetailsAfter.FileNumber, |
| 88 | + "FileNumber changed after FE restart") |
| 89 | + assertEquals(jobDetailsBefore.FileSize, jobDetailsAfter.FileSize, |
| 90 | + "FileSize changed after FE restart") |
| 91 | + } |
| 92 | +} |
0 commit comments