0

我正在按照本指南测试 DSS 的分布式事务。

没关系。由于 addAccountToBank2 操作中的错误,addAccountToBank1 服务调用回滚。在本次测试中,这两个操作都涉及到 H2 DB。

然后我做另一个测试:

在此测试中,我将其中一个 H2 DB 替换为 MySQL DB。这是我的步骤:

  1. 运行 begin_boxcar 操作。
  2. 将一些数据插入 MySQL DB。
  3. 运行 addToAccountBalanceInBank2 操作并为“accountId”字段指定值“1”,为“value”字段指定值“h200”。
  4. 运行 end_boxcar 操作。
  5. 运行 getAccountBalanceFromBank2 操作。(余额不变)
  6. 查询 MySQL 数据库中的数据。(已被插入操作更改)

我不知道为什么 MySQL DB 不会发生回滚?DSS的分布式事务回滚需要什么条件?

.dbs 文件的内容:

    <data enableBoxcarring="true" enableDTP="true" name="DTPSampleService" serviceNamespace="http://ws.wso2.org/dataservice/samples/dtp_sample">
<config id="H2DataSource1">
    <property name="org.wso2.ws.dataservice.xa_datasource_class">org.h2.jdbcx.JdbcDataSource</property>
    <property name="org.wso2.ws.dataservice.xa_datasource_properties">
        <property name="URL">jdbc:h2:file:./samples/database/DATA_SERV_SAMP</property>
        <property name="User">wso2ds</property>
        <property name="Password">wso2ds</property>
    </property>
</config>
<config id="H2DataSource2">
    <property name="org.wso2.ws.dataservice.xa_datasource_class">org.h2.jdbcx.JdbcDataSource</property>
    <property name="org.wso2.ws.dataservice.xa_datasource_properties">
        <property name="URL">jdbc:h2:file:./samples/database/DATA_SERV_SAMP2</property>
        <property name="User">wso2ds</property>
        <property name="Password">wso2ds</property>
    </property>
</config>
<config id="MySQL">
    <property name="org.wso2.ws.dataservice.driver">com.mysql.jdbc.Driver</property>                              
    <property name="org.wso2.ws.dataservice.protocol">jdbc:mysql://localhost:3306/customersdatabase</property>                              
    <property name="org.wso2.ws.dataservice.user">root</property>                              
    <property name="org.wso2.ws.dataservice.password">root123</property>  
    </config>
<config id="MySQL1">
  <property name="org.wso2.ws.dataservice.driver">com.mysql.jdbc.Driver</property>                              
  <property name="org.wso2.ws.dataservice.protocol">jdbc:mysql://192.168.31.44:3306/guohtdb</property>                              
  <property name="org.wso2.ws.dataservice.user">root</property>                              
  <property name="org.wso2.ws.dataservice.password">root123</property>  
</config>
<query id="addAccountToBank1Query" returnGeneratedKeys="true" useConfig="H2DataSource1">
    <sql>insert into Accounts (balance) values (:balance)</sql>
    <param defaultValue="0" name="balance" sqlType="DOUBLE"/>
    <result element="GeneratedKeys" rowName="Entry" useColumnNumbers="true">
        <element column="1" name="ID" xsdType="integer"/>
    </result>
</query>
<operation name="addAccountToBank1">
    <call-query href="addAccountToBank1Query">
        <with-param name="balance" query-param="balance"/>
    </call-query>
</operation>
<query id="addToAccountBalanceInBank1Query" useConfig="H2DataSource1">
    <sql>update Accounts set balance = balance + :value where accountId= :accountId</sql>
    <param name="accountId" sqlType="INTEGER"/>
    <param name="value" sqlType="DOUBLE">
        <validateDoubleRange maximum="2000" minimum="-2000"/>
    </param>
</query>
<operation name="addToAccountBalanceInBank1">
    <call-query href="addToAccountBalanceInBank1Query">
        <with-param name="accountId" query-param="accountId"/>
        <with-param name="value" query-param="value"/>
    </call-query>
</operation>
<query id="getAccountBalanceFromBank1Query" useConfig="H2DataSource1">
    <sql>select balance from Accounts where accountId=:accountId</sql>
    <param name="accountId" sqlType="INTEGER"/>
    <result element="Balance">
        <element column="balance" name="Value" xsdType="double"/>
    </result>
</query>
<operation name="getAccountBalanceFromBank1">
    <call-query href="getAccountBalanceFromBank1Query">
        <with-param name="accountId" query-param="accountId"/>
    </call-query>
</operation>
<query id="addAccountToBank2Query" returnGeneratedKeys="true" useConfig="H2DataSource2">
    <sql>insert into Accounts (balance) values (:balance)</sql>
    <param defaultValue="0" name="balance" sqlType="DOUBLE"/>
    <result element="GeneratedKeys" rowName="Entry" useColumnNumbers="true">
        <element column="1" name="ID" xsdType="integer"/>
    </result>
</query>
<operation disableStreaming="true" name="addAccountToBank2">
    <call-query href="addAccountToBank2Query">
        <with-param name="balance" query-param="balance"/>
    </call-query>
</operation>
<query id="addToAccountBalanceInBank2Query" useConfig="H2DataSource2">
    <sql>update Accounts set balance = balance + :value where accountId= :accountId</sql>
    <param name="accountId" sqlType="INTEGER"/>
    <param name="value" sqlType="DOUBLE">
        <validateDoubleRange maximum="2000" minimum="-2000"/>
    </param>
</query>
<operation name="addToAccountBalanceInBank2">
    <call-query href="addToAccountBalanceInBank2Query">
        <with-param name="accountId" query-param="accountId"/>
        <with-param name="value" query-param="value"/>
    </call-query>
</operation>
<query id="getAccountBalanceFromBank2Query" useConfig="H2DataSource2">
    <sql>select balance from Accounts where accountId=:accountId</sql>
    <param name="accountId" sqlType="INTEGER"/>
    <result element="Balance">
        <element column="balance" name="Value" xsdType="double"/>
    </result>
</query>
<operation name="getAccountBalanceFromBank2">
    <call-query href="getAccountBalanceFromBank2Query">
        <with-param name="accountId" query-param="accountId"/>
    </call-query>
</operation>
<query id="insert_customer_query" useConfig="MySQL">
    <sql>INSERT INTO customer(NID,Name,customerID) VALUES(?,?,?)</sql>
    <param name="NID" ordinal="1" paramType="SCALAR" sqlType="STRING" type="IN"/>
    <param name="Name" ordinal="2" paramType="SCALAR" sqlType="STRING" type="IN"/>
    <param name="customerID" ordinal="3" paramType="SCALAR" sqlType="STRING" type="IN"/>
</query>
<operation name="insert_customer_operation">
    <call-query href="insert_customer_query">
        <with-param name="Name" query-param="Name"/>
        <with-param name="customerID" query-param="customerID"/>
        <with-param name="NID" query-param="NID"/>
    </call-query>
</operation>
<query id="select_with_key_customer_query" useConfig="MySQL">
    <sql>SELECT NID, Name, customerID FROM customer WHERE customerID=?</sql>
    <param name="customerID" ordinal="1" paramType="SCALAR" sqlType="STRING" type="IN"/>
    <result element="customerCollection" rowName="customer">
        <element column="NID" name="NID" xsdType="xs:string"/>
        <element column="Name" name="Name" xsdType="xs:string"/>
        <element column="customerID" name="customerID" xsdType="xs:string"/>
    </result>
</query>
<operation name="select_with_key_customer_operation">
    <call-query href="select_with_key_customer_query">
        <with-param name="customerID" query-param="customerID"/>
    </call-query>
</operation>
<query id="select_all_customer_query" useConfig="MySQL">
    <sql>SELECT NID, Name, customerID FROM customer</sql>
    <result element="customerCollection" rowName="customer">
        <element column="NID" name="NID" xsdType="xs:string"/>
        <element column="Name" name="Name" xsdType="xs:string"/>
        <element column="customerID" name="customerID" xsdType="xs:string"/>
    </result>
</query>
<operation name="select_all_customer_operation">
    <call-query href="select_all_customer_query"/>
</operation>   
<query id="insert_customer_query1" useConfig="MySQL1">
    <sql>INSERT INTO user(NID,Name,customerID) VALUES(?,?,?)</sql>
    <param name="NID" ordinal="1" paramType="SCALAR" sqlType="STRING" type="IN"/>
    <param name="Name" ordinal="2" paramType="SCALAR" sqlType="STRING" type="IN"/>
    <param name="customerID" ordinal="3" paramType="SCALAR" sqlType="STRING" type="IN"/>
</query>
<operation name="insert_customer_operation1">
    <call-query href="insert_customer_query1">
        <with-param name="Name" query-param="Name"/>
        <with-param name="customerID" query-param="customerID"/>
        <with-param name="NID" query-param="NID"/>
    </call-query>
</operation>
<query id="select_with_key_customer_query1" useConfig="MySQL1">
    <sql>SELECT NID, Name, customerID FROM user WHERE customerID=?</sql>
    <param name="customerID" ordinal="1" paramType="SCALAR" sqlType="STRING" type="IN"/>
    <result element="customerCollection" rowName="user">
        <element column="NID" name="NID" xsdType="xs:string"/>
        <element column="Name" name="Name" xsdType="xs:string"/>
        <element column="customerID" name="customerID" xsdType="xs:string"/>
    </result>
</query>
<operation name="select_with_key_customer_operation1">
    <call-query href="select_with_key_customer_query1">
        <with-param name="customerID" query-param="customerID"/>
    </call-query>
</operation>
<query id="select_all_customer_query1" useConfig="MySQL1">
    <sql>SELECT NID, Name, customerID FROM user</sql>
    <result element="customerCollection" rowName="user">
        <element column="NID" name="NID" xsdType="xs:string"/>
        <element column="Name" name="Name" xsdType="xs:string"/>
        <element column="customerID" name="customerID" xsdType="xs:string"/>
    </result>
</query>
<operation name="select_all_customer_operation1">
    <call-query href="select_all_customer_query1"/>
</operation>
</data>
4

1 回答 1

1

看来您没有正确地将 MySQL 数据源配置为 XA 数据源。请在您的情况下将此示例配置用于“MySQL”数据源。

   <config id="MySQL">
     <property name="org.wso2.ws.dataservice.xa_datasource_class">com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</property>
      <property name="org.wso2.ws.dataservice.xa_datasource_properties">
         <property name="URL">dbc:mysql://localhost:3306/customersdatabase</property>
         <property name="User">root</property>
         <property name="Password">root123</property>
      </property>
   </config>

请从这里找到更多信息。

谢谢

查尼卡

于 2013-11-20T05:13:23.823 回答