【问题标题】:XA transactions in Ballerina with mysqlBallerina 中的 XA 事务与 mysql
【发布时间】:2018-07-12 05:16:17
【问题描述】:

尝试使用 mysql 而不是 h2 来遵循 [1]。但是,在事务块之间添加它时似乎存在问题。在 bre/lib 文件夹下包含了 mysql lib。以下是端点定义和事务块。在创建表后运行 .bal 文件时,会启动一个事务,但随后它会直接重试事务并最终中止它。知道这里缺少什么吗? [1]https://ballerina.io/learn/by-example/xa-transactions.html

endpoint mysql:Client testDB1 {
    host: "localhost",
    port: 3306,
    name: "customerdb",
    username: "root",
    password: "root",
    poolOptions: { maximumPoolSize: 5, isXA:true },
    dbOptions: { useSSL: false }
};

endpoint mysql:Client testDB2 {
    host: "localhost",
    port: 3306,
    name: "salarydb",
    username: "root",
    password: "root",
    poolOptions: { maximumPoolSize: 5, isXA:true },
    dbOptions: { useSSL: false }
};


  transaction with retries = 3, oncommit = onCommitFunction, onabort = onAbortFunction {
      var retWithKey = testDB1->updateWithGeneratedKeys("INSERT INTO
                                CUSTOMER(NAME) VALUES ('Anne')", ());
        string generatedKey;
        match retWithKey {
            (int, string[]) y => {
                var (count, ids) = y;
                generatedKey = ids[0];
                io:println("Inserted row count: " + count);
                io:println("Generated key: " + generatedKey);
            }
            error err => io:println("Insert to customer table failed: "
                                    + err.message);
        }

        ret = <int>generatedKey;
        int key = -1;
        match ret {
            int retInt => key = retInt;
            error err => io:println("Converting key to string failed: "
                                    + err.message);
        }
        io:println("Generated key for the inserted row: " + key);

        ret = testDB2->update("INSERT INTO SALARY (ID, VALUE)
                               VALUES (?, ?)", key, 2500);
        handleUpdate(ret, "Insert to SALARY table");


   } onretry {
       io:println("Retrying transaction");
   }

【问题讨论】:

    标签: ballerina


    【解决方案1】:

    当您尝试对同一服务器中的两个数据库执行 XA 事务时,会发生这种情况。这是 [1] 中报告的已知问题。正如 [1] 中所解释的,找到了此问题背后的根本原因,但由于 mysql 端的错误 [2],建议的解决方案在 mysql 上不起作用。我们将进一步调查此问题。

    [1]https://github.com/ballerina-platform/ballerina-lang/issues/7963

    [2]https://bugs.mysql.com/bug.php?id=78498

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-07
      • 2012-12-19
      • 1970-01-01
      • 2014-04-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多