use of io.seata.core.protocol.transaction.UndoLogDeleteRequest in project seata by seata.
the class DefaultCoordinator method undoLogDelete.
/**
* Undo log delete.
*/
protected void undoLogDelete() {
Map<String, Channel> rmChannels = ChannelManager.getRmChannels();
if (rmChannels == null || rmChannels.isEmpty()) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("no active rm channels to delete undo log");
}
return;
}
short saveDays = CONFIG.getShort(ConfigurationKeys.TRANSACTION_UNDO_LOG_SAVE_DAYS, UndoLogDeleteRequest.DEFAULT_SAVE_DAYS);
for (Map.Entry<String, Channel> channelEntry : rmChannels.entrySet()) {
String resourceId = channelEntry.getKey();
UndoLogDeleteRequest deleteRequest = new UndoLogDeleteRequest();
deleteRequest.setResourceId(resourceId);
deleteRequest.setSaveDays(saveDays > 0 ? saveDays : UndoLogDeleteRequest.DEFAULT_SAVE_DAYS);
try {
remotingServer.sendAsyncRequest(channelEntry.getValue(), deleteRequest);
} catch (Exception e) {
LOGGER.error("Failed to async delete undo log resourceId = {}, exception: {}", resourceId, e.getMessage());
}
}
}
use of io.seata.core.protocol.transaction.UndoLogDeleteRequest in project seata by seata.
the class UndoLogDeleteRequestSerializerTest method test_codec.
/**
* Test codec.
*/
@Test
public void test_codec() {
UndoLogDeleteRequest logDeleteRequest1 = new UndoLogDeleteRequest();
logDeleteRequest1.setBranchType(BranchType.AT);
logDeleteRequest1.setResourceId("t");
logDeleteRequest1.setSaveDays((short) 7);
byte[] bytes = seataSerializer.serialize(logDeleteRequest1);
UndoLogDeleteRequest logDeleteRequest2 = seataSerializer.deserialize(bytes);
assertThat(logDeleteRequest2.getBranchType()).isEqualTo(logDeleteRequest1.getBranchType());
assertThat(logDeleteRequest2.getResourceId()).isEqualTo(logDeleteRequest1.getResourceId());
assertThat(logDeleteRequest2.getSaveDays()).isEqualTo(logDeleteRequest1.getSaveDays());
}
use of io.seata.core.protocol.transaction.UndoLogDeleteRequest in project seata by seata.
the class UndoLogDeleteRequestCodec method decode.
@Override
public <T> void decode(T t, ByteBuffer in) {
UndoLogDeleteRequest undoLogDeleteRequest = (UndoLogDeleteRequest) t;
if (in.remaining() < 1) {
return;
}
undoLogDeleteRequest.setBranchType(BranchType.get(in.get()));
if (in.remaining() < 2) {
return;
}
int resourceIdLen = in.getShort();
if (resourceIdLen <= 0 || in.remaining() < resourceIdLen) {
return;
}
byte[] bs = new byte[resourceIdLen];
in.get(bs);
undoLogDeleteRequest.setResourceId(new String(bs, UTF8));
if (in.remaining() < 2) {
return;
}
undoLogDeleteRequest.setSaveDays(in.getShort());
}
use of io.seata.core.protocol.transaction.UndoLogDeleteRequest in project seata by seata.
the class UndoLogDeleteRequestCodec method encode.
@Override
public <T> void encode(T t, ByteBuf out) {
UndoLogDeleteRequest undoLogDeleteRequest = (UndoLogDeleteRequest) t;
short saveDays = undoLogDeleteRequest.getSaveDays();
BranchType branchType = undoLogDeleteRequest.getBranchType();
String resourceId = undoLogDeleteRequest.getResourceId();
// 1. Branch Type
out.writeByte((byte) branchType.ordinal());
// 2. Resource Id
if (resourceId != null) {
byte[] bs = resourceId.getBytes(UTF8);
out.writeShort((short) bs.length);
if (bs.length > 0) {
out.writeBytes(bs);
}
} else {
out.writeShort((short) 0);
}
// 3.save days
out.writeShort(saveDays);
}
use of io.seata.core.protocol.transaction.UndoLogDeleteRequest in project seata by seata.
the class UndoLogDeleteRequestConvertorTest method convert2Proto.
@Test
public void convert2Proto() {
UndoLogDeleteRequest undoLogDeleteRequest = new UndoLogDeleteRequest();
undoLogDeleteRequest.setBranchType(BranchType.AT);
undoLogDeleteRequest.setResourceId(RESOURCE_ID);
undoLogDeleteRequest.setSaveDays(SAVE_DAYS);
UndoLogDeleteRequestConvertor undoLogDeleteRequestConvertor = new UndoLogDeleteRequestConvertor();
UndoLogDeleteRequestProto proto = undoLogDeleteRequestConvertor.convert2Proto(undoLogDeleteRequest);
UndoLogDeleteRequest realRequest = undoLogDeleteRequestConvertor.convert2Model(proto);
assertThat(realRequest.getTypeCode()).isEqualTo(undoLogDeleteRequest.getTypeCode());
assertThat(realRequest.getBranchType()).isEqualTo(undoLogDeleteRequest.getBranchType());
assertThat(realRequest.getResourceId()).isEqualTo(undoLogDeleteRequest.getResourceId());
assertThat(realRequest.getSaveDays()).isEqualTo(undoLogDeleteRequest.getSaveDays());
}
Aggregations