Skip to content

Commit

Permalink
Feature: Saga provide a switch to skip branch report on branch succes…
Browse files Browse the repository at this point in the history
…s, in order to optimize performance. (#2151)
  • Loading branch information
long187 authored and zjinlei committed Jan 10, 2020
1 parent b179c78 commit 6ec6ab6
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public class ConfigurationKeys {
/**
* The constant CLIENT_REPORT_SUCCESS_ENABLE.
*/
public static final String CLIENT_REPORT_SUCCESS_ENABLE = CLIENT_PREFIX + "report.success.enable";
public static final String CLIENT_REPORT_SUCCESS_ENABLE = CLIENT_RM_PREFIX + "report.success.enable";

/**
* The constant CLIENT_REPORT_RETRY_COUNT.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

import javax.sql.DataSource;

import io.seata.config.ConfigurationFactory;
import io.seata.core.constants.ConfigurationKeys;
import io.seata.saga.engine.impl.DefaultStateMachineConfig;
import io.seata.saga.engine.store.db.DbAndReportTcStateLogStore;
import io.seata.saga.engine.store.db.DbStateLangStore;
Expand Down Expand Up @@ -48,6 +50,7 @@ public class DbStateMachineConfig extends DefaultStateMachineConfig implements D
private String dbType;
private int transOperationTimeout = DEFAULT_TRANS_OPER_TIMEOUT;
private SagaTransactionalTemplate sagaTransactionalTemplate;
private boolean rmReportSuccessEnable = ConfigurationFactory.getInstance().getBoolean(ConfigurationKeys.CLIENT_REPORT_SUCCESS_ENABLE, true);

public static String getDbTypeFromDataSource(DataSource dataSource) throws SQLException {
Connection con = null;
Expand Down Expand Up @@ -165,4 +168,12 @@ public int getTransOperationTimeout() {
public void setTransOperationTimeout(int transOperationTimeout) {
this.transOperationTimeout = transOperationTimeout;
}

public boolean isRmReportSuccessEnable() {
return rmReportSuccessEnable;
}

public void setRmReportSuccessEnable(boolean rmReportSuccessEnable) {
this.rmReportSuccessEnable = rmReportSuccessEnable;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import io.seata.core.exception.TransactionException;
import io.seata.core.model.BranchStatus;
import io.seata.core.model.GlobalStatus;
import io.seata.saga.engine.StateMachineConfig;
import io.seata.saga.engine.config.DbStateMachineConfig;
import io.seata.saga.engine.exception.EngineExecutionException;
import io.seata.saga.engine.sequence.SeqGenerator;
import io.seata.saga.engine.serializer.Serializer;
Expand Down Expand Up @@ -404,7 +406,14 @@ public void recordStateFinished(StateInstance stateInstance, ProcessContext cont
executeUpdate(stateLogStoreSqls.getRecordStateFinishedSql(dbType), STATE_INSTANCE_TO_STATEMENT_FOR_UPDATE,
stateInstance);

branchReport(stateInstance, context);
//A switch to skip branch report on branch success, in order to optimize performance
StateMachineConfig stateMachineConfig = (StateMachineConfig) context.getVariable(
DomainConstants.VAR_NAME_STATEMACHINE_CONFIG);
if (!(stateMachineConfig instanceof DbStateMachineConfig
&& !((DbStateMachineConfig)stateMachineConfig).isRmReportSuccessEnable()
&& ExecutionStatus.SU.equals(stateInstance.getStatus()))) {
branchReport(stateInstance, context);
}
}
}

Expand Down
6 changes: 6 additions & 0 deletions test/src/test/resources/file.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,10 @@ service {
default.grouplist = "127.0.0.1:8091"
#disable seata
disableGlobalTransaction = false
}

client {
rm {
report.success.enable = false
}
}

0 comments on commit 6ec6ab6

Please sign in to comment.