Skip to content

Commit ca47d75

Browse files
authored
[fix](regression) Add regression for group commit executed on observe… (#26692)
1 parent 70fdd1f commit ca47d75

2 files changed

Lines changed: 57 additions & 1 deletion

File tree

‎fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1813,6 +1813,7 @@ private void handleInsertStmt() throws Exception {
18131813
TransactionStatus txnStatus = TransactionStatus.ABORTED;
18141814
String errMsg = "";
18151815
TableType tblType = insertStmt.getTargetTable().getType();
1816+
boolean isGroupCommit = false;
18161817
if (context.isTxnModel()) {
18171818
if (insertStmt.getQueryStmt() instanceof SelectStmt) {
18181819
if (((SelectStmt) insertStmt.getQueryStmt()).getTableRefs().size() > 0) {
@@ -1824,6 +1825,7 @@ private void handleInsertStmt() throws Exception {
18241825
label = context.getTxnEntry().getLabel();
18251826
txnId = context.getTxnEntry().getTxnConf().getTxnId();
18261827
} else if (insertStmt instanceof NativeInsertStmt && ((NativeInsertStmt) insertStmt).isGroupCommit()) {
1828+
isGroupCommit = true;
18271829
NativeInsertStmt nativeInsertStmt = (NativeInsertStmt) insertStmt;
18281830
int maxRetry = 3;
18291831
for (int i = 0; i < maxRetry; i++) {
@@ -2013,6 +2015,9 @@ private void handleInsertStmt() throws Exception {
20132015
if (!Strings.isNullOrEmpty(errMsg)) {
20142016
sb.append(", 'err':'").append(errMsg).append("'");
20152017
}
2018+
if (isGroupCommit) {
2019+
sb.append(", 'query_id':'").append(DebugUtil.printId(context.queryId)).append("'");
2020+
}
20162021
sb.append("}");
20172022

20182023
context.getState().setOk(loadedRows, filteredRows, sb.toString());

‎regression-test/suites/insert_p0/insert_group_commit_into.groovy‎

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
// under the License.
1717

1818
import com.mysql.cj.jdbc.StatementImpl
19+
import org.codehaus.groovy.runtime.IOGroovyMethods
1920

2021
suite("insert_group_commit_into") {
2122
def dbName = "regression_test_insert_p0"
@@ -65,6 +66,7 @@ suite("insert_group_commit_into") {
6566
// assertEquals(result, expected_row_count)
6667
assertTrue(serverInfo.contains("'status':'PREPARE'"))
6768
assertTrue(serverInfo.contains("'label':'group_commit_"))
69+
return serverInfo
6870
}
6971

7072
def none_group_commit_insert = { sql, expected_row_count ->
@@ -211,6 +213,55 @@ suite("insert_group_commit_into") {
211213
// try_sql("DROP TABLE ${table}")
212214
}
213215

216+
// test connect to observer fe
217+
try {
218+
def fes = sql_return_maparray "show frontends"
219+
logger.info("frontends: ${fes}")
220+
if (fes.size() > 1) {
221+
def observer_fe = null
222+
for (def fe : fes) {
223+
if (fe.IsMaster == "false") {
224+
observer_fe = fe
225+
break
226+
}
227+
}
228+
if (observer_fe != null) {
229+
def url = "jdbc:mysql://${observer_fe.Host}:${observer_fe.QueryPort}/"
230+
logger.info("observer url: " + url)
231+
connect(user = context.config.jdbcUser, password = context.config.jdbcPassword, url = url) {
232+
sql """ set enable_insert_group_commit = true; """
233+
sql """ set enable_nereids_dml = false; """
234+
sql """ set enable_profile= true; """
235+
236+
// 1. insert into
237+
def server_info = group_commit_insert """ insert into ${table}(name, id) values('c', 3); """, 1
238+
assertTrue(server_info.contains('query_id'))
239+
// get query_id, such as 43f87963586a482a-b0496bcf9e2b5555
240+
def query_id_index = server_info.indexOf("'query_id':'") + "'query_id':'".length()
241+
def query_id = server_info.substring(query_id_index, query_id_index + 33)
242+
logger.info("query_id: " + query_id)
243+
// 2. check profile
244+
StringBuilder sb = new StringBuilder();
245+
sb.append("curl -X GET -u ${context.config.jdbcUser}:${context.config.jdbcPassword} http://${observer_fe.Host}:${observer_fe.HttpPort}")
246+
sb.append("/api/profile?query_id=").append(query_id)
247+
String command = sb.toString()
248+
logger.info(command)
249+
def process = command.execute()
250+
def code = process.waitFor()
251+
def err = IOGroovyMethods.getText(new BufferedReader(new InputStreamReader(process.getErrorStream())));
252+
def out = process.getText()
253+
logger.info("Get profile: code=" + code + ", out=" + out + ", err=" + err)
254+
assertEquals(code, 0)
255+
def json = parseJson(out)
256+
assertEquals("success", json.msg.toLowerCase())
257+
}
258+
}
259+
} else {
260+
logger.info("only one fe, skip test connect to observer fe")
261+
}
262+
} finally {
263+
}
264+
214265
// table with array type
215266
tableName = "insert_group_commit_into_duplicate_array"
216267
table = dbName + "." + tableName
@@ -266,4 +317,4 @@ suite("insert_group_commit_into") {
266317
// try_sql("DROP TABLE ${table}")
267318
}
268319
}
269-
}
320+
}

0 commit comments

Comments
 (0)