Search in sources :

Example 1 with UndoLogDeleteRequest

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());
        }
    }
}
Also used : Channel(io.netty.channel.Channel) UndoLogDeleteRequest(io.seata.core.protocol.transaction.UndoLogDeleteRequest) Map(java.util.Map) TransactionException(io.seata.core.exception.TransactionException)

Example 2 with UndoLogDeleteRequest

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());
}
Also used : UndoLogDeleteRequest(io.seata.core.protocol.transaction.UndoLogDeleteRequest) Test(org.junit.jupiter.api.Test)

Example 3 with UndoLogDeleteRequest

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());
}
Also used : UndoLogDeleteRequest(io.seata.core.protocol.transaction.UndoLogDeleteRequest)

Example 4 with UndoLogDeleteRequest

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);
}
Also used : BranchType(io.seata.core.model.BranchType) UndoLogDeleteRequest(io.seata.core.protocol.transaction.UndoLogDeleteRequest)

Example 5 with UndoLogDeleteRequest

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());
}
Also used : UndoLogDeleteRequest(io.seata.core.protocol.transaction.UndoLogDeleteRequest) UndoLogDeleteRequestProto(io.seata.serializer.protobuf.generated.UndoLogDeleteRequestProto) Test(org.junit.jupiter.api.Test)

Aggregations

UndoLogDeleteRequest (io.seata.core.protocol.transaction.UndoLogDeleteRequest)6 Test (org.junit.jupiter.api.Test)2 Channel (io.netty.channel.Channel)1 TransactionException (io.seata.core.exception.TransactionException)1 BranchType (io.seata.core.model.BranchType)1 UndoLogDeleteRequestProto (io.seata.serializer.protobuf.generated.UndoLogDeleteRequestProto)1 Map (java.util.Map)1