Search in sources :

Example 1 with BranchRollbackResponse

use of io.seata.core.protocol.transaction.BranchRollbackResponse in project seata by seata.

the class RmBranchRollbackProcessor method handleBranchRollback.

private void handleBranchRollback(RpcMessage request, String serverAddress, BranchRollbackRequest branchRollbackRequest) {
    BranchRollbackResponse resultMessage;
    resultMessage = (BranchRollbackResponse) handler.onRequest(branchRollbackRequest, null);
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("branch rollback result:" + resultMessage);
    }
    try {
        this.remotingClient.sendAsyncResponse(serverAddress, request, resultMessage);
    } catch (Throwable throwable) {
        LOGGER.error("send response error: {}", throwable.getMessage(), throwable);
    }
}
Also used : BranchRollbackResponse(io.seata.core.protocol.transaction.BranchRollbackResponse)

Example 2 with BranchRollbackResponse

use of io.seata.core.protocol.transaction.BranchRollbackResponse in project seata by seata.

the class BranchRollbackResponseSerializerTest method test_codec.

/**
 * Test codec.
 */
@Test
public void test_codec() {
    BranchRollbackResponse branchRollbackResponse = new BranchRollbackResponse();
    branchRollbackResponse.setBranchId(112232);
    branchRollbackResponse.setXid("123");
    branchRollbackResponse.setBranchStatus(BranchStatus.PhaseOne_Done);
    branchRollbackResponse.setResultCode(ResultCode.Success);
    branchRollbackResponse.setMsg("abc");
    branchRollbackResponse.setTransactionExceptionCode(TransactionExceptionCode.BranchTransactionNotExist);
    byte[] bytes = seataSerializer.serialize(branchRollbackResponse);
    BranchRollbackResponse branchRollbackResponse2 = seataSerializer.deserialize(bytes);
    assertThat(branchRollbackResponse2.getBranchId()).isEqualTo(branchRollbackResponse.getBranchId());
    assertThat(branchRollbackResponse2.getBranchStatus()).isEqualTo(branchRollbackResponse.getBranchStatus());
    assertThat(branchRollbackResponse2.getResultCode()).isEqualTo(branchRollbackResponse.getResultCode());
    assertThat(branchRollbackResponse2.getXid()).isEqualTo(branchRollbackResponse.getXid());
    assertThat(branchRollbackResponse2.getBranchStatus()).isEqualTo(branchRollbackResponse.getBranchStatus());
    assertThat(branchRollbackResponse2.getTransactionExceptionCode()).isEqualTo(branchRollbackResponse.getTransactionExceptionCode());
}
Also used : BranchRollbackResponse(io.seata.core.protocol.transaction.BranchRollbackResponse) Test(org.junit.jupiter.api.Test)

Example 3 with BranchRollbackResponse

use of io.seata.core.protocol.transaction.BranchRollbackResponse in project seata by seata.

the class BranchRollbackResponseConvertor method convert2Model.

@Override
public BranchRollbackResponse convert2Model(BranchRollbackResponseProto branchRollbackResponseProto) {
    BranchRollbackResponse branchCommitResponse = new BranchRollbackResponse();
    branchCommitResponse.setBranchId(branchRollbackResponseProto.getAbstractBranchEndResponse().getBranchId());
    branchCommitResponse.setBranchStatus(BranchStatus.get(branchRollbackResponseProto.getAbstractBranchEndResponse().getBranchStatusValue()));
    branchCommitResponse.setXid(branchRollbackResponseProto.getAbstractBranchEndResponse().getXid());
    branchCommitResponse.setMsg(branchRollbackResponseProto.getAbstractBranchEndResponse().getAbstractTransactionResponse().getAbstractResultMessage().getMsg());
    branchCommitResponse.setResultCode(ResultCode.valueOf(branchRollbackResponseProto.getAbstractBranchEndResponse().getAbstractTransactionResponse().getAbstractResultMessage().getResultCode().name()));
    branchCommitResponse.setTransactionExceptionCode(TransactionExceptionCode.valueOf(branchRollbackResponseProto.getAbstractBranchEndResponse().getAbstractTransactionResponse().getTransactionExceptionCode().name()));
    return branchCommitResponse;
}
Also used : BranchRollbackResponse(io.seata.core.protocol.transaction.BranchRollbackResponse)

Example 4 with BranchRollbackResponse

use of io.seata.core.protocol.transaction.BranchRollbackResponse in project seata by seata.

the class BranchRollbackResponseConvertorTest method convert2Proto.

@Test
public void convert2Proto() {
    BranchRollbackResponse branchRollbackResponse = new BranchRollbackResponse();
    branchRollbackResponse.setTransactionExceptionCode(TransactionExceptionCode.BranchTransactionNotExist);
    branchRollbackResponse.setResultCode(ResultCode.Success);
    branchRollbackResponse.setMsg("xx");
    branchRollbackResponse.setXid("xid");
    branchRollbackResponse.setBranchStatus(BranchStatus.PhaseTwo_Rollbacked);
    branchRollbackResponse.setBranchId(123);
    BranchRollbackResponseConvertor convertor = new BranchRollbackResponseConvertor();
    BranchRollbackResponseProto proto = convertor.convert2Proto(branchRollbackResponse);
    BranchRollbackResponse real = convertor.convert2Model(proto);
    assertThat(real.getTypeCode()).isEqualTo(branchRollbackResponse.getTypeCode());
    assertThat(real.getMsg()).isEqualTo(branchRollbackResponse.getMsg());
    assertThat(real.getXid()).isEqualTo(branchRollbackResponse.getXid());
    assertThat(real.getTransactionExceptionCode()).isEqualTo(branchRollbackResponse.getTransactionExceptionCode());
    assertThat(real.getBranchStatus()).isEqualTo(branchRollbackResponse.getBranchStatus());
    assertThat(real.getResultCode()).isEqualTo(branchRollbackResponse.getResultCode());
}
Also used : BranchRollbackResponseProto(io.seata.serializer.protobuf.generated.BranchRollbackResponseProto) BranchRollbackResponse(io.seata.core.protocol.transaction.BranchRollbackResponse) Test(org.junit.jupiter.api.Test)

Example 5 with BranchRollbackResponse

use of io.seata.core.protocol.transaction.BranchRollbackResponse in project XHuiCloud by sindaZeng.

the class SagaCore method branchRollbackSend.

@Override
public BranchStatus branchRollbackSend(BranchRollbackRequest request, GlobalSession globalSession, BranchSession branchSession) throws IOException, TimeoutException {
    Map<String, Channel> channels = ChannelManager.getRmChannels();
    if (CollectionUtils.isEmpty(channels)) {
        LOGGER.error("Failed to rollback SAGA global[" + globalSession.getXid() + ", RM channels is empty.");
        return BranchStatus.PhaseTwo_RollbackFailed_Retryable;
    }
    String sagaResourceId = getSagaResourceId(globalSession);
    Channel sagaChannel = channels.get(sagaResourceId);
    if (sagaChannel == null) {
        LOGGER.error("Failed to rollback SAGA global[" + globalSession.getXid() + ", cannot find channel by resourceId[" + sagaResourceId + "]");
        return BranchStatus.PhaseTwo_RollbackFailed_Retryable;
    }
    BranchRollbackResponse response = (BranchRollbackResponse) remotingServer.sendSyncRequest(sagaChannel, request);
    return response.getBranchStatus();
}
Also used : Channel(io.netty.channel.Channel) BranchRollbackResponse(io.seata.core.protocol.transaction.BranchRollbackResponse)

Aggregations

BranchRollbackResponse (io.seata.core.protocol.transaction.BranchRollbackResponse)7 Channel (io.netty.channel.Channel)2 Test (org.junit.jupiter.api.Test)2 TransactionException (io.seata.core.exception.TransactionException)1 BranchRollbackRequest (io.seata.core.protocol.transaction.BranchRollbackRequest)1 BranchRollbackResponseProto (io.seata.serializer.protobuf.generated.BranchRollbackResponseProto)1