0

尝试使用 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");
   }
4

1 回答 1

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

于 2018-07-13T08:03:02.697 回答