Skip to content

Commit

Permalink
update to v1.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
yedongfu committed Nov 8, 2021
1 parent d87912e commit 2c22bb1
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 14 deletions.
18 changes: 9 additions & 9 deletions dtmcli/barrier.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ def __exit__(self, type, value, trace):


class BranchBarrier(object):
def __init__(self, trans_type, gid, branch_id, branch_type):
def __init__(self, trans_type, gid, branch_id, op):
self.trans_type = trans_type
self.gid = gid
self.branch_id = branch_id
self.branch_type = branch_type
self.op = op
self.barrier_id = 0
def call(self, cursor, busi_callback):
self.barrier_id = self.barrier_id + 1
Expand All @@ -28,12 +28,12 @@ def call(self, cursor, busi_callback):
orgin_branch = {
"cancel": "try",
"compensate": "action",
}.get(self.branch_type, "")
origin_affected = insert_barrier(cursor, self.trans_type, self.gid, self.branch_id, orgin_branch, bid, self.branch_type)
current_affected = insert_barrier(cursor, self.trans_type, self.gid, self.branch_id, self.branch_type, bid, self.branch_type)
}.get(self.op, "")
origin_affected = insert_barrier(cursor, self.trans_type, self.gid, self.branch_id, orgin_branch, bid, self.op)
current_affected = insert_barrier(cursor, self.trans_type, self.gid, self.branch_id, self.op, bid, self.op)
print("origin_affected: %d, current_affected: %d" % (origin_affected, current_affected))
# origin_affected > 0 这个是空补偿; current_affected == 0 这个是重复请求或悬挂
if (self.branch_type == "cancel" or self.branch_type == "compensate") and origin_affected > 0 or current_affected == 0:
if (self.op == "cancel" or self.op == "compensate") and origin_affected > 0 or current_affected == 0:
return None
busi_callback(cursor)
cursor.connection.commit()
Expand All @@ -42,7 +42,7 @@ def call(self, cursor, busi_callback):
raise

# return affected_rows
def insert_barrier(cursor, trans_type, gid, branch_id, branch_type, barrier_id, reason):
if branch_type == "":
def insert_barrier(cursor, trans_type, gid, branch_id, op, barrier_id, reason):
if op == "":
return 0
return utils.sqlexec(cursor, "insert ignore into dtm_barrier.barrier(trans_type, gid, branch_id, branch_type, barrier_id, reason) values('%s','%s','%s','%s','%s','%s')" % (trans_type, gid, branch_id, branch_type, barrier_id, reason))
return utils.sqlexec(cursor, "insert ignore into dtm_barrier.barrier(trans_type, gid, branch_id, op, barrier_id, reason) values('%s','%s','%s','%s','%s','%s')" % (trans_type, gid, branch_id, op, barrier_id, reason))
5 changes: 2 additions & 3 deletions dtmcli/tcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@ def __init__(self, dtmUrl, gid):
self.id_generator = utils.IdGenerator()
def call_branch(self, body, tryUrl, confirmUrl, cancalUrl):
branch_id = self.id_generator.new_branch_id()
r = requests.post(self.dtm + "/registerTccBranch", json={
r = requests.post(self.dtm + "/registerBranch", json={
"gid": self.gid,
"branch_id": branch_id,
"trans_type": "tcc",
"status": "prepared",
"data": json.dumps(body),
"try": tryUrl,
"confirm": confirmUrl,
"cancel": cancalUrl,
})
Expand All @@ -29,7 +28,7 @@ def call_branch(self, body, tryUrl, confirmUrl, cancalUrl):
"gid": self.gid,
"trans_type": "tcc",
"branch_id": branch_id,
"branch_type": "try",
"op": "try",
})
utils.check_result(r)
return r
Expand Down
5 changes: 5 additions & 0 deletions publish.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# 发版说明

1. 修改版本号
2. `python3 setup.py sdist bdist_wheel`
3. `twine upload dist/dtmcli- #指定到具体版本`
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

setuptools.setup(
name="dtmcli",
version="0.2.1",
version="1.5.0",
author="yedf2",
author_email="dongfuye@163.com",
author_email="120050102@qq.com",
description="python client for dtm",
long_description=long_description,
long_description_content_type="text/markdown",
Expand Down

0 comments on commit 2c22bb1

Please sign in to comment.