|
| 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.awaitility.Awaitility |
| 19 | +import static java.util.concurrent.TimeUnit.SECONDS |
| 20 | + |
| 21 | +suite("test_group_commit_wal_row_count", "nonConcurrent") { |
| 22 | + sql "DROP TABLE IF EXISTS test_group_commit_wal_row_count" |
| 23 | + sql """ |
| 24 | + CREATE TABLE test_group_commit_wal_row_count ( |
| 25 | + k INT NOT NULL, |
| 26 | + v INT NULL |
| 27 | + ) ENGINE=OLAP |
| 28 | + DUPLICATE KEY(k) |
| 29 | + DISTRIBUTED BY HASH(k) BUCKETS 1 |
| 30 | + PROPERTIES ( |
| 31 | + "replication_num" = "1", |
| 32 | + "group_commit_interval_ms" = "2000" |
| 33 | + ) |
| 34 | + """ |
| 35 | + |
| 36 | + String loadError = "LoadBlockQueue._finish_group_commit_load.load_error" |
| 37 | + String replayStop = "WalTable.replay_wals.stop" |
| 38 | + try { |
| 39 | + GetDebugPoint().enableDebugPointForAllBEs(loadError) |
| 40 | + GetDebugPoint().enableDebugPointForAllBEs(replayStop) |
| 41 | + |
| 42 | + // Abort each original transaction before the next load so both WALs must be replayed. |
| 43 | + for (String data : ["1,10\n2,20\n3,\\N\n", "4,40\n5,50\n"]) { |
| 44 | + long txnId = 0 |
| 45 | + streamLoad { |
| 46 | + table "test_group_commit_wal_row_count" |
| 47 | + set "column_separator", "," |
| 48 | + set "group_commit", "async_mode" |
| 49 | + unset "label" |
| 50 | + inputStream new ByteArrayInputStream(data.getBytes("UTF-8")) |
| 51 | + time 10000 |
| 52 | + check { result, exception, startTime, endTime -> |
| 53 | + assertNull(exception) |
| 54 | + def response = parseJson(result) |
| 55 | + assertEquals("Success", response.Status) |
| 56 | + assertEquals(data.readLines().size(), response.NumberTotalRows as int) |
| 57 | + txnId = response.TxnId as long |
| 58 | + assertTrue(txnId > 0) |
| 59 | + } |
| 60 | + } |
| 61 | + Awaitility.await().atMost(30, SECONDS).pollInterval(1, SECONDS).until { |
| 62 | + def txn = sql_return_maparray "SHOW TRANSACTION WHERE ID = ${txnId}" |
| 63 | + return txn.size() == 1 && txn[0].TransactionStatus == "ABORTED" |
| 64 | + } |
| 65 | + } |
| 66 | + qt_before_replay "SELECT COUNT(*) FROM test_group_commit_wal_row_count" |
| 67 | + |
| 68 | + // Keep the original-load failure enabled: rows can become visible only through WAL replay. |
| 69 | + GetDebugPoint().disableDebugPointForAllBEs(replayStop) |
| 70 | + Awaitility.await().atMost(90, SECONDS).pollInterval(1, SECONDS).until { |
| 71 | + def rows = sql "SELECT COUNT(*) FROM test_group_commit_wal_row_count" |
| 72 | + return rows[0][0] == 5 |
| 73 | + } |
| 74 | + qt_counts """SELECT COUNT(*), COUNT(v), SUM(k), SUM(v) |
| 75 | + FROM test_group_commit_wal_row_count""" |
| 76 | + qt_values "SELECT k, v FROM test_group_commit_wal_row_count ORDER BY k" |
| 77 | + qt_filtered_count "SELECT COUNT(*) FROM test_group_commit_wal_row_count WHERE v >= 20" |
| 78 | + } finally { |
| 79 | + try { |
| 80 | + GetDebugPoint().disableDebugPointForAllBEs(replayStop) |
| 81 | + } finally { |
| 82 | + GetDebugPoint().disableDebugPointForAllBEs(loadError) |
| 83 | + } |
| 84 | + } |
| 85 | +} |
0 commit comments