Skip to content

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

@ipwwp-git

Description

@ipwwp-git

// 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions