Skip to content

Commit

Permalink
[fix](regression-test) Fix regiressin test syncer suit use master fe …
Browse files Browse the repository at this point in the history
…directly (#26456) (#26583)

Signed-off-by: Jack Drogon <jack.xsuperman@gmail.com>
  • Loading branch information
JackDrogon authored Nov 8, 2023
1 parent 9b8d3b9 commit e8ab033
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> 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<Map<String, Object>> res = new ArrayList<>()
for (int i = 0; i < result.size(); i++) {
Map<String, Object> 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<List<Object>> 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
}
Expand Down

0 comments on commit e8ab033

Please sign in to comment.