Skip to content

Commit 7b39870

Browse files
mergify[bot]meegoo
andauthored
[Enhancement] Add transaction error message to loads internal table (backport StarRocks#61364) (StarRocks#62852)
Signed-off-by: meegoo <[email protected]> Co-authored-by: meegoo <[email protected]>
1 parent 6c87b5f commit 7b39870

File tree

6 files changed

+40
-2
lines changed

6 files changed

+40
-2
lines changed

fe/fe-core/src/main/java/com/starrocks/common/Config.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1216,7 +1216,7 @@ public class Config extends ConfigBase {
12161216
* Online optimize table allows to optimize a table without blocking write operations.
12171217
*/
12181218
@ConfField(mutable = true)
1219-
public static boolean enable_online_optimize_table = true;
1219+
public static boolean enable_online_optimize_table = false;
12201220

12211221
/**
12221222
* If set to true, FE will check backend available capacity by storage medium when create table

fe/fe-core/src/main/java/com/starrocks/load/LoadConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public class LoadConstants {
2929
public static final String RUNTIME_DETAILS_PLAN_TIME_MS = "plan_time_ms";
3030
public static final String RUNTIME_DETAILS_RECEIVE_DATA_TIME_MS = "receive_data_time_ms";
3131
public static final String RUNTIME_DETAILS_BEGIN_TXN_TIME_MS = "begin_txn_time_ms";
32+
public static final String RUNTIME_DETAILS_TXN_ERROR_MSG = "txn_error_msg";
3233

3334
public static final String PROPERTIES_TIMEOUT = "timeout";
3435
public static final String PROPERTIES_MAX_FILTER_RATIO = "max_filter_ratio";

fe/fe-core/src/main/java/com/starrocks/load/loadv2/LoadJob.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -927,6 +927,16 @@ public String toRuntimeDetails() {
927927
}
928928
runtimeDetails.put(LoadConstants.RUNTIME_DETAILS_LOAD_ID, Joiner.on(", ").join(loadIds));
929929
runtimeDetails.put(LoadConstants.RUNTIME_DETAILS_TXN_ID, transactionId);
930+
TransactionState txnState = GlobalStateMgr.getCurrentState()
931+
.getGlobalTransactionMgr().getTransactionState(dbId, transactionId);
932+
if (txnState != null) {
933+
txnState.writeLock();
934+
try {
935+
runtimeDetails.put(LoadConstants.RUNTIME_DETAILS_TXN_ERROR_MSG, txnState.getErrMsg());
936+
} finally {
937+
txnState.writeUnlock();
938+
}
939+
}
930940
runtimeDetails.putAll(loadingStatus.getLoadStatistic().toRuntimeDetails());
931941
Gson gson = new Gson();
932942
return gson.toJson(runtimeDetails);

fe/fe-core/src/main/java/com/starrocks/load/streamload/StreamLoadTask.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1534,6 +1534,15 @@ public String toRuntimeDetails() {
15341534
runtimeDetails.put(LoadConstants.RUNTIME_DETAILS_BEGIN_TXN_TIME_MS, beginTxnTimeMs);
15351535
runtimeDetails.put(LoadConstants.RUNTIME_DETAILS_RECEIVE_DATA_TIME_MS, receiveDataTimeMs);
15361536
runtimeDetails.put(LoadConstants.RUNTIME_DETAILS_PLAN_TIME_MS, planTimeMs);
1537+
TransactionState txnState = GlobalStateMgr.getCurrentState().getGlobalTransactionMgr().getTransactionState(dbId, txnId);
1538+
if (txnState != null) {
1539+
txnState.writeLock();
1540+
try {
1541+
runtimeDetails.put(LoadConstants.RUNTIME_DETAILS_TXN_ERROR_MSG, txnState.getErrMsg());
1542+
} finally {
1543+
txnState.writeUnlock();
1544+
}
1545+
}
15371546
Gson gson = new Gson();
15381547
return gson.toJson(runtimeDetails);
15391548
}

fe/fe-core/src/main/java/com/starrocks/transaction/PublishVersionDaemon.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,15 @@ public boolean publishPartitionBatch(Database db, long tableId, PartitionPublish
613613
stateBatch.putBeTablets(partitionId, nodeToTablets);
614614
}
615615
} catch (Exception e) {
616+
for (int i = 0; i < transactionStates.size(); i++) {
617+
TransactionState txnState = transactionStates.get(i);
618+
txnState.writeLock();
619+
try {
620+
txnState.setErrorMsg("Fail to publish partition " + partitionId + " error " + e.getMessage());
621+
} finally {
622+
txnState.writeUnlock();
623+
}
624+
}
616625
LOG.error("Fail to publish partition {} of txnIds {}:", partitionId,
617626
txnInfos.stream().map(i -> i.txnId).collect(Collectors.toList()), e);
618627
return false;
@@ -892,6 +901,13 @@ private boolean publishPartition(@NotNull Database db, @NotNull TableCommitInfo
892901
}
893902
return true;
894903
} catch (Throwable e) {
904+
txnState.writeLock();
905+
try {
906+
txnState.setErrorMsg("Fail to publish partition " + partitionCommitInfo.getPhysicalPartitionId()
907+
+ " error " + e.getMessage());
908+
} finally {
909+
txnState.writeUnlock();
910+
}
895911
// prevent excessive logging
896912
if (partitionCommitInfo.getVersionTime() < 0 &&
897913
Math.abs(partitionCommitInfo.getVersionTime()) + 10000 < System.currentTimeMillis()) {

fe/fe-core/src/test/java/com/starrocks/alter/OptimizeJobV2BuilderTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package com.starrocks.alter;
1616

1717
import com.starrocks.catalog.OlapTable;
18+
import com.starrocks.common.Config;
1819
import com.starrocks.common.StarRocksException;
1920
import com.starrocks.sql.ast.KeysDesc;
2021
import com.starrocks.sql.ast.OptimizeClause;
@@ -86,6 +87,7 @@ public void testBuildMergePartitionsJob() throws StarRocksException {
8687

8788
@Test
8889
public void testBuildWithoutOptimizeClause() throws StarRocksException {
90+
Config.enable_online_optimize_table = true;
8991
// Create a mock OlapTable
9092
OlapTable table = Mockito.mock(OlapTable.class);
9193
Mockito.when(table.getId()).thenReturn(123L);
@@ -108,4 +110,4 @@ public void testBuildWithoutOptimizeClause() throws StarRocksException {
108110
Assertions.assertEquals(123L, onlineOptimizeJob.getTableId());
109111
Assertions.assertEquals("myTable", onlineOptimizeJob.getTableName());
110112
}
111-
}
113+
}

0 commit comments

Comments
 (0)