|
| 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 | +// Altering a compaction setting of a row binlog table must not reach its hidden row binlog |
| 19 | +// tablets: they keep the binlog compaction policy they were created with. |
| 20 | +suite("test_row_binlog_alter_compaction_policy") { |
| 21 | + if (isCloudMode()) { |
| 22 | + return |
| 23 | + } |
| 24 | + |
| 25 | + def backendIdToIp = [:] |
| 26 | + def backendIdToHttpPort = [:] |
| 27 | + getBackendIpHttpPort(backendIdToIp, backendIdToHttpPort) |
| 28 | + |
| 29 | + def getTabletMeta = { tablet -> |
| 30 | + def meta = null |
| 31 | + httpTest { |
| 32 | + endpoint "${backendIdToIp["${tablet.BackendId}"]}:${backendIdToHttpPort["${tablet.BackendId}"]}" |
| 33 | + uri "/api/meta/header/${tablet.TabletId}" |
| 34 | + op "get" |
| 35 | + check { respCode, body -> |
| 36 | + assertEquals(200, respCode as int) |
| 37 | + meta = parseJson(body.toString()) |
| 38 | + } |
| 39 | + } |
| 40 | + return meta |
| 41 | + } |
| 42 | + |
| 43 | + // A manual compaction makes a tablet switch to the policy in its tablet meta, so after it |
| 44 | + // the tablet status shows the policy the tablet really compacts with. |
| 45 | + def checkCompactionPolicy = { String tableName, String dataTabletPolicy -> |
| 46 | + trigger_and_wait_compaction(tableName, "cumulative") |
| 47 | + def rowBinlogTabletNum = 0 |
| 48 | + for (def tablet : sql_return_maparray("SHOW TABLETS FROM ${tableName}")) { |
| 49 | + def expectedPolicy = dataTabletPolicy |
| 50 | + if (tablet.IsRowBinlog == "true") { |
| 51 | + expectedPolicy = "binlog" |
| 52 | + rowBinlogTabletNum++ |
| 53 | + } |
| 54 | + assertEquals(expectedPolicy, getTabletMeta(tablet).compaction_policy) |
| 55 | + def (code, out, err) = be_show_tablet_status(backendIdToIp["${tablet.BackendId}"], |
| 56 | + backendIdToHttpPort["${tablet.BackendId}"], tablet.TabletId) |
| 57 | + assertEquals(0, code) |
| 58 | + assertEquals(expectedPolicy, parseJson(out.trim())["cumulative policy type"]) |
| 59 | + } |
| 60 | + assertTrue(rowBinlogTabletNum > 0) |
| 61 | + } |
| 62 | + |
| 63 | + // Case 1: change the compaction policy. |
| 64 | + sql "DROP TABLE IF EXISTS test_row_binlog_alter_compaction_policy_dup FORCE" |
| 65 | + sql """ |
| 66 | + CREATE TABLE test_row_binlog_alter_compaction_policy_dup ( |
| 67 | + k1 INT, |
| 68 | + v1 INT |
| 69 | + ) |
| 70 | + DUPLICATE KEY(k1) |
| 71 | + DISTRIBUTED BY HASH(k1) BUCKETS 1 |
| 72 | + PROPERTIES ( |
| 73 | + "replication_num" = "1", |
| 74 | + "disable_auto_compaction" = "true", |
| 75 | + "binlog.enable" = "true", |
| 76 | + "binlog.format" = "ROW" |
| 77 | + ) |
| 78 | + """ |
| 79 | + sql "INSERT INTO test_row_binlog_alter_compaction_policy_dup VALUES (1, 10), (2, 20)" |
| 80 | + sql "INSERT INTO test_row_binlog_alter_compaction_policy_dup VALUES (1, 11), (3, 30)" |
| 81 | + |
| 82 | + sql """ALTER TABLE test_row_binlog_alter_compaction_policy_dup SET ("compaction_policy" = "time_series")""" |
| 83 | + checkCompactionPolicy("test_row_binlog_alter_compaction_policy_dup", "time_series") |
| 84 | + order_qt_alter_policy """ |
| 85 | + SELECT __DORIS_BINLOG_OP__ AS op, k1, v1 |
| 86 | + FROM binlog("table" = "test_row_binlog_alter_compaction_policy_dup") |
| 87 | + """ |
| 88 | + |
| 89 | + // Case 2: change a time series setting. The row binlog tablets are not on the time_series |
| 90 | + // policy, so the setting must not be sent to them. |
| 91 | + sql "DROP TABLE IF EXISTS test_row_binlog_alter_compaction_policy_ts FORCE" |
| 92 | + sql """ |
| 93 | + CREATE TABLE test_row_binlog_alter_compaction_policy_ts ( |
| 94 | + k1 INT, |
| 95 | + v1 INT |
| 96 | + ) |
| 97 | + DUPLICATE KEY(k1) |
| 98 | + DISTRIBUTED BY HASH(k1) BUCKETS 1 |
| 99 | + PROPERTIES ( |
| 100 | + "replication_num" = "1", |
| 101 | + "disable_auto_compaction" = "true", |
| 102 | + "compaction_policy" = "time_series", |
| 103 | + "binlog.enable" = "true", |
| 104 | + "binlog.format" = "ROW" |
| 105 | + ) |
| 106 | + """ |
| 107 | + sql "INSERT INTO test_row_binlog_alter_compaction_policy_ts VALUES (1, 10), (2, 20)" |
| 108 | + sql "INSERT INTO test_row_binlog_alter_compaction_policy_ts VALUES (1, 11), (3, 30)" |
| 109 | + |
| 110 | + sql """ |
| 111 | + ALTER TABLE test_row_binlog_alter_compaction_policy_ts |
| 112 | + SET ("time_series_compaction_goal_size_mbytes" = "2048") |
| 113 | + """ |
| 114 | + for (def tablet : sql_return_maparray("SHOW TABLETS FROM test_row_binlog_alter_compaction_policy_ts")) { |
| 115 | + if (tablet.IsRowBinlog != "true") { |
| 116 | + assertEquals(2048L, getTabletMeta(tablet).time_series_compaction_goal_size_mbytes as Long) |
| 117 | + } |
| 118 | + } |
| 119 | + checkCompactionPolicy("test_row_binlog_alter_compaction_policy_ts", "time_series") |
| 120 | + order_qt_alter_time_series_setting """ |
| 121 | + SELECT __DORIS_BINLOG_OP__ AS op, k1, v1 |
| 122 | + FROM binlog("table" = "test_row_binlog_alter_compaction_policy_ts") |
| 123 | + """ |
| 124 | +} |
0 commit comments