Skip to content

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

@mrglint

Description

@mrglint

协调者如果没有执行本地数据库操作会抛异常。
回调该方法: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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions