加入vscode调试方式
This commit is contained in:
parent
4fa9035983
commit
1ea40571d9
18
.vscode/launch.json
vendored
Normal file
18
.vscode/launch.json
vendored
Normal file
|
@ -0,0 +1,18 @@
|
|||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"type": "java",
|
||||
"name": "Launch Server",
|
||||
"request": "launch",
|
||||
"mainClass": "com.yuandian.dataflow.Server",
|
||||
"projectName": "dataflow",
|
||||
"args": "2",
|
||||
"preLaunchTask": "restart",
|
||||
"postDebugTask": "stopall",
|
||||
}
|
||||
]
|
||||
}
|
3
.vscode/settings.json
vendored
Normal file
3
.vscode/settings.json
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"java.configuration.updateBuildConfiguration": "automatic"
|
||||
}
|
27
.vscode/tasks.json
vendored
Normal file
27
.vscode/tasks.json
vendored
Normal file
|
@ -0,0 +1,27 @@
|
|||
{
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"label": "restart",
|
||||
"type": "shell",
|
||||
"command": "sh restart.sh",
|
||||
"presentation": {
|
||||
"echo": true,
|
||||
"reveal": "always",
|
||||
"focus": false,
|
||||
"panel": "shared",
|
||||
"showReuseMessage": true,
|
||||
"clear": false,
|
||||
"close": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"label": "stopall",
|
||||
"type": "shell",
|
||||
"command": "sh stop.sh",
|
||||
"presentation": {
|
||||
"close": true
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
|
@ -1,2 +1,2 @@
|
|||
#! /bin/bash
|
||||
sh stop.sh & rm raftdata/ -rf && mvn -T4 package && truncate -s 0 screenlog.0 && sh start.sh
|
||||
sh stop.sh & rm raftdata/ -rf && mvn package && truncate -s 0 screenlog.0 && sh start.sh
|
||||
|
|
|
@ -53,15 +53,24 @@ public class PacketsProcessor implements RpcProcessor<PacketsProcessor.PacketsRe
|
|||
public void handleRequest(RpcContext rpcCtx, PacketsRequest request) {
|
||||
// StateServerFactory.getStateServer().updateFsmStateAsync(s, onCompleted);
|
||||
|
||||
var resp = new RaftResponse<>();
|
||||
resp.setSuccess(true);
|
||||
rpcCtx.sendResponse(resp);
|
||||
|
||||
var ss = StateServerFactory.getStateServer();
|
||||
log.info("{} handler request.packets.size(): {}", StateServerFactory.getServerId(), request.packets.size());
|
||||
log.debug("{} handler request.packets.size(): {}", StateServerFactory.getServerId(), request.packets.size());
|
||||
|
||||
|
||||
ss.readIndexState( new GenericClosure<State>() {
|
||||
|
||||
@Override
|
||||
public void run(Status status) {
|
||||
|
||||
log.debug("status {}", status);
|
||||
if(status.isOk()) {
|
||||
var state = this.getValue();
|
||||
var ws = state.getWorkers().get(StateServerFactory.getServerId());
|
||||
|
||||
|
||||
ws.setTaskQueueSize( ws.getTaskQueueSize() - request.packets.size());
|
||||
ws.setUpdateAt(Instant.now());
|
||||
|
||||
|
@ -70,19 +79,15 @@ public class PacketsProcessor implements RpcProcessor<PacketsProcessor.PacketsRe
|
|||
Operate.CallOperate(new Operate(OperateType.PUT,ws), new GenericClosure<Operate>() {
|
||||
@Override
|
||||
public void run(Status status) {
|
||||
var resp = this.getResponse();
|
||||
resp.setMsg(rpcCtx.getRemoteAddress());
|
||||
if(status.isOk()) {
|
||||
resp.setSuccess(true);
|
||||
log.info("{}", resp);
|
||||
} else {
|
||||
resp.setSuccess(false);
|
||||
}
|
||||
rpcCtx.sendResponse(resp);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} );
|
||||
|
||||
|
||||
|
|
|
@ -38,7 +38,8 @@ import lombok.extern.slf4j.Slf4j;
|
|||
@Slf4j
|
||||
public class StateMachine extends StateMachineAdapter {
|
||||
|
||||
// private static final Logger LOG = LoggerFactory.getLogger(StateMachine.class);
|
||||
// private static final Logger LOG =
|
||||
// LoggerFactory.getLogger(StateMachine.class);
|
||||
|
||||
/**
|
||||
* State value 全局使用的唯一状态
|
||||
|
@ -78,7 +79,9 @@ public class StateMachine extends StateMachineAdapter {
|
|||
final ByteBuffer data = iter.getData();
|
||||
try {
|
||||
|
||||
op = SerializerManager.getSerializer(SerializerManager.Hessian2).deserialize(data.array(),Operate.class.getName());
|
||||
op = SerializerManager.getSerializer(SerializerManager.Hessian2).deserialize(
|
||||
data.array(),
|
||||
Operate.class.getName());
|
||||
} catch (CodecException e) {
|
||||
log.info("{}", e.toString());
|
||||
}
|
||||
|
@ -109,8 +112,6 @@ public class StateMachine extends StateMachineAdapter {
|
|||
|
||||
}
|
||||
|
||||
|
||||
|
||||
iter.next();
|
||||
}
|
||||
}
|
||||
|
@ -179,18 +180,14 @@ public class StateMachine extends StateMachineAdapter {
|
|||
MasterFactory.getMasterExecute().interrupt();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void onShutdown() {
|
||||
log.debug("onShutdown");
|
||||
super.onShutdown();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onStartFollowing(LeaderChangeContext ctx) {
|
||||
log.debug("[onStartFollowing] {} {}", ctx, StateServerFactory.getCluster().getServerId());
|
||||
|
@ -243,14 +240,7 @@ public class StateMachine extends StateMachineAdapter {
|
|||
}
|
||||
});
|
||||
|
||||
|
||||
super.onStopFollowing(ctx);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -189,16 +189,17 @@ public class StateServerFactory {
|
|||
@Override
|
||||
public void run(Status status, long index, byte[] reqCtx) {
|
||||
if(status.isOk()) {
|
||||
// 回调失败
|
||||
closure.success(ss.fsm.getState());
|
||||
closure.run(status);
|
||||
}
|
||||
closure.run(status);
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void applyOperate(Operate op, GenericClosure closure) {
|
||||
public void applyOperate(Operate op, GenericClosure<Operate> closure) {
|
||||
// 所有的提交都必须再leader进行
|
||||
if (!ss.isLeader()) {
|
||||
ss.handlerNotLeaderError(closure);
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.yuandian.dataflow.statemachine.operate;
|
|||
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.alipay.sofa.jraft.Status;
|
||||
import com.alipay.sofa.jraft.error.RemotingException;
|
||||
import com.alipay.sofa.jraft.rpc.InvokeCallback;
|
||||
import com.yuandian.dataflow.statemachine.StateServerFactory;
|
||||
|
@ -75,6 +76,7 @@ public class Operate implements Serializable {
|
|||
var resp = (RaftResponse<Operate>) result;
|
||||
closure.setResponse(resp);
|
||||
closure.success(resp.getValue());
|
||||
closure.run(Status.OK());
|
||||
}
|
||||
|
||||
}, 5000);
|
||||
|
|
|
@ -64,7 +64,7 @@ public class OperateProcessor implements RpcProcessor<OperateProcessor.OperateRe
|
|||
|
||||
log.info("request: {}", request);
|
||||
|
||||
final GenericClosure closure = new GenericClosure() {
|
||||
final GenericClosure<Operate> closure = new GenericClosure<Operate>() {
|
||||
@Override
|
||||
public void run(Status status) {
|
||||
rpcCtx.sendResponse(getResponse());
|
||||
|
|
8
src/main/java/com/yuandian/dataflow/utils/Utils.java
Normal file
8
src/main/java/com/yuandian/dataflow/utils/Utils.java
Normal file
|
@ -0,0 +1,8 @@
|
|||
package com.yuandian.dataflow.utils;
|
||||
|
||||
public class Utils {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
}
|
||||
}
|
4
start.sh
4
start.sh
|
@ -10,10 +10,10 @@ sleep 1
|
|||
|
||||
screen -dmS raft-0 -L java -jar target/dataflow-${VERSION}.jar 0
|
||||
screen -dmS raft-1 -L java -jar target/dataflow-${VERSION}.jar 1
|
||||
screen -dmS raft-2 -L java -jar target/dataflow-${VERSION}.jar 2
|
||||
# screen -dmS raft-2 -L java -jar target/dataflow-${VERSION}.jar 2
|
||||
|
||||
sleep 1
|
||||
|
||||
screen -S raft-0 -X logfile flush 0
|
||||
screen -S raft-1 -X logfile flush 0
|
||||
screen -S raft-2 -X logfile flush 0
|
||||
# screen -S raft-2 -X logfile flush 0
|
Loading…
Reference in New Issue
Block a user