From a7f9d2b0bedc3efa6f56488e7b1bd435823e343b Mon Sep 17 00:00:00 2001 From: Jack Drogon Date: Mon, 6 Nov 2023 22:51:54 +0800 Subject: [PATCH] [fix](regression-test) Fix regiressin test syncer suit use master fe directly (#26456) Signed-off-by: Jack Drogon --- .../doris/regression/suite/Suite.groovy | 22 +++++++++++ .../doris/regression/suite/Syncer.groovy | 2 +- .../regression/suite/SyncerContext.groovy | 37 +++++++++++++++++-- 3 files changed, 57 insertions(+), 4 deletions(-) diff --git a/regression-test/framework/src/main/groovy/org/apache/doris/regression/suite/Suite.groovy b/regression-test/framework/src/main/groovy/org/apache/doris/regression/suite/Suite.groovy index 9902e30678e408..f347a6cc9413ac 100644 --- a/regression-test/framework/src/main/groovy/org/apache/doris/regression/suite/Suite.groovy +++ b/regression-test/framework/src/main/groovy/org/apache/doris/regression/suite/Suite.groovy @@ -259,6 +259,28 @@ class Suite implements GroovyInterceptable { return result } + def sql_return_maparray(String sqlStr) { + logger.info("Execute sql: ${sqlStr}".toString()) + def (result, meta) = JdbcUtils.executeToList(context.getConnection(), sqlStr) + + // get all column names as list + List columnNames = new ArrayList<>() + for (int i = 0; i < meta.getColumnCount(); i++) { + columnNames.add(meta.getColumnName(i + 1)) + } + + // add result to res map list, each row is a map with key is column name + List> res = new ArrayList<>() + for (int i = 0; i < result.size(); i++) { + Map row = new HashMap<>() + for (int j = 0; j < columnNames.size(); j++) { + row.put(columnNames.get(j), result.get(i).get(j)) + } + res.add(row) + } + return res; + } + List> target_sql(String sqlStr, boolean isOrder = false) { logger.info("Execute ${isOrder ? "order_" : ""}target_sql: ${sqlStr}".toString()) def (result, meta) = JdbcUtils.executeToList(context.getTargetConnection(this), sqlStr) diff --git a/regression-test/framework/src/main/groovy/org/apache/doris/regression/suite/Syncer.groovy b/regression-test/framework/src/main/groovy/org/apache/doris/regression/suite/Syncer.groovy index 493c4daa493b46..a808db7accf705 100644 --- a/regression-test/framework/src/main/groovy/org/apache/doris/regression/suite/Syncer.groovy +++ b/regression-test/framework/src/main/groovy/org/apache/doris/regression/suite/Syncer.groovy @@ -55,7 +55,7 @@ class Syncer { Syncer(Suite suite, Config config) { this.suite = suite - context = new SyncerContext(suite.context.dbName, config) + context = new SyncerContext(suite, suite.context.dbName, config) } enum ccrCluster { diff --git a/regression-test/framework/src/main/groovy/org/apache/doris/regression/suite/SyncerContext.groovy b/regression-test/framework/src/main/groovy/org/apache/doris/regression/suite/SyncerContext.groovy index eb5823e9a012df..388904ec2da4d2 100644 --- a/regression-test/framework/src/main/groovy/org/apache/doris/regression/suite/SyncerContext.groovy +++ b/regression-test/framework/src/main/groovy/org/apache/doris/regression/suite/SyncerContext.groovy @@ -23,7 +23,11 @@ import org.apache.doris.regression.suite.client.BackendClientImpl import org.apache.doris.regression.suite.client.FrontendClientImpl import org.apache.doris.thrift.TTabletCommitInfo import org.apache.doris.thrift.TGetSnapshotResult +import org.apache.doris.thrift.TNetworkAddress; import com.google.gson.annotations.SerializedName +import org.slf4j.Logger +import org.slf4j.LoggerFactory +import groovy.util.logging.Slf4j import java.sql.Connection @@ -93,6 +97,9 @@ class ExtraInfo { } class SyncerContext { + final Logger logger = LoggerFactory.getLogger(this.class) + + final Suite suite protected Connection targetConnection protected FrontendClientImpl sourceFrontendClient protected FrontendClientImpl targetFrontendClient @@ -121,7 +128,8 @@ class SyncerContext { public long txnId public long seq - SyncerContext(String dbName, Config config) { + SyncerContext(Suite suite, String dbName, Config config) { + this.suite = suite this.sourceDbId = -1 this.targetDbId = -1 this.db = dbName @@ -139,16 +147,39 @@ class SyncerContext { return info } + FrontendClientImpl getMasterFrontClient() { + def result = suite.sql_return_maparray "select Host, RpcPort, IsMaster from frontends();" + logger.info("get master fe: ${result}") + + def masterHost = "" + def masterPort = 0 + for (def row : result) { + if (row.IsMaster == "true") { + masterHost = row.Host + masterPort = row.RpcPort.toInteger() + break + } + } + + if (masterHost == "" || masterPort == 0) { + throw new Exception("can not find master fe") + } + + def masterNetworkAddr = new TNetworkAddress(masterHost, masterPort) + logger.info("master fe network addr: ${masterNetworkAddr}") + return new FrontendClientImpl(masterNetworkAddr) + } + FrontendClientImpl getSourceFrontClient() { if (sourceFrontendClient == null) { - sourceFrontendClient = new FrontendClientImpl(config.feSourceThriftNetworkAddress) + sourceFrontendClient = getMasterFrontClient() } return sourceFrontendClient } FrontendClientImpl getTargetFrontClient() { if (targetFrontendClient == null) { - targetFrontendClient = new FrontendClientImpl(config.feTargetThriftNetworkAddress) + targetFrontendClient = getMasterFrontClient() } return targetFrontendClient }