Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions dledger/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@
<dependency>
<groupId>org.apache.rocketmq</groupId>
<artifactId>rocketmq-remoting</artifactId>
<exclusions>
<exclusion>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2</artifactId>
<version>2.0.59</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package io.openmessaging.storage.dledger;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson2.JSON;
import io.openmessaging.storage.dledger.common.Closure;
import io.openmessaging.storage.dledger.common.ShutdownAbleThread;
import io.openmessaging.storage.dledger.common.Status;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package io.openmessaging.storage.dledger;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson2.JSON;
import io.openmessaging.storage.dledger.common.ShutdownAbleThread;
import io.openmessaging.storage.dledger.protocol.DLedgerResponseCode;
import io.openmessaging.storage.dledger.protocol.HeartBeatRequest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package io.openmessaging.storage.dledger;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson2.JSON;
import io.netty.channel.ChannelHandlerContext;
import io.openmessaging.storage.dledger.common.NamedThreadFactory;
import io.openmessaging.storage.dledger.protocol.AppendEntryRequest;
Expand Down Expand Up @@ -52,11 +52,13 @@
import java.util.concurrent.Executors;

import org.apache.rocketmq.remoting.ChannelEventListener;
import org.apache.rocketmq.remoting.InvokeCallback;
import org.apache.rocketmq.remoting.netty.NettyClientConfig;
import org.apache.rocketmq.remoting.netty.NettyRemotingClient;
import org.apache.rocketmq.remoting.netty.NettyRemotingServer;
import org.apache.rocketmq.remoting.netty.NettyRequestProcessor;
import org.apache.rocketmq.remoting.netty.NettyServerConfig;
import org.apache.rocketmq.remoting.netty.ResponseFuture;
import org.apache.rocketmq.remoting.protocol.RemotingCommand;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -156,13 +158,22 @@ public CompletableFuture<HeartBeatResponse> heartBeat(HeartBeatRequest request)
try {
RemotingCommand wrapperRequest = RemotingCommand.createRequestCommand(DLedgerRequestCode.HEART_BEAT.getCode(), null);
wrapperRequest.setBody(JSON.toJSONBytes(request));
remotingClient.invokeAsync(getPeerAddr(request.getGroup(), request.getRemoteId()), wrapperRequest, 3000, responseFuture -> {
RemotingCommand responseCommand = responseFuture.getResponseCommand();
if (responseCommand != null) {
HeartBeatResponse response = JSON.parseObject(responseCommand.getBody(), HeartBeatResponse.class);
future.complete(response);
} else {
LOGGER.error("HeartBeat request time out, {}", request.baseInfo());
remotingClient.invokeAsync(getPeerAddr(request.getGroup(), request.getRemoteId()), wrapperRequest, 3000, new InvokeCallback() {
@Override
public void operationComplete(ResponseFuture responseFuture) {
RemotingCommand responseCommand = responseFuture.getResponseCommand();
if (responseCommand != null) {
HeartBeatResponse response = JSON.parseObject(responseCommand.getBody(), HeartBeatResponse.class);
future.complete(response);
} else {
LOGGER.error("HeartBeat request time out, {}", request.baseInfo());
future.complete(new HeartBeatResponse().code(DLedgerResponseCode.NETWORK_ERROR.getCode()));
}
}

@Override
public void operationFail(Throwable throwable) {
LOGGER.error("HeartBeat request failed due to network error, {}", request.baseInfo(), throwable);
future.complete(new HeartBeatResponse().code(DLedgerResponseCode.NETWORK_ERROR.getCode()));
}
});
Expand All @@ -181,13 +192,22 @@ public CompletableFuture<VoteResponse> vote(VoteRequest request) {
try {
RemotingCommand wrapperRequest = RemotingCommand.createRequestCommand(DLedgerRequestCode.VOTE.getCode(), null);
wrapperRequest.setBody(JSON.toJSONBytes(request));
this.remotingClient.invokeAsync(getPeerAddr(request.getGroup(), request.getRemoteId()), wrapperRequest, 3000, responseFuture -> {
RemotingCommand responseCommand = responseFuture.getResponseCommand();
if (responseCommand != null) {
VoteResponse response = JSON.parseObject(responseCommand.getBody(), VoteResponse.class);
future.complete(response);
} else {
LOGGER.error("Vote request time out, {}", request.baseInfo());
this.remotingClient.invokeAsync(getPeerAddr(request.getGroup(), request.getRemoteId()), wrapperRequest, 3000, new InvokeCallback() {
@Override
public void operationComplete(ResponseFuture responseFuture) {
RemotingCommand responseCommand = responseFuture.getResponseCommand();
if (responseCommand != null) {
VoteResponse response = JSON.parseObject(responseCommand.getBody(), VoteResponse.class);
future.complete(response);
} else {
LOGGER.error("Vote request time out, {}", request.baseInfo());
future.complete(new VoteResponse());
}
}

@Override
public void operationFail(Throwable throwable) {
LOGGER.error("Vote request failed due to network error, {}", request.baseInfo(), throwable);
future.complete(new VoteResponse());
}
});
Expand All @@ -212,18 +232,28 @@ public CompletableFuture<AppendEntryResponse> append(AppendEntryRequest request)
try {
RemotingCommand wrapperRequest = RemotingCommand.createRequestCommand(DLedgerRequestCode.APPEND.getCode(), null);
wrapperRequest.setBody(JSON.toJSONBytes(request));
remotingClient.invokeAsync(getPeerAddr(request.getGroup(), request.getRemoteId()), wrapperRequest, 3000, responseFuture -> {
RemotingCommand responseCommand = responseFuture.getResponseCommand();

AppendEntryResponse response;
if (responseCommand != null) {
response = JSON.parseObject(responseCommand.getBody(), AppendEntryResponse.class);
} else {
response = new AppendEntryResponse();
remotingClient.invokeAsync(getPeerAddr(request.getGroup(), request.getRemoteId()), wrapperRequest, 3000, new InvokeCallback() {
@Override
public void operationComplete(ResponseFuture responseFuture) {
RemotingCommand responseCommand = responseFuture.getResponseCommand();
AppendEntryResponse response;
if (responseCommand != null) {
response = JSON.parseObject(responseCommand.getBody(), AppendEntryResponse.class);
} else {
response = new AppendEntryResponse();
response.copyBaseInfo(request);
response.setCode(DLedgerResponseCode.NETWORK_ERROR.getCode());
}
future.complete(response);
}

@Override
public void operationFail(Throwable throwable) {
AppendEntryResponse response = new AppendEntryResponse();
response.copyBaseInfo(request);
response.setCode(DLedgerResponseCode.NETWORK_ERROR.getCode());
future.complete(response);
}
future.complete(response);
});
} catch (Throwable t) {
LOGGER.error("Send append request failed, {}", request.baseInfo(), t);
Expand Down Expand Up @@ -257,18 +287,28 @@ public CompletableFuture<PushEntryResponse> push(PushEntryRequest request) {
try {
RemotingCommand wrapperRequest = RemotingCommand.createRequestCommand(DLedgerRequestCode.PUSH.getCode(), null);
wrapperRequest.setBody(JSON.toJSONBytes(request));
remotingClient.invokeAsync(getPeerAddr(request.getGroup(), request.getRemoteId()), wrapperRequest, 3000, responseFuture -> {
RemotingCommand responseCommand = responseFuture.getResponseCommand();

PushEntryResponse response;
if (responseCommand != null) {
response = JSON.parseObject(responseCommand.getBody(), PushEntryResponse.class);
} else {
response = new PushEntryResponse();
remotingClient.invokeAsync(getPeerAddr(request.getGroup(), request.getRemoteId()), wrapperRequest, 3000, new InvokeCallback() {
@Override
public void operationComplete(ResponseFuture responseFuture) {
RemotingCommand responseCommand = responseFuture.getResponseCommand();
PushEntryResponse response;
if (responseCommand != null) {
response = JSON.parseObject(responseCommand.getBody(), PushEntryResponse.class);
} else {
response = new PushEntryResponse();
response.copyBaseInfo(request);
response.setCode(DLedgerResponseCode.NETWORK_ERROR.getCode());
}
future.complete(response);
}

@Override
public void operationFail(Throwable throwable) {
PushEntryResponse response = new PushEntryResponse();
response.copyBaseInfo(request);
response.setCode(DLedgerResponseCode.NETWORK_ERROR.getCode());
future.complete(response);
}
future.complete(response);
});
} catch (Throwable t) {
LOGGER.error("Send push request failed, {}", request.baseInfo(), t);
Expand All @@ -287,18 +327,28 @@ public CompletableFuture<InstallSnapshotResponse> installSnapshot(InstallSnapsho
try {
RemotingCommand wrapperRequest = RemotingCommand.createRequestCommand(DLedgerRequestCode.INSTALL_SNAPSHOT.getCode(), null);
wrapperRequest.setBody(JSON.toJSONBytes(request));
remotingClient.invokeAsync(getPeerAddr(request.getGroup(), request.getRemoteId()), wrapperRequest, 3000, responseFuture -> {
RemotingCommand responseCommand = responseFuture.getResponseCommand();

InstallSnapshotResponse response;
if (responseCommand != null) {
response = JSON.parseObject(responseFuture.getResponseCommand().getBody(), InstallSnapshotResponse.class);
} else {
response = new InstallSnapshotResponse();
remotingClient.invokeAsync(getPeerAddr(request.getGroup(), request.getRemoteId()), wrapperRequest, 3000, new InvokeCallback() {
@Override
public void operationComplete(ResponseFuture responseFuture) {
RemotingCommand responseCommand = responseFuture.getResponseCommand();
InstallSnapshotResponse response;
if (responseCommand != null) {
response = JSON.parseObject(responseFuture.getResponseCommand().getBody(), InstallSnapshotResponse.class);
} else {
response = new InstallSnapshotResponse();
response.copyBaseInfo(request);
response.setCode(DLedgerResponseCode.NETWORK_ERROR.getCode());
}
future.complete(response);
}

@Override
public void operationFail(Throwable throwable) {
InstallSnapshotResponse response = new InstallSnapshotResponse();
response.copyBaseInfo(request);
response.setCode(DLedgerResponseCode.NETWORK_ERROR.getCode());
future.complete(response);
}
future.complete(response);
});
} catch (Throwable t) {
LOGGER.error("Send install snapshot request failed, {}", request.baseInfo(), t);
Expand All @@ -317,18 +367,28 @@ public CompletableFuture<LeadershipTransferResponse> leadershipTransfer(
try {
RemotingCommand wrapperRequest = RemotingCommand.createRequestCommand(DLedgerRequestCode.LEADERSHIP_TRANSFER.getCode(), null);
wrapperRequest.setBody(JSON.toJSONBytes(request));
remotingClient.invokeAsync(getPeerAddr(request.getGroup(), request.getRemoteId()), wrapperRequest, 3000, responseFuture -> {
RemotingCommand responseCommand = responseFuture.getResponseCommand();

LeadershipTransferResponse response;
if (responseCommand != null) {
response = JSON.parseObject(responseFuture.getResponseCommand().getBody(), LeadershipTransferResponse.class);
} else {
response = new LeadershipTransferResponse();
remotingClient.invokeAsync(getPeerAddr(request.getGroup(), request.getRemoteId()), wrapperRequest, 3000, new InvokeCallback() {
@Override
public void operationComplete(ResponseFuture responseFuture) {
RemotingCommand responseCommand = responseFuture.getResponseCommand();
LeadershipTransferResponse response;
if (responseCommand != null) {
response = JSON.parseObject(responseFuture.getResponseCommand().getBody(), LeadershipTransferResponse.class);
} else {
response = new LeadershipTransferResponse();
response.copyBaseInfo(request);
response.setCode(DLedgerResponseCode.NETWORK_ERROR.getCode());
}
future.complete(response);
}

@Override
public void operationFail(Throwable throwable) {
LeadershipTransferResponse response = new LeadershipTransferResponse();
response.copyBaseInfo(request);
response.setCode(DLedgerResponseCode.NETWORK_ERROR.getCode());
future.complete(response);
}
future.complete(response);
});
} catch (Throwable t) {
LOGGER.error("Send leadershipTransfer request failed, {}", request.baseInfo(), t);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package io.openmessaging.storage.dledger.client;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson2.JSON;
import io.openmessaging.storage.dledger.protocol.AppendEntryRequest;
import io.openmessaging.storage.dledger.protocol.AppendEntryResponse;
import io.openmessaging.storage.dledger.protocol.DLedgerRequestCode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package io.openmessaging.storage.dledger.snapshot.file;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson2.JSON;
import io.openmessaging.storage.dledger.snapshot.DownloadSnapshot;
import io.openmessaging.storage.dledger.snapshot.SnapshotManager;
import io.openmessaging.storage.dledger.snapshot.SnapshotMeta;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package io.openmessaging.storage.dledger.snapshot.file;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson2.JSON;
import io.openmessaging.storage.dledger.snapshot.SnapshotManager;
import io.openmessaging.storage.dledger.snapshot.SnapshotMeta;
import io.openmessaging.storage.dledger.snapshot.SnapshotStatus;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.openmessaging.storage.dledger.snapshot;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson2.JSON;
import io.openmessaging.storage.dledger.DLedgerConfig;
import io.openmessaging.storage.dledger.DLedgerServer;
import io.openmessaging.storage.dledger.MemberState;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.openmessaging.storage.dledger.snapshot;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson2.JSON;
import io.openmessaging.storage.dledger.snapshot.file.FileSnapshotReader;
import io.openmessaging.storage.dledger.util.FileTestUtil;
import io.openmessaging.storage.dledger.utils.IOUtils;
Expand All @@ -9,7 +9,6 @@

import java.io.File;
import java.io.IOException;
import java.util.UUID;

public class SnapshotReaderTest {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.openmessaging.storage.dledger.snapshot;

import com.alibaba.fastjson.JSON;
import io.openmessaging.storage.dledger.snapshot.file.FileSnapshotStore;
import io.openmessaging.storage.dledger.util.FileTestUtil;
import io.openmessaging.storage.dledger.utils.IOUtils;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.openmessaging.storage.dledger.snapshot;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson2.JSON;
import io.openmessaging.storage.dledger.snapshot.file.FileSnapshotStore;
import io.openmessaging.storage.dledger.snapshot.file.FileSnapshotWriter;
import io.openmessaging.storage.dledger.util.FileTestUtil;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package io.openmessaging.storage.dledger.statemachine;

import com.alibaba.fastjson2.JSON;
import io.openmessaging.storage.dledger.common.Status;
import io.openmessaging.storage.dledger.common.WriteClosure;
import io.openmessaging.storage.dledger.common.WriteTask;
Expand All @@ -25,7 +26,6 @@
import java.util.UUID;
import java.util.concurrent.CountDownLatch;

import com.alibaba.fastjson.JSON;
import io.openmessaging.storage.dledger.DLedgerConfig;
import io.openmessaging.storage.dledger.DLedgerServer;
import io.openmessaging.storage.dledger.MemberState;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package io.openmessaging.storage.dledger.example.appender;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson2.JSON;
import io.openmessaging.storage.dledger.DLedgerConfig;
import io.openmessaging.storage.dledger.proxy.DLedgerProxy;
import java.util.Collections;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package io.openmessaging.storage.dledger.example.appender.command;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson2.JSON;
import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters;
import io.openmessaging.storage.dledger.client.DLedgerClient;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package io.openmessaging.storage.dledger.example.appender.command;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson2.JSON;
import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters;
import io.openmessaging.storage.dledger.client.DLedgerClient;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package io.openmessaging.storage.dledger.example.common.command;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson2.JSON;
import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters;
import io.openmessaging.storage.dledger.client.DLedgerClient;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package io.openmessaging.storage.dledger.example.common.command;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson2.JSON;
import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters;
import io.openmessaging.storage.dledger.entry.DLedgerEntry;
Expand Down
Loading
Loading