Giter VIP home page Giter VIP logo

dtmcli-java's People

Contributors

8q757 avatar babyfish-ct avatar catcherwong avatar horselk avatar li-xiao-shuang avatar yedf2 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dtmcli-java's Issues

dtmcli-core没有实现Saga模式下的空补偿,只实现了TCC模式下的空补偿

// pub.dtm.client.barrier.BranchBarrier#insertBarrier

private boolean insertBarrier(Connection connection) throws SQLException {
log.info("insert barrier {}", this);
if (Objects.isNull(connection)) {
return false;
}
PreparedStatement preparedStatement = null;
try {
String sql = "insert ignore into barrier(trans_type, gid, branch_id, op, barrier_id, reason) values(?,?,?,?,?,?)";
preparedStatement = connection.prepareStatement(sql);
preparedStatement.setString(1, this.getTransTypeEnum().getValue());
preparedStatement.setString(2, this.getGid());
preparedStatement.setString(3, branchId);
preparedStatement.setString(4, op);
preparedStatement.setString(5, String.format("%02d", barrierId));
preparedStatement.setString(6, op);

        if (preparedStatement.executeUpdate() == 0) {
            return false;
        }
        if (ParamFieldConstants.CANCEL.equals(op)) {
            int opIndex = 4;
            preparedStatement.setString(opIndex, ParamFieldConstants.TRY);
            if (preparedStatement.executeUpdate() > 0) {
                return false;
            }
        }
    } finally {
        if (Objects.nonNull(preparedStatement)) {
            preparedStatement.close();
        }
    }
    return true;
}

这个地方,只判断了ParamFieldConstants.CANCEL.equals(op),而Saga模式的补偿op是compensate,不是cancel

tcc:get response.body().string() closed

tcc模式下想要解析 response的body内容
但response.body().string()只能请求一次,在dtm内已经调用过此方法
请问是否还有其他解决方案可以获取返回值吗?

public static void checkResult(Response response) throws Exception { if (response.code() >= 400) { throw new FailureException(response.message()); } else { ResponseBody body = response.body(); String result; if (body != null && !StringUtils.isBlank(result = body.string())) { if (result.contains("FAILURE")) { throw new FailureException("Service returned failed"); } } else { throw new FailureException("response is null"); } } }

missing java-sample-demo sql script

CREATE TABLE barrier (
id bigint NOT NULL AUTO_INCREMENT,
user_id int DEFAULT NULL,
amount int DEFAULT NULL,
trans_type varchar(255) DEFAULT NULL,
gid varchar(100) DEFAULT NULL,
branch_id varchar(100) DEFAULT NULL,
op varchar(255) DEFAULT NULL,
barrier_id varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL,
reason varchar(255) DEFAULT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

阅读代码发现的4个问题

看了一下Java SDK的源码,发现如下几个问题(由大到小排序)

---大问题---

  1. 为完成本地事务屏障,私自打开和关闭JDBC链接,导致和原有Spring 的连接/事务管理功能脱钩。实际项目中,用户代码不太可能直接基于指定的JDBC连接执行,一般是基于Spring技术栈提供的更高级的数据访问技术操作,这会导致SDK保证事务屏障的JDBC连接和实际业务的连接并非同一连接。

---小问题---

  1. 本地事务屏障只支持MySQL

  2. 不会自动创建barrier表

BUG: tcc query-string

BUG:
FILE: tcc.java

HttpResponse response2 = HttpRequest.post(tryUrl)
                    .body(JSONUtil.toJsonStr(body))
                    .form(paramMap2) // HERE
                    .execute();

maybe FIX :

            HttpResponse response2 = HttpRequest.post(tryUrl + "?" + mapToQueryString(paramMap2))
                    .body(JSONUtil.toJsonStr(body))
                    //.form(paramMap2)
                    .execute();

  private static String mapToQueryString(Map<String, Object> queryParams) {
        String queryString = queryParams.entrySet().stream()
                .map(e -> e.getKey() + "=" + e.getValue())
                .collect(Collectors.joining("&"));
        return URLUtil.encode(queryString);
    }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.