github-actions[bot] commented on code in PR #61951: URL: https://github.com/apache/doris/pull/61951#discussion_r3084541624
########## regression-test/suites/fault_injection_p0/test_forward_reopen_timeout.groovy: ########## @@ -0,0 +1,116 @@ +// 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. + +import org.apache.doris.regression.suite.ClusterOptions +import org.apache.doris.regression.util.NodeType + +// Test that GenericPool.reopen() uses a short connect timeout instead of +// the inherited large RPC timeout when reconnecting stale connections. +// +// Two debug points work together: +// 1. "GenericPool.borrowObject.break_connection" - closes the underlying socket +// after borrowObject, simulating a TCP half-open (stale) connection. The next +// RPC will fail with TTransportException, triggering reopen(). +// 2. "GenericPool.reopen.simulate_stale" - reads TSocket's connectTimeout_ via +// reflection and sleeps that duration, simulating a blocked TCP connect. +// +// With fix: connectTimeout_ = thrift_rpc_connect_timeout_ms (5s) → sleeps 5s +// Without fix: connectTimeout_ = query_timeout * 1.2 (36s) → sleeps 36s +suite('test_forward_reopen_timeout', 'docker') { + def options = new ClusterOptions() + options.setFeNum(2) + options.setBeNum(1) + options.enableDebugPoints() + options.connectToFollower = true + options.feConfigs += [ + 'thrift_rpc_connect_timeout_ms=5000', + ] + + docker(options) { + // Step 1: Basic DDL forwarding works + sql "DROP DATABASE IF EXISTS test_reopen_timeout" + sql "CREATE DATABASE test_reopen_timeout" + sql "USE test_reopen_timeout" + sql """ + CREATE TABLE tbl1 (k1 INT) + DISTRIBUTED BY HASH(k1) BUCKETS 1 + PROPERTIES ("replication_num" = "1") + """ + sql "INSERT INTO tbl1 VALUES (1)" + def result = sql "SELECT * FROM tbl1" + assertEquals(1, result.size()) + logger.info("Step 1 passed: basic DDL forwarding works") + + // Step 2: Inject both debug points on follower FE + def followerFe = cluster.getAllFrontends().find { !it.isMaster } + assertNotNull(followerFe) + logger.info("Injecting debug points on follower FE (index=${followerFe.index})") + // This breaks the connection after borrow → forces TTransportException → triggers reopen + followerFe.enableDebugPoint('GenericPool.borrowObject.break_connection', null) + // This simulates stale connect in reopen by sleeping for connectTimeout_ duration + followerFe.enableDebugPoint('GenericPool.reopen.simulate_stale', null) + + // Step 3: Set query timeout so borrowObject sets connectTimeout_ to 30*1.2=36s + sql "SET query_timeout = 30" + + // Step 4: DDL from follower triggers the full chain: + // borrowObject → break_connection closes socket → forward() fails → + // TTransportException → reopen() → simulate_stale reads connectTimeout_ and sleeps. + // + // With fix: setTimeout(5000) called before close → connectTimeout_=5s → sleeps 5s + // Without fix: connectTimeout_=36s (from borrowObject) → sleeps 36s → exceeds 15s + def startTime = System.currentTimeMillis() + def ddlError = null + try { + sql "USE test_reopen_timeout" + sql """ + CREATE TABLE tbl_blocked (k1 INT) + DISTRIBUTED BY HASH(k1) BUCKETS 1 + PROPERTIES ("replication_num" = "1") + """ + } catch (Exception e) { + ddlError = e.getMessage() + } + def elapsed = System.currentTimeMillis() - startTime + logger.info("Step 4: DDL attempt took ${elapsed}ms, error=${ddlError}") + + // Key assertion: should complete within 15s. + // With fix (connectTimeout=5s): debug point sleeps ~5s → PASS + // Without fix (connectTimeout=36s): debug point sleeps ~36s → FAIL + assertTrue(elapsed < 15000, Review Comment: This regression test currently passes on any *fast* failure. Step 4 catches every exception into `ddlError`, but the only assertion is `elapsed < 15000`; there is no check that the forwarded DDL actually succeeded or even failed for the injected transport reason. That means unrelated regressions that fail immediately would still keep the test green. Please assert the expected outcome explicitly, such as checking that `ddlError == null` and that `tbl_blocked` exists, or asserting a precise expected injected error if failure is intentional. ########## fe/fe-core/src/test/java/org/apache/doris/common/GenericPoolTest.java: ########## @@ -295,6 +296,114 @@ public void testSetMaxPerKey() throws Exception { backendService.returnObject(address, object3); } + @Test + public void testReopenSetsShortTimeoutBeforeOpen() throws Exception { + TNetworkAddress address = new TNetworkAddress(ip, port); + // Borrow with a high timeout (simulating FEOpExecutor's thriftTimeoutMs) + BackendService.Client client = backendService.borrowObject(address, 1080000); + + // Verify the high timeout is set + TSocket socket = (TSocket) client.getOutputProtocol().getTransport(); + Assert.assertTrue(socket.isOpen()); + + // reopen should succeed and restore the provided timeout + int savedConnectTimeout = Config.thrift_rpc_connect_timeout_ms; + Config.thrift_rpc_connect_timeout_ms = 5000; + try { + boolean ok = backendService.reopen(client, 60000); + Assert.assertTrue(ok); + Assert.assertTrue(client.getOutputProtocol().getTransport().isOpen()); + } finally { + Config.thrift_rpc_connect_timeout_ms = savedConnectTimeout; + } + + backendService.returnObject(address, client); + } + + @Test + public void testReopenNoArgRestoresPoolDefaultTimeout() throws Exception { + TNetworkAddress address = new TNetworkAddress(ip, port); + BackendService.Client client = backendService.borrowObject(address); + + int savedConnectTimeout = Config.thrift_rpc_connect_timeout_ms; + Config.thrift_rpc_connect_timeout_ms = 5000; + try { + boolean ok = backendService.reopen(client); + Assert.assertTrue(ok); + Assert.assertTrue(client.getOutputProtocol().getTransport().isOpen()); + } finally { + Config.thrift_rpc_connect_timeout_ms = savedConnectTimeout; + } + + backendService.returnObject(address, client); + } + + @Test + public void testReopenOrClearSuccessDoesNotClearPool() throws Exception { + TNetworkAddress address = new TNetworkAddress(ip, port); + // Borrow two connections to pool + BackendService.Client client1 = backendService.borrowObject(address); + BackendService.Client client2 = backendService.borrowObject(address); + backendService.returnObject(address, client2); + + // reopenOrClear should succeed and NOT clear the pool + boolean ok = backendService.reopenOrClear(address, client1, 60000); + Assert.assertTrue(ok); + + // The other idle connection should still be available + BackendService.Client client3 = backendService.borrowObject(address); + Assert.assertNotNull(client3); + + backendService.returnObject(address, client1); + backendService.returnObject(address, client3); + } + + @Test + public void testReopenOrClearFailureClearsPool() throws Exception { + TNetworkAddress address = new TNetworkAddress(ip, port); + // Borrow and return a connection so pool has an idle one + BackendService.Client client1 = backendService.borrowObject(address); + backendService.returnObject(address, client1); + + // Borrow a connection, then try reopenOrClear + BackendService.Client client2 = backendService.borrowObject(address); + Review Comment: `testReopenOrClearFailureClearsPool()` never drives `reopenOrClear()` into the `!ok` branch it is supposed to validate: the test keeps the mock server alive, calls `reopenOrClear(...)`, and then asserts `ok`. If `clearPool(address)` were accidentally removed, this test would still pass. Please force `reopen()` to fail here and assert an observable postcondition of the cleanup path (for example, that previously idle clients for this key are discarded). -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
