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;
}
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;
}
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());
}
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());
}
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);
}
}
Aggregations