Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如果分布式事务的协调者没有执行本地数据库操作会抛异常 Illegal state: maybe the try phase operation has timed out! #141

Open
mrglint opened this issue Sep 4, 2021 · 1 comment

Comments

@mrglint
Copy link

mrglint commented Sep 4, 2021

协调者如果没有执行本地数据库操作会抛异常。
回调该方法:org.bytesoft.bytetcc.CompensableTransactionImpl#onCommitSuccess,会抛出异常。
代码如下

private void onCompletionPhaseCommitSuccess(Xid actualXid) {
                //  this.archive.getCompensableXid() 返回空,将导致异常

		Xid expectXid = this.archive == null ? null : this.archive.getCompensableXid();
		byte[] expectKey = expectXid == null ? null : expectXid.getGlobalTransactionId();
		byte[] actualKey = actualXid.getGlobalTransactionId();
		if (Arrays.equals(expectKey, actualKey) == false) {
			// this.onInvocationPhaseParticipantCommitSuccess(actualXid);
			throw new IllegalStateException("Illegal state: maybe the try phase operation has timed out!");
		} // end-if (CommonUtils.equals(expectXid, actualXid) == false)

		if (this.positive == null) {
			this.beanFactory.getCompensableLogger().updateCompensable(this.archive);
			return;
		}

		if (this.positive) {
			logger.info("{}| confirm: identifier= {}, resourceKey= {}, resourceXid= {}.",
					ByteUtils.byteArrayToString(transactionContext.getXid().getGlobalTransactionId()),
					ByteUtils.byteArrayToString(this.archive.getIdentifier().getGlobalTransactionId()),
					this.archive.getCompensableResourceKey(), this.archive.getCompensableXid());

			this.archive.setConfirmed(true);
		} else {
			logger.info("{}| cancel: identifier= {}, resourceKey= {}, resourceXid= {}.",
					ByteUtils.byteArrayToString(transactionContext.getXid().getGlobalTransactionId()),
					ByteUtils.byteArrayToString(this.archive.getIdentifier().getGlobalTransactionId()),
					this.archive.getCompensableResourceKey(), this.archive.getCompensableXid());

			this.archive.setCancelled(true);
		}

		this.beanFactory.getCompensableLogger().updateCompensable(this.archive);
	}

因为只有在进行本地数据库操作时,this.archive 的 compensableXid 属性才会设置值,流程如下
image

@liuyangming
Copy link
Owner

该问题已被确认,并在0.5.11版本中予以修复,请更新至最新版本。谢谢反馈!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants