Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -99,26 +99,16 @@ public void beginTransaction() {
throw new BeginTransactionException("current running txns on db is larger than limit");
}
this.txnId = Env.getCurrentGlobalTransactionMgr().beginTransaction(
database.getId(), ImmutableList.of(table.getId()), labelName, null,
database.getId(), ImmutableList.of(table.getId()), labelName,
new TxnCoordinator(TxnSourceType.FE, 0,
FrontendOptions.getLocalHostAddress(),
ExecuteEnv.getInstance().getStartupTime()),
LoadJobSourceType.INSERT_STREAMING, getListenerId(), ctx.getExecTimeoutS());
LoadJobSourceType.INSERT_STREAMING, ctx.getExecTimeoutS());
} catch (Exception e) {
throw new AnalysisException("begin transaction failed. " + e.getMessage(), e);
}
}

private long getListenerId() {
long listenerId = -1;
StreamingInsertTask streamingInsertTask =
Env.getCurrentEnv().getJobManager().getStreamingTaskManager().getStreamingInsertTaskById(jobId);
if (streamingInsertTask != null) {
listenerId = streamingInsertTask.getJobId();
}
return listenerId;
}

@Override
public void finalizeSink(PlanFragment fragment, DataSink sink, PhysicalSink physicalSink) {
OlapTableSink olapTableSink = (OlapTableSink) sink;
Expand Down Expand Up @@ -199,6 +189,7 @@ protected void beforeExec() {

@Override
protected void onComplete() throws UserException {
setTxnCallbackId();
if (ctx.getState().getStateType() == MysqlStateType.ERR) {
try {
String errMsg = Strings.emptyToNull(ctx.getState().getErrorMessage());
Expand Down Expand Up @@ -234,6 +225,18 @@ protected void onComplete() throws UserException {
}
}

private void setTxnCallbackId() {
TransactionState state = Env.getCurrentGlobalTransactionMgr().getTransactionState(database.getId(), txnId);
if (state == null) {
throw new AnalysisException("txn does not exist: " + txnId);
}
StreamingInsertTask streamingInsertTask =
Env.getCurrentEnv().getJobManager().getStreamingTaskManager().getStreamingInsertTaskById(jobId);
if (streamingInsertTask != null) {
state.setCallbackId(streamingInsertTask.getJobId());
}
}

@Override
protected void onFail(Throwable t) {
errMsg = t.getMessage() == null ? "unknown reason" : t.getMessage();
Expand Down