Search in sources :

Example 1 with GlobalLockQueryRequest

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

the class AbstractTCInboundHandler method handle.

@Override
public GlobalLockQueryResponse handle(GlobalLockQueryRequest request, final RpcContext rpcContext) {
    GlobalLockQueryResponse response = new GlobalLockQueryResponse();
    exceptionHandleTemplate(new AbstractCallback<GlobalLockQueryRequest, GlobalLockQueryResponse>() {

        @Override
        public void execute(GlobalLockQueryRequest request, GlobalLockQueryResponse response) throws TransactionException {
            try {
                doLockCheck(request, response, rpcContext);
            } catch (StoreException e) {
                throw new TransactionException(TransactionExceptionCode.FailedStore, String.format("global lock query request failed. xid=%s, msg=%s", request.getXid(), e.getMessage()), e);
            }
        }
    }, request, response);
    return response;
}
Also used : TransactionException(io.seata.core.exception.TransactionException) GlobalLockQueryRequest(io.seata.core.protocol.transaction.GlobalLockQueryRequest) GlobalLockQueryResponse(io.seata.core.protocol.transaction.GlobalLockQueryResponse) StoreException(io.seata.common.exception.StoreException)

Example 2 with GlobalLockQueryRequest

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

the class GlobalLockQueryRequestConvertor method convert2Model.

@Override
public GlobalLockQueryRequest convert2Model(GlobalLockQueryRequestProto globalLockQueryRequestProto) {
    GlobalLockQueryRequest branchRegisterRequest = new GlobalLockQueryRequest();
    BranchRegisterRequestProto branchRegisterRequestProto = globalLockQueryRequestProto.getBranchRegisterRequest();
    branchRegisterRequest.setApplicationData(branchRegisterRequestProto.getApplicationData());
    branchRegisterRequest.setBranchType(BranchType.valueOf(branchRegisterRequestProto.getBranchType().name()));
    branchRegisterRequest.setLockKey(branchRegisterRequestProto.getLockKey());
    branchRegisterRequest.setResourceId(branchRegisterRequestProto.getResourceId());
    branchRegisterRequest.setXid(branchRegisterRequestProto.getXid());
    return branchRegisterRequest;
}
Also used : GlobalLockQueryRequest(io.seata.core.protocol.transaction.GlobalLockQueryRequest) BranchRegisterRequestProto(io.seata.serializer.protobuf.generated.BranchRegisterRequestProto)

Example 3 with GlobalLockQueryRequest

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

the class GlobalLockQueryRequestConvertorTest method convert2Proto.

@Test
public void convert2Proto() {
    GlobalLockQueryRequest globalLockQueryRequest = new GlobalLockQueryRequest();
    globalLockQueryRequest.setApplicationData("data");
    globalLockQueryRequest.setBranchType(BranchType.AT);
    globalLockQueryRequest.setLockKey("localKey");
    globalLockQueryRequest.setResourceId("resourceId");
    globalLockQueryRequest.setXid("xid");
    GlobalLockQueryRequestConvertor convertor = new GlobalLockQueryRequestConvertor();
    GlobalLockQueryRequestProto proto = convertor.convert2Proto(globalLockQueryRequest);
    GlobalLockQueryRequest real = convertor.convert2Model(proto);
    assertThat(real.getTypeCode()).isEqualTo(globalLockQueryRequest.getTypeCode());
    assertThat(real.getApplicationData()).isEqualTo(globalLockQueryRequest.getApplicationData());
    assertThat(real.getXid()).isEqualTo(globalLockQueryRequest.getXid());
    assertThat(real.getBranchType()).isEqualTo(globalLockQueryRequest.getBranchType());
    assertThat(real.getLockKey()).isEqualTo(globalLockQueryRequest.getLockKey());
    assertThat(real.getResourceId()).isEqualTo(globalLockQueryRequest.getResourceId());
}
Also used : GlobalLockQueryRequest(io.seata.core.protocol.transaction.GlobalLockQueryRequest) GlobalLockQueryRequestProto(io.seata.serializer.protobuf.generated.GlobalLockQueryRequestProto) Test(org.junit.jupiter.api.Test)

Example 4 with GlobalLockQueryRequest

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

the class GlobalLockQueryRequestSerializerTest method test_codec.

/**
 * Test codec.
 */
@Test
public void test_codec() {
    GlobalLockQueryRequest globalLockQueryRequest = new GlobalLockQueryRequest();
    globalLockQueryRequest.setApplicationData("aaaa");
    globalLockQueryRequest.setBranchType(BranchType.TCC);
    globalLockQueryRequest.setLockKey("a:1,b,2");
    globalLockQueryRequest.setXid("aaa");
    globalLockQueryRequest.setResourceId("1s");
    byte[] bytes = seataSerializer.serialize(globalLockQueryRequest);
    GlobalLockQueryRequest globalLockQueryRequest2 = seataSerializer.deserialize(bytes);
    assertThat(globalLockQueryRequest2.getApplicationData()).isEqualTo(globalLockQueryRequest.getApplicationData());
    assertThat(globalLockQueryRequest2.getBranchType()).isEqualTo(globalLockQueryRequest.getBranchType());
    assertThat(globalLockQueryRequest2.getLockKey()).isEqualTo(globalLockQueryRequest.getLockKey());
    assertThat(globalLockQueryRequest2.getResourceId()).isEqualTo(globalLockQueryRequest.getResourceId());
    assertThat(globalLockQueryRequest2.getXid()).isEqualTo(globalLockQueryRequest.getXid());
}
Also used : GlobalLockQueryRequest(io.seata.core.protocol.transaction.GlobalLockQueryRequest) Test(org.junit.jupiter.api.Test)

Example 5 with GlobalLockQueryRequest

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

the class DataSourceManager method lockQuery.

@Override
public boolean lockQuery(BranchType branchType, String resourceId, String xid, String lockKeys) throws TransactionException {
    GlobalLockQueryRequest request = new GlobalLockQueryRequest();
    request.setXid(xid);
    request.setLockKey(lockKeys);
    request.setResourceId(resourceId);
    try {
        GlobalLockQueryResponse response;
        if (RootContext.inGlobalTransaction() || RootContext.requireGlobalLock()) {
            response = (GlobalLockQueryResponse) RmNettyRemotingClient.getInstance().sendSyncRequest(request);
        } else {
            throw new RuntimeException("unknow situation!");
        }
        if (response.getResultCode() == ResultCode.Failed) {
            throw new TransactionException(response.getTransactionExceptionCode(), "Response[" + response.getMsg() + "]");
        }
        return response.isLockable();
    } catch (TimeoutException toe) {
        throw new RmTransactionException(TransactionExceptionCode.IO, "RPC Timeout", toe);
    } catch (RuntimeException rex) {
        throw new RmTransactionException(TransactionExceptionCode.LockableCheckFailed, "Runtime", rex);
    }
}
Also used : TransactionException(io.seata.core.exception.TransactionException) RmTransactionException(io.seata.core.exception.RmTransactionException) GlobalLockQueryRequest(io.seata.core.protocol.transaction.GlobalLockQueryRequest) RmTransactionException(io.seata.core.exception.RmTransactionException) GlobalLockQueryResponse(io.seata.core.protocol.transaction.GlobalLockQueryResponse) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

GlobalLockQueryRequest (io.seata.core.protocol.transaction.GlobalLockQueryRequest)5 TransactionException (io.seata.core.exception.TransactionException)2 GlobalLockQueryResponse (io.seata.core.protocol.transaction.GlobalLockQueryResponse)2 Test (org.junit.jupiter.api.Test)2 StoreException (io.seata.common.exception.StoreException)1 RmTransactionException (io.seata.core.exception.RmTransactionException)1 BranchRegisterRequestProto (io.seata.serializer.protobuf.generated.BranchRegisterRequestProto)1 GlobalLockQueryRequestProto (io.seata.serializer.protobuf.generated.GlobalLockQueryRequestProto)1 TimeoutException (java.util.concurrent.TimeoutException)1