From e8f990d883adcaec21cfe27c02bac68eb03de8a6 Mon Sep 17 00:00:00 2001 From: huangsimin Date: Tue, 12 Jul 2022 18:08:55 +0800 Subject: [PATCH 01/37] =?UTF-8?q?=E5=90=88=E5=B9=B6=E4=B8=80=E6=AE=B5?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=90=8E=E7=9A=84jraft=E4=BB=A3=E7=A0=81=20T?= =?UTF-8?q?ODO:=20=E7=8A=B6=E6=80=81=E6=9C=BA=E7=9A=84SyncData?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/yuandian/dataflow/Server.java | 77 ++----------- .../dataflow/statemachine/StateMachine.java | 4 +- .../dataflow/statemachine/StateServer.java | 97 ++++++++++++++++ .../dataflow/statemachine/rpc/SyncData.java | 104 ++++++++++++++++++ .../statemachine/rpc/SyncDataProcessor.java | 39 +++++++ start.sh | 6 +- 6 files changed, 257 insertions(+), 70 deletions(-) create mode 100644 src/main/java/com/yuandian/dataflow/statemachine/StateServer.java create mode 100644 src/main/java/com/yuandian/dataflow/statemachine/rpc/SyncData.java create mode 100644 src/main/java/com/yuandian/dataflow/statemachine/rpc/SyncDataProcessor.java diff --git a/src/main/java/com/yuandian/dataflow/Server.java b/src/main/java/com/yuandian/dataflow/Server.java index 2c3acfb..9a0d35a 100644 --- a/src/main/java/com/yuandian/dataflow/Server.java +++ b/src/main/java/com/yuandian/dataflow/Server.java @@ -1,50 +1,25 @@ package com.yuandian.dataflow; -import com.yuandian.common.Config; -import com.yuandian.dataflow.statemachine.RaftClosure; -import com.yuandian.dataflow.statemachine.StateMachine; - -import lombok.val; -import lombok.var; +import java.io.File; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringBootConfiguration; import org.springframework.boot.autoconfigure.SpringBootApplication; -import java.io.File; -import java.nio.ByteBuffer; - -import com.alipay.remoting.rpc.protocol.RpcResponseProcessor; -import com.alipay.sofa.jraft.Closure; -import com.alipay.sofa.jraft.Iterator; import com.alipay.sofa.jraft.JRaftUtils; import com.alipay.sofa.jraft.Node; -import com.alipay.sofa.jraft.NodeManager; import com.alipay.sofa.jraft.RaftGroupService; -import com.alipay.sofa.jraft.RaftServiceFactory; import com.alipay.sofa.jraft.conf.Configuration; -import com.alipay.sofa.jraft.core.IteratorImpl; -import com.alipay.sofa.jraft.core.NodeImpl; -import com.alipay.sofa.jraft.core.ReplicatorGroupImpl; -import com.alipay.sofa.jraft.entity.NodeId; import com.alipay.sofa.jraft.entity.PeerId; -import com.alipay.sofa.jraft.entity.Task; import com.alipay.sofa.jraft.option.NodeOptions; -import com.alipay.sofa.jraft.option.RaftOptions; -import com.alipay.sofa.jraft.rpc.CliClientService; -import com.alipay.sofa.jraft.rpc.RpcProcessor; -import com.alipay.sofa.jraft.rpc.RaftRpcServerFactory; -import com.alipay.sofa.jraft.rpc.RpcClient; -import com.alipay.sofa.jraft.rpc.RpcRequestProcessor; -import com.alipay.sofa.jraft.rpc.RpcServer; -import com.alipay.sofa.jraft.rpc.impl.BoltRpcServer; -import com.alipay.sofa.jraft.rpc.impl.BoltRaftRpcFactory; -import com.alipay.sofa.jraft.rpc.impl.BoltRpcClient; -import com.alipay.sofa.jraft.util.Endpoint; +import com.yuandian.dataflow.statemachine.RaftClosure; +import com.yuandian.dataflow.statemachine.StateMachine; +import com.yuandian.dataflow.statemachine.StateServer; +import com.yuandian.dataflow.statemachine.rpc.SyncDataProcessor; -import com.alipay.sofa.jraft.option.ReplicatorGroupOptions; +import lombok.var; @@ -60,6 +35,7 @@ public class Server { @Autowired public static Node node; public static RaftClosure done; + private static StateServer stateServer; public static Node GetNode() { return node; @@ -73,47 +49,18 @@ public class Server { public static void main(String[] args) { - - - - /*String[] peers = new String[]{"localhost:4440","localhost:4441","localhost:4442"}; + String[] peers = new String[]{"localhost:4440","localhost:4441","localhost:4442"}; String[] sprPeers = new String[]{"3440","3441","3442"}; - - - var peeridstr = peers[ Integer.parseInt(args[0] ) ]; + var peeridstr = peers[ Integer.parseInt(args[0] )]; var sprPort = sprPeers[Integer.parseInt(args[0] )]; - String groupId = "jraft"; Configuration conf = JRaftUtils.getConfiguration("localhost:4440,localhost:4441,localhost:4442"); + stateServer = new StateServer(peeridstr, conf); - PeerId serverId = JRaftUtils.getPeerId(peeridstr); - int port = serverId.getPort(); - - NodeOptions nodeOptions = new NodeOptions(); - nodeOptions.setElectionTimeoutMs(1000); - nodeOptions.setSnapshotLogIndexMargin(3600); - nodeOptions.setInitialConf(conf); - - File RaftDataFile = new File(String.format("./raftdata/%d", port) ); - System.out.print(RaftDataFile.mkdirs()); - - nodeOptions.setLogUri( String.format("./raftdata/%d/logs", port) ); - nodeOptions.setRaftMetaUri(String.format("./raftdata/%d/rafts", port)); - nodeOptions.setSnapshotUri(String.format("./raftdata/%d/snaps", port)); - nodeOptions.setFsm(new StateMachine()); - - RaftGroupService cluster = new RaftGroupService(groupId, serverId, nodeOptions); - node = cluster.start(); - done = new RaftClosure(); - - System.setProperty("server.port", sprPort);*/ - - System.setProperty("server.port", "3440"); + + System.setProperty("server.port", sprPort); var app = SpringApplication.run(Server.class, args); app.start(); - - - // node.shutdown(done); } } diff --git a/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java b/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java index 3bfcc1b..c93f337 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java @@ -60,11 +60,11 @@ public class StateMachine extends StateMachineAdapter { // This task is applied by this node, get value from closure to avoid additional // parsing. - log.error("done:%1$s",iter.getData().toString()); + log.error("done:{}",iter.getData().toString()); } else { // Have to parse FetchAddRequest from this user log. - log.error("null:%1$s",iter.getData().toString()); + log.error("null:{}",iter.getData().toString()); } iter.next(); diff --git a/src/main/java/com/yuandian/dataflow/statemachine/StateServer.java b/src/main/java/com/yuandian/dataflow/statemachine/StateServer.java new file mode 100644 index 0000000..01e970c --- /dev/null +++ b/src/main/java/com/yuandian/dataflow/statemachine/StateServer.java @@ -0,0 +1,97 @@ +/** + * description + * + * @author eson + *2022年7月12日-13:36:24 + */ +package com.yuandian.dataflow.statemachine; + +import java.io.File; + +import com.alibaba.nacos.common.remote.client.RpcClient; +import com.alipay.sofa.jraft.JRaftUtils; +import com.alipay.sofa.jraft.Node; +import com.alipay.sofa.jraft.RaftGroupService; +import com.alipay.sofa.jraft.conf.Configuration; +import com.alipay.sofa.jraft.entity.PeerId; +import com.alipay.sofa.jraft.error.RemotingException; +import com.alipay.sofa.jraft.option.CliOptions; +import com.alipay.sofa.jraft.option.NodeOptions; +import com.alipay.sofa.jraft.rpc.InvokeCallback; +import com.alipay.sofa.jraft.rpc.impl.BoltRaftRpcFactory; +import com.alipay.sofa.jraft.util.Endpoint; +import com.yuandian.dataflow.statemachine.RaftClosure; +import com.yuandian.dataflow.statemachine.StateMachine; +import com.yuandian.dataflow.statemachine.rpc.SyncData; +import com.yuandian.dataflow.statemachine.rpc.SyncDataProcessor; + +import lombok.var; +import lombok.extern.slf4j.Slf4j; + +/** + * description + * + * @author eson + *2022年7月12日-13:36:24 + */ +@Slf4j +@var +public class StateServer { + + public Node node; + public RaftGroupService cluster; + public StateMachine fsm; + + private String groupId = "dataflow"; + + public StateServer(String addr, Configuration conf) { + String[] peers = new String[]{"localhost:4440","localhost:4441","localhost:4442"}; + String[] sprPeers = new String[]{"3440","3441","3442"}; + + // var peeridstr = peers[Integer.parseInt(serverId)]; + // var sprPort = sprPeers[Integer.parseInt(args[0])]; + + // String groupId = "jraft"; + + // Configuration conf = JRaftUtils.getConfiguration("localhost:4440,localhost:4441,localhost:4442"); + + PeerId serverId = JRaftUtils.getPeerId(addr); + int port = serverId.getPort(); + + NodeOptions nodeOptions = new NodeOptions(); + nodeOptions.setElectionTimeoutMs(1000); + nodeOptions.setSnapshotLogIndexMargin(3600); + nodeOptions.setInitialConf(conf); + + File RaftDataFile = new File(String.format("./raftdata/%d", port) ); + log.info("{}",RaftDataFile.mkdirs()); + + nodeOptions.setLogUri( String.format("./raftdata/%d/logs", port) ); + nodeOptions.setRaftMetaUri(String.format("./raftdata/%d/rafts", port)); + nodeOptions.setSnapshotUri(String.format("./raftdata/%d/snaps", port)); + fsm = new StateMachine(); // 状态实例初始化 + nodeOptions.setFsm(fsm); + + cluster = new RaftGroupService(groupId, serverId, nodeOptions); + cluster.getRpcServer().registerProcessor(new SyncDataProcessor()); + + + + + node = cluster.start(); + } + + + public static void main(String[] args) throws InterruptedException, RemotingException { + var rpcClient = new BoltRaftRpcFactory().createRpcClient(); + + + rpcClient.init(new CliOptions()); + + var resp = rpcClient.invokeSync(new Endpoint("localhost",4441), new SyncData(), 5000); + log.info("{}", resp); + + // done = new RaftClosure(); + // node.shutdown(done); + } +} diff --git a/src/main/java/com/yuandian/dataflow/statemachine/rpc/SyncData.java b/src/main/java/com/yuandian/dataflow/statemachine/rpc/SyncData.java new file mode 100644 index 0000000..928702a --- /dev/null +++ b/src/main/java/com/yuandian/dataflow/statemachine/rpc/SyncData.java @@ -0,0 +1,104 @@ +/** + * description + * + * @author eson + *2022年7月11日-16:01:07 + */ +package com.yuandian.dataflow.statemachine.rpc; + +import java.io.Serializable; + +import com.alipay.sofa.jraft.Closure; + +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import lombok.extern.slf4j.Slf4j; + +/** + * description + * + * @author eson + *2022年7月11日-16:01:07 + */ +@Slf4j +@Getter +@Setter +@ToString +public class SyncData implements Serializable { + + private static final long serialVersionUID = 1L; + + private long queueSize = 0; + + + // @Getter + // @Setter + // public class IncrementAndGetRequest implements Serializable { + // private long delta; + // } + + // public class GetValueRequest implements Serializable { + // private static final long serialVersionUID = 9218253805003988802L; + + // public GetValueRequest() { + // super(); + // } + // } + + + // @Getter + // @Setter + // public class ValueResponse implements Serializable { + + // private static final long serialVersionUID = -4220017686727146773L; + + // private long value; + // private boolean success; + // /** + // * redirect peer id + // */ + // private String redirect; + + // private String errorMsg; + + // } + + // public class IncrementAndAddClosure implements Closure { + // // private CounterServer counterServer; + // private IncrementAndGetRequest request; + // private ValueResponse response; + // private Closure done; // 网络应答callback + + // public IncrementAndAddClosure(CounterServer counterServer, IncrementAndGetRequest request, ValueResponse response, + // Closure done) { + // super(); + // this.counterServer = counterServer; + // this.request = request; + // this.response = response; + // this.done = done; + // } + + // @Override + // public void run(Status status) { + // // 返回应答给客户端 + // if (this.done != null) { + // done.run(status); + // } + // } + + // public IncrementAndGetRequest getRequest() { + // return this.request; + // } + + // public void setRequest(IncrementAndGetRequest request) { + // this.request = request; + // } + + // public ValueResponse getResponse() { + // return this.response; + // } + + // } + +} diff --git a/src/main/java/com/yuandian/dataflow/statemachine/rpc/SyncDataProcessor.java b/src/main/java/com/yuandian/dataflow/statemachine/rpc/SyncDataProcessor.java new file mode 100644 index 0000000..a682e27 --- /dev/null +++ b/src/main/java/com/yuandian/dataflow/statemachine/rpc/SyncDataProcessor.java @@ -0,0 +1,39 @@ +/** + * description + * + * @author eson + *2022年7月12日-11:10:54 + */ +package com.yuandian.dataflow.statemachine.rpc; + +import com.alipay.sofa.jraft.rpc.RpcContext; +import com.alipay.sofa.jraft.rpc.RpcProcessor; + +import lombok.extern.slf4j.Slf4j; + +/** + * description + * + * @author eson + *2022年7月12日-11:10:54 + */ +@Slf4j +public class SyncDataProcessor implements RpcProcessor { + + @Override + public void handleRequest(RpcContext rpcCtx, SyncData request) { + log.info("{}", rpcCtx); + log.info("{}", request); + rpcCtx.sendResponse(null); // + } + + @Override + public String interest() { + return SyncData.class.getName(); + } + + public static void main(String[] args) { + + } + +} diff --git a/start.sh b/start.sh index a19f6b2..5997f9d 100755 --- a/start.sh +++ b/start.sh @@ -4,6 +4,6 @@ screen -S raft-2 -X quit sleep 2 -screen -dmS raft-0 -L java -jar target/dataflow-1.0-SNAPSHOT.jar 0 -screen -dmS raft-1 -L java -jar target/dataflow-1.0-SNAPSHOT.jar 1 -screen -dmS raft-2 -L java -jar target/dataflow-1.0-SNAPSHOT.jar 2 +screen -dmS raft-0 -L java -jar target/dataflow-1.0.0-SNAPSHOT.jar 0 +screen -dmS raft-1 -L java -jar target/dataflow-1.0.0-SNAPSHOT.jar 1 +screen -dmS raft-2 -L java -jar target/dataflow-1.0.0-SNAPSHOT.jar 2 From fc2431811491a6045bc7bfceef509777b7953f71 Mon Sep 17 00:00:00 2001 From: linxianying Date: Wed, 13 Jul 2022 09:07:44 +0800 Subject: [PATCH 02/37] =?UTF-8?q?fix:=20=E6=8A=8Astring=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E6=94=B9=E4=B8=BAbytes=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yuandian/dataflow/controller/TaskLog.java | 22 +- .../msgtype/ApmBaseDataFlowOuterClass.java | 376 +-- .../proto/msgtype/AppFlowOuterClass.java | 126 +- .../proto/msgtype/BussFlowDbOuterClass.java | 1130 ++------ .../msgtype/BussFlowExternalOuterClass.java | 1000 ++----- .../proto/msgtype/BussFlowMiddOuterClass.java | 1258 ++------- .../proto/msgtype/BussFlowWebOuterClass.java | 2372 +++-------------- .../proto/msgtype/UsrFlowOuterClass.java | 502 +--- src/main/proto | 2 +- 9 files changed, 1279 insertions(+), 5509 deletions(-) diff --git a/src/main/java/com/yuandian/dataflow/controller/TaskLog.java b/src/main/java/com/yuandian/dataflow/controller/TaskLog.java index ed07bc8..aa46689 100644 --- a/src/main/java/com/yuandian/dataflow/controller/TaskLog.java +++ b/src/main/java/com/yuandian/dataflow/controller/TaskLog.java @@ -1,6 +1,8 @@ package com.yuandian.dataflow.controller; import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.stream.Collectors; import com.alipay.sofa.jraft.Closure; import com.alipay.sofa.jraft.entity.Task; @@ -66,10 +68,22 @@ public class TaskLog { return new ResponseEntity(response, HttpStatus.OK); } - @GetMapping(path = "/test2") - public ResponseEntity MongodbTest(@RequestBody int status) { + // ip + private static String convertIpToString(com.google.protobuf.ByteString byteString) { + ArrayList res = new ArrayList<>(); + byteString.forEach(byteStr -> { + res.add(String.valueOf(byteStr & 0xff)); + }); + return res.stream().collect(Collectors.joining(".")); + } - Response response = new Response(); - return new ResponseEntity(response, HttpStatus.OK); + // mac + private static String convertMacToString(com.google.protobuf.ByteString byteString) { + ArrayList res = new ArrayList<>(); + byteString.forEach(byteStr -> { + String str = Integer.toHexString(byteStr & 0xff); + res.add(str.length() < 2 ? "0" + str : str); + }); + return res.stream().collect(Collectors.joining("-")); } } diff --git a/src/main/java/com/yuandian/dataflow/proto/msgtype/ApmBaseDataFlowOuterClass.java b/src/main/java/com/yuandian/dataflow/proto/msgtype/ApmBaseDataFlowOuterClass.java index 59421c7..f99e487 100644 --- a/src/main/java/com/yuandian/dataflow/proto/msgtype/ApmBaseDataFlowOuterClass.java +++ b/src/main/java/com/yuandian/dataflow/proto/msgtype/ApmBaseDataFlowOuterClass.java @@ -77,28 +77,16 @@ public final class ApmBaseDataFlowOuterClass { com.yuandian.dataflow.proto.Base.IPAddressOrBuilder getTupleDaddrOrBuilder(); /** - * string src_mac = 7; + * bytes src_mac = 7; * @return The srcMac. */ - java.lang.String getSrcMac(); - /** - * string src_mac = 7; - * @return The bytes for srcMac. - */ - com.google.protobuf.ByteString - getSrcMacBytes(); + com.google.protobuf.ByteString getSrcMac(); /** - * string dst_mac = 8; + * bytes dst_mac = 8; * @return The dstMac. */ - java.lang.String getDstMac(); - /** - * string dst_mac = 8; - * @return The bytes for dstMac. - */ - com.google.protobuf.ByteString - getDstMacBytes(); + com.google.protobuf.ByteString getDstMac(); /** * uint32 vlan_id = 9; @@ -269,16 +257,10 @@ public final class ApmBaseDataFlowOuterClass { int getScAlert(); /** - * string protocol = 37; + * bytes protocol = 37; * @return The protocol. */ - java.lang.String getProtocol(); - /** - * string protocol = 37; - * @return The bytes for protocol. - */ - com.google.protobuf.ByteString - getProtocolBytes(); + com.google.protobuf.ByteString getProtocol(); } /** * Protobuf type {@code dataflow.ApmBaseDataFlow} @@ -293,9 +275,9 @@ public final class ApmBaseDataFlowOuterClass { super(builder); } private ApmBaseDataFlow() { - srcMac_ = ""; - dstMac_ = ""; - protocol_ = ""; + srcMac_ = com.google.protobuf.ByteString.EMPTY; + dstMac_ = com.google.protobuf.ByteString.EMPTY; + protocol_ = com.google.protobuf.ByteString.EMPTY; } @java.lang.Override @@ -375,15 +357,13 @@ public final class ApmBaseDataFlowOuterClass { break; } case 58: { - java.lang.String s = input.readStringRequireUtf8(); - srcMac_ = s; + srcMac_ = input.readBytes(); break; } case 66: { - java.lang.String s = input.readStringRequireUtf8(); - dstMac_ = s; + dstMac_ = input.readBytes(); break; } case 72: { @@ -527,9 +507,8 @@ public final class ApmBaseDataFlowOuterClass { break; } case 298: { - java.lang.String s = input.readStringRequireUtf8(); - protocol_ = s; + protocol_ = input.readBytes(); break; } default: { @@ -667,79 +646,25 @@ public final class ApmBaseDataFlowOuterClass { } public static final int SRC_MAC_FIELD_NUMBER = 7; - private volatile java.lang.Object srcMac_; + private com.google.protobuf.ByteString srcMac_; /** - * string src_mac = 7; + * bytes src_mac = 7; * @return The srcMac. */ @java.lang.Override - public java.lang.String getSrcMac() { - java.lang.Object ref = srcMac_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - srcMac_ = s; - return s; - } - } - /** - * string src_mac = 7; - * @return The bytes for srcMac. - */ - @java.lang.Override - public com.google.protobuf.ByteString - getSrcMacBytes() { - java.lang.Object ref = srcMac_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - srcMac_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } + public com.google.protobuf.ByteString getSrcMac() { + return srcMac_; } public static final int DST_MAC_FIELD_NUMBER = 8; - private volatile java.lang.Object dstMac_; + private com.google.protobuf.ByteString dstMac_; /** - * string dst_mac = 8; + * bytes dst_mac = 8; * @return The dstMac. */ @java.lang.Override - public java.lang.String getDstMac() { - java.lang.Object ref = dstMac_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - dstMac_ = s; - return s; - } - } - /** - * string dst_mac = 8; - * @return The bytes for dstMac. - */ - @java.lang.Override - public com.google.protobuf.ByteString - getDstMacBytes() { - java.lang.Object ref = dstMac_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - dstMac_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } + public com.google.protobuf.ByteString getDstMac() { + return dstMac_; } public static final int VLAN_ID_FIELD_NUMBER = 9; @@ -1051,41 +976,14 @@ public final class ApmBaseDataFlowOuterClass { } public static final int PROTOCOL_FIELD_NUMBER = 37; - private volatile java.lang.Object protocol_; + private com.google.protobuf.ByteString protocol_; /** - * string protocol = 37; + * bytes protocol = 37; * @return The protocol. */ @java.lang.Override - public java.lang.String getProtocol() { - java.lang.Object ref = protocol_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - protocol_ = s; - return s; - } - } - /** - * string protocol = 37; - * @return The bytes for protocol. - */ - @java.lang.Override - public com.google.protobuf.ByteString - getProtocolBytes() { - java.lang.Object ref = protocol_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - protocol_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } + public com.google.protobuf.ByteString getProtocol() { + return protocol_; } private byte memoizedIsInitialized = -1; @@ -1120,11 +1018,11 @@ public final class ApmBaseDataFlowOuterClass { if (tupleDaddr_ != null) { output.writeMessage(6, getTupleDaddr()); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(srcMac_)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 7, srcMac_); + if (!srcMac_.isEmpty()) { + output.writeBytes(7, srcMac_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(dstMac_)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 8, dstMac_); + if (!dstMac_.isEmpty()) { + output.writeBytes(8, dstMac_); } if (vlanId_ != 0) { output.writeUInt32(9, vlanId_); @@ -1210,8 +1108,8 @@ public final class ApmBaseDataFlowOuterClass { if (scAlert_ != 0) { output.writeUInt32(36, scAlert_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(protocol_)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 37, protocol_); + if (!protocol_.isEmpty()) { + output.writeBytes(37, protocol_); } unknownFields.writeTo(output); } @@ -1246,11 +1144,13 @@ public final class ApmBaseDataFlowOuterClass { size += com.google.protobuf.CodedOutputStream .computeMessageSize(6, getTupleDaddr()); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(srcMac_)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(7, srcMac_); + if (!srcMac_.isEmpty()) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(7, srcMac_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(dstMac_)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(8, dstMac_); + if (!dstMac_.isEmpty()) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(8, dstMac_); } if (vlanId_ != 0) { size += com.google.protobuf.CodedOutputStream @@ -1364,8 +1264,9 @@ public final class ApmBaseDataFlowOuterClass { size += com.google.protobuf.CodedOutputStream .computeUInt32Size(36, scAlert_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(protocol_)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(37, protocol_); + if (!protocol_.isEmpty()) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(37, protocol_); } size += unknownFields.getSerializedSize(); memoizedSize = size; @@ -1704,9 +1605,9 @@ public final class ApmBaseDataFlowOuterClass { tupleDaddr_ = null; tupleDaddrBuilder_ = null; } - srcMac_ = ""; + srcMac_ = com.google.protobuf.ByteString.EMPTY; - dstMac_ = ""; + dstMac_ = com.google.protobuf.ByteString.EMPTY; vlanId_ = 0; @@ -1764,7 +1665,7 @@ public final class ApmBaseDataFlowOuterClass { scAlert_ = 0; - protocol_ = ""; + protocol_ = com.google.protobuf.ByteString.EMPTY; return this; } @@ -1903,13 +1804,11 @@ public final class ApmBaseDataFlowOuterClass { if (other.hasTupleDaddr()) { mergeTupleDaddr(other.getTupleDaddr()); } - if (!other.getSrcMac().isEmpty()) { - srcMac_ = other.srcMac_; - onChanged(); + if (other.getSrcMac() != com.google.protobuf.ByteString.EMPTY) { + setSrcMac(other.getSrcMac()); } - if (!other.getDstMac().isEmpty()) { - dstMac_ = other.dstMac_; - onChanged(); + if (other.getDstMac() != com.google.protobuf.ByteString.EMPTY) { + setDstMac(other.getDstMac()); } if (other.getVlanId() != 0) { setVlanId(other.getVlanId()); @@ -1995,9 +1894,8 @@ public final class ApmBaseDataFlowOuterClass { if (other.getScAlert() != 0) { setScAlert(other.getScAlert()); } - if (!other.getProtocol().isEmpty()) { - protocol_ = other.protocol_; - onChanged(); + if (other.getProtocol() != com.google.protobuf.ByteString.EMPTY) { + setProtocol(other.getProtocol()); } this.mergeUnknownFields(other.unknownFields); onChanged(); @@ -2402,47 +2300,21 @@ public final class ApmBaseDataFlowOuterClass { return tupleDaddrBuilder_; } - private java.lang.Object srcMac_ = ""; + private com.google.protobuf.ByteString srcMac_ = com.google.protobuf.ByteString.EMPTY; /** - * string src_mac = 7; + * bytes src_mac = 7; * @return The srcMac. */ - public java.lang.String getSrcMac() { - java.lang.Object ref = srcMac_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - srcMac_ = s; - return s; - } else { - return (java.lang.String) ref; - } + @java.lang.Override + public com.google.protobuf.ByteString getSrcMac() { + return srcMac_; } /** - * string src_mac = 7; - * @return The bytes for srcMac. - */ - public com.google.protobuf.ByteString - getSrcMacBytes() { - java.lang.Object ref = srcMac_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - srcMac_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * string src_mac = 7; + * bytes src_mac = 7; * @param value The srcMac to set. * @return This builder for chaining. */ - public Builder setSrcMac( - java.lang.String value) { + public Builder setSrcMac(com.google.protobuf.ByteString value) { if (value == null) { throw new NullPointerException(); } @@ -2452,7 +2324,7 @@ public final class ApmBaseDataFlowOuterClass { return this; } /** - * string src_mac = 7; + * bytes src_mac = 7; * @return This builder for chaining. */ public Builder clearSrcMac() { @@ -2461,64 +2333,22 @@ public final class ApmBaseDataFlowOuterClass { onChanged(); return this; } - /** - * string src_mac = 7; - * @param value The bytes for srcMac to set. - * @return This builder for chaining. - */ - public Builder setSrcMacBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - srcMac_ = value; - onChanged(); - return this; - } - private java.lang.Object dstMac_ = ""; + private com.google.protobuf.ByteString dstMac_ = com.google.protobuf.ByteString.EMPTY; /** - * string dst_mac = 8; + * bytes dst_mac = 8; * @return The dstMac. */ - public java.lang.String getDstMac() { - java.lang.Object ref = dstMac_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - dstMac_ = s; - return s; - } else { - return (java.lang.String) ref; - } + @java.lang.Override + public com.google.protobuf.ByteString getDstMac() { + return dstMac_; } /** - * string dst_mac = 8; - * @return The bytes for dstMac. - */ - public com.google.protobuf.ByteString - getDstMacBytes() { - java.lang.Object ref = dstMac_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - dstMac_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * string dst_mac = 8; + * bytes dst_mac = 8; * @param value The dstMac to set. * @return This builder for chaining. */ - public Builder setDstMac( - java.lang.String value) { + public Builder setDstMac(com.google.protobuf.ByteString value) { if (value == null) { throw new NullPointerException(); } @@ -2528,7 +2358,7 @@ public final class ApmBaseDataFlowOuterClass { return this; } /** - * string dst_mac = 8; + * bytes dst_mac = 8; * @return This builder for chaining. */ public Builder clearDstMac() { @@ -2537,22 +2367,6 @@ public final class ApmBaseDataFlowOuterClass { onChanged(); return this; } - /** - * string dst_mac = 8; - * @param value The bytes for dstMac to set. - * @return This builder for chaining. - */ - public Builder setDstMacBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - dstMac_ = value; - onChanged(); - return this; - } private int vlanId_ ; /** @@ -3422,47 +3236,21 @@ public final class ApmBaseDataFlowOuterClass { return this; } - private java.lang.Object protocol_ = ""; + private com.google.protobuf.ByteString protocol_ = com.google.protobuf.ByteString.EMPTY; /** - * string protocol = 37; + * bytes protocol = 37; * @return The protocol. */ - public java.lang.String getProtocol() { - java.lang.Object ref = protocol_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - protocol_ = s; - return s; - } else { - return (java.lang.String) ref; - } + @java.lang.Override + public com.google.protobuf.ByteString getProtocol() { + return protocol_; } /** - * string protocol = 37; - * @return The bytes for protocol. - */ - public com.google.protobuf.ByteString - getProtocolBytes() { - java.lang.Object ref = protocol_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - protocol_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * string protocol = 37; + * bytes protocol = 37; * @param value The protocol to set. * @return This builder for chaining. */ - public Builder setProtocol( - java.lang.String value) { + public Builder setProtocol(com.google.protobuf.ByteString value) { if (value == null) { throw new NullPointerException(); } @@ -3472,7 +3260,7 @@ public final class ApmBaseDataFlowOuterClass { return this; } /** - * string protocol = 37; + * bytes protocol = 37; * @return This builder for chaining. */ public Builder clearProtocol() { @@ -3481,22 +3269,6 @@ public final class ApmBaseDataFlowOuterClass { onChanged(); return this; } - /** - * string protocol = 37; - * @param value The bytes for protocol to set. - * @return This builder for chaining. - */ - public Builder setProtocolBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - protocol_ = value; - onChanged(); - return this; - } @java.lang.Override public final Builder setUnknownFields( final com.google.protobuf.UnknownFieldSet unknownFields) { @@ -3570,7 +3342,7 @@ public final class ApmBaseDataFlowOuterClass { "\001(\r\022\022\n\ntuple_dest\030\004 \001(\r\022(\n\013tuple_saddr\030\005" + " \001(\0132\023.dataflow.IPAddress\022(\n\013tuple_daddr" + "\030\006 \001(\0132\023.dataflow.IPAddress\022\017\n\007src_mac\030\007" + - " \001(\t\022\017\n\007dst_mac\030\010 \001(\t\022\017\n\007vlan_id\030\t \001(\r\022\027" + + " \001(\014\022\017\n\007dst_mac\030\010 \001(\014\022\017\n\007vlan_id\030\t \001(\r\022\027" + "\n\017start_tm_tv_sec\030\n \001(\r\022\030\n\020start_tm_tv_u" + "sec\030\013 \001(\r\022\023\n\013total_bytes\030\014 \001(\r\022\025\n\rtotal_" + "packets\030\r \001(\r\022\032\n\022total_drop_packets\030\016 \001(" + @@ -3585,7 +3357,7 @@ public final class ApmBaseDataFlowOuterClass { "\001(\r\022\020\n\010sc_reset\030\036 \001(\r\022\021\n\tcs_retran\030\037 \001(\r" + "\022\021\n\tsc_retran\030 \001(\r\022\025\n\rconn_setup_tm\030! \001" + "(\r\022\023\n\013new_session\030\" \001(\r\022\020\n\010cs_alert\030# \001(" + - "\r\022\020\n\010sc_alert\030$ \001(\r\022\020\n\010protocol\030% \001(\tB<\n" + + "\r\022\020\n\010sc_alert\030$ \001(\r\022\020\n\010protocol\030% \001(\014B<\n" + "#com.yuandian.dataflow.proto.msgtypeP\000Z\023" + "../grpc-gen;grpcgenb\006proto3" }; diff --git a/src/main/java/com/yuandian/dataflow/proto/msgtype/AppFlowOuterClass.java b/src/main/java/com/yuandian/dataflow/proto/msgtype/AppFlowOuterClass.java index f659344..87942d2 100644 --- a/src/main/java/com/yuandian/dataflow/proto/msgtype/AppFlowOuterClass.java +++ b/src/main/java/com/yuandian/dataflow/proto/msgtype/AppFlowOuterClass.java @@ -131,16 +131,10 @@ public final class AppFlowOuterClass { int getOutputBytes(); /** - * string protocol = 16; + * bytes protocol = 16; * @return The protocol. */ - java.lang.String getProtocol(); - /** - * string protocol = 16; - * @return The bytes for protocol. - */ - com.google.protobuf.ByteString - getProtocolBytes(); + com.google.protobuf.ByteString getProtocol(); /** * uint32 app_id = 17; @@ -203,7 +197,7 @@ public final class AppFlowOuterClass { super(builder); } private AppFlow() { - protocol_ = ""; + protocol_ = com.google.protobuf.ByteString.EMPTY; } @java.lang.Override @@ -328,9 +322,8 @@ public final class AppFlowOuterClass { break; } case 130: { - java.lang.String s = input.readStringRequireUtf8(); - protocol_ = s; + protocol_ = input.readBytes(); break; } case 136: { @@ -607,41 +600,14 @@ public final class AppFlowOuterClass { } public static final int PROTOCOL_FIELD_NUMBER = 16; - private volatile java.lang.Object protocol_; + private com.google.protobuf.ByteString protocol_; /** - * string protocol = 16; + * bytes protocol = 16; * @return The protocol. */ @java.lang.Override - public java.lang.String getProtocol() { - java.lang.Object ref = protocol_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - protocol_ = s; - return s; - } - } - /** - * string protocol = 16; - * @return The bytes for protocol. - */ - @java.lang.Override - public com.google.protobuf.ByteString - getProtocolBytes() { - java.lang.Object ref = protocol_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - protocol_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } + public com.google.protobuf.ByteString getProtocol() { + return protocol_; } public static final int APP_ID_FIELD_NUMBER = 17; @@ -791,8 +757,8 @@ public final class AppFlowOuterClass { if (outputBytes_ != 0) { output.writeUInt32(15, outputBytes_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(protocol_)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 16, protocol_); + if (!protocol_.isEmpty()) { + output.writeBytes(16, protocol_); } if (appId_ != 0) { output.writeUInt32(17, appId_); @@ -887,8 +853,9 @@ public final class AppFlowOuterClass { size += com.google.protobuf.CodedOutputStream .computeUInt32Size(15, outputBytes_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(protocol_)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(16, protocol_); + if (!protocol_.isEmpty()) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(16, protocol_); } if (appId_ != 0) { size += com.google.protobuf.CodedOutputStream @@ -1225,7 +1192,7 @@ public final class AppFlowOuterClass { outputBytes_ = 0; - protocol_ = ""; + protocol_ = com.google.protobuf.ByteString.EMPTY; appId_ = 0; @@ -1394,9 +1361,8 @@ public final class AppFlowOuterClass { if (other.getOutputBytes() != 0) { setOutputBytes(other.getOutputBytes()); } - if (!other.getProtocol().isEmpty()) { - protocol_ = other.protocol_; - onChanged(); + if (other.getProtocol() != com.google.protobuf.ByteString.EMPTY) { + setProtocol(other.getProtocol()); } if (other.getAppId() != 0) { setAppId(other.getAppId()); @@ -2104,47 +2070,21 @@ public final class AppFlowOuterClass { return this; } - private java.lang.Object protocol_ = ""; + private com.google.protobuf.ByteString protocol_ = com.google.protobuf.ByteString.EMPTY; /** - * string protocol = 16; + * bytes protocol = 16; * @return The protocol. */ - public java.lang.String getProtocol() { - java.lang.Object ref = protocol_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - protocol_ = s; - return s; - } else { - return (java.lang.String) ref; - } + @java.lang.Override + public com.google.protobuf.ByteString getProtocol() { + return protocol_; } /** - * string protocol = 16; - * @return The bytes for protocol. - */ - public com.google.protobuf.ByteString - getProtocolBytes() { - java.lang.Object ref = protocol_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - protocol_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * string protocol = 16; + * bytes protocol = 16; * @param value The protocol to set. * @return This builder for chaining. */ - public Builder setProtocol( - java.lang.String value) { + public Builder setProtocol(com.google.protobuf.ByteString value) { if (value == null) { throw new NullPointerException(); } @@ -2154,7 +2094,7 @@ public final class AppFlowOuterClass { return this; } /** - * string protocol = 16; + * bytes protocol = 16; * @return This builder for chaining. */ public Builder clearProtocol() { @@ -2163,22 +2103,6 @@ public final class AppFlowOuterClass { onChanged(); return this; } - /** - * string protocol = 16; - * @param value The bytes for protocol to set. - * @return This builder for chaining. - */ - public Builder setProtocolBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - protocol_ = value; - onChanged(); - return this; - } private int appId_ ; /** @@ -2503,7 +2427,7 @@ public final class AppFlowOuterClass { "_usec\030\t \001(\r\022\020\n\010e_tv_sec\030\n \001(\r\022\021\n\te_tv_us" + "ec\030\013 \001(\r\022\025\n\rinput_packets\030\014 \001(\r\022\026\n\016outpu" + "t_packets\030\r \001(\r\022\023\n\013input_bytes\030\016 \001(\r\022\024\n\014" + - "output_bytes\030\017 \001(\r\022\020\n\010protocol\030\020 \001(\t\022\016\n\006" + + "output_bytes\030\017 \001(\r\022\020\n\010protocol\030\020 \001(\014\022\016\n\006" + "app_id\030\021 \001(\r\022\024\n\014app_group_id\030\022 \001(\r\022\020\n\010pr" + "obe_if\030\023 \001(\r\022\021\n\tapp_style\030\024 \001(\r\022\021\n\ttime_" + "flag\030\025 \001(\r\022\017\n\007vlan_id\030\026 \001(\005\022\022\n\nmpls_labe" + diff --git a/src/main/java/com/yuandian/dataflow/proto/msgtype/BussFlowDbOuterClass.java b/src/main/java/com/yuandian/dataflow/proto/msgtype/BussFlowDbOuterClass.java index c620770..235d86c 100644 --- a/src/main/java/com/yuandian/dataflow/proto/msgtype/BussFlowDbOuterClass.java +++ b/src/main/java/com/yuandian/dataflow/proto/msgtype/BussFlowDbOuterClass.java @@ -35,16 +35,10 @@ public final class BussFlowDbOuterClass { int getMsgType(); /** - * string msg_version = 3; + * bytes msg_version = 3; * @return The msgVersion. */ - java.lang.String getMsgVersion(); - /** - * string msg_version = 3; - * @return The bytes for msgVersion. - */ - com.google.protobuf.ByteString - getMsgVersionBytes(); + com.google.protobuf.ByteString getMsgVersion(); /** * uint32 msg_seq = 4; @@ -131,16 +125,10 @@ public final class BussFlowDbOuterClass { int getRequestPackets(); /** - * string seq_ack = 18; + * bytes seq_ack = 18; * @return The seqAck. */ - java.lang.String getSeqAck(); - /** - * string seq_ack = 18; - * @return The bytes for seqAck. - */ - com.google.protobuf.ByteString - getSeqAckBytes(); + com.google.protobuf.ByteString getSeqAck(); /** * uint32 recog_status = 19; @@ -155,28 +143,16 @@ public final class BussFlowDbOuterClass { int getProbeIf(); /** - * string channel = 21; + * bytes channel = 21; * @return The channel. */ - java.lang.String getChannel(); - /** - * string channel = 21; - * @return The bytes for channel. - */ - com.google.protobuf.ByteString - getChannelBytes(); + com.google.protobuf.ByteString getChannel(); /** - * string dbname = 22; + * bytes dbname = 22; * @return The dbname. */ - java.lang.String getDbname(); - /** - * string dbname = 22; - * @return The bytes for dbname. - */ - com.google.protobuf.ByteString - getDbnameBytes(); + com.google.protobuf.ByteString getDbname(); /** * .dataflow.IPAddress request_ip = 23; @@ -335,64 +311,34 @@ public final class BussFlowDbOuterClass { int getReservedLen(); /** - * string sql = 46; + * bytes sql = 46; * @return The sql. */ - java.lang.String getSql(); - /** - * string sql = 46; - * @return The bytes for sql. - */ - com.google.protobuf.ByteString - getSqlBytes(); + com.google.protobuf.ByteString getSql(); /** - * string bussiness_detail_mesg = 47; + * bytes bussiness_detail_mesg = 47; * @return The bussinessDetailMesg. */ - java.lang.String getBussinessDetailMesg(); - /** - * string bussiness_detail_mesg = 47; - * @return The bytes for bussinessDetailMesg. - */ - com.google.protobuf.ByteString - getBussinessDetailMesgBytes(); + com.google.protobuf.ByteString getBussinessDetailMesg(); /** - * string req_data = 48; + * bytes req_data = 48; * @return The reqData. */ - java.lang.String getReqData(); - /** - * string req_data = 48; - * @return The bytes for reqData. - */ - com.google.protobuf.ByteString - getReqDataBytes(); + com.google.protobuf.ByteString getReqData(); /** - * string res_data = 49; + * bytes res_data = 49; * @return The resData. */ - java.lang.String getResData(); - /** - * string res_data = 49; - * @return The bytes for resData. - */ - com.google.protobuf.ByteString - getResDataBytes(); + com.google.protobuf.ByteString getResData(); /** - * string reserved = 50; + * bytes reserved = 50; * @return The reserved. */ - java.lang.String getReserved(); - /** - * string reserved = 50; - * @return The bytes for reserved. - */ - com.google.protobuf.ByteString - getReservedBytes(); + com.google.protobuf.ByteString getReserved(); } /** * Protobuf type {@code dataflow.BussFlowDb} @@ -407,15 +353,15 @@ public final class BussFlowDbOuterClass { super(builder); } private BussFlowDb() { - msgVersion_ = ""; - seqAck_ = ""; - channel_ = ""; - dbname_ = ""; - sql_ = ""; - bussinessDetailMesg_ = ""; - reqData_ = ""; - resData_ = ""; - reserved_ = ""; + msgVersion_ = com.google.protobuf.ByteString.EMPTY; + seqAck_ = com.google.protobuf.ByteString.EMPTY; + channel_ = com.google.protobuf.ByteString.EMPTY; + dbname_ = com.google.protobuf.ByteString.EMPTY; + sql_ = com.google.protobuf.ByteString.EMPTY; + bussinessDetailMesg_ = com.google.protobuf.ByteString.EMPTY; + reqData_ = com.google.protobuf.ByteString.EMPTY; + resData_ = com.google.protobuf.ByteString.EMPTY; + reserved_ = com.google.protobuf.ByteString.EMPTY; } @java.lang.Override @@ -459,9 +405,8 @@ public final class BussFlowDbOuterClass { break; } case 26: { - java.lang.String s = input.readStringRequireUtf8(); - msgVersion_ = s; + msgVersion_ = input.readBytes(); break; } case 32: { @@ -535,9 +480,8 @@ public final class BussFlowDbOuterClass { break; } case 146: { - java.lang.String s = input.readStringRequireUtf8(); - seqAck_ = s; + seqAck_ = input.readBytes(); break; } case 152: { @@ -551,15 +495,13 @@ public final class BussFlowDbOuterClass { break; } case 170: { - java.lang.String s = input.readStringRequireUtf8(); - channel_ = s; + channel_ = input.readBytes(); break; } case 178: { - java.lang.String s = input.readStringRequireUtf8(); - dbname_ = s; + dbname_ = input.readBytes(); break; } case 186: { @@ -694,33 +636,28 @@ public final class BussFlowDbOuterClass { break; } case 370: { - java.lang.String s = input.readStringRequireUtf8(); - sql_ = s; + sql_ = input.readBytes(); break; } case 378: { - java.lang.String s = input.readStringRequireUtf8(); - bussinessDetailMesg_ = s; + bussinessDetailMesg_ = input.readBytes(); break; } case 386: { - java.lang.String s = input.readStringRequireUtf8(); - reqData_ = s; + reqData_ = input.readBytes(); break; } case 394: { - java.lang.String s = input.readStringRequireUtf8(); - resData_ = s; + resData_ = input.readBytes(); break; } case 402: { - java.lang.String s = input.readStringRequireUtf8(); - reserved_ = s; + reserved_ = input.readBytes(); break; } default: { @@ -784,41 +721,14 @@ public final class BussFlowDbOuterClass { } public static final int MSG_VERSION_FIELD_NUMBER = 3; - private volatile java.lang.Object msgVersion_; + private com.google.protobuf.ByteString msgVersion_; /** - * string msg_version = 3; + * bytes msg_version = 3; * @return The msgVersion. */ @java.lang.Override - public java.lang.String getMsgVersion() { - java.lang.Object ref = msgVersion_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - msgVersion_ = s; - return s; - } - } - /** - * string msg_version = 3; - * @return The bytes for msgVersion. - */ - @java.lang.Override - public com.google.protobuf.ByteString - getMsgVersionBytes() { - java.lang.Object ref = msgVersion_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - msgVersion_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } + public com.google.protobuf.ByteString getMsgVersion() { + return msgVersion_; } public static final int MSG_SEQ_FIELD_NUMBER = 4; @@ -976,41 +886,14 @@ public final class BussFlowDbOuterClass { } public static final int SEQ_ACK_FIELD_NUMBER = 18; - private volatile java.lang.Object seqAck_; + private com.google.protobuf.ByteString seqAck_; /** - * string seq_ack = 18; + * bytes seq_ack = 18; * @return The seqAck. */ @java.lang.Override - public java.lang.String getSeqAck() { - java.lang.Object ref = seqAck_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - seqAck_ = s; - return s; - } - } - /** - * string seq_ack = 18; - * @return The bytes for seqAck. - */ - @java.lang.Override - public com.google.protobuf.ByteString - getSeqAckBytes() { - java.lang.Object ref = seqAck_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - seqAck_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } + public com.google.protobuf.ByteString getSeqAck() { + return seqAck_; } public static final int RECOG_STATUS_FIELD_NUMBER = 19; @@ -1036,79 +919,25 @@ public final class BussFlowDbOuterClass { } public static final int CHANNEL_FIELD_NUMBER = 21; - private volatile java.lang.Object channel_; + private com.google.protobuf.ByteString channel_; /** - * string channel = 21; + * bytes channel = 21; * @return The channel. */ @java.lang.Override - public java.lang.String getChannel() { - java.lang.Object ref = channel_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - channel_ = s; - return s; - } - } - /** - * string channel = 21; - * @return The bytes for channel. - */ - @java.lang.Override - public com.google.protobuf.ByteString - getChannelBytes() { - java.lang.Object ref = channel_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - channel_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } + public com.google.protobuf.ByteString getChannel() { + return channel_; } public static final int DBNAME_FIELD_NUMBER = 22; - private volatile java.lang.Object dbname_; + private com.google.protobuf.ByteString dbname_; /** - * string dbname = 22; + * bytes dbname = 22; * @return The dbname. */ @java.lang.Override - public java.lang.String getDbname() { - java.lang.Object ref = dbname_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - dbname_ = s; - return s; - } - } - /** - * string dbname = 22; - * @return The bytes for dbname. - */ - @java.lang.Override - public com.google.protobuf.ByteString - getDbnameBytes() { - java.lang.Object ref = dbname_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - dbname_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } + public com.google.protobuf.ByteString getDbname() { + return dbname_; } public static final int REQUEST_IP_FIELD_NUMBER = 23; @@ -1395,193 +1224,58 @@ public final class BussFlowDbOuterClass { } public static final int SQL_FIELD_NUMBER = 46; - private volatile java.lang.Object sql_; + private com.google.protobuf.ByteString sql_; /** - * string sql = 46; + * bytes sql = 46; * @return The sql. */ @java.lang.Override - public java.lang.String getSql() { - java.lang.Object ref = sql_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - sql_ = s; - return s; - } - } - /** - * string sql = 46; - * @return The bytes for sql. - */ - @java.lang.Override - public com.google.protobuf.ByteString - getSqlBytes() { - java.lang.Object ref = sql_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - sql_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } + public com.google.protobuf.ByteString getSql() { + return sql_; } public static final int BUSSINESS_DETAIL_MESG_FIELD_NUMBER = 47; - private volatile java.lang.Object bussinessDetailMesg_; + private com.google.protobuf.ByteString bussinessDetailMesg_; /** - * string bussiness_detail_mesg = 47; + * bytes bussiness_detail_mesg = 47; * @return The bussinessDetailMesg. */ @java.lang.Override - public java.lang.String getBussinessDetailMesg() { - java.lang.Object ref = bussinessDetailMesg_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - bussinessDetailMesg_ = s; - return s; - } - } - /** - * string bussiness_detail_mesg = 47; - * @return The bytes for bussinessDetailMesg. - */ - @java.lang.Override - public com.google.protobuf.ByteString - getBussinessDetailMesgBytes() { - java.lang.Object ref = bussinessDetailMesg_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - bussinessDetailMesg_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } + public com.google.protobuf.ByteString getBussinessDetailMesg() { + return bussinessDetailMesg_; } public static final int REQ_DATA_FIELD_NUMBER = 48; - private volatile java.lang.Object reqData_; + private com.google.protobuf.ByteString reqData_; /** - * string req_data = 48; + * bytes req_data = 48; * @return The reqData. */ @java.lang.Override - public java.lang.String getReqData() { - java.lang.Object ref = reqData_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - reqData_ = s; - return s; - } - } - /** - * string req_data = 48; - * @return The bytes for reqData. - */ - @java.lang.Override - public com.google.protobuf.ByteString - getReqDataBytes() { - java.lang.Object ref = reqData_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - reqData_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } + public com.google.protobuf.ByteString getReqData() { + return reqData_; } public static final int RES_DATA_FIELD_NUMBER = 49; - private volatile java.lang.Object resData_; + private com.google.protobuf.ByteString resData_; /** - * string res_data = 49; + * bytes res_data = 49; * @return The resData. */ @java.lang.Override - public java.lang.String getResData() { - java.lang.Object ref = resData_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - resData_ = s; - return s; - } - } - /** - * string res_data = 49; - * @return The bytes for resData. - */ - @java.lang.Override - public com.google.protobuf.ByteString - getResDataBytes() { - java.lang.Object ref = resData_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - resData_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } + public com.google.protobuf.ByteString getResData() { + return resData_; } public static final int RESERVED_FIELD_NUMBER = 50; - private volatile java.lang.Object reserved_; + private com.google.protobuf.ByteString reserved_; /** - * string reserved = 50; + * bytes reserved = 50; * @return The reserved. */ @java.lang.Override - public java.lang.String getReserved() { - java.lang.Object ref = reserved_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - reserved_ = s; - return s; - } - } - /** - * string reserved = 50; - * @return The bytes for reserved. - */ - @java.lang.Override - public com.google.protobuf.ByteString - getReservedBytes() { - java.lang.Object ref = reserved_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - reserved_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } + public com.google.protobuf.ByteString getReserved() { + return reserved_; } private byte memoizedIsInitialized = -1; @@ -1604,8 +1298,8 @@ public final class BussFlowDbOuterClass { if (msgType_ != 0) { output.writeUInt32(2, msgType_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(msgVersion_)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 3, msgVersion_); + if (!msgVersion_.isEmpty()) { + output.writeBytes(3, msgVersion_); } if (msgSeq_ != 0) { output.writeUInt32(4, msgSeq_); @@ -1649,8 +1343,8 @@ public final class BussFlowDbOuterClass { if (requestPackets_ != 0) { output.writeUInt32(17, requestPackets_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(seqAck_)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 18, seqAck_); + if (!seqAck_.isEmpty()) { + output.writeBytes(18, seqAck_); } if (recogStatus_ != 0) { output.writeUInt32(19, recogStatus_); @@ -1658,11 +1352,11 @@ public final class BussFlowDbOuterClass { if (probeIf_ != 0) { output.writeUInt32(20, probeIf_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(channel_)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 21, channel_); + if (!channel_.isEmpty()) { + output.writeBytes(21, channel_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(dbname_)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 22, dbname_); + if (!dbname_.isEmpty()) { + output.writeBytes(22, dbname_); } if (requestIp_ != null) { output.writeMessage(23, getRequestIp()); @@ -1733,20 +1427,20 @@ public final class BussFlowDbOuterClass { if (reservedLen_ != 0) { output.writeUInt32(45, reservedLen_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(sql_)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 46, sql_); + if (!sql_.isEmpty()) { + output.writeBytes(46, sql_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(bussinessDetailMesg_)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 47, bussinessDetailMesg_); + if (!bussinessDetailMesg_.isEmpty()) { + output.writeBytes(47, bussinessDetailMesg_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(reqData_)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 48, reqData_); + if (!reqData_.isEmpty()) { + output.writeBytes(48, reqData_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(resData_)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 49, resData_); + if (!resData_.isEmpty()) { + output.writeBytes(49, resData_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(reserved_)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 50, reserved_); + if (!reserved_.isEmpty()) { + output.writeBytes(50, reserved_); } unknownFields.writeTo(output); } @@ -1765,8 +1459,9 @@ public final class BussFlowDbOuterClass { size += com.google.protobuf.CodedOutputStream .computeUInt32Size(2, msgType_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(msgVersion_)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(3, msgVersion_); + if (!msgVersion_.isEmpty()) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(3, msgVersion_); } if (msgSeq_ != 0) { size += com.google.protobuf.CodedOutputStream @@ -1824,8 +1519,9 @@ public final class BussFlowDbOuterClass { size += com.google.protobuf.CodedOutputStream .computeUInt32Size(17, requestPackets_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(seqAck_)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(18, seqAck_); + if (!seqAck_.isEmpty()) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(18, seqAck_); } if (recogStatus_ != 0) { size += com.google.protobuf.CodedOutputStream @@ -1835,11 +1531,13 @@ public final class BussFlowDbOuterClass { size += com.google.protobuf.CodedOutputStream .computeUInt32Size(20, probeIf_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(channel_)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(21, channel_); + if (!channel_.isEmpty()) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(21, channel_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(dbname_)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(22, dbname_); + if (!dbname_.isEmpty()) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(22, dbname_); } if (requestIp_ != null) { size += com.google.protobuf.CodedOutputStream @@ -1933,20 +1631,25 @@ public final class BussFlowDbOuterClass { size += com.google.protobuf.CodedOutputStream .computeUInt32Size(45, reservedLen_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(sql_)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(46, sql_); + if (!sql_.isEmpty()) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(46, sql_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(bussinessDetailMesg_)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(47, bussinessDetailMesg_); + if (!bussinessDetailMesg_.isEmpty()) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(47, bussinessDetailMesg_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(reqData_)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(48, reqData_); + if (!reqData_.isEmpty()) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(48, reqData_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(resData_)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(49, resData_); + if (!resData_.isEmpty()) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(49, resData_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(reserved_)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(50, reserved_); + if (!reserved_.isEmpty()) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(50, reserved_); } size += unknownFields.getSerializedSize(); memoizedSize = size; @@ -2327,7 +2030,7 @@ public final class BussFlowDbOuterClass { msgType_ = 0; - msgVersion_ = ""; + msgVersion_ = com.google.protobuf.ByteString.EMPTY; msgSeq_ = 0; @@ -2357,15 +2060,15 @@ public final class BussFlowDbOuterClass { requestPackets_ = 0; - seqAck_ = ""; + seqAck_ = com.google.protobuf.ByteString.EMPTY; recogStatus_ = 0; probeIf_ = 0; - channel_ = ""; + channel_ = com.google.protobuf.ByteString.EMPTY; - dbname_ = ""; + dbname_ = com.google.protobuf.ByteString.EMPTY; if (requestIpBuilder_ == null) { requestIp_ = null; @@ -2421,15 +2124,15 @@ public final class BussFlowDbOuterClass { reservedLen_ = 0; - sql_ = ""; + sql_ = com.google.protobuf.ByteString.EMPTY; - bussinessDetailMesg_ = ""; + bussinessDetailMesg_ = com.google.protobuf.ByteString.EMPTY; - reqData_ = ""; + reqData_ = com.google.protobuf.ByteString.EMPTY; - resData_ = ""; + resData_ = com.google.protobuf.ByteString.EMPTY; - reserved_ = ""; + reserved_ = com.google.protobuf.ByteString.EMPTY; return this; } @@ -2569,9 +2272,8 @@ public final class BussFlowDbOuterClass { if (other.getMsgType() != 0) { setMsgType(other.getMsgType()); } - if (!other.getMsgVersion().isEmpty()) { - msgVersion_ = other.msgVersion_; - onChanged(); + if (other.getMsgVersion() != com.google.protobuf.ByteString.EMPTY) { + setMsgVersion(other.getMsgVersion()); } if (other.getMsgSeq() != 0) { setMsgSeq(other.getMsgSeq()); @@ -2615,9 +2317,8 @@ public final class BussFlowDbOuterClass { if (other.getRequestPackets() != 0) { setRequestPackets(other.getRequestPackets()); } - if (!other.getSeqAck().isEmpty()) { - seqAck_ = other.seqAck_; - onChanged(); + if (other.getSeqAck() != com.google.protobuf.ByteString.EMPTY) { + setSeqAck(other.getSeqAck()); } if (other.getRecogStatus() != 0) { setRecogStatus(other.getRecogStatus()); @@ -2625,13 +2326,11 @@ public final class BussFlowDbOuterClass { if (other.getProbeIf() != 0) { setProbeIf(other.getProbeIf()); } - if (!other.getChannel().isEmpty()) { - channel_ = other.channel_; - onChanged(); + if (other.getChannel() != com.google.protobuf.ByteString.EMPTY) { + setChannel(other.getChannel()); } - if (!other.getDbname().isEmpty()) { - dbname_ = other.dbname_; - onChanged(); + if (other.getDbname() != com.google.protobuf.ByteString.EMPTY) { + setDbname(other.getDbname()); } if (other.hasRequestIp()) { mergeRequestIp(other.getRequestIp()); @@ -2702,25 +2401,20 @@ public final class BussFlowDbOuterClass { if (other.getReservedLen() != 0) { setReservedLen(other.getReservedLen()); } - if (!other.getSql().isEmpty()) { - sql_ = other.sql_; - onChanged(); + if (other.getSql() != com.google.protobuf.ByteString.EMPTY) { + setSql(other.getSql()); } - if (!other.getBussinessDetailMesg().isEmpty()) { - bussinessDetailMesg_ = other.bussinessDetailMesg_; - onChanged(); + if (other.getBussinessDetailMesg() != com.google.protobuf.ByteString.EMPTY) { + setBussinessDetailMesg(other.getBussinessDetailMesg()); } - if (!other.getReqData().isEmpty()) { - reqData_ = other.reqData_; - onChanged(); + if (other.getReqData() != com.google.protobuf.ByteString.EMPTY) { + setReqData(other.getReqData()); } - if (!other.getResData().isEmpty()) { - resData_ = other.resData_; - onChanged(); + if (other.getResData() != com.google.protobuf.ByteString.EMPTY) { + setResData(other.getResData()); } - if (!other.getReserved().isEmpty()) { - reserved_ = other.reserved_; - onChanged(); + if (other.getReserved() != com.google.protobuf.ByteString.EMPTY) { + setReserved(other.getReserved()); } this.mergeUnknownFields(other.unknownFields); onChanged(); @@ -2825,47 +2519,21 @@ public final class BussFlowDbOuterClass { return this; } - private java.lang.Object msgVersion_ = ""; + private com.google.protobuf.ByteString msgVersion_ = com.google.protobuf.ByteString.EMPTY; /** - * string msg_version = 3; + * bytes msg_version = 3; * @return The msgVersion. */ - public java.lang.String getMsgVersion() { - java.lang.Object ref = msgVersion_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - msgVersion_ = s; - return s; - } else { - return (java.lang.String) ref; - } + @java.lang.Override + public com.google.protobuf.ByteString getMsgVersion() { + return msgVersion_; } /** - * string msg_version = 3; - * @return The bytes for msgVersion. - */ - public com.google.protobuf.ByteString - getMsgVersionBytes() { - java.lang.Object ref = msgVersion_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - msgVersion_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * string msg_version = 3; + * bytes msg_version = 3; * @param value The msgVersion to set. * @return This builder for chaining. */ - public Builder setMsgVersion( - java.lang.String value) { + public Builder setMsgVersion(com.google.protobuf.ByteString value) { if (value == null) { throw new NullPointerException(); } @@ -2875,7 +2543,7 @@ public final class BussFlowDbOuterClass { return this; } /** - * string msg_version = 3; + * bytes msg_version = 3; * @return This builder for chaining. */ public Builder clearMsgVersion() { @@ -2884,22 +2552,6 @@ public final class BussFlowDbOuterClass { onChanged(); return this; } - /** - * string msg_version = 3; - * @param value The bytes for msgVersion to set. - * @return This builder for chaining. - */ - public Builder setMsgVersionBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - msgVersion_ = value; - onChanged(); - return this; - } private int msgSeq_ ; /** @@ -3335,47 +2987,21 @@ public final class BussFlowDbOuterClass { return this; } - private java.lang.Object seqAck_ = ""; + private com.google.protobuf.ByteString seqAck_ = com.google.protobuf.ByteString.EMPTY; /** - * string seq_ack = 18; + * bytes seq_ack = 18; * @return The seqAck. */ - public java.lang.String getSeqAck() { - java.lang.Object ref = seqAck_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - seqAck_ = s; - return s; - } else { - return (java.lang.String) ref; - } + @java.lang.Override + public com.google.protobuf.ByteString getSeqAck() { + return seqAck_; } /** - * string seq_ack = 18; - * @return The bytes for seqAck. - */ - public com.google.protobuf.ByteString - getSeqAckBytes() { - java.lang.Object ref = seqAck_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - seqAck_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * string seq_ack = 18; + * bytes seq_ack = 18; * @param value The seqAck to set. * @return This builder for chaining. */ - public Builder setSeqAck( - java.lang.String value) { + public Builder setSeqAck(com.google.protobuf.ByteString value) { if (value == null) { throw new NullPointerException(); } @@ -3385,7 +3011,7 @@ public final class BussFlowDbOuterClass { return this; } /** - * string seq_ack = 18; + * bytes seq_ack = 18; * @return This builder for chaining. */ public Builder clearSeqAck() { @@ -3394,22 +3020,6 @@ public final class BussFlowDbOuterClass { onChanged(); return this; } - /** - * string seq_ack = 18; - * @param value The bytes for seqAck to set. - * @return This builder for chaining. - */ - public Builder setSeqAckBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - seqAck_ = value; - onChanged(); - return this; - } private int recogStatus_ ; /** @@ -3473,47 +3083,21 @@ public final class BussFlowDbOuterClass { return this; } - private java.lang.Object channel_ = ""; + private com.google.protobuf.ByteString channel_ = com.google.protobuf.ByteString.EMPTY; /** - * string channel = 21; + * bytes channel = 21; * @return The channel. */ - public java.lang.String getChannel() { - java.lang.Object ref = channel_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - channel_ = s; - return s; - } else { - return (java.lang.String) ref; - } + @java.lang.Override + public com.google.protobuf.ByteString getChannel() { + return channel_; } /** - * string channel = 21; - * @return The bytes for channel. - */ - public com.google.protobuf.ByteString - getChannelBytes() { - java.lang.Object ref = channel_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - channel_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * string channel = 21; + * bytes channel = 21; * @param value The channel to set. * @return This builder for chaining. */ - public Builder setChannel( - java.lang.String value) { + public Builder setChannel(com.google.protobuf.ByteString value) { if (value == null) { throw new NullPointerException(); } @@ -3523,7 +3107,7 @@ public final class BussFlowDbOuterClass { return this; } /** - * string channel = 21; + * bytes channel = 21; * @return This builder for chaining. */ public Builder clearChannel() { @@ -3532,64 +3116,22 @@ public final class BussFlowDbOuterClass { onChanged(); return this; } - /** - * string channel = 21; - * @param value The bytes for channel to set. - * @return This builder for chaining. - */ - public Builder setChannelBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - channel_ = value; - onChanged(); - return this; - } - private java.lang.Object dbname_ = ""; + private com.google.protobuf.ByteString dbname_ = com.google.protobuf.ByteString.EMPTY; /** - * string dbname = 22; + * bytes dbname = 22; * @return The dbname. */ - public java.lang.String getDbname() { - java.lang.Object ref = dbname_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - dbname_ = s; - return s; - } else { - return (java.lang.String) ref; - } + @java.lang.Override + public com.google.protobuf.ByteString getDbname() { + return dbname_; } /** - * string dbname = 22; - * @return The bytes for dbname. - */ - public com.google.protobuf.ByteString - getDbnameBytes() { - java.lang.Object ref = dbname_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - dbname_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * string dbname = 22; + * bytes dbname = 22; * @param value The dbname to set. * @return This builder for chaining. */ - public Builder setDbname( - java.lang.String value) { + public Builder setDbname(com.google.protobuf.ByteString value) { if (value == null) { throw new NullPointerException(); } @@ -3599,7 +3141,7 @@ public final class BussFlowDbOuterClass { return this; } /** - * string dbname = 22; + * bytes dbname = 22; * @return This builder for chaining. */ public Builder clearDbname() { @@ -3608,22 +3150,6 @@ public final class BussFlowDbOuterClass { onChanged(); return this; } - /** - * string dbname = 22; - * @param value The bytes for dbname to set. - * @return This builder for chaining. - */ - public Builder setDbnameBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - dbname_ = value; - onChanged(); - return this; - } private com.yuandian.dataflow.proto.Base.IPAddress requestIp_; private com.google.protobuf.SingleFieldBuilderV3< @@ -4514,47 +4040,21 @@ public final class BussFlowDbOuterClass { return this; } - private java.lang.Object sql_ = ""; + private com.google.protobuf.ByteString sql_ = com.google.protobuf.ByteString.EMPTY; /** - * string sql = 46; + * bytes sql = 46; * @return The sql. */ - public java.lang.String getSql() { - java.lang.Object ref = sql_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - sql_ = s; - return s; - } else { - return (java.lang.String) ref; - } + @java.lang.Override + public com.google.protobuf.ByteString getSql() { + return sql_; } /** - * string sql = 46; - * @return The bytes for sql. - */ - public com.google.protobuf.ByteString - getSqlBytes() { - java.lang.Object ref = sql_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - sql_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * string sql = 46; + * bytes sql = 46; * @param value The sql to set. * @return This builder for chaining. */ - public Builder setSql( - java.lang.String value) { + public Builder setSql(com.google.protobuf.ByteString value) { if (value == null) { throw new NullPointerException(); } @@ -4564,7 +4064,7 @@ public final class BussFlowDbOuterClass { return this; } /** - * string sql = 46; + * bytes sql = 46; * @return This builder for chaining. */ public Builder clearSql() { @@ -4573,64 +4073,22 @@ public final class BussFlowDbOuterClass { onChanged(); return this; } - /** - * string sql = 46; - * @param value The bytes for sql to set. - * @return This builder for chaining. - */ - public Builder setSqlBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - sql_ = value; - onChanged(); - return this; - } - private java.lang.Object bussinessDetailMesg_ = ""; + private com.google.protobuf.ByteString bussinessDetailMesg_ = com.google.protobuf.ByteString.EMPTY; /** - * string bussiness_detail_mesg = 47; + * bytes bussiness_detail_mesg = 47; * @return The bussinessDetailMesg. */ - public java.lang.String getBussinessDetailMesg() { - java.lang.Object ref = bussinessDetailMesg_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - bussinessDetailMesg_ = s; - return s; - } else { - return (java.lang.String) ref; - } + @java.lang.Override + public com.google.protobuf.ByteString getBussinessDetailMesg() { + return bussinessDetailMesg_; } /** - * string bussiness_detail_mesg = 47; - * @return The bytes for bussinessDetailMesg. - */ - public com.google.protobuf.ByteString - getBussinessDetailMesgBytes() { - java.lang.Object ref = bussinessDetailMesg_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - bussinessDetailMesg_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * string bussiness_detail_mesg = 47; + * bytes bussiness_detail_mesg = 47; * @param value The bussinessDetailMesg to set. * @return This builder for chaining. */ - public Builder setBussinessDetailMesg( - java.lang.String value) { + public Builder setBussinessDetailMesg(com.google.protobuf.ByteString value) { if (value == null) { throw new NullPointerException(); } @@ -4640,7 +4098,7 @@ public final class BussFlowDbOuterClass { return this; } /** - * string bussiness_detail_mesg = 47; + * bytes bussiness_detail_mesg = 47; * @return This builder for chaining. */ public Builder clearBussinessDetailMesg() { @@ -4649,64 +4107,22 @@ public final class BussFlowDbOuterClass { onChanged(); return this; } - /** - * string bussiness_detail_mesg = 47; - * @param value The bytes for bussinessDetailMesg to set. - * @return This builder for chaining. - */ - public Builder setBussinessDetailMesgBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - bussinessDetailMesg_ = value; - onChanged(); - return this; - } - private java.lang.Object reqData_ = ""; + private com.google.protobuf.ByteString reqData_ = com.google.protobuf.ByteString.EMPTY; /** - * string req_data = 48; + * bytes req_data = 48; * @return The reqData. */ - public java.lang.String getReqData() { - java.lang.Object ref = reqData_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - reqData_ = s; - return s; - } else { - return (java.lang.String) ref; - } + @java.lang.Override + public com.google.protobuf.ByteString getReqData() { + return reqData_; } /** - * string req_data = 48; - * @return The bytes for reqData. - */ - public com.google.protobuf.ByteString - getReqDataBytes() { - java.lang.Object ref = reqData_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - reqData_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * string req_data = 48; + * bytes req_data = 48; * @param value The reqData to set. * @return This builder for chaining. */ - public Builder setReqData( - java.lang.String value) { + public Builder setReqData(com.google.protobuf.ByteString value) { if (value == null) { throw new NullPointerException(); } @@ -4716,7 +4132,7 @@ public final class BussFlowDbOuterClass { return this; } /** - * string req_data = 48; + * bytes req_data = 48; * @return This builder for chaining. */ public Builder clearReqData() { @@ -4725,64 +4141,22 @@ public final class BussFlowDbOuterClass { onChanged(); return this; } - /** - * string req_data = 48; - * @param value The bytes for reqData to set. - * @return This builder for chaining. - */ - public Builder setReqDataBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - reqData_ = value; - onChanged(); - return this; - } - private java.lang.Object resData_ = ""; + private com.google.protobuf.ByteString resData_ = com.google.protobuf.ByteString.EMPTY; /** - * string res_data = 49; + * bytes res_data = 49; * @return The resData. */ - public java.lang.String getResData() { - java.lang.Object ref = resData_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - resData_ = s; - return s; - } else { - return (java.lang.String) ref; - } + @java.lang.Override + public com.google.protobuf.ByteString getResData() { + return resData_; } /** - * string res_data = 49; - * @return The bytes for resData. - */ - public com.google.protobuf.ByteString - getResDataBytes() { - java.lang.Object ref = resData_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - resData_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * string res_data = 49; + * bytes res_data = 49; * @param value The resData to set. * @return This builder for chaining. */ - public Builder setResData( - java.lang.String value) { + public Builder setResData(com.google.protobuf.ByteString value) { if (value == null) { throw new NullPointerException(); } @@ -4792,7 +4166,7 @@ public final class BussFlowDbOuterClass { return this; } /** - * string res_data = 49; + * bytes res_data = 49; * @return This builder for chaining. */ public Builder clearResData() { @@ -4801,64 +4175,22 @@ public final class BussFlowDbOuterClass { onChanged(); return this; } - /** - * string res_data = 49; - * @param value The bytes for resData to set. - * @return This builder for chaining. - */ - public Builder setResDataBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - resData_ = value; - onChanged(); - return this; - } - private java.lang.Object reserved_ = ""; + private com.google.protobuf.ByteString reserved_ = com.google.protobuf.ByteString.EMPTY; /** - * string reserved = 50; + * bytes reserved = 50; * @return The reserved. */ - public java.lang.String getReserved() { - java.lang.Object ref = reserved_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - reserved_ = s; - return s; - } else { - return (java.lang.String) ref; - } + @java.lang.Override + public com.google.protobuf.ByteString getReserved() { + return reserved_; } /** - * string reserved = 50; - * @return The bytes for reserved. - */ - public com.google.protobuf.ByteString - getReservedBytes() { - java.lang.Object ref = reserved_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - reserved_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * string reserved = 50; + * bytes reserved = 50; * @param value The reserved to set. * @return This builder for chaining. */ - public Builder setReserved( - java.lang.String value) { + public Builder setReserved(com.google.protobuf.ByteString value) { if (value == null) { throw new NullPointerException(); } @@ -4868,7 +4200,7 @@ public final class BussFlowDbOuterClass { return this; } /** - * string reserved = 50; + * bytes reserved = 50; * @return This builder for chaining. */ public Builder clearReserved() { @@ -4877,22 +4209,6 @@ public final class BussFlowDbOuterClass { onChanged(); return this; } - /** - * string reserved = 50; - * @param value The bytes for reserved to set. - * @return This builder for chaining. - */ - public Builder setReservedBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - reserved_ = value; - onChanged(); - return this; - } @java.lang.Override public final Builder setUnknownFields( final com.google.protobuf.UnknownFieldSet unknownFields) { @@ -4962,7 +4278,7 @@ public final class BussFlowDbOuterClass { java.lang.String[] descriptorData = { "\n\020BussFlowDb.proto\022\010dataflow\032\nBase.proto" + "\"\244\t\n\nBussFlowDb\022\020\n\010table_id\030\001 \001(\005\022\020\n\010msg" + - "_type\030\002 \001(\r\022\023\n\013msg_version\030\003 \001(\t\022\017\n\007msg_" + + "_type\030\002 \001(\r\022\023\n\013msg_version\030\003 \001(\014\022\017\n\007msg_" + "seq\030\004 \001(\r\022\017\n\007msg_len\030\005 \001(\r\022\017\n\007src_mac\030\006 " + "\001(\004\022\017\n\007dst_mac\030\007 \001(\004\022\017\n\007vlan_id\030\010 \001(\r\022\013\n" + "\003tos\030\t \001(\r\022\024\n\014retran_count\030\n \001(\r\022\023\n\013rese" + @@ -4970,9 +4286,9 @@ public final class BussFlowDbOuterClass { "protocol\030\r \001(\r\022\026\n\016response_bytes\030\016 \001(\r\022\025" + "\n\rrequest_bytes\030\017 \001(\r\022\030\n\020response_packet" + "s\030\020 \001(\r\022\027\n\017request_packets\030\021 \001(\r\022\017\n\007seq_" + - "ack\030\022 \001(\t\022\024\n\014recog_status\030\023 \001(\r\022\020\n\010probe" + - "_if\030\024 \001(\r\022\017\n\007channel\030\025 \001(\t\022\016\n\006dbname\030\026 \001" + - "(\t\022\'\n\nrequest_ip\030\027 \001(\0132\023.dataflow.IPAddr" + + "ack\030\022 \001(\014\022\024\n\014recog_status\030\023 \001(\r\022\020\n\010probe" + + "_if\030\024 \001(\r\022\017\n\007channel\030\025 \001(\014\022\016\n\006dbname\030\026 \001" + + "(\014\022\'\n\nrequest_ip\030\027 \001(\0132\023.dataflow.IPAddr" + "ess\022\024\n\014request_port\030\030 \001(\r\022(\n\013response_ip" + "\030\031 \001(\0132\023.dataflow.IPAddress\022\025\n\rresponse_" + "port\030\032 \001(\r\022\016\n\006status\030\033 \001(\003\022\035\n\025server_tra" + @@ -4988,9 +4304,9 @@ public final class BussFlowDbOuterClass { "_uncomplete\030\' \001(\005\022\021\n\ttime_flag\030( \001(\r\022\017\n\007" + "sql_len\030) \001(\r\022\026\n\016detail_msg_len\030* \001(\r\022\017\n" + "\007req_len\030+ \001(\r\022\017\n\007res_len\030, \001(\r\022\024\n\014reser" + - "ved_len\030- \001(\r\022\013\n\003sql\030. \001(\t\022\035\n\025bussiness_" + - "detail_mesg\030/ \001(\t\022\020\n\010req_data\0300 \001(\t\022\020\n\010r" + - "es_data\0301 \001(\t\022\020\n\010reserved\0302 \001(\tB<\n#com.y" + + "ved_len\030- \001(\r\022\013\n\003sql\030. \001(\014\022\035\n\025bussiness_" + + "detail_mesg\030/ \001(\014\022\020\n\010req_data\0300 \001(\014\022\020\n\010r" + + "es_data\0301 \001(\014\022\020\n\010reserved\0302 \001(\014B<\n#com.y" + "uandian.dataflow.proto.msgtypeP\000Z\023../grp" + "c-gen;grpcgenb\006proto3" }; diff --git a/src/main/java/com/yuandian/dataflow/proto/msgtype/BussFlowExternalOuterClass.java b/src/main/java/com/yuandian/dataflow/proto/msgtype/BussFlowExternalOuterClass.java index bb62a1b..739d506 100644 --- a/src/main/java/com/yuandian/dataflow/proto/msgtype/BussFlowExternalOuterClass.java +++ b/src/main/java/com/yuandian/dataflow/proto/msgtype/BussFlowExternalOuterClass.java @@ -179,100 +179,52 @@ public final class BussFlowExternalOuterClass { int getRemainLen(); /** - * string busi_code = 24; + * bytes busi_code = 24; * @return The busiCode. */ - java.lang.String getBusiCode(); - /** - * string busi_code = 24; - * @return The bytes for busiCode. - */ - com.google.protobuf.ByteString - getBusiCodeBytes(); + com.google.protobuf.ByteString getBusiCode(); /** - * string sessionid = 25; + * bytes sessionid = 25; * @return The sessionid. */ - java.lang.String getSessionid(); - /** - * string sessionid = 25; - * @return The bytes for sessionid. - */ - com.google.protobuf.ByteString - getSessionidBytes(); + com.google.protobuf.ByteString getSessionid(); /** - * string req_data = 26; + * bytes req_data = 26; * @return The reqData. */ - java.lang.String getReqData(); - /** - * string req_data = 26; - * @return The bytes for reqData. - */ - com.google.protobuf.ByteString - getReqDataBytes(); + com.google.protobuf.ByteString getReqData(); /** - * string res_data = 27; + * bytes res_data = 27; * @return The resData. */ - java.lang.String getResData(); - /** - * string res_data = 27; - * @return The bytes for resData. - */ - com.google.protobuf.ByteString - getResDataBytes(); + com.google.protobuf.ByteString getResData(); /** - * string busi_msg = 28; + * bytes busi_msg = 28; * @return The busiMsg. */ - java.lang.String getBusiMsg(); - /** - * string busi_msg = 28; - * @return The bytes for busiMsg. - */ - com.google.protobuf.ByteString - getBusiMsgBytes(); + com.google.protobuf.ByteString getBusiMsg(); /** - * string busi_key_msg = 29; + * bytes busi_key_msg = 29; * @return The busiKeyMsg. */ - java.lang.String getBusiKeyMsg(); - /** - * string busi_key_msg = 29; - * @return The bytes for busiKeyMsg. - */ - com.google.protobuf.ByteString - getBusiKeyMsgBytes(); + com.google.protobuf.ByteString getBusiKeyMsg(); /** - * string busi_detail_msg = 30; + * bytes busi_detail_msg = 30; * @return The busiDetailMsg. */ - java.lang.String getBusiDetailMsg(); - /** - * string busi_detail_msg = 30; - * @return The bytes for busiDetailMsg. - */ - com.google.protobuf.ByteString - getBusiDetailMsgBytes(); + com.google.protobuf.ByteString getBusiDetailMsg(); /** - * string remain_data = 31; + * bytes remain_data = 31; * @return The remainData. */ - java.lang.String getRemainData(); - /** - * string remain_data = 31; - * @return The bytes for remainData. - */ - com.google.protobuf.ByteString - getRemainDataBytes(); + com.google.protobuf.ByteString getRemainData(); } /** * Protobuf type {@code dataflow.BussFlowExternal} @@ -287,14 +239,14 @@ public final class BussFlowExternalOuterClass { super(builder); } private BussFlowExternal() { - busiCode_ = ""; - sessionid_ = ""; - reqData_ = ""; - resData_ = ""; - busiMsg_ = ""; - busiKeyMsg_ = ""; - busiDetailMsg_ = ""; - remainData_ = ""; + busiCode_ = com.google.protobuf.ByteString.EMPTY; + sessionid_ = com.google.protobuf.ByteString.EMPTY; + reqData_ = com.google.protobuf.ByteString.EMPTY; + resData_ = com.google.protobuf.ByteString.EMPTY; + busiMsg_ = com.google.protobuf.ByteString.EMPTY; + busiKeyMsg_ = com.google.protobuf.ByteString.EMPTY; + busiDetailMsg_ = com.google.protobuf.ByteString.EMPTY; + remainData_ = com.google.protobuf.ByteString.EMPTY; } @java.lang.Override @@ -459,51 +411,43 @@ public final class BussFlowExternalOuterClass { break; } case 194: { - java.lang.String s = input.readStringRequireUtf8(); - busiCode_ = s; + busiCode_ = input.readBytes(); break; } case 202: { - java.lang.String s = input.readStringRequireUtf8(); - sessionid_ = s; + sessionid_ = input.readBytes(); break; } case 210: { - java.lang.String s = input.readStringRequireUtf8(); - reqData_ = s; + reqData_ = input.readBytes(); break; } case 218: { - java.lang.String s = input.readStringRequireUtf8(); - resData_ = s; + resData_ = input.readBytes(); break; } case 226: { - java.lang.String s = input.readStringRequireUtf8(); - busiMsg_ = s; + busiMsg_ = input.readBytes(); break; } case 234: { - java.lang.String s = input.readStringRequireUtf8(); - busiKeyMsg_ = s; + busiKeyMsg_ = input.readBytes(); break; } case 242: { - java.lang.String s = input.readStringRequireUtf8(); - busiDetailMsg_ = s; + busiDetailMsg_ = input.readBytes(); break; } case 250: { - java.lang.String s = input.readStringRequireUtf8(); - remainData_ = s; + remainData_ = input.readBytes(); break; } default: { @@ -828,307 +772,91 @@ public final class BussFlowExternalOuterClass { } public static final int BUSI_CODE_FIELD_NUMBER = 24; - private volatile java.lang.Object busiCode_; + private com.google.protobuf.ByteString busiCode_; /** - * string busi_code = 24; + * bytes busi_code = 24; * @return The busiCode. */ @java.lang.Override - public java.lang.String getBusiCode() { - java.lang.Object ref = busiCode_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - busiCode_ = s; - return s; - } - } - /** - * string busi_code = 24; - * @return The bytes for busiCode. - */ - @java.lang.Override - public com.google.protobuf.ByteString - getBusiCodeBytes() { - java.lang.Object ref = busiCode_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - busiCode_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } + public com.google.protobuf.ByteString getBusiCode() { + return busiCode_; } public static final int SESSIONID_FIELD_NUMBER = 25; - private volatile java.lang.Object sessionid_; + private com.google.protobuf.ByteString sessionid_; /** - * string sessionid = 25; + * bytes sessionid = 25; * @return The sessionid. */ @java.lang.Override - public java.lang.String getSessionid() { - java.lang.Object ref = sessionid_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - sessionid_ = s; - return s; - } - } - /** - * string sessionid = 25; - * @return The bytes for sessionid. - */ - @java.lang.Override - public com.google.protobuf.ByteString - getSessionidBytes() { - java.lang.Object ref = sessionid_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - sessionid_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } + public com.google.protobuf.ByteString getSessionid() { + return sessionid_; } public static final int REQ_DATA_FIELD_NUMBER = 26; - private volatile java.lang.Object reqData_; + private com.google.protobuf.ByteString reqData_; /** - * string req_data = 26; + * bytes req_data = 26; * @return The reqData. */ @java.lang.Override - public java.lang.String getReqData() { - java.lang.Object ref = reqData_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - reqData_ = s; - return s; - } - } - /** - * string req_data = 26; - * @return The bytes for reqData. - */ - @java.lang.Override - public com.google.protobuf.ByteString - getReqDataBytes() { - java.lang.Object ref = reqData_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - reqData_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } + public com.google.protobuf.ByteString getReqData() { + return reqData_; } public static final int RES_DATA_FIELD_NUMBER = 27; - private volatile java.lang.Object resData_; + private com.google.protobuf.ByteString resData_; /** - * string res_data = 27; + * bytes res_data = 27; * @return The resData. */ @java.lang.Override - public java.lang.String getResData() { - java.lang.Object ref = resData_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - resData_ = s; - return s; - } - } - /** - * string res_data = 27; - * @return The bytes for resData. - */ - @java.lang.Override - public com.google.protobuf.ByteString - getResDataBytes() { - java.lang.Object ref = resData_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - resData_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } + public com.google.protobuf.ByteString getResData() { + return resData_; } public static final int BUSI_MSG_FIELD_NUMBER = 28; - private volatile java.lang.Object busiMsg_; + private com.google.protobuf.ByteString busiMsg_; /** - * string busi_msg = 28; + * bytes busi_msg = 28; * @return The busiMsg. */ @java.lang.Override - public java.lang.String getBusiMsg() { - java.lang.Object ref = busiMsg_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - busiMsg_ = s; - return s; - } - } - /** - * string busi_msg = 28; - * @return The bytes for busiMsg. - */ - @java.lang.Override - public com.google.protobuf.ByteString - getBusiMsgBytes() { - java.lang.Object ref = busiMsg_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - busiMsg_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } + public com.google.protobuf.ByteString getBusiMsg() { + return busiMsg_; } public static final int BUSI_KEY_MSG_FIELD_NUMBER = 29; - private volatile java.lang.Object busiKeyMsg_; + private com.google.protobuf.ByteString busiKeyMsg_; /** - * string busi_key_msg = 29; + * bytes busi_key_msg = 29; * @return The busiKeyMsg. */ @java.lang.Override - public java.lang.String getBusiKeyMsg() { - java.lang.Object ref = busiKeyMsg_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - busiKeyMsg_ = s; - return s; - } - } - /** - * string busi_key_msg = 29; - * @return The bytes for busiKeyMsg. - */ - @java.lang.Override - public com.google.protobuf.ByteString - getBusiKeyMsgBytes() { - java.lang.Object ref = busiKeyMsg_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - busiKeyMsg_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } + public com.google.protobuf.ByteString getBusiKeyMsg() { + return busiKeyMsg_; } public static final int BUSI_DETAIL_MSG_FIELD_NUMBER = 30; - private volatile java.lang.Object busiDetailMsg_; + private com.google.protobuf.ByteString busiDetailMsg_; /** - * string busi_detail_msg = 30; + * bytes busi_detail_msg = 30; * @return The busiDetailMsg. */ @java.lang.Override - public java.lang.String getBusiDetailMsg() { - java.lang.Object ref = busiDetailMsg_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - busiDetailMsg_ = s; - return s; - } - } - /** - * string busi_detail_msg = 30; - * @return The bytes for busiDetailMsg. - */ - @java.lang.Override - public com.google.protobuf.ByteString - getBusiDetailMsgBytes() { - java.lang.Object ref = busiDetailMsg_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - busiDetailMsg_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } + public com.google.protobuf.ByteString getBusiDetailMsg() { + return busiDetailMsg_; } public static final int REMAIN_DATA_FIELD_NUMBER = 31; - private volatile java.lang.Object remainData_; + private com.google.protobuf.ByteString remainData_; /** - * string remain_data = 31; + * bytes remain_data = 31; * @return The remainData. */ @java.lang.Override - public java.lang.String getRemainData() { - java.lang.Object ref = remainData_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - remainData_ = s; - return s; - } - } - /** - * string remain_data = 31; - * @return The bytes for remainData. - */ - @java.lang.Override - public com.google.protobuf.ByteString - getRemainDataBytes() { - java.lang.Object ref = remainData_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - remainData_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } + public com.google.protobuf.ByteString getRemainData() { + return remainData_; } private byte memoizedIsInitialized = -1; @@ -1214,29 +942,29 @@ public final class BussFlowExternalOuterClass { if (remainLen_ != 0) { output.writeUInt32(23, remainLen_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(busiCode_)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 24, busiCode_); + if (!busiCode_.isEmpty()) { + output.writeBytes(24, busiCode_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(sessionid_)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 25, sessionid_); + if (!sessionid_.isEmpty()) { + output.writeBytes(25, sessionid_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(reqData_)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 26, reqData_); + if (!reqData_.isEmpty()) { + output.writeBytes(26, reqData_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(resData_)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 27, resData_); + if (!resData_.isEmpty()) { + output.writeBytes(27, resData_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(busiMsg_)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 28, busiMsg_); + if (!busiMsg_.isEmpty()) { + output.writeBytes(28, busiMsg_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(busiKeyMsg_)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 29, busiKeyMsg_); + if (!busiKeyMsg_.isEmpty()) { + output.writeBytes(29, busiKeyMsg_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(busiDetailMsg_)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 30, busiDetailMsg_); + if (!busiDetailMsg_.isEmpty()) { + output.writeBytes(30, busiDetailMsg_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(remainData_)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 31, remainData_); + if (!remainData_.isEmpty()) { + output.writeBytes(31, remainData_); } unknownFields.writeTo(output); } @@ -1339,29 +1067,37 @@ public final class BussFlowExternalOuterClass { size += com.google.protobuf.CodedOutputStream .computeUInt32Size(23, remainLen_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(busiCode_)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(24, busiCode_); + if (!busiCode_.isEmpty()) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(24, busiCode_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(sessionid_)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(25, sessionid_); + if (!sessionid_.isEmpty()) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(25, sessionid_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(reqData_)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(26, reqData_); + if (!reqData_.isEmpty()) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(26, reqData_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(resData_)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(27, resData_); + if (!resData_.isEmpty()) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(27, resData_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(busiMsg_)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(28, busiMsg_); + if (!busiMsg_.isEmpty()) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(28, busiMsg_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(busiKeyMsg_)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(29, busiKeyMsg_); + if (!busiKeyMsg_.isEmpty()) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(29, busiKeyMsg_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(busiDetailMsg_)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(30, busiDetailMsg_); + if (!busiDetailMsg_.isEmpty()) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(30, busiDetailMsg_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(remainData_)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(31, remainData_); + if (!remainData_.isEmpty()) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(31, remainData_); } size += unknownFields.getSerializedSize(); memoizedSize = size; @@ -1712,21 +1448,21 @@ public final class BussFlowExternalOuterClass { remainLen_ = 0; - busiCode_ = ""; + busiCode_ = com.google.protobuf.ByteString.EMPTY; - sessionid_ = ""; + sessionid_ = com.google.protobuf.ByteString.EMPTY; - reqData_ = ""; + reqData_ = com.google.protobuf.ByteString.EMPTY; - resData_ = ""; + resData_ = com.google.protobuf.ByteString.EMPTY; - busiMsg_ = ""; + busiMsg_ = com.google.protobuf.ByteString.EMPTY; - busiKeyMsg_ = ""; + busiKeyMsg_ = com.google.protobuf.ByteString.EMPTY; - busiDetailMsg_ = ""; + busiDetailMsg_ = com.google.protobuf.ByteString.EMPTY; - remainData_ = ""; + remainData_ = com.google.protobuf.ByteString.EMPTY; return this; } @@ -1910,37 +1646,29 @@ public final class BussFlowExternalOuterClass { if (other.getRemainLen() != 0) { setRemainLen(other.getRemainLen()); } - if (!other.getBusiCode().isEmpty()) { - busiCode_ = other.busiCode_; - onChanged(); + if (other.getBusiCode() != com.google.protobuf.ByteString.EMPTY) { + setBusiCode(other.getBusiCode()); } - if (!other.getSessionid().isEmpty()) { - sessionid_ = other.sessionid_; - onChanged(); + if (other.getSessionid() != com.google.protobuf.ByteString.EMPTY) { + setSessionid(other.getSessionid()); } - if (!other.getReqData().isEmpty()) { - reqData_ = other.reqData_; - onChanged(); + if (other.getReqData() != com.google.protobuf.ByteString.EMPTY) { + setReqData(other.getReqData()); } - if (!other.getResData().isEmpty()) { - resData_ = other.resData_; - onChanged(); + if (other.getResData() != com.google.protobuf.ByteString.EMPTY) { + setResData(other.getResData()); } - if (!other.getBusiMsg().isEmpty()) { - busiMsg_ = other.busiMsg_; - onChanged(); + if (other.getBusiMsg() != com.google.protobuf.ByteString.EMPTY) { + setBusiMsg(other.getBusiMsg()); } - if (!other.getBusiKeyMsg().isEmpty()) { - busiKeyMsg_ = other.busiKeyMsg_; - onChanged(); + if (other.getBusiKeyMsg() != com.google.protobuf.ByteString.EMPTY) { + setBusiKeyMsg(other.getBusiKeyMsg()); } - if (!other.getBusiDetailMsg().isEmpty()) { - busiDetailMsg_ = other.busiDetailMsg_; - onChanged(); + if (other.getBusiDetailMsg() != com.google.protobuf.ByteString.EMPTY) { + setBusiDetailMsg(other.getBusiDetailMsg()); } - if (!other.getRemainData().isEmpty()) { - remainData_ = other.remainData_; - onChanged(); + if (other.getRemainData() != com.google.protobuf.ByteString.EMPTY) { + setRemainData(other.getRemainData()); } this.mergeUnknownFields(other.unknownFields); onChanged(); @@ -2872,47 +2600,21 @@ public final class BussFlowExternalOuterClass { return this; } - private java.lang.Object busiCode_ = ""; + private com.google.protobuf.ByteString busiCode_ = com.google.protobuf.ByteString.EMPTY; /** - * string busi_code = 24; + * bytes busi_code = 24; * @return The busiCode. */ - public java.lang.String getBusiCode() { - java.lang.Object ref = busiCode_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - busiCode_ = s; - return s; - } else { - return (java.lang.String) ref; - } + @java.lang.Override + public com.google.protobuf.ByteString getBusiCode() { + return busiCode_; } /** - * string busi_code = 24; - * @return The bytes for busiCode. - */ - public com.google.protobuf.ByteString - getBusiCodeBytes() { - java.lang.Object ref = busiCode_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - busiCode_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * string busi_code = 24; + * bytes busi_code = 24; * @param value The busiCode to set. * @return This builder for chaining. */ - public Builder setBusiCode( - java.lang.String value) { + public Builder setBusiCode(com.google.protobuf.ByteString value) { if (value == null) { throw new NullPointerException(); } @@ -2922,7 +2624,7 @@ public final class BussFlowExternalOuterClass { return this; } /** - * string busi_code = 24; + * bytes busi_code = 24; * @return This builder for chaining. */ public Builder clearBusiCode() { @@ -2931,64 +2633,22 @@ public final class BussFlowExternalOuterClass { onChanged(); return this; } - /** - * string busi_code = 24; - * @param value The bytes for busiCode to set. - * @return This builder for chaining. - */ - public Builder setBusiCodeBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - busiCode_ = value; - onChanged(); - return this; - } - private java.lang.Object sessionid_ = ""; + private com.google.protobuf.ByteString sessionid_ = com.google.protobuf.ByteString.EMPTY; /** - * string sessionid = 25; + * bytes sessionid = 25; * @return The sessionid. */ - public java.lang.String getSessionid() { - java.lang.Object ref = sessionid_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - sessionid_ = s; - return s; - } else { - return (java.lang.String) ref; - } + @java.lang.Override + public com.google.protobuf.ByteString getSessionid() { + return sessionid_; } /** - * string sessionid = 25; - * @return The bytes for sessionid. - */ - public com.google.protobuf.ByteString - getSessionidBytes() { - java.lang.Object ref = sessionid_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - sessionid_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * string sessionid = 25; + * bytes sessionid = 25; * @param value The sessionid to set. * @return This builder for chaining. */ - public Builder setSessionid( - java.lang.String value) { + public Builder setSessionid(com.google.protobuf.ByteString value) { if (value == null) { throw new NullPointerException(); } @@ -2998,7 +2658,7 @@ public final class BussFlowExternalOuterClass { return this; } /** - * string sessionid = 25; + * bytes sessionid = 25; * @return This builder for chaining. */ public Builder clearSessionid() { @@ -3007,64 +2667,22 @@ public final class BussFlowExternalOuterClass { onChanged(); return this; } - /** - * string sessionid = 25; - * @param value The bytes for sessionid to set. - * @return This builder for chaining. - */ - public Builder setSessionidBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - sessionid_ = value; - onChanged(); - return this; - } - private java.lang.Object reqData_ = ""; + private com.google.protobuf.ByteString reqData_ = com.google.protobuf.ByteString.EMPTY; /** - * string req_data = 26; + * bytes req_data = 26; * @return The reqData. */ - public java.lang.String getReqData() { - java.lang.Object ref = reqData_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - reqData_ = s; - return s; - } else { - return (java.lang.String) ref; - } + @java.lang.Override + public com.google.protobuf.ByteString getReqData() { + return reqData_; } /** - * string req_data = 26; - * @return The bytes for reqData. - */ - public com.google.protobuf.ByteString - getReqDataBytes() { - java.lang.Object ref = reqData_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - reqData_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * string req_data = 26; + * bytes req_data = 26; * @param value The reqData to set. * @return This builder for chaining. */ - public Builder setReqData( - java.lang.String value) { + public Builder setReqData(com.google.protobuf.ByteString value) { if (value == null) { throw new NullPointerException(); } @@ -3074,7 +2692,7 @@ public final class BussFlowExternalOuterClass { return this; } /** - * string req_data = 26; + * bytes req_data = 26; * @return This builder for chaining. */ public Builder clearReqData() { @@ -3083,64 +2701,22 @@ public final class BussFlowExternalOuterClass { onChanged(); return this; } - /** - * string req_data = 26; - * @param value The bytes for reqData to set. - * @return This builder for chaining. - */ - public Builder setReqDataBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - reqData_ = value; - onChanged(); - return this; - } - private java.lang.Object resData_ = ""; + private com.google.protobuf.ByteString resData_ = com.google.protobuf.ByteString.EMPTY; /** - * string res_data = 27; + * bytes res_data = 27; * @return The resData. */ - public java.lang.String getResData() { - java.lang.Object ref = resData_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - resData_ = s; - return s; - } else { - return (java.lang.String) ref; - } + @java.lang.Override + public com.google.protobuf.ByteString getResData() { + return resData_; } /** - * string res_data = 27; - * @return The bytes for resData. - */ - public com.google.protobuf.ByteString - getResDataBytes() { - java.lang.Object ref = resData_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - resData_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * string res_data = 27; + * bytes res_data = 27; * @param value The resData to set. * @return This builder for chaining. */ - public Builder setResData( - java.lang.String value) { + public Builder setResData(com.google.protobuf.ByteString value) { if (value == null) { throw new NullPointerException(); } @@ -3150,7 +2726,7 @@ public final class BussFlowExternalOuterClass { return this; } /** - * string res_data = 27; + * bytes res_data = 27; * @return This builder for chaining. */ public Builder clearResData() { @@ -3159,64 +2735,22 @@ public final class BussFlowExternalOuterClass { onChanged(); return this; } - /** - * string res_data = 27; - * @param value The bytes for resData to set. - * @return This builder for chaining. - */ - public Builder setResDataBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - resData_ = value; - onChanged(); - return this; - } - private java.lang.Object busiMsg_ = ""; + private com.google.protobuf.ByteString busiMsg_ = com.google.protobuf.ByteString.EMPTY; /** - * string busi_msg = 28; + * bytes busi_msg = 28; * @return The busiMsg. */ - public java.lang.String getBusiMsg() { - java.lang.Object ref = busiMsg_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - busiMsg_ = s; - return s; - } else { - return (java.lang.String) ref; - } + @java.lang.Override + public com.google.protobuf.ByteString getBusiMsg() { + return busiMsg_; } /** - * string busi_msg = 28; - * @return The bytes for busiMsg. - */ - public com.google.protobuf.ByteString - getBusiMsgBytes() { - java.lang.Object ref = busiMsg_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - busiMsg_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * string busi_msg = 28; + * bytes busi_msg = 28; * @param value The busiMsg to set. * @return This builder for chaining. */ - public Builder setBusiMsg( - java.lang.String value) { + public Builder setBusiMsg(com.google.protobuf.ByteString value) { if (value == null) { throw new NullPointerException(); } @@ -3226,7 +2760,7 @@ public final class BussFlowExternalOuterClass { return this; } /** - * string busi_msg = 28; + * bytes busi_msg = 28; * @return This builder for chaining. */ public Builder clearBusiMsg() { @@ -3235,64 +2769,22 @@ public final class BussFlowExternalOuterClass { onChanged(); return this; } - /** - * string busi_msg = 28; - * @param value The bytes for busiMsg to set. - * @return This builder for chaining. - */ - public Builder setBusiMsgBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - busiMsg_ = value; - onChanged(); - return this; - } - private java.lang.Object busiKeyMsg_ = ""; + private com.google.protobuf.ByteString busiKeyMsg_ = com.google.protobuf.ByteString.EMPTY; /** - * string busi_key_msg = 29; + * bytes busi_key_msg = 29; * @return The busiKeyMsg. */ - public java.lang.String getBusiKeyMsg() { - java.lang.Object ref = busiKeyMsg_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - busiKeyMsg_ = s; - return s; - } else { - return (java.lang.String) ref; - } + @java.lang.Override + public com.google.protobuf.ByteString getBusiKeyMsg() { + return busiKeyMsg_; } /** - * string busi_key_msg = 29; - * @return The bytes for busiKeyMsg. - */ - public com.google.protobuf.ByteString - getBusiKeyMsgBytes() { - java.lang.Object ref = busiKeyMsg_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - busiKeyMsg_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * string busi_key_msg = 29; + * bytes busi_key_msg = 29; * @param value The busiKeyMsg to set. * @return This builder for chaining. */ - public Builder setBusiKeyMsg( - java.lang.String value) { + public Builder setBusiKeyMsg(com.google.protobuf.ByteString value) { if (value == null) { throw new NullPointerException(); } @@ -3302,7 +2794,7 @@ public final class BussFlowExternalOuterClass { return this; } /** - * string busi_key_msg = 29; + * bytes busi_key_msg = 29; * @return This builder for chaining. */ public Builder clearBusiKeyMsg() { @@ -3311,64 +2803,22 @@ public final class BussFlowExternalOuterClass { onChanged(); return this; } - /** - * string busi_key_msg = 29; - * @param value The bytes for busiKeyMsg to set. - * @return This builder for chaining. - */ - public Builder setBusiKeyMsgBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - busiKeyMsg_ = value; - onChanged(); - return this; - } - private java.lang.Object busiDetailMsg_ = ""; + private com.google.protobuf.ByteString busiDetailMsg_ = com.google.protobuf.ByteString.EMPTY; /** - * string busi_detail_msg = 30; + * bytes busi_detail_msg = 30; * @return The busiDetailMsg. */ - public java.lang.String getBusiDetailMsg() { - java.lang.Object ref = busiDetailMsg_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - busiDetailMsg_ = s; - return s; - } else { - return (java.lang.String) ref; - } + @java.lang.Override + public com.google.protobuf.ByteString getBusiDetailMsg() { + return busiDetailMsg_; } /** - * string busi_detail_msg = 30; - * @return The bytes for busiDetailMsg. - */ - public com.google.protobuf.ByteString - getBusiDetailMsgBytes() { - java.lang.Object ref = busiDetailMsg_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - busiDetailMsg_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * string busi_detail_msg = 30; + * bytes busi_detail_msg = 30; * @param value The busiDetailMsg to set. * @return This builder for chaining. */ - public Builder setBusiDetailMsg( - java.lang.String value) { + public Builder setBusiDetailMsg(com.google.protobuf.ByteString value) { if (value == null) { throw new NullPointerException(); } @@ -3378,7 +2828,7 @@ public final class BussFlowExternalOuterClass { return this; } /** - * string busi_detail_msg = 30; + * bytes busi_detail_msg = 30; * @return This builder for chaining. */ public Builder clearBusiDetailMsg() { @@ -3387,64 +2837,22 @@ public final class BussFlowExternalOuterClass { onChanged(); return this; } - /** - * string busi_detail_msg = 30; - * @param value The bytes for busiDetailMsg to set. - * @return This builder for chaining. - */ - public Builder setBusiDetailMsgBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - busiDetailMsg_ = value; - onChanged(); - return this; - } - private java.lang.Object remainData_ = ""; + private com.google.protobuf.ByteString remainData_ = com.google.protobuf.ByteString.EMPTY; /** - * string remain_data = 31; + * bytes remain_data = 31; * @return The remainData. */ - public java.lang.String getRemainData() { - java.lang.Object ref = remainData_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - remainData_ = s; - return s; - } else { - return (java.lang.String) ref; - } + @java.lang.Override + public com.google.protobuf.ByteString getRemainData() { + return remainData_; } /** - * string remain_data = 31; - * @return The bytes for remainData. - */ - public com.google.protobuf.ByteString - getRemainDataBytes() { - java.lang.Object ref = remainData_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - remainData_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * string remain_data = 31; + * bytes remain_data = 31; * @param value The remainData to set. * @return This builder for chaining. */ - public Builder setRemainData( - java.lang.String value) { + public Builder setRemainData(com.google.protobuf.ByteString value) { if (value == null) { throw new NullPointerException(); } @@ -3454,7 +2862,7 @@ public final class BussFlowExternalOuterClass { return this; } /** - * string remain_data = 31; + * bytes remain_data = 31; * @return This builder for chaining. */ public Builder clearRemainData() { @@ -3463,22 +2871,6 @@ public final class BussFlowExternalOuterClass { onChanged(); return this; } - /** - * string remain_data = 31; - * @param value The bytes for remainData to set. - * @return This builder for chaining. - */ - public Builder setRemainDataBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - remainData_ = value; - onChanged(); - return this; - } @java.lang.Override public final Builder setUnknownFields( final com.google.protobuf.UnknownFieldSet unknownFields) { @@ -3561,10 +2953,10 @@ public final class BussFlowExternalOuterClass { "\n\007res_len\030\023 \001(\r\022\024\n\014busi_msg_len\030\024 \001(\r\022\023\n" + "\013key_msg_len\030\025 \001(\r\022\026\n\016detail_msg_len\030\026 \001" + "(\r\022\022\n\nremain_len\030\027 \001(\r\022\021\n\tbusi_code\030\030 \001(" + - "\t\022\021\n\tsessionid\030\031 \001(\t\022\020\n\010req_data\030\032 \001(\t\022\020" + - "\n\010res_data\030\033 \001(\t\022\020\n\010busi_msg\030\034 \001(\t\022\024\n\014bu" + - "si_key_msg\030\035 \001(\t\022\027\n\017busi_detail_msg\030\036 \001(" + - "\t\022\023\n\013remain_data\030\037 \001(\tB<\n#com.yuandian.d" + + "\014\022\021\n\tsessionid\030\031 \001(\014\022\020\n\010req_data\030\032 \001(\014\022\020" + + "\n\010res_data\030\033 \001(\014\022\020\n\010busi_msg\030\034 \001(\014\022\024\n\014bu" + + "si_key_msg\030\035 \001(\014\022\027\n\017busi_detail_msg\030\036 \001(" + + "\014\022\023\n\013remain_data\030\037 \001(\014B<\n#com.yuandian.d" + "ataflow.proto.msgtypeP\000Z\023../grpc-gen;grp" + "cgenb\006proto3" }; diff --git a/src/main/java/com/yuandian/dataflow/proto/msgtype/BussFlowMiddOuterClass.java b/src/main/java/com/yuandian/dataflow/proto/msgtype/BussFlowMiddOuterClass.java index 097ff06..0bcd280 100644 --- a/src/main/java/com/yuandian/dataflow/proto/msgtype/BussFlowMiddOuterClass.java +++ b/src/main/java/com/yuandian/dataflow/proto/msgtype/BussFlowMiddOuterClass.java @@ -43,20 +43,10 @@ public final class BussFlowMiddOuterClass { *数据库版本 * * - * string msg_version = 3; + * bytes msg_version = 3; * @return The msgVersion. */ - java.lang.String getMsgVersion(); - /** - *
-     *数据库版本
-     * 
- * - * string msg_version = 3; - * @return The bytes for msgVersion. - */ - com.google.protobuf.ByteString - getMsgVersionBytes(); + com.google.protobuf.ByteString getMsgVersion(); /** *
@@ -199,20 +189,10 @@ public final class BussFlowMiddOuterClass {
      *序列号和响应序号
      * 
* - * string seq_ack = 18; + * bytes seq_ack = 18; * @return The seqAck. */ - java.lang.String getSeqAck(); - /** - *
-     *序列号和响应序号
-     * 
- * - * string seq_ack = 18; - * @return The bytes for seqAck. - */ - com.google.protobuf.ByteString - getSeqAckBytes(); + com.google.protobuf.ByteString getSeqAck(); /** * uint32 recog_status = 19; @@ -235,20 +215,10 @@ public final class BussFlowMiddOuterClass { *通道 * * - * string channel = 21; + * bytes channel = 21; * @return The channel. */ - java.lang.String getChannel(); - /** - *
-     *通道
-     * 
- * - * string channel = 21; - * @return The bytes for channel. - */ - com.google.protobuf.ByteString - getChannelBytes(); + com.google.protobuf.ByteString getChannel(); /** *
@@ -531,112 +501,56 @@ public final class BussFlowMiddOuterClass {
      *业务纤细信息
      * 
* - * string bussiness_detail_mesg = 47; + * bytes bussiness_detail_mesg = 47; * @return The bussinessDetailMesg. */ - java.lang.String getBussinessDetailMesg(); - /** - *
-     *业务纤细信息
-     * 
- * - * string bussiness_detail_mesg = 47; - * @return The bytes for bussinessDetailMesg. - */ - com.google.protobuf.ByteString - getBussinessDetailMesgBytes(); + com.google.protobuf.ByteString getBussinessDetailMesg(); /** *
      *业务关键字
      * 
* - * string bussiness_key_mesg = 48; + * bytes bussiness_key_mesg = 48; * @return The bussinessKeyMesg. */ - java.lang.String getBussinessKeyMesg(); - /** - *
-     *业务关键字
-     * 
- * - * string bussiness_key_mesg = 48; - * @return The bytes for bussinessKeyMesg. - */ - com.google.protobuf.ByteString - getBussinessKeyMesgBytes(); + com.google.protobuf.ByteString getBussinessKeyMesg(); /** *
      *应用名称
      * 
* - * string api = 49; + * bytes api = 49; * @return The api. */ - java.lang.String getApi(); - /** - *
-     *应用名称
-     * 
- * - * string api = 49; - * @return The bytes for api. - */ - com.google.protobuf.ByteString - getApiBytes(); + com.google.protobuf.ByteString getApi(); /** *
      *请求详情报文
      * 
* - * string req_data = 50; + * bytes req_data = 50; * @return The reqData. */ - java.lang.String getReqData(); - /** - *
-     *请求详情报文
-     * 
- * - * string req_data = 50; - * @return The bytes for reqData. - */ - com.google.protobuf.ByteString - getReqDataBytes(); + com.google.protobuf.ByteString getReqData(); /** *
      *响应详情报文
      * 
* - * string res_data = 51; + * bytes res_data = 51; * @return The resData. */ - java.lang.String getResData(); - /** - *
-     *响应详情报文
-     * 
- * - * string res_data = 51; - * @return The bytes for resData. - */ - com.google.protobuf.ByteString - getResDataBytes(); + com.google.protobuf.ByteString getResData(); /** - * string remain_data = 52; + * bytes remain_data = 52; * @return The remainData. */ - java.lang.String getRemainData(); - /** - * string remain_data = 52; - * @return The bytes for remainData. - */ - com.google.protobuf.ByteString - getRemainDataBytes(); + com.google.protobuf.ByteString getRemainData(); } /** * Protobuf type {@code dataflow.BussFlowMidd} @@ -651,15 +565,15 @@ public final class BussFlowMiddOuterClass { super(builder); } private BussFlowMidd() { - msgVersion_ = ""; - seqAck_ = ""; - channel_ = ""; - bussinessDetailMesg_ = ""; - bussinessKeyMesg_ = ""; - api_ = ""; - reqData_ = ""; - resData_ = ""; - remainData_ = ""; + msgVersion_ = com.google.protobuf.ByteString.EMPTY; + seqAck_ = com.google.protobuf.ByteString.EMPTY; + channel_ = com.google.protobuf.ByteString.EMPTY; + bussinessDetailMesg_ = com.google.protobuf.ByteString.EMPTY; + bussinessKeyMesg_ = com.google.protobuf.ByteString.EMPTY; + api_ = com.google.protobuf.ByteString.EMPTY; + reqData_ = com.google.protobuf.ByteString.EMPTY; + resData_ = com.google.protobuf.ByteString.EMPTY; + remainData_ = com.google.protobuf.ByteString.EMPTY; } @java.lang.Override @@ -703,9 +617,8 @@ public final class BussFlowMiddOuterClass { break; } case 26: { - java.lang.String s = input.readStringRequireUtf8(); - msgVersion_ = s; + msgVersion_ = input.readBytes(); break; } case 32: { @@ -779,9 +692,8 @@ public final class BussFlowMiddOuterClass { break; } case 146: { - java.lang.String s = input.readStringRequireUtf8(); - seqAck_ = s; + seqAck_ = input.readBytes(); break; } case 152: { @@ -795,9 +707,8 @@ public final class BussFlowMiddOuterClass { break; } case 170: { - java.lang.String s = input.readStringRequireUtf8(); - channel_ = s; + channel_ = input.readBytes(); break; } case 178: { @@ -942,39 +853,33 @@ public final class BussFlowMiddOuterClass { break; } case 378: { - java.lang.String s = input.readStringRequireUtf8(); - bussinessDetailMesg_ = s; + bussinessDetailMesg_ = input.readBytes(); break; } case 386: { - java.lang.String s = input.readStringRequireUtf8(); - bussinessKeyMesg_ = s; + bussinessKeyMesg_ = input.readBytes(); break; } case 394: { - java.lang.String s = input.readStringRequireUtf8(); - api_ = s; + api_ = input.readBytes(); break; } case 402: { - java.lang.String s = input.readStringRequireUtf8(); - reqData_ = s; + reqData_ = input.readBytes(); break; } case 410: { - java.lang.String s = input.readStringRequireUtf8(); - resData_ = s; + resData_ = input.readBytes(); break; } case 418: { - java.lang.String s = input.readStringRequireUtf8(); - remainData_ = s; + remainData_ = input.readBytes(); break; } default: { @@ -1042,49 +947,18 @@ public final class BussFlowMiddOuterClass { } public static final int MSG_VERSION_FIELD_NUMBER = 3; - private volatile java.lang.Object msgVersion_; + private com.google.protobuf.ByteString msgVersion_; /** *
      *数据库版本
      * 
* - * string msg_version = 3; + * bytes msg_version = 3; * @return The msgVersion. */ @java.lang.Override - public java.lang.String getMsgVersion() { - java.lang.Object ref = msgVersion_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - msgVersion_ = s; - return s; - } - } - /** - *
-     *数据库版本
-     * 
- * - * string msg_version = 3; - * @return The bytes for msgVersion. - */ - @java.lang.Override - public com.google.protobuf.ByteString - getMsgVersionBytes() { - java.lang.Object ref = msgVersion_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - msgVersion_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } + public com.google.protobuf.ByteString getMsgVersion() { + return msgVersion_; } public static final int MSG_SEQ_FIELD_NUMBER = 4; @@ -1294,49 +1168,18 @@ public final class BussFlowMiddOuterClass { } public static final int SEQ_ACK_FIELD_NUMBER = 18; - private volatile java.lang.Object seqAck_; + private com.google.protobuf.ByteString seqAck_; /** *
      *序列号和响应序号
      * 
* - * string seq_ack = 18; + * bytes seq_ack = 18; * @return The seqAck. */ @java.lang.Override - public java.lang.String getSeqAck() { - java.lang.Object ref = seqAck_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - seqAck_ = s; - return s; - } - } - /** - *
-     *序列号和响应序号
-     * 
- * - * string seq_ack = 18; - * @return The bytes for seqAck. - */ - @java.lang.Override - public com.google.protobuf.ByteString - getSeqAckBytes() { - java.lang.Object ref = seqAck_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - seqAck_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } + public com.google.protobuf.ByteString getSeqAck() { + return seqAck_; } public static final int RECOG_STATUS_FIELD_NUMBER = 19; @@ -1366,49 +1209,18 @@ public final class BussFlowMiddOuterClass { } public static final int CHANNEL_FIELD_NUMBER = 21; - private volatile java.lang.Object channel_; + private com.google.protobuf.ByteString channel_; /** *
      *通道
      * 
* - * string channel = 21; + * bytes channel = 21; * @return The channel. */ @java.lang.Override - public java.lang.String getChannel() { - java.lang.Object ref = channel_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - channel_ = s; - return s; - } - } - /** - *
-     *通道
-     * 
- * - * string channel = 21; - * @return The bytes for channel. - */ - @java.lang.Override - public com.google.protobuf.ByteString - getChannelBytes() { - java.lang.Object ref = channel_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - channel_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } + public com.google.protobuf.ByteString getChannel() { + return channel_; } public static final int REQUEST_IP_FIELD_NUMBER = 22; @@ -1825,271 +1637,89 @@ public final class BussFlowMiddOuterClass { } public static final int BUSSINESS_DETAIL_MESG_FIELD_NUMBER = 47; - private volatile java.lang.Object bussinessDetailMesg_; + private com.google.protobuf.ByteString bussinessDetailMesg_; /** *
      *业务纤细信息
      * 
* - * string bussiness_detail_mesg = 47; + * bytes bussiness_detail_mesg = 47; * @return The bussinessDetailMesg. */ @java.lang.Override - public java.lang.String getBussinessDetailMesg() { - java.lang.Object ref = bussinessDetailMesg_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - bussinessDetailMesg_ = s; - return s; - } - } - /** - *
-     *业务纤细信息
-     * 
- * - * string bussiness_detail_mesg = 47; - * @return The bytes for bussinessDetailMesg. - */ - @java.lang.Override - public com.google.protobuf.ByteString - getBussinessDetailMesgBytes() { - java.lang.Object ref = bussinessDetailMesg_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - bussinessDetailMesg_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } + public com.google.protobuf.ByteString getBussinessDetailMesg() { + return bussinessDetailMesg_; } public static final int BUSSINESS_KEY_MESG_FIELD_NUMBER = 48; - private volatile java.lang.Object bussinessKeyMesg_; + private com.google.protobuf.ByteString bussinessKeyMesg_; /** *
      *业务关键字
      * 
* - * string bussiness_key_mesg = 48; + * bytes bussiness_key_mesg = 48; * @return The bussinessKeyMesg. */ @java.lang.Override - public java.lang.String getBussinessKeyMesg() { - java.lang.Object ref = bussinessKeyMesg_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - bussinessKeyMesg_ = s; - return s; - } - } - /** - *
-     *业务关键字
-     * 
- * - * string bussiness_key_mesg = 48; - * @return The bytes for bussinessKeyMesg. - */ - @java.lang.Override - public com.google.protobuf.ByteString - getBussinessKeyMesgBytes() { - java.lang.Object ref = bussinessKeyMesg_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - bussinessKeyMesg_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } + public com.google.protobuf.ByteString getBussinessKeyMesg() { + return bussinessKeyMesg_; } public static final int API_FIELD_NUMBER = 49; - private volatile java.lang.Object api_; + private com.google.protobuf.ByteString api_; /** *
      *应用名称
      * 
* - * string api = 49; + * bytes api = 49; * @return The api. */ @java.lang.Override - public java.lang.String getApi() { - java.lang.Object ref = api_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - api_ = s; - return s; - } - } - /** - *
-     *应用名称
-     * 
- * - * string api = 49; - * @return The bytes for api. - */ - @java.lang.Override - public com.google.protobuf.ByteString - getApiBytes() { - java.lang.Object ref = api_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - api_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } + public com.google.protobuf.ByteString getApi() { + return api_; } public static final int REQ_DATA_FIELD_NUMBER = 50; - private volatile java.lang.Object reqData_; + private com.google.protobuf.ByteString reqData_; /** *
      *请求详情报文
      * 
* - * string req_data = 50; + * bytes req_data = 50; * @return The reqData. */ @java.lang.Override - public java.lang.String getReqData() { - java.lang.Object ref = reqData_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - reqData_ = s; - return s; - } - } - /** - *
-     *请求详情报文
-     * 
- * - * string req_data = 50; - * @return The bytes for reqData. - */ - @java.lang.Override - public com.google.protobuf.ByteString - getReqDataBytes() { - java.lang.Object ref = reqData_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - reqData_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } + public com.google.protobuf.ByteString getReqData() { + return reqData_; } public static final int RES_DATA_FIELD_NUMBER = 51; - private volatile java.lang.Object resData_; + private com.google.protobuf.ByteString resData_; /** *
      *响应详情报文
      * 
* - * string res_data = 51; + * bytes res_data = 51; * @return The resData. */ @java.lang.Override - public java.lang.String getResData() { - java.lang.Object ref = resData_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - resData_ = s; - return s; - } - } - /** - *
-     *响应详情报文
-     * 
- * - * string res_data = 51; - * @return The bytes for resData. - */ - @java.lang.Override - public com.google.protobuf.ByteString - getResDataBytes() { - java.lang.Object ref = resData_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - resData_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } + public com.google.protobuf.ByteString getResData() { + return resData_; } public static final int REMAIN_DATA_FIELD_NUMBER = 52; - private volatile java.lang.Object remainData_; + private com.google.protobuf.ByteString remainData_; /** - * string remain_data = 52; + * bytes remain_data = 52; * @return The remainData. */ @java.lang.Override - public java.lang.String getRemainData() { - java.lang.Object ref = remainData_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - remainData_ = s; - return s; - } - } - /** - * string remain_data = 52; - * @return The bytes for remainData. - */ - @java.lang.Override - public com.google.protobuf.ByteString - getRemainDataBytes() { - java.lang.Object ref = remainData_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - remainData_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } + public com.google.protobuf.ByteString getRemainData() { + return remainData_; } private byte memoizedIsInitialized = -1; @@ -2112,8 +1742,8 @@ public final class BussFlowMiddOuterClass { if (msgType_ != 0) { output.writeUInt32(2, msgType_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(msgVersion_)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 3, msgVersion_); + if (!msgVersion_.isEmpty()) { + output.writeBytes(3, msgVersion_); } if (msgSeq_ != 0) { output.writeUInt32(4, msgSeq_); @@ -2157,8 +1787,8 @@ public final class BussFlowMiddOuterClass { if (requestPackets_ != 0) { output.writeUInt32(17, requestPackets_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(seqAck_)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 18, seqAck_); + if (!seqAck_.isEmpty()) { + output.writeBytes(18, seqAck_); } if (recogStatus_ != 0) { output.writeUInt32(19, recogStatus_); @@ -2166,8 +1796,8 @@ public final class BussFlowMiddOuterClass { if (probeIf_ != 0) { output.writeUInt32(20, probeIf_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(channel_)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 21, channel_); + if (!channel_.isEmpty()) { + output.writeBytes(21, channel_); } if (requestIp_ != null) { output.writeMessage(22, getRequestIp()); @@ -2244,23 +1874,23 @@ public final class BussFlowMiddOuterClass { if (remainLen_ != 0) { output.writeUInt32(46, remainLen_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(bussinessDetailMesg_)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 47, bussinessDetailMesg_); + if (!bussinessDetailMesg_.isEmpty()) { + output.writeBytes(47, bussinessDetailMesg_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(bussinessKeyMesg_)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 48, bussinessKeyMesg_); + if (!bussinessKeyMesg_.isEmpty()) { + output.writeBytes(48, bussinessKeyMesg_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(api_)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 49, api_); + if (!api_.isEmpty()) { + output.writeBytes(49, api_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(reqData_)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 50, reqData_); + if (!reqData_.isEmpty()) { + output.writeBytes(50, reqData_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(resData_)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 51, resData_); + if (!resData_.isEmpty()) { + output.writeBytes(51, resData_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(remainData_)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 52, remainData_); + if (!remainData_.isEmpty()) { + output.writeBytes(52, remainData_); } unknownFields.writeTo(output); } @@ -2279,8 +1909,9 @@ public final class BussFlowMiddOuterClass { size += com.google.protobuf.CodedOutputStream .computeUInt32Size(2, msgType_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(msgVersion_)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(3, msgVersion_); + if (!msgVersion_.isEmpty()) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(3, msgVersion_); } if (msgSeq_ != 0) { size += com.google.protobuf.CodedOutputStream @@ -2338,8 +1969,9 @@ public final class BussFlowMiddOuterClass { size += com.google.protobuf.CodedOutputStream .computeUInt32Size(17, requestPackets_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(seqAck_)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(18, seqAck_); + if (!seqAck_.isEmpty()) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(18, seqAck_); } if (recogStatus_ != 0) { size += com.google.protobuf.CodedOutputStream @@ -2349,8 +1981,9 @@ public final class BussFlowMiddOuterClass { size += com.google.protobuf.CodedOutputStream .computeUInt32Size(20, probeIf_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(channel_)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(21, channel_); + if (!channel_.isEmpty()) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(21, channel_); } if (requestIp_ != null) { size += com.google.protobuf.CodedOutputStream @@ -2452,23 +2085,29 @@ public final class BussFlowMiddOuterClass { size += com.google.protobuf.CodedOutputStream .computeUInt32Size(46, remainLen_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(bussinessDetailMesg_)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(47, bussinessDetailMesg_); + if (!bussinessDetailMesg_.isEmpty()) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(47, bussinessDetailMesg_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(bussinessKeyMesg_)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(48, bussinessKeyMesg_); + if (!bussinessKeyMesg_.isEmpty()) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(48, bussinessKeyMesg_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(api_)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(49, api_); + if (!api_.isEmpty()) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(49, api_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(reqData_)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(50, reqData_); + if (!reqData_.isEmpty()) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(50, reqData_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(resData_)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(51, resData_); + if (!resData_.isEmpty()) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(51, resData_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(remainData_)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(52, remainData_); + if (!remainData_.isEmpty()) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(52, remainData_); } size += unknownFields.getSerializedSize(); memoizedSize = size; @@ -2856,7 +2495,7 @@ public final class BussFlowMiddOuterClass { msgType_ = 0; - msgVersion_ = ""; + msgVersion_ = com.google.protobuf.ByteString.EMPTY; msgSeq_ = 0; @@ -2886,13 +2525,13 @@ public final class BussFlowMiddOuterClass { requestPackets_ = 0; - seqAck_ = ""; + seqAck_ = com.google.protobuf.ByteString.EMPTY; recogStatus_ = 0; probeIf_ = 0; - channel_ = ""; + channel_ = com.google.protobuf.ByteString.EMPTY; if (requestIpBuilder_ == null) { requestIp_ = null; @@ -2952,17 +2591,17 @@ public final class BussFlowMiddOuterClass { remainLen_ = 0; - bussinessDetailMesg_ = ""; + bussinessDetailMesg_ = com.google.protobuf.ByteString.EMPTY; - bussinessKeyMesg_ = ""; + bussinessKeyMesg_ = com.google.protobuf.ByteString.EMPTY; - api_ = ""; + api_ = com.google.protobuf.ByteString.EMPTY; - reqData_ = ""; + reqData_ = com.google.protobuf.ByteString.EMPTY; - resData_ = ""; + resData_ = com.google.protobuf.ByteString.EMPTY; - remainData_ = ""; + remainData_ = com.google.protobuf.ByteString.EMPTY; return this; } @@ -3104,9 +2743,8 @@ public final class BussFlowMiddOuterClass { if (other.getMsgType() != 0) { setMsgType(other.getMsgType()); } - if (!other.getMsgVersion().isEmpty()) { - msgVersion_ = other.msgVersion_; - onChanged(); + if (other.getMsgVersion() != com.google.protobuf.ByteString.EMPTY) { + setMsgVersion(other.getMsgVersion()); } if (other.getMsgSeq() != 0) { setMsgSeq(other.getMsgSeq()); @@ -3150,9 +2788,8 @@ public final class BussFlowMiddOuterClass { if (other.getRequestPackets() != 0) { setRequestPackets(other.getRequestPackets()); } - if (!other.getSeqAck().isEmpty()) { - seqAck_ = other.seqAck_; - onChanged(); + if (other.getSeqAck() != com.google.protobuf.ByteString.EMPTY) { + setSeqAck(other.getSeqAck()); } if (other.getRecogStatus() != 0) { setRecogStatus(other.getRecogStatus()); @@ -3160,9 +2797,8 @@ public final class BussFlowMiddOuterClass { if (other.getProbeIf() != 0) { setProbeIf(other.getProbeIf()); } - if (!other.getChannel().isEmpty()) { - channel_ = other.channel_; - onChanged(); + if (other.getChannel() != com.google.protobuf.ByteString.EMPTY) { + setChannel(other.getChannel()); } if (other.hasRequestIp()) { mergeRequestIp(other.getRequestIp()); @@ -3239,29 +2875,23 @@ public final class BussFlowMiddOuterClass { if (other.getRemainLen() != 0) { setRemainLen(other.getRemainLen()); } - if (!other.getBussinessDetailMesg().isEmpty()) { - bussinessDetailMesg_ = other.bussinessDetailMesg_; - onChanged(); + if (other.getBussinessDetailMesg() != com.google.protobuf.ByteString.EMPTY) { + setBussinessDetailMesg(other.getBussinessDetailMesg()); } - if (!other.getBussinessKeyMesg().isEmpty()) { - bussinessKeyMesg_ = other.bussinessKeyMesg_; - onChanged(); + if (other.getBussinessKeyMesg() != com.google.protobuf.ByteString.EMPTY) { + setBussinessKeyMesg(other.getBussinessKeyMesg()); } - if (!other.getApi().isEmpty()) { - api_ = other.api_; - onChanged(); + if (other.getApi() != com.google.protobuf.ByteString.EMPTY) { + setApi(other.getApi()); } - if (!other.getReqData().isEmpty()) { - reqData_ = other.reqData_; - onChanged(); + if (other.getReqData() != com.google.protobuf.ByteString.EMPTY) { + setReqData(other.getReqData()); } - if (!other.getResData().isEmpty()) { - resData_ = other.resData_; - onChanged(); + if (other.getResData() != com.google.protobuf.ByteString.EMPTY) { + setResData(other.getResData()); } - if (!other.getRemainData().isEmpty()) { - remainData_ = other.remainData_; - onChanged(); + if (other.getRemainData() != com.google.protobuf.ByteString.EMPTY) { + setRemainData(other.getRemainData()); } this.mergeUnknownFields(other.unknownFields); onChanged(); @@ -3378,59 +3008,29 @@ public final class BussFlowMiddOuterClass { return this; } - private java.lang.Object msgVersion_ = ""; + private com.google.protobuf.ByteString msgVersion_ = com.google.protobuf.ByteString.EMPTY; /** *
        *数据库版本
        * 
* - * string msg_version = 3; + * bytes msg_version = 3; * @return The msgVersion. */ - public java.lang.String getMsgVersion() { - java.lang.Object ref = msgVersion_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - msgVersion_ = s; - return s; - } else { - return (java.lang.String) ref; - } + @java.lang.Override + public com.google.protobuf.ByteString getMsgVersion() { + return msgVersion_; } /** *
        *数据库版本
        * 
* - * string msg_version = 3; - * @return The bytes for msgVersion. - */ - public com.google.protobuf.ByteString - getMsgVersionBytes() { - java.lang.Object ref = msgVersion_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - msgVersion_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - *
-       *数据库版本
-       * 
- * - * string msg_version = 3; + * bytes msg_version = 3; * @param value The msgVersion to set. * @return This builder for chaining. */ - public Builder setMsgVersion( - java.lang.String value) { + public Builder setMsgVersion(com.google.protobuf.ByteString value) { if (value == null) { throw new NullPointerException(); } @@ -3444,7 +3044,7 @@ public final class BussFlowMiddOuterClass { *数据库版本 * * - * string msg_version = 3; + * bytes msg_version = 3; * @return This builder for chaining. */ public Builder clearMsgVersion() { @@ -3453,26 +3053,6 @@ public final class BussFlowMiddOuterClass { onChanged(); return this; } - /** - *
-       *数据库版本
-       * 
- * - * string msg_version = 3; - * @param value The bytes for msgVersion to set. - * @return This builder for chaining. - */ - public Builder setMsgVersionBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - msgVersion_ = value; - onChanged(); - return this; - } private int msgSeq_ ; /** @@ -4064,59 +3644,29 @@ public final class BussFlowMiddOuterClass { return this; } - private java.lang.Object seqAck_ = ""; + private com.google.protobuf.ByteString seqAck_ = com.google.protobuf.ByteString.EMPTY; /** *
        *序列号和响应序号
        * 
* - * string seq_ack = 18; + * bytes seq_ack = 18; * @return The seqAck. */ - public java.lang.String getSeqAck() { - java.lang.Object ref = seqAck_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - seqAck_ = s; - return s; - } else { - return (java.lang.String) ref; - } + @java.lang.Override + public com.google.protobuf.ByteString getSeqAck() { + return seqAck_; } /** *
        *序列号和响应序号
        * 
* - * string seq_ack = 18; - * @return The bytes for seqAck. - */ - public com.google.protobuf.ByteString - getSeqAckBytes() { - java.lang.Object ref = seqAck_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - seqAck_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - *
-       *序列号和响应序号
-       * 
- * - * string seq_ack = 18; + * bytes seq_ack = 18; * @param value The seqAck to set. * @return This builder for chaining. */ - public Builder setSeqAck( - java.lang.String value) { + public Builder setSeqAck(com.google.protobuf.ByteString value) { if (value == null) { throw new NullPointerException(); } @@ -4130,7 +3680,7 @@ public final class BussFlowMiddOuterClass { *序列号和响应序号 * * - * string seq_ack = 18; + * bytes seq_ack = 18; * @return This builder for chaining. */ public Builder clearSeqAck() { @@ -4139,26 +3689,6 @@ public final class BussFlowMiddOuterClass { onChanged(); return this; } - /** - *
-       *序列号和响应序号
-       * 
- * - * string seq_ack = 18; - * @param value The bytes for seqAck to set. - * @return This builder for chaining. - */ - public Builder setSeqAckBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - seqAck_ = value; - onChanged(); - return this; - } private int recogStatus_ ; /** @@ -4234,59 +3764,29 @@ public final class BussFlowMiddOuterClass { return this; } - private java.lang.Object channel_ = ""; + private com.google.protobuf.ByteString channel_ = com.google.protobuf.ByteString.EMPTY; /** *
        *通道
        * 
* - * string channel = 21; + * bytes channel = 21; * @return The channel. */ - public java.lang.String getChannel() { - java.lang.Object ref = channel_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - channel_ = s; - return s; - } else { - return (java.lang.String) ref; - } + @java.lang.Override + public com.google.protobuf.ByteString getChannel() { + return channel_; } /** *
        *通道
        * 
* - * string channel = 21; - * @return The bytes for channel. - */ - public com.google.protobuf.ByteString - getChannelBytes() { - java.lang.Object ref = channel_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - channel_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - *
-       *通道
-       * 
- * - * string channel = 21; + * bytes channel = 21; * @param value The channel to set. * @return This builder for chaining. */ - public Builder setChannel( - java.lang.String value) { + public Builder setChannel(com.google.protobuf.ByteString value) { if (value == null) { throw new NullPointerException(); } @@ -4300,7 +3800,7 @@ public final class BussFlowMiddOuterClass { *通道 * * - * string channel = 21; + * bytes channel = 21; * @return This builder for chaining. */ public Builder clearChannel() { @@ -4309,26 +3809,6 @@ public final class BussFlowMiddOuterClass { onChanged(); return this; } - /** - *
-       *通道
-       * 
- * - * string channel = 21; - * @param value The bytes for channel to set. - * @return This builder for chaining. - */ - public Builder setChannelBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - channel_ = value; - onChanged(); - return this; - } private com.yuandian.dataflow.proto.Base.IPAddress requestIp_; private com.google.protobuf.SingleFieldBuilderV3< @@ -5605,59 +5085,29 @@ public final class BussFlowMiddOuterClass { return this; } - private java.lang.Object bussinessDetailMesg_ = ""; + private com.google.protobuf.ByteString bussinessDetailMesg_ = com.google.protobuf.ByteString.EMPTY; /** *
        *业务纤细信息
        * 
* - * string bussiness_detail_mesg = 47; + * bytes bussiness_detail_mesg = 47; * @return The bussinessDetailMesg. */ - public java.lang.String getBussinessDetailMesg() { - java.lang.Object ref = bussinessDetailMesg_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - bussinessDetailMesg_ = s; - return s; - } else { - return (java.lang.String) ref; - } + @java.lang.Override + public com.google.protobuf.ByteString getBussinessDetailMesg() { + return bussinessDetailMesg_; } /** *
        *业务纤细信息
        * 
* - * string bussiness_detail_mesg = 47; - * @return The bytes for bussinessDetailMesg. - */ - public com.google.protobuf.ByteString - getBussinessDetailMesgBytes() { - java.lang.Object ref = bussinessDetailMesg_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - bussinessDetailMesg_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - *
-       *业务纤细信息
-       * 
- * - * string bussiness_detail_mesg = 47; + * bytes bussiness_detail_mesg = 47; * @param value The bussinessDetailMesg to set. * @return This builder for chaining. */ - public Builder setBussinessDetailMesg( - java.lang.String value) { + public Builder setBussinessDetailMesg(com.google.protobuf.ByteString value) { if (value == null) { throw new NullPointerException(); } @@ -5671,7 +5121,7 @@ public final class BussFlowMiddOuterClass { *业务纤细信息 * * - * string bussiness_detail_mesg = 47; + * bytes bussiness_detail_mesg = 47; * @return This builder for chaining. */ public Builder clearBussinessDetailMesg() { @@ -5680,80 +5130,30 @@ public final class BussFlowMiddOuterClass { onChanged(); return this; } - /** - *
-       *业务纤细信息
-       * 
- * - * string bussiness_detail_mesg = 47; - * @param value The bytes for bussinessDetailMesg to set. - * @return This builder for chaining. - */ - public Builder setBussinessDetailMesgBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - bussinessDetailMesg_ = value; - onChanged(); - return this; - } - private java.lang.Object bussinessKeyMesg_ = ""; + private com.google.protobuf.ByteString bussinessKeyMesg_ = com.google.protobuf.ByteString.EMPTY; /** *
        *业务关键字
        * 
* - * string bussiness_key_mesg = 48; + * bytes bussiness_key_mesg = 48; * @return The bussinessKeyMesg. */ - public java.lang.String getBussinessKeyMesg() { - java.lang.Object ref = bussinessKeyMesg_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - bussinessKeyMesg_ = s; - return s; - } else { - return (java.lang.String) ref; - } + @java.lang.Override + public com.google.protobuf.ByteString getBussinessKeyMesg() { + return bussinessKeyMesg_; } /** *
        *业务关键字
        * 
* - * string bussiness_key_mesg = 48; - * @return The bytes for bussinessKeyMesg. - */ - public com.google.protobuf.ByteString - getBussinessKeyMesgBytes() { - java.lang.Object ref = bussinessKeyMesg_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - bussinessKeyMesg_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - *
-       *业务关键字
-       * 
- * - * string bussiness_key_mesg = 48; + * bytes bussiness_key_mesg = 48; * @param value The bussinessKeyMesg to set. * @return This builder for chaining. */ - public Builder setBussinessKeyMesg( - java.lang.String value) { + public Builder setBussinessKeyMesg(com.google.protobuf.ByteString value) { if (value == null) { throw new NullPointerException(); } @@ -5767,7 +5167,7 @@ public final class BussFlowMiddOuterClass { *业务关键字 * * - * string bussiness_key_mesg = 48; + * bytes bussiness_key_mesg = 48; * @return This builder for chaining. */ public Builder clearBussinessKeyMesg() { @@ -5776,80 +5176,30 @@ public final class BussFlowMiddOuterClass { onChanged(); return this; } - /** - *
-       *业务关键字
-       * 
- * - * string bussiness_key_mesg = 48; - * @param value The bytes for bussinessKeyMesg to set. - * @return This builder for chaining. - */ - public Builder setBussinessKeyMesgBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - bussinessKeyMesg_ = value; - onChanged(); - return this; - } - private java.lang.Object api_ = ""; + private com.google.protobuf.ByteString api_ = com.google.protobuf.ByteString.EMPTY; /** *
        *应用名称
        * 
* - * string api = 49; + * bytes api = 49; * @return The api. */ - public java.lang.String getApi() { - java.lang.Object ref = api_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - api_ = s; - return s; - } else { - return (java.lang.String) ref; - } + @java.lang.Override + public com.google.protobuf.ByteString getApi() { + return api_; } /** *
        *应用名称
        * 
* - * string api = 49; - * @return The bytes for api. - */ - public com.google.protobuf.ByteString - getApiBytes() { - java.lang.Object ref = api_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - api_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - *
-       *应用名称
-       * 
- * - * string api = 49; + * bytes api = 49; * @param value The api to set. * @return This builder for chaining. */ - public Builder setApi( - java.lang.String value) { + public Builder setApi(com.google.protobuf.ByteString value) { if (value == null) { throw new NullPointerException(); } @@ -5863,7 +5213,7 @@ public final class BussFlowMiddOuterClass { *应用名称 * * - * string api = 49; + * bytes api = 49; * @return This builder for chaining. */ public Builder clearApi() { @@ -5872,80 +5222,30 @@ public final class BussFlowMiddOuterClass { onChanged(); return this; } - /** - *
-       *应用名称
-       * 
- * - * string api = 49; - * @param value The bytes for api to set. - * @return This builder for chaining. - */ - public Builder setApiBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - api_ = value; - onChanged(); - return this; - } - private java.lang.Object reqData_ = ""; + private com.google.protobuf.ByteString reqData_ = com.google.protobuf.ByteString.EMPTY; /** *
        *请求详情报文
        * 
* - * string req_data = 50; + * bytes req_data = 50; * @return The reqData. */ - public java.lang.String getReqData() { - java.lang.Object ref = reqData_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - reqData_ = s; - return s; - } else { - return (java.lang.String) ref; - } + @java.lang.Override + public com.google.protobuf.ByteString getReqData() { + return reqData_; } /** *
        *请求详情报文
        * 
* - * string req_data = 50; - * @return The bytes for reqData. - */ - public com.google.protobuf.ByteString - getReqDataBytes() { - java.lang.Object ref = reqData_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - reqData_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - *
-       *请求详情报文
-       * 
- * - * string req_data = 50; + * bytes req_data = 50; * @param value The reqData to set. * @return This builder for chaining. */ - public Builder setReqData( - java.lang.String value) { + public Builder setReqData(com.google.protobuf.ByteString value) { if (value == null) { throw new NullPointerException(); } @@ -5959,7 +5259,7 @@ public final class BussFlowMiddOuterClass { *请求详情报文 * * - * string req_data = 50; + * bytes req_data = 50; * @return This builder for chaining. */ public Builder clearReqData() { @@ -5968,80 +5268,30 @@ public final class BussFlowMiddOuterClass { onChanged(); return this; } - /** - *
-       *请求详情报文
-       * 
- * - * string req_data = 50; - * @param value The bytes for reqData to set. - * @return This builder for chaining. - */ - public Builder setReqDataBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - reqData_ = value; - onChanged(); - return this; - } - private java.lang.Object resData_ = ""; + private com.google.protobuf.ByteString resData_ = com.google.protobuf.ByteString.EMPTY; /** *
        *响应详情报文
        * 
* - * string res_data = 51; + * bytes res_data = 51; * @return The resData. */ - public java.lang.String getResData() { - java.lang.Object ref = resData_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - resData_ = s; - return s; - } else { - return (java.lang.String) ref; - } + @java.lang.Override + public com.google.protobuf.ByteString getResData() { + return resData_; } /** *
        *响应详情报文
        * 
* - * string res_data = 51; - * @return The bytes for resData. - */ - public com.google.protobuf.ByteString - getResDataBytes() { - java.lang.Object ref = resData_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - resData_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - *
-       *响应详情报文
-       * 
- * - * string res_data = 51; + * bytes res_data = 51; * @param value The resData to set. * @return This builder for chaining. */ - public Builder setResData( - java.lang.String value) { + public Builder setResData(com.google.protobuf.ByteString value) { if (value == null) { throw new NullPointerException(); } @@ -6055,7 +5305,7 @@ public final class BussFlowMiddOuterClass { *响应详情报文 * * - * string res_data = 51; + * bytes res_data = 51; * @return This builder for chaining. */ public Builder clearResData() { @@ -6064,68 +5314,22 @@ public final class BussFlowMiddOuterClass { onChanged(); return this; } - /** - *
-       *响应详情报文
-       * 
- * - * string res_data = 51; - * @param value The bytes for resData to set. - * @return This builder for chaining. - */ - public Builder setResDataBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - resData_ = value; - onChanged(); - return this; - } - private java.lang.Object remainData_ = ""; + private com.google.protobuf.ByteString remainData_ = com.google.protobuf.ByteString.EMPTY; /** - * string remain_data = 52; + * bytes remain_data = 52; * @return The remainData. */ - public java.lang.String getRemainData() { - java.lang.Object ref = remainData_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - remainData_ = s; - return s; - } else { - return (java.lang.String) ref; - } + @java.lang.Override + public com.google.protobuf.ByteString getRemainData() { + return remainData_; } /** - * string remain_data = 52; - * @return The bytes for remainData. - */ - public com.google.protobuf.ByteString - getRemainDataBytes() { - java.lang.Object ref = remainData_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - remainData_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * string remain_data = 52; + * bytes remain_data = 52; * @param value The remainData to set. * @return This builder for chaining. */ - public Builder setRemainData( - java.lang.String value) { + public Builder setRemainData(com.google.protobuf.ByteString value) { if (value == null) { throw new NullPointerException(); } @@ -6135,7 +5339,7 @@ public final class BussFlowMiddOuterClass { return this; } /** - * string remain_data = 52; + * bytes remain_data = 52; * @return This builder for chaining. */ public Builder clearRemainData() { @@ -6144,22 +5348,6 @@ public final class BussFlowMiddOuterClass { onChanged(); return this; } - /** - * string remain_data = 52; - * @param value The bytes for remainData to set. - * @return This builder for chaining. - */ - public Builder setRemainDataBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - remainData_ = value; - onChanged(); - return this; - } @java.lang.Override public final Builder setUnknownFields( final com.google.protobuf.UnknownFieldSet unknownFields) { @@ -6229,7 +5417,7 @@ public final class BussFlowMiddOuterClass { java.lang.String[] descriptorData = { "\n\022BussFlowMidd.proto\022\010dataflow\032\nBase.pro" + "to\"\345\t\n\014BussFlowMidd\022\020\n\010table_id\030\001 \001(\005\022\020\n" + - "\010msg_type\030\002 \001(\r\022\023\n\013msg_version\030\003 \001(\t\022\017\n\007" + + "\010msg_type\030\002 \001(\r\022\023\n\013msg_version\030\003 \001(\014\022\017\n\007" + "msg_seq\030\004 \001(\r\022\017\n\007msg_len\030\005 \001(\r\022\017\n\007src_ma" + "c\030\006 \001(\004\022\017\n\007dst_mac\030\007 \001(\004\022\017\n\007vlan_id\030\010 \001(" + "\r\022\013\n\003tos\030\t \001(\r\022\024\n\014retran_count\030\n \001(\r\022\023\n\013" + @@ -6237,8 +5425,8 @@ public final class BussFlowMiddOuterClass { "\022\020\n\010protocol\030\r \001(\r\022\026\n\016response_bytes\030\016 \001" + "(\r\022\025\n\rrequest_bytes\030\017 \001(\r\022\030\n\020response_pa" + "ckets\030\020 \001(\r\022\027\n\017request_packets\030\021 \001(\r\022\017\n\007" + - "seq_ack\030\022 \001(\t\022\024\n\014recog_status\030\023 \001(\r\022\020\n\010p" + - "robe_if\030\024 \001(\r\022\017\n\007channel\030\025 \001(\t\022\'\n\nreques" + + "seq_ack\030\022 \001(\014\022\024\n\014recog_status\030\023 \001(\r\022\020\n\010p" + + "robe_if\030\024 \001(\r\022\017\n\007channel\030\025 \001(\014\022\'\n\nreques" + "t_ip\030\026 \001(\0132\023.dataflow.IPAddress\022\024\n\014reque" + "st_port\030\027 \001(\r\022(\n\013response_ip\030\030 \001(\0132\023.dat" + "aflow.IPAddress\022\025\n\rresponse_port\030\031 \001(\r\022\031" + @@ -6256,10 +5444,10 @@ public final class BussFlowMiddOuterClass { "me_flag\030( \001(\r\022\026\n\016detail_msg_len\030) \001(\r\022\023\n" + "\013key_msg_len\030* \001(\r\022\017\n\007api_len\030+ \001(\r\022\017\n\007r" + "eq_len\030, \001(\r\022\017\n\007res_len\030- \001(\r\022\022\n\nremain_" + - "len\030. \001(\r\022\035\n\025bussiness_detail_mesg\030/ \001(\t" + - "\022\032\n\022bussiness_key_mesg\0300 \001(\t\022\013\n\003api\0301 \001(" + - "\t\022\020\n\010req_data\0302 \001(\t\022\020\n\010res_data\0303 \001(\t\022\023\n" + - "\013remain_data\0304 \001(\tB<\n#com.yuandian.dataf" + + "len\030. \001(\r\022\035\n\025bussiness_detail_mesg\030/ \001(\014" + + "\022\032\n\022bussiness_key_mesg\0300 \001(\014\022\013\n\003api\0301 \001(" + + "\014\022\020\n\010req_data\0302 \001(\014\022\020\n\010res_data\0303 \001(\014\022\023\n" + + "\013remain_data\0304 \001(\014B<\n#com.yuandian.dataf" + "low.proto.msgtypeP\000Z\023../grpc-gen;grpcgen" + "b\006proto3" }; diff --git a/src/main/java/com/yuandian/dataflow/proto/msgtype/BussFlowWebOuterClass.java b/src/main/java/com/yuandian/dataflow/proto/msgtype/BussFlowWebOuterClass.java index cc28fca..b5d5f5f 100644 --- a/src/main/java/com/yuandian/dataflow/proto/msgtype/BussFlowWebOuterClass.java +++ b/src/main/java/com/yuandian/dataflow/proto/msgtype/BussFlowWebOuterClass.java @@ -43,20 +43,10 @@ public final class BussFlowWebOuterClass { *数据库版本 * * - * string msg_version = 3; + * bytes msg_version = 3; * @return The msgVersion. */ - java.lang.String getMsgVersion(); - /** - *
-     *数据库版本
-     * 
- * - * string msg_version = 3; - * @return The bytes for msgVersion. - */ - com.google.protobuf.ByteString - getMsgVersionBytes(); + com.google.protobuf.ByteString getMsgVersion(); /** *
@@ -199,20 +189,10 @@ public final class BussFlowWebOuterClass {
      *序列号和响应序号
      * 
* - * string seq_ack = 18; + * bytes seq_ack = 18; * @return The seqAck. */ - java.lang.String getSeqAck(); - /** - *
-     *序列号和响应序号
-     * 
- * - * string seq_ack = 18; - * @return The bytes for seqAck. - */ - com.google.protobuf.ByteString - getSeqAckBytes(); + com.google.protobuf.ByteString getSeqAck(); /** * uint32 recog_status = 19; @@ -235,40 +215,20 @@ public final class BussFlowWebOuterClass { *请求内容 * * - * string content_type = 21; + * bytes content_type = 21; * @return The contentType. */ - java.lang.String getContentType(); - /** - *
-     *请求内容
-     * 
- * - * string content_type = 21; - * @return The bytes for contentType. - */ - com.google.protobuf.ByteString - getContentTypeBytes(); + com.google.protobuf.ByteString getContentType(); /** *
      *接受
      * 
* - * string accept = 22; + * bytes accept = 22; * @return The accept. */ - java.lang.String getAccept(); - /** - *
-     *接受
-     * 
- * - * string accept = 22; - * @return The bytes for accept. - */ - com.google.protobuf.ByteString - getAcceptBytes(); + com.google.protobuf.ByteString getAccept(); /** *
@@ -285,40 +245,20 @@ public final class BussFlowWebOuterClass {
      *业务类型
      * 
* - * string channel = 24; + * bytes channel = 24; * @return The channel. */ - java.lang.String getChannel(); - /** - *
-     *业务类型
-     * 
- * - * string channel = 24; - * @return The bytes for channel. - */ - com.google.protobuf.ByteString - getChannelBytes(); + com.google.protobuf.ByteString getChannel(); /** *
      *会话id
      * 
* - * string sessionid = 25; + * bytes sessionid = 25; * @return The sessionid. */ - java.lang.String getSessionid(); - /** - *
-     *会话id
-     * 
- * - * string sessionid = 25; - * @return The bytes for sessionid. - */ - com.google.protobuf.ByteString - getSessionidBytes(); + com.google.protobuf.ByteString getSessionid(); /** *
@@ -535,36 +475,20 @@ public final class BussFlowWebOuterClass {
     long getLocateClientTranslateTime();
 
     /**
-     * string x_requested_with = 44;
+     * bytes x_requested_with = 44;
      * @return The xRequestedWith.
      */
-    java.lang.String getXRequestedWith();
-    /**
-     * string x_requested_with = 44;
-     * @return The bytes for xRequestedWith.
-     */
-    com.google.protobuf.ByteString
-        getXRequestedWithBytes();
+    com.google.protobuf.ByteString getXRequestedWith();
 
     /**
      * 
      *操作系统
      * 
* - * string operating_sytem = 45; + * bytes operating_sytem = 45; * @return The operatingSytem. */ - java.lang.String getOperatingSytem(); - /** - *
-     *操作系统
-     * 
- * - * string operating_sytem = 45; - * @return The bytes for operatingSytem. - */ - com.google.protobuf.ByteString - getOperatingSytemBytes(); + com.google.protobuf.ByteString getOperatingSytem(); /** *
@@ -581,20 +505,10 @@ public final class BussFlowWebOuterClass {
      *浏览器名称
      * 
* - * string browser = 47; + * bytes browser = 47; * @return The browser. */ - java.lang.String getBrowser(); - /** - *
-     *浏览器名称
-     * 
- * - * string browser = 47; - * @return The bytes for browser. - */ - com.google.protobuf.ByteString - getBrowserBytes(); + com.google.protobuf.ByteString getBrowser(); /** *
@@ -697,152 +611,76 @@ public final class BussFlowWebOuterClass {
      *业务纤细信息
      * 
* - * string bussiness_detail_mesg = 58; + * bytes bussiness_detail_mesg = 58; * @return The bussinessDetailMesg. */ - java.lang.String getBussinessDetailMesg(); - /** - *
-     *业务纤细信息
-     * 
- * - * string bussiness_detail_mesg = 58; - * @return The bytes for bussinessDetailMesg. - */ - com.google.protobuf.ByteString - getBussinessDetailMesgBytes(); + com.google.protobuf.ByteString getBussinessDetailMesg(); /** *
      *业务关键字
      * 
* - * string bussiness_key_mesg = 59; + * bytes bussiness_key_mesg = 59; * @return The bussinessKeyMesg. */ - java.lang.String getBussinessKeyMesg(); - /** - *
-     *业务关键字
-     * 
- * - * string bussiness_key_mesg = 59; - * @return The bytes for bussinessKeyMesg. - */ - com.google.protobuf.ByteString - getBussinessKeyMesgBytes(); + com.google.protobuf.ByteString getBussinessKeyMesg(); /** *
      *请求详情报文
      * 
* - * string req_data = 60; + * bytes req_data = 60; * @return The reqData. */ - java.lang.String getReqData(); - /** - *
-     *请求详情报文
-     * 
- * - * string req_data = 60; - * @return The bytes for reqData. - */ - com.google.protobuf.ByteString - getReqDataBytes(); + com.google.protobuf.ByteString getReqData(); /** *
      *响应详情报文
      * 
* - * string res_data = 61; + * bytes res_data = 61; * @return The resData. */ - java.lang.String getResData(); - /** - *
-     *响应详情报文
-     * 
- * - * string res_data = 61; - * @return The bytes for resData. - */ - com.google.protobuf.ByteString - getResDataBytes(); + com.google.protobuf.ByteString getResData(); /** *
      *cookie详情报文
      * 
* - * string cookie_data = 62; + * bytes cookie_data = 62; * @return The cookieData. */ - java.lang.String getCookieData(); - /** - *
-     *cookie详情报文
-     * 
- * - * string cookie_data = 62; - * @return The bytes for cookieData. - */ - com.google.protobuf.ByteString - getCookieDataBytes(); + com.google.protobuf.ByteString getCookieData(); /** *
      *主url详情
      * 
* - * string begin_url = 63; + * bytes begin_url = 63; * @return The beginUrl. */ - java.lang.String getBeginUrl(); - /** - *
-     *主url详情
-     * 
- * - * string begin_url = 63; - * @return The bytes for beginUrl. - */ - com.google.protobuf.ByteString - getBeginUrlBytes(); + com.google.protobuf.ByteString getBeginUrl(); /** *
      *引用url详情
      * 
* - * string refer_url = 64; + * bytes refer_url = 64; * @return The referUrl. */ - java.lang.String getReferUrl(); - /** - *
-     *引用url详情
-     * 
- * - * string refer_url = 64; - * @return The bytes for referUrl. - */ - com.google.protobuf.ByteString - getReferUrlBytes(); + com.google.protobuf.ByteString getReferUrl(); /** - * string remain_data = 65; + * bytes remain_data = 65; * @return The remainData. */ - java.lang.String getRemainData(); - /** - * string remain_data = 65; - * @return The bytes for remainData. - */ - com.google.protobuf.ByteString - getRemainDataBytes(); + com.google.protobuf.ByteString getRemainData(); } /** * Protobuf type {@code dataflow.BussFlowWeb} @@ -857,23 +695,23 @@ public final class BussFlowWebOuterClass { super(builder); } private BussFlowWeb() { - msgVersion_ = ""; - seqAck_ = ""; - contentType_ = ""; - accept_ = ""; - channel_ = ""; - sessionid_ = ""; - xRequestedWith_ = ""; - operatingSytem_ = ""; - browser_ = ""; - bussinessDetailMesg_ = ""; - bussinessKeyMesg_ = ""; - reqData_ = ""; - resData_ = ""; - cookieData_ = ""; - beginUrl_ = ""; - referUrl_ = ""; - remainData_ = ""; + msgVersion_ = com.google.protobuf.ByteString.EMPTY; + seqAck_ = com.google.protobuf.ByteString.EMPTY; + contentType_ = com.google.protobuf.ByteString.EMPTY; + accept_ = com.google.protobuf.ByteString.EMPTY; + channel_ = com.google.protobuf.ByteString.EMPTY; + sessionid_ = com.google.protobuf.ByteString.EMPTY; + xRequestedWith_ = com.google.protobuf.ByteString.EMPTY; + operatingSytem_ = com.google.protobuf.ByteString.EMPTY; + browser_ = com.google.protobuf.ByteString.EMPTY; + bussinessDetailMesg_ = com.google.protobuf.ByteString.EMPTY; + bussinessKeyMesg_ = com.google.protobuf.ByteString.EMPTY; + reqData_ = com.google.protobuf.ByteString.EMPTY; + resData_ = com.google.protobuf.ByteString.EMPTY; + cookieData_ = com.google.protobuf.ByteString.EMPTY; + beginUrl_ = com.google.protobuf.ByteString.EMPTY; + referUrl_ = com.google.protobuf.ByteString.EMPTY; + remainData_ = com.google.protobuf.ByteString.EMPTY; } @java.lang.Override @@ -917,9 +755,8 @@ public final class BussFlowWebOuterClass { break; } case 26: { - java.lang.String s = input.readStringRequireUtf8(); - msgVersion_ = s; + msgVersion_ = input.readBytes(); break; } case 32: { @@ -993,9 +830,8 @@ public final class BussFlowWebOuterClass { break; } case 146: { - java.lang.String s = input.readStringRequireUtf8(); - seqAck_ = s; + seqAck_ = input.readBytes(); break; } case 152: { @@ -1009,15 +845,13 @@ public final class BussFlowWebOuterClass { break; } case 170: { - java.lang.String s = input.readStringRequireUtf8(); - contentType_ = s; + contentType_ = input.readBytes(); break; } case 178: { - java.lang.String s = input.readStringRequireUtf8(); - accept_ = s; + accept_ = input.readBytes(); break; } case 184: { @@ -1026,15 +860,13 @@ public final class BussFlowWebOuterClass { break; } case 194: { - java.lang.String s = input.readStringRequireUtf8(); - channel_ = s; + channel_ = input.readBytes(); break; } case 202: { - java.lang.String s = input.readStringRequireUtf8(); - sessionid_ = s; + sessionid_ = input.readBytes(); break; } case 210: { @@ -1144,15 +976,13 @@ public final class BussFlowWebOuterClass { break; } case 354: { - java.lang.String s = input.readStringRequireUtf8(); - xRequestedWith_ = s; + xRequestedWith_ = input.readBytes(); break; } case 362: { - java.lang.String s = input.readStringRequireUtf8(); - operatingSytem_ = s; + operatingSytem_ = input.readBytes(); break; } case 368: { @@ -1161,9 +991,8 @@ public final class BussFlowWebOuterClass { break; } case 378: { - java.lang.String s = input.readStringRequireUtf8(); - browser_ = s; + browser_ = input.readBytes(); break; } case 384: { @@ -1217,51 +1046,43 @@ public final class BussFlowWebOuterClass { break; } case 466: { - java.lang.String s = input.readStringRequireUtf8(); - bussinessDetailMesg_ = s; + bussinessDetailMesg_ = input.readBytes(); break; } case 474: { - java.lang.String s = input.readStringRequireUtf8(); - bussinessKeyMesg_ = s; + bussinessKeyMesg_ = input.readBytes(); break; } case 482: { - java.lang.String s = input.readStringRequireUtf8(); - reqData_ = s; + reqData_ = input.readBytes(); break; } case 490: { - java.lang.String s = input.readStringRequireUtf8(); - resData_ = s; + resData_ = input.readBytes(); break; } case 498: { - java.lang.String s = input.readStringRequireUtf8(); - cookieData_ = s; + cookieData_ = input.readBytes(); break; } case 506: { - java.lang.String s = input.readStringRequireUtf8(); - beginUrl_ = s; + beginUrl_ = input.readBytes(); break; } case 514: { - java.lang.String s = input.readStringRequireUtf8(); - referUrl_ = s; + referUrl_ = input.readBytes(); break; } case 522: { - java.lang.String s = input.readStringRequireUtf8(); - remainData_ = s; + remainData_ = input.readBytes(); break; } default: { @@ -1329,49 +1150,18 @@ public final class BussFlowWebOuterClass { } public static final int MSG_VERSION_FIELD_NUMBER = 3; - private volatile java.lang.Object msgVersion_; + private com.google.protobuf.ByteString msgVersion_; /** *
      *数据库版本
      * 
* - * string msg_version = 3; + * bytes msg_version = 3; * @return The msgVersion. */ @java.lang.Override - public java.lang.String getMsgVersion() { - java.lang.Object ref = msgVersion_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - msgVersion_ = s; - return s; - } - } - /** - *
-     *数据库版本
-     * 
- * - * string msg_version = 3; - * @return The bytes for msgVersion. - */ - @java.lang.Override - public com.google.protobuf.ByteString - getMsgVersionBytes() { - java.lang.Object ref = msgVersion_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - msgVersion_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } + public com.google.protobuf.ByteString getMsgVersion() { + return msgVersion_; } public static final int MSG_SEQ_FIELD_NUMBER = 4; @@ -1581,49 +1371,18 @@ public final class BussFlowWebOuterClass { } public static final int SEQ_ACK_FIELD_NUMBER = 18; - private volatile java.lang.Object seqAck_; + private com.google.protobuf.ByteString seqAck_; /** *
      *序列号和响应序号
      * 
* - * string seq_ack = 18; + * bytes seq_ack = 18; * @return The seqAck. */ @java.lang.Override - public java.lang.String getSeqAck() { - java.lang.Object ref = seqAck_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - seqAck_ = s; - return s; - } - } - /** - *
-     *序列号和响应序号
-     * 
- * - * string seq_ack = 18; - * @return The bytes for seqAck. - */ - @java.lang.Override - public com.google.protobuf.ByteString - getSeqAckBytes() { - java.lang.Object ref = seqAck_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - seqAck_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } + public com.google.protobuf.ByteString getSeqAck() { + return seqAck_; } public static final int RECOG_STATUS_FIELD_NUMBER = 19; @@ -1653,95 +1412,33 @@ public final class BussFlowWebOuterClass { } public static final int CONTENT_TYPE_FIELD_NUMBER = 21; - private volatile java.lang.Object contentType_; + private com.google.protobuf.ByteString contentType_; /** *
      *请求内容
      * 
* - * string content_type = 21; + * bytes content_type = 21; * @return The contentType. */ @java.lang.Override - public java.lang.String getContentType() { - java.lang.Object ref = contentType_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - contentType_ = s; - return s; - } - } - /** - *
-     *请求内容
-     * 
- * - * string content_type = 21; - * @return The bytes for contentType. - */ - @java.lang.Override - public com.google.protobuf.ByteString - getContentTypeBytes() { - java.lang.Object ref = contentType_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - contentType_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } + public com.google.protobuf.ByteString getContentType() { + return contentType_; } public static final int ACCEPT_FIELD_NUMBER = 22; - private volatile java.lang.Object accept_; + private com.google.protobuf.ByteString accept_; /** *
      *接受
      * 
* - * string accept = 22; + * bytes accept = 22; * @return The accept. */ @java.lang.Override - public java.lang.String getAccept() { - java.lang.Object ref = accept_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - accept_ = s; - return s; - } - } - /** - *
-     *接受
-     * 
- * - * string accept = 22; - * @return The bytes for accept. - */ - @java.lang.Override - public com.google.protobuf.ByteString - getAcceptBytes() { - java.lang.Object ref = accept_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - accept_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } + public com.google.protobuf.ByteString getAccept() { + return accept_; } public static final int PROBE_IF_FIELD_NUMBER = 23; @@ -1760,95 +1457,33 @@ public final class BussFlowWebOuterClass { } public static final int CHANNEL_FIELD_NUMBER = 24; - private volatile java.lang.Object channel_; + private com.google.protobuf.ByteString channel_; /** *
      *业务类型
      * 
* - * string channel = 24; + * bytes channel = 24; * @return The channel. */ @java.lang.Override - public java.lang.String getChannel() { - java.lang.Object ref = channel_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - channel_ = s; - return s; - } - } - /** - *
-     *业务类型
-     * 
- * - * string channel = 24; - * @return The bytes for channel. - */ - @java.lang.Override - public com.google.protobuf.ByteString - getChannelBytes() { - java.lang.Object ref = channel_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - channel_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } + public com.google.protobuf.ByteString getChannel() { + return channel_; } public static final int SESSIONID_FIELD_NUMBER = 25; - private volatile java.lang.Object sessionid_; + private com.google.protobuf.ByteString sessionid_; /** *
      *会话id
      * 
* - * string sessionid = 25; + * bytes sessionid = 25; * @return The sessionid. */ @java.lang.Override - public java.lang.String getSessionid() { - java.lang.Object ref = sessionid_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - sessionid_ = s; - return s; - } - } - /** - *
-     *会话id
-     * 
- * - * string sessionid = 25; - * @return The bytes for sessionid. - */ - @java.lang.Override - public com.google.protobuf.ByteString - getSessionidBytes() { - java.lang.Object ref = sessionid_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - sessionid_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } + public com.google.protobuf.ByteString getSessionid() { + return sessionid_; } public static final int REQUEST_IP_FIELD_NUMBER = 26; @@ -2168,87 +1803,29 @@ public final class BussFlowWebOuterClass { } public static final int X_REQUESTED_WITH_FIELD_NUMBER = 44; - private volatile java.lang.Object xRequestedWith_; + private com.google.protobuf.ByteString xRequestedWith_; /** - * string x_requested_with = 44; + * bytes x_requested_with = 44; * @return The xRequestedWith. */ @java.lang.Override - public java.lang.String getXRequestedWith() { - java.lang.Object ref = xRequestedWith_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - xRequestedWith_ = s; - return s; - } - } - /** - * string x_requested_with = 44; - * @return The bytes for xRequestedWith. - */ - @java.lang.Override - public com.google.protobuf.ByteString - getXRequestedWithBytes() { - java.lang.Object ref = xRequestedWith_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - xRequestedWith_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } + public com.google.protobuf.ByteString getXRequestedWith() { + return xRequestedWith_; } public static final int OPERATING_SYTEM_FIELD_NUMBER = 45; - private volatile java.lang.Object operatingSytem_; + private com.google.protobuf.ByteString operatingSytem_; /** *
      *操作系统
      * 
* - * string operating_sytem = 45; + * bytes operating_sytem = 45; * @return The operatingSytem. */ @java.lang.Override - public java.lang.String getOperatingSytem() { - java.lang.Object ref = operatingSytem_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - operatingSytem_ = s; - return s; - } - } - /** - *
-     *操作系统
-     * 
- * - * string operating_sytem = 45; - * @return The bytes for operatingSytem. - */ - @java.lang.Override - public com.google.protobuf.ByteString - getOperatingSytemBytes() { - java.lang.Object ref = operatingSytem_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - operatingSytem_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } + public com.google.protobuf.ByteString getOperatingSytem() { + return operatingSytem_; } public static final int SERVER_RES_CODE_FIELD_NUMBER = 46; @@ -2267,49 +1844,18 @@ public final class BussFlowWebOuterClass { } public static final int BROWSER_FIELD_NUMBER = 47; - private volatile java.lang.Object browser_; + private com.google.protobuf.ByteString browser_; /** *
      *浏览器名称
      * 
* - * string browser = 47; + * bytes browser = 47; * @return The browser. */ @java.lang.Override - public java.lang.String getBrowser() { - java.lang.Object ref = browser_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - browser_ = s; - return s; - } - } - /** - *
-     *浏览器名称
-     * 
- * - * string browser = 47; - * @return The bytes for browser. - */ - @java.lang.Override - public com.google.protobuf.ByteString - getBrowserBytes() { - java.lang.Object ref = browser_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - browser_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } + public com.google.protobuf.ByteString getBrowser() { + return browser_; } public static final int IS_UNCOMPLETE_FIELD_NUMBER = 48; @@ -2459,363 +2005,119 @@ public final class BussFlowWebOuterClass { } public static final int BUSSINESS_DETAIL_MESG_FIELD_NUMBER = 58; - private volatile java.lang.Object bussinessDetailMesg_; + private com.google.protobuf.ByteString bussinessDetailMesg_; /** *
      *业务纤细信息
      * 
* - * string bussiness_detail_mesg = 58; + * bytes bussiness_detail_mesg = 58; * @return The bussinessDetailMesg. */ @java.lang.Override - public java.lang.String getBussinessDetailMesg() { - java.lang.Object ref = bussinessDetailMesg_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - bussinessDetailMesg_ = s; - return s; - } - } - /** - *
-     *业务纤细信息
-     * 
- * - * string bussiness_detail_mesg = 58; - * @return The bytes for bussinessDetailMesg. - */ - @java.lang.Override - public com.google.protobuf.ByteString - getBussinessDetailMesgBytes() { - java.lang.Object ref = bussinessDetailMesg_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - bussinessDetailMesg_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } + public com.google.protobuf.ByteString getBussinessDetailMesg() { + return bussinessDetailMesg_; } public static final int BUSSINESS_KEY_MESG_FIELD_NUMBER = 59; - private volatile java.lang.Object bussinessKeyMesg_; + private com.google.protobuf.ByteString bussinessKeyMesg_; /** *
      *业务关键字
      * 
* - * string bussiness_key_mesg = 59; + * bytes bussiness_key_mesg = 59; * @return The bussinessKeyMesg. */ @java.lang.Override - public java.lang.String getBussinessKeyMesg() { - java.lang.Object ref = bussinessKeyMesg_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - bussinessKeyMesg_ = s; - return s; - } - } - /** - *
-     *业务关键字
-     * 
- * - * string bussiness_key_mesg = 59; - * @return The bytes for bussinessKeyMesg. - */ - @java.lang.Override - public com.google.protobuf.ByteString - getBussinessKeyMesgBytes() { - java.lang.Object ref = bussinessKeyMesg_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - bussinessKeyMesg_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } + public com.google.protobuf.ByteString getBussinessKeyMesg() { + return bussinessKeyMesg_; } public static final int REQ_DATA_FIELD_NUMBER = 60; - private volatile java.lang.Object reqData_; + private com.google.protobuf.ByteString reqData_; /** *
      *请求详情报文
      * 
* - * string req_data = 60; + * bytes req_data = 60; * @return The reqData. */ @java.lang.Override - public java.lang.String getReqData() { - java.lang.Object ref = reqData_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - reqData_ = s; - return s; - } - } - /** - *
-     *请求详情报文
-     * 
- * - * string req_data = 60; - * @return The bytes for reqData. - */ - @java.lang.Override - public com.google.protobuf.ByteString - getReqDataBytes() { - java.lang.Object ref = reqData_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - reqData_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } + public com.google.protobuf.ByteString getReqData() { + return reqData_; } public static final int RES_DATA_FIELD_NUMBER = 61; - private volatile java.lang.Object resData_; + private com.google.protobuf.ByteString resData_; /** *
      *响应详情报文
      * 
* - * string res_data = 61; + * bytes res_data = 61; * @return The resData. */ @java.lang.Override - public java.lang.String getResData() { - java.lang.Object ref = resData_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - resData_ = s; - return s; - } - } - /** - *
-     *响应详情报文
-     * 
- * - * string res_data = 61; - * @return The bytes for resData. - */ - @java.lang.Override - public com.google.protobuf.ByteString - getResDataBytes() { - java.lang.Object ref = resData_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - resData_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } + public com.google.protobuf.ByteString getResData() { + return resData_; } public static final int COOKIE_DATA_FIELD_NUMBER = 62; - private volatile java.lang.Object cookieData_; + private com.google.protobuf.ByteString cookieData_; /** *
      *cookie详情报文
      * 
* - * string cookie_data = 62; + * bytes cookie_data = 62; * @return The cookieData. */ @java.lang.Override - public java.lang.String getCookieData() { - java.lang.Object ref = cookieData_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - cookieData_ = s; - return s; - } - } - /** - *
-     *cookie详情报文
-     * 
- * - * string cookie_data = 62; - * @return The bytes for cookieData. - */ - @java.lang.Override - public com.google.protobuf.ByteString - getCookieDataBytes() { - java.lang.Object ref = cookieData_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - cookieData_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } + public com.google.protobuf.ByteString getCookieData() { + return cookieData_; } public static final int BEGIN_URL_FIELD_NUMBER = 63; - private volatile java.lang.Object beginUrl_; + private com.google.protobuf.ByteString beginUrl_; /** *
      *主url详情
      * 
* - * string begin_url = 63; + * bytes begin_url = 63; * @return The beginUrl. */ @java.lang.Override - public java.lang.String getBeginUrl() { - java.lang.Object ref = beginUrl_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - beginUrl_ = s; - return s; - } - } - /** - *
-     *主url详情
-     * 
- * - * string begin_url = 63; - * @return The bytes for beginUrl. - */ - @java.lang.Override - public com.google.protobuf.ByteString - getBeginUrlBytes() { - java.lang.Object ref = beginUrl_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - beginUrl_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } + public com.google.protobuf.ByteString getBeginUrl() { + return beginUrl_; } public static final int REFER_URL_FIELD_NUMBER = 64; - private volatile java.lang.Object referUrl_; + private com.google.protobuf.ByteString referUrl_; /** *
      *引用url详情
      * 
* - * string refer_url = 64; + * bytes refer_url = 64; * @return The referUrl. */ @java.lang.Override - public java.lang.String getReferUrl() { - java.lang.Object ref = referUrl_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - referUrl_ = s; - return s; - } - } - /** - *
-     *引用url详情
-     * 
- * - * string refer_url = 64; - * @return The bytes for referUrl. - */ - @java.lang.Override - public com.google.protobuf.ByteString - getReferUrlBytes() { - java.lang.Object ref = referUrl_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - referUrl_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } + public com.google.protobuf.ByteString getReferUrl() { + return referUrl_; } public static final int REMAIN_DATA_FIELD_NUMBER = 65; - private volatile java.lang.Object remainData_; + private com.google.protobuf.ByteString remainData_; /** - * string remain_data = 65; + * bytes remain_data = 65; * @return The remainData. */ @java.lang.Override - public java.lang.String getRemainData() { - java.lang.Object ref = remainData_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - remainData_ = s; - return s; - } - } - /** - * string remain_data = 65; - * @return The bytes for remainData. - */ - @java.lang.Override - public com.google.protobuf.ByteString - getRemainDataBytes() { - java.lang.Object ref = remainData_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - remainData_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } + public com.google.protobuf.ByteString getRemainData() { + return remainData_; } private byte memoizedIsInitialized = -1; @@ -2838,8 +2140,8 @@ public final class BussFlowWebOuterClass { if (msgType_ != 0) { output.writeUInt32(2, msgType_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(msgVersion_)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 3, msgVersion_); + if (!msgVersion_.isEmpty()) { + output.writeBytes(3, msgVersion_); } if (msgSeq_ != 0) { output.writeUInt32(4, msgSeq_); @@ -2883,8 +2185,8 @@ public final class BussFlowWebOuterClass { if (requestPackets_ != 0) { output.writeUInt32(17, requestPackets_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(seqAck_)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 18, seqAck_); + if (!seqAck_.isEmpty()) { + output.writeBytes(18, seqAck_); } if (recogStatus_ != 0) { output.writeUInt32(19, recogStatus_); @@ -2892,20 +2194,20 @@ public final class BussFlowWebOuterClass { if (reqMethod_ != 0) { output.writeUInt32(20, reqMethod_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(contentType_)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 21, contentType_); + if (!contentType_.isEmpty()) { + output.writeBytes(21, contentType_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(accept_)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 22, accept_); + if (!accept_.isEmpty()) { + output.writeBytes(22, accept_); } if (probeIf_ != 0) { output.writeUInt32(23, probeIf_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(channel_)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 24, channel_); + if (!channel_.isEmpty()) { + output.writeBytes(24, channel_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(sessionid_)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 25, sessionid_); + if (!sessionid_.isEmpty()) { + output.writeBytes(25, sessionid_); } if (requestIp_ != null) { output.writeMessage(26, getRequestIp()); @@ -2961,17 +2263,17 @@ public final class BussFlowWebOuterClass { if (locateClientTranslateTime_ != 0L) { output.writeInt64(43, locateClientTranslateTime_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(xRequestedWith_)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 44, xRequestedWith_); + if (!xRequestedWith_.isEmpty()) { + output.writeBytes(44, xRequestedWith_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(operatingSytem_)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 45, operatingSytem_); + if (!operatingSytem_.isEmpty()) { + output.writeBytes(45, operatingSytem_); } if (serverResCode_ != 0) { output.writeUInt32(46, serverResCode_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(browser_)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 47, browser_); + if (!browser_.isEmpty()) { + output.writeBytes(47, browser_); } if (isUncomplete_ != 0) { output.writeInt32(48, isUncomplete_); @@ -3003,29 +2305,29 @@ public final class BussFlowWebOuterClass { if (remainLen_ != 0) { output.writeUInt32(57, remainLen_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(bussinessDetailMesg_)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 58, bussinessDetailMesg_); + if (!bussinessDetailMesg_.isEmpty()) { + output.writeBytes(58, bussinessDetailMesg_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(bussinessKeyMesg_)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 59, bussinessKeyMesg_); + if (!bussinessKeyMesg_.isEmpty()) { + output.writeBytes(59, bussinessKeyMesg_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(reqData_)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 60, reqData_); + if (!reqData_.isEmpty()) { + output.writeBytes(60, reqData_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(resData_)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 61, resData_); + if (!resData_.isEmpty()) { + output.writeBytes(61, resData_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(cookieData_)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 62, cookieData_); + if (!cookieData_.isEmpty()) { + output.writeBytes(62, cookieData_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(beginUrl_)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 63, beginUrl_); + if (!beginUrl_.isEmpty()) { + output.writeBytes(63, beginUrl_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(referUrl_)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 64, referUrl_); + if (!referUrl_.isEmpty()) { + output.writeBytes(64, referUrl_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(remainData_)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 65, remainData_); + if (!remainData_.isEmpty()) { + output.writeBytes(65, remainData_); } unknownFields.writeTo(output); } @@ -3044,8 +2346,9 @@ public final class BussFlowWebOuterClass { size += com.google.protobuf.CodedOutputStream .computeUInt32Size(2, msgType_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(msgVersion_)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(3, msgVersion_); + if (!msgVersion_.isEmpty()) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(3, msgVersion_); } if (msgSeq_ != 0) { size += com.google.protobuf.CodedOutputStream @@ -3103,8 +2406,9 @@ public final class BussFlowWebOuterClass { size += com.google.protobuf.CodedOutputStream .computeUInt32Size(17, requestPackets_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(seqAck_)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(18, seqAck_); + if (!seqAck_.isEmpty()) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(18, seqAck_); } if (recogStatus_ != 0) { size += com.google.protobuf.CodedOutputStream @@ -3114,21 +2418,25 @@ public final class BussFlowWebOuterClass { size += com.google.protobuf.CodedOutputStream .computeUInt32Size(20, reqMethod_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(contentType_)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(21, contentType_); + if (!contentType_.isEmpty()) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(21, contentType_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(accept_)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(22, accept_); + if (!accept_.isEmpty()) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(22, accept_); } if (probeIf_ != 0) { size += com.google.protobuf.CodedOutputStream .computeUInt32Size(23, probeIf_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(channel_)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(24, channel_); + if (!channel_.isEmpty()) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(24, channel_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(sessionid_)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(25, sessionid_); + if (!sessionid_.isEmpty()) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(25, sessionid_); } if (requestIp_ != null) { size += com.google.protobuf.CodedOutputStream @@ -3202,18 +2510,21 @@ public final class BussFlowWebOuterClass { size += com.google.protobuf.CodedOutputStream .computeInt64Size(43, locateClientTranslateTime_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(xRequestedWith_)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(44, xRequestedWith_); + if (!xRequestedWith_.isEmpty()) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(44, xRequestedWith_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(operatingSytem_)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(45, operatingSytem_); + if (!operatingSytem_.isEmpty()) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(45, operatingSytem_); } if (serverResCode_ != 0) { size += com.google.protobuf.CodedOutputStream .computeUInt32Size(46, serverResCode_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(browser_)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(47, browser_); + if (!browser_.isEmpty()) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(47, browser_); } if (isUncomplete_ != 0) { size += com.google.protobuf.CodedOutputStream @@ -3255,29 +2566,37 @@ public final class BussFlowWebOuterClass { size += com.google.protobuf.CodedOutputStream .computeUInt32Size(57, remainLen_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(bussinessDetailMesg_)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(58, bussinessDetailMesg_); + if (!bussinessDetailMesg_.isEmpty()) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(58, bussinessDetailMesg_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(bussinessKeyMesg_)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(59, bussinessKeyMesg_); + if (!bussinessKeyMesg_.isEmpty()) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(59, bussinessKeyMesg_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(reqData_)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(60, reqData_); + if (!reqData_.isEmpty()) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(60, reqData_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(resData_)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(61, resData_); + if (!resData_.isEmpty()) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(61, resData_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(cookieData_)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(62, cookieData_); + if (!cookieData_.isEmpty()) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(62, cookieData_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(beginUrl_)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(63, beginUrl_); + if (!beginUrl_.isEmpty()) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(63, beginUrl_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(referUrl_)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(64, referUrl_); + if (!referUrl_.isEmpty()) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(64, referUrl_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(remainData_)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(65, remainData_); + if (!remainData_.isEmpty()) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(65, remainData_); } size += unknownFields.getSerializedSize(); memoizedSize = size; @@ -3720,7 +3039,7 @@ public final class BussFlowWebOuterClass { msgType_ = 0; - msgVersion_ = ""; + msgVersion_ = com.google.protobuf.ByteString.EMPTY; msgSeq_ = 0; @@ -3750,21 +3069,21 @@ public final class BussFlowWebOuterClass { requestPackets_ = 0; - seqAck_ = ""; + seqAck_ = com.google.protobuf.ByteString.EMPTY; recogStatus_ = 0; reqMethod_ = 0; - contentType_ = ""; + contentType_ = com.google.protobuf.ByteString.EMPTY; - accept_ = ""; + accept_ = com.google.protobuf.ByteString.EMPTY; probeIf_ = 0; - channel_ = ""; + channel_ = com.google.protobuf.ByteString.EMPTY; - sessionid_ = ""; + sessionid_ = com.google.protobuf.ByteString.EMPTY; if (requestIpBuilder_ == null) { requestIp_ = null; @@ -3810,13 +3129,13 @@ public final class BussFlowWebOuterClass { locateClientTranslateTime_ = 0L; - xRequestedWith_ = ""; + xRequestedWith_ = com.google.protobuf.ByteString.EMPTY; - operatingSytem_ = ""; + operatingSytem_ = com.google.protobuf.ByteString.EMPTY; serverResCode_ = 0; - browser_ = ""; + browser_ = com.google.protobuf.ByteString.EMPTY; isUncomplete_ = 0; @@ -3838,21 +3157,21 @@ public final class BussFlowWebOuterClass { remainLen_ = 0; - bussinessDetailMesg_ = ""; + bussinessDetailMesg_ = com.google.protobuf.ByteString.EMPTY; - bussinessKeyMesg_ = ""; + bussinessKeyMesg_ = com.google.protobuf.ByteString.EMPTY; - reqData_ = ""; + reqData_ = com.google.protobuf.ByteString.EMPTY; - resData_ = ""; + resData_ = com.google.protobuf.ByteString.EMPTY; - cookieData_ = ""; + cookieData_ = com.google.protobuf.ByteString.EMPTY; - beginUrl_ = ""; + beginUrl_ = com.google.protobuf.ByteString.EMPTY; - referUrl_ = ""; + referUrl_ = com.google.protobuf.ByteString.EMPTY; - remainData_ = ""; + remainData_ = com.google.protobuf.ByteString.EMPTY; return this; } @@ -4007,9 +3326,8 @@ public final class BussFlowWebOuterClass { if (other.getMsgType() != 0) { setMsgType(other.getMsgType()); } - if (!other.getMsgVersion().isEmpty()) { - msgVersion_ = other.msgVersion_; - onChanged(); + if (other.getMsgVersion() != com.google.protobuf.ByteString.EMPTY) { + setMsgVersion(other.getMsgVersion()); } if (other.getMsgSeq() != 0) { setMsgSeq(other.getMsgSeq()); @@ -4053,9 +3371,8 @@ public final class BussFlowWebOuterClass { if (other.getRequestPackets() != 0) { setRequestPackets(other.getRequestPackets()); } - if (!other.getSeqAck().isEmpty()) { - seqAck_ = other.seqAck_; - onChanged(); + if (other.getSeqAck() != com.google.protobuf.ByteString.EMPTY) { + setSeqAck(other.getSeqAck()); } if (other.getRecogStatus() != 0) { setRecogStatus(other.getRecogStatus()); @@ -4063,24 +3380,20 @@ public final class BussFlowWebOuterClass { if (other.getReqMethod() != 0) { setReqMethod(other.getReqMethod()); } - if (!other.getContentType().isEmpty()) { - contentType_ = other.contentType_; - onChanged(); + if (other.getContentType() != com.google.protobuf.ByteString.EMPTY) { + setContentType(other.getContentType()); } - if (!other.getAccept().isEmpty()) { - accept_ = other.accept_; - onChanged(); + if (other.getAccept() != com.google.protobuf.ByteString.EMPTY) { + setAccept(other.getAccept()); } if (other.getProbeIf() != 0) { setProbeIf(other.getProbeIf()); } - if (!other.getChannel().isEmpty()) { - channel_ = other.channel_; - onChanged(); + if (other.getChannel() != com.google.protobuf.ByteString.EMPTY) { + setChannel(other.getChannel()); } - if (!other.getSessionid().isEmpty()) { - sessionid_ = other.sessionid_; - onChanged(); + if (other.getSessionid() != com.google.protobuf.ByteString.EMPTY) { + setSessionid(other.getSessionid()); } if (other.hasRequestIp()) { mergeRequestIp(other.getRequestIp()); @@ -4136,20 +3449,17 @@ public final class BussFlowWebOuterClass { if (other.getLocateClientTranslateTime() != 0L) { setLocateClientTranslateTime(other.getLocateClientTranslateTime()); } - if (!other.getXRequestedWith().isEmpty()) { - xRequestedWith_ = other.xRequestedWith_; - onChanged(); + if (other.getXRequestedWith() != com.google.protobuf.ByteString.EMPTY) { + setXRequestedWith(other.getXRequestedWith()); } - if (!other.getOperatingSytem().isEmpty()) { - operatingSytem_ = other.operatingSytem_; - onChanged(); + if (other.getOperatingSytem() != com.google.protobuf.ByteString.EMPTY) { + setOperatingSytem(other.getOperatingSytem()); } if (other.getServerResCode() != 0) { setServerResCode(other.getServerResCode()); } - if (!other.getBrowser().isEmpty()) { - browser_ = other.browser_; - onChanged(); + if (other.getBrowser() != com.google.protobuf.ByteString.EMPTY) { + setBrowser(other.getBrowser()); } if (other.getIsUncomplete() != 0) { setIsUncomplete(other.getIsUncomplete()); @@ -4181,37 +3491,29 @@ public final class BussFlowWebOuterClass { if (other.getRemainLen() != 0) { setRemainLen(other.getRemainLen()); } - if (!other.getBussinessDetailMesg().isEmpty()) { - bussinessDetailMesg_ = other.bussinessDetailMesg_; - onChanged(); + if (other.getBussinessDetailMesg() != com.google.protobuf.ByteString.EMPTY) { + setBussinessDetailMesg(other.getBussinessDetailMesg()); } - if (!other.getBussinessKeyMesg().isEmpty()) { - bussinessKeyMesg_ = other.bussinessKeyMesg_; - onChanged(); + if (other.getBussinessKeyMesg() != com.google.protobuf.ByteString.EMPTY) { + setBussinessKeyMesg(other.getBussinessKeyMesg()); } - if (!other.getReqData().isEmpty()) { - reqData_ = other.reqData_; - onChanged(); + if (other.getReqData() != com.google.protobuf.ByteString.EMPTY) { + setReqData(other.getReqData()); } - if (!other.getResData().isEmpty()) { - resData_ = other.resData_; - onChanged(); + if (other.getResData() != com.google.protobuf.ByteString.EMPTY) { + setResData(other.getResData()); } - if (!other.getCookieData().isEmpty()) { - cookieData_ = other.cookieData_; - onChanged(); + if (other.getCookieData() != com.google.protobuf.ByteString.EMPTY) { + setCookieData(other.getCookieData()); } - if (!other.getBeginUrl().isEmpty()) { - beginUrl_ = other.beginUrl_; - onChanged(); + if (other.getBeginUrl() != com.google.protobuf.ByteString.EMPTY) { + setBeginUrl(other.getBeginUrl()); } - if (!other.getReferUrl().isEmpty()) { - referUrl_ = other.referUrl_; - onChanged(); + if (other.getReferUrl() != com.google.protobuf.ByteString.EMPTY) { + setReferUrl(other.getReferUrl()); } - if (!other.getRemainData().isEmpty()) { - remainData_ = other.remainData_; - onChanged(); + if (other.getRemainData() != com.google.protobuf.ByteString.EMPTY) { + setRemainData(other.getRemainData()); } this.mergeUnknownFields(other.unknownFields); onChanged(); @@ -4328,59 +3630,29 @@ public final class BussFlowWebOuterClass { return this; } - private java.lang.Object msgVersion_ = ""; + private com.google.protobuf.ByteString msgVersion_ = com.google.protobuf.ByteString.EMPTY; /** *
        *数据库版本
        * 
* - * string msg_version = 3; + * bytes msg_version = 3; * @return The msgVersion. */ - public java.lang.String getMsgVersion() { - java.lang.Object ref = msgVersion_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - msgVersion_ = s; - return s; - } else { - return (java.lang.String) ref; - } + @java.lang.Override + public com.google.protobuf.ByteString getMsgVersion() { + return msgVersion_; } /** *
        *数据库版本
        * 
* - * string msg_version = 3; - * @return The bytes for msgVersion. - */ - public com.google.protobuf.ByteString - getMsgVersionBytes() { - java.lang.Object ref = msgVersion_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - msgVersion_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - *
-       *数据库版本
-       * 
- * - * string msg_version = 3; + * bytes msg_version = 3; * @param value The msgVersion to set. * @return This builder for chaining. */ - public Builder setMsgVersion( - java.lang.String value) { + public Builder setMsgVersion(com.google.protobuf.ByteString value) { if (value == null) { throw new NullPointerException(); } @@ -4394,7 +3666,7 @@ public final class BussFlowWebOuterClass { *数据库版本 *
* - * string msg_version = 3; + * bytes msg_version = 3; * @return This builder for chaining. */ public Builder clearMsgVersion() { @@ -4403,26 +3675,6 @@ public final class BussFlowWebOuterClass { onChanged(); return this; } - /** - *
-       *数据库版本
-       * 
- * - * string msg_version = 3; - * @param value The bytes for msgVersion to set. - * @return This builder for chaining. - */ - public Builder setMsgVersionBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - msgVersion_ = value; - onChanged(); - return this; - } private int msgSeq_ ; /** @@ -5014,59 +4266,29 @@ public final class BussFlowWebOuterClass { return this; } - private java.lang.Object seqAck_ = ""; + private com.google.protobuf.ByteString seqAck_ = com.google.protobuf.ByteString.EMPTY; /** *
        *序列号和响应序号
        * 
* - * string seq_ack = 18; + * bytes seq_ack = 18; * @return The seqAck. */ - public java.lang.String getSeqAck() { - java.lang.Object ref = seqAck_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - seqAck_ = s; - return s; - } else { - return (java.lang.String) ref; - } + @java.lang.Override + public com.google.protobuf.ByteString getSeqAck() { + return seqAck_; } /** *
        *序列号和响应序号
        * 
* - * string seq_ack = 18; - * @return The bytes for seqAck. - */ - public com.google.protobuf.ByteString - getSeqAckBytes() { - java.lang.Object ref = seqAck_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - seqAck_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - *
-       *序列号和响应序号
-       * 
- * - * string seq_ack = 18; + * bytes seq_ack = 18; * @param value The seqAck to set. * @return This builder for chaining. */ - public Builder setSeqAck( - java.lang.String value) { + public Builder setSeqAck(com.google.protobuf.ByteString value) { if (value == null) { throw new NullPointerException(); } @@ -5080,7 +4302,7 @@ public final class BussFlowWebOuterClass { *序列号和响应序号 * * - * string seq_ack = 18; + * bytes seq_ack = 18; * @return This builder for chaining. */ public Builder clearSeqAck() { @@ -5089,26 +4311,6 @@ public final class BussFlowWebOuterClass { onChanged(); return this; } - /** - *
-       *序列号和响应序号
-       * 
- * - * string seq_ack = 18; - * @param value The bytes for seqAck to set. - * @return This builder for chaining. - */ - public Builder setSeqAckBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - seqAck_ = value; - onChanged(); - return this; - } private int recogStatus_ ; /** @@ -5184,59 +4386,29 @@ public final class BussFlowWebOuterClass { return this; } - private java.lang.Object contentType_ = ""; + private com.google.protobuf.ByteString contentType_ = com.google.protobuf.ByteString.EMPTY; /** *
        *请求内容
        * 
* - * string content_type = 21; + * bytes content_type = 21; * @return The contentType. */ - public java.lang.String getContentType() { - java.lang.Object ref = contentType_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - contentType_ = s; - return s; - } else { - return (java.lang.String) ref; - } + @java.lang.Override + public com.google.protobuf.ByteString getContentType() { + return contentType_; } /** *
        *请求内容
        * 
* - * string content_type = 21; - * @return The bytes for contentType. - */ - public com.google.protobuf.ByteString - getContentTypeBytes() { - java.lang.Object ref = contentType_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - contentType_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - *
-       *请求内容
-       * 
- * - * string content_type = 21; + * bytes content_type = 21; * @param value The contentType to set. * @return This builder for chaining. */ - public Builder setContentType( - java.lang.String value) { + public Builder setContentType(com.google.protobuf.ByteString value) { if (value == null) { throw new NullPointerException(); } @@ -5250,7 +4422,7 @@ public final class BussFlowWebOuterClass { *请求内容 * * - * string content_type = 21; + * bytes content_type = 21; * @return This builder for chaining. */ public Builder clearContentType() { @@ -5259,80 +4431,30 @@ public final class BussFlowWebOuterClass { onChanged(); return this; } - /** - *
-       *请求内容
-       * 
- * - * string content_type = 21; - * @param value The bytes for contentType to set. - * @return This builder for chaining. - */ - public Builder setContentTypeBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - contentType_ = value; - onChanged(); - return this; - } - private java.lang.Object accept_ = ""; + private com.google.protobuf.ByteString accept_ = com.google.protobuf.ByteString.EMPTY; /** *
        *接受
        * 
* - * string accept = 22; + * bytes accept = 22; * @return The accept. */ - public java.lang.String getAccept() { - java.lang.Object ref = accept_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - accept_ = s; - return s; - } else { - return (java.lang.String) ref; - } + @java.lang.Override + public com.google.protobuf.ByteString getAccept() { + return accept_; } /** *
        *接受
        * 
* - * string accept = 22; - * @return The bytes for accept. - */ - public com.google.protobuf.ByteString - getAcceptBytes() { - java.lang.Object ref = accept_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - accept_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - *
-       *接受
-       * 
- * - * string accept = 22; + * bytes accept = 22; * @param value The accept to set. * @return This builder for chaining. */ - public Builder setAccept( - java.lang.String value) { + public Builder setAccept(com.google.protobuf.ByteString value) { if (value == null) { throw new NullPointerException(); } @@ -5346,7 +4468,7 @@ public final class BussFlowWebOuterClass { *接受 * * - * string accept = 22; + * bytes accept = 22; * @return This builder for chaining. */ public Builder clearAccept() { @@ -5355,26 +4477,6 @@ public final class BussFlowWebOuterClass { onChanged(); return this; } - /** - *
-       *接受
-       * 
- * - * string accept = 22; - * @param value The bytes for accept to set. - * @return This builder for chaining. - */ - public Builder setAcceptBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - accept_ = value; - onChanged(); - return this; - } private int probeIf_ ; /** @@ -5419,59 +4521,29 @@ public final class BussFlowWebOuterClass { return this; } - private java.lang.Object channel_ = ""; + private com.google.protobuf.ByteString channel_ = com.google.protobuf.ByteString.EMPTY; /** *
        *业务类型
        * 
* - * string channel = 24; + * bytes channel = 24; * @return The channel. */ - public java.lang.String getChannel() { - java.lang.Object ref = channel_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - channel_ = s; - return s; - } else { - return (java.lang.String) ref; - } + @java.lang.Override + public com.google.protobuf.ByteString getChannel() { + return channel_; } /** *
        *业务类型
        * 
* - * string channel = 24; - * @return The bytes for channel. - */ - public com.google.protobuf.ByteString - getChannelBytes() { - java.lang.Object ref = channel_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - channel_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - *
-       *业务类型
-       * 
- * - * string channel = 24; + * bytes channel = 24; * @param value The channel to set. * @return This builder for chaining. */ - public Builder setChannel( - java.lang.String value) { + public Builder setChannel(com.google.protobuf.ByteString value) { if (value == null) { throw new NullPointerException(); } @@ -5485,7 +4557,7 @@ public final class BussFlowWebOuterClass { *业务类型 * * - * string channel = 24; + * bytes channel = 24; * @return This builder for chaining. */ public Builder clearChannel() { @@ -5494,80 +4566,30 @@ public final class BussFlowWebOuterClass { onChanged(); return this; } - /** - *
-       *业务类型
-       * 
- * - * string channel = 24; - * @param value The bytes for channel to set. - * @return This builder for chaining. - */ - public Builder setChannelBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - channel_ = value; - onChanged(); - return this; - } - private java.lang.Object sessionid_ = ""; + private com.google.protobuf.ByteString sessionid_ = com.google.protobuf.ByteString.EMPTY; /** *
        *会话id
        * 
* - * string sessionid = 25; + * bytes sessionid = 25; * @return The sessionid. */ - public java.lang.String getSessionid() { - java.lang.Object ref = sessionid_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - sessionid_ = s; - return s; - } else { - return (java.lang.String) ref; - } + @java.lang.Override + public com.google.protobuf.ByteString getSessionid() { + return sessionid_; } /** *
        *会话id
        * 
* - * string sessionid = 25; - * @return The bytes for sessionid. - */ - public com.google.protobuf.ByteString - getSessionidBytes() { - java.lang.Object ref = sessionid_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - sessionid_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - *
-       *会话id
-       * 
- * - * string sessionid = 25; + * bytes sessionid = 25; * @param value The sessionid to set. * @return This builder for chaining. */ - public Builder setSessionid( - java.lang.String value) { + public Builder setSessionid(com.google.protobuf.ByteString value) { if (value == null) { throw new NullPointerException(); } @@ -5581,7 +4603,7 @@ public final class BussFlowWebOuterClass { *会话id * * - * string sessionid = 25; + * bytes sessionid = 25; * @return This builder for chaining. */ public Builder clearSessionid() { @@ -5590,26 +4612,6 @@ public final class BussFlowWebOuterClass { onChanged(); return this; } - /** - *
-       *会话id
-       * 
- * - * string sessionid = 25; - * @param value The bytes for sessionid to set. - * @return This builder for chaining. - */ - public Builder setSessionidBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - sessionid_ = value; - onChanged(); - return this; - } private com.yuandian.dataflow.proto.Base.IPAddress requestIp_; private com.google.protobuf.SingleFieldBuilderV3< @@ -6609,47 +5611,21 @@ public final class BussFlowWebOuterClass { return this; } - private java.lang.Object xRequestedWith_ = ""; + private com.google.protobuf.ByteString xRequestedWith_ = com.google.protobuf.ByteString.EMPTY; /** - * string x_requested_with = 44; + * bytes x_requested_with = 44; * @return The xRequestedWith. */ - public java.lang.String getXRequestedWith() { - java.lang.Object ref = xRequestedWith_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - xRequestedWith_ = s; - return s; - } else { - return (java.lang.String) ref; - } + @java.lang.Override + public com.google.protobuf.ByteString getXRequestedWith() { + return xRequestedWith_; } /** - * string x_requested_with = 44; - * @return The bytes for xRequestedWith. - */ - public com.google.protobuf.ByteString - getXRequestedWithBytes() { - java.lang.Object ref = xRequestedWith_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - xRequestedWith_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * string x_requested_with = 44; + * bytes x_requested_with = 44; * @param value The xRequestedWith to set. * @return This builder for chaining. */ - public Builder setXRequestedWith( - java.lang.String value) { + public Builder setXRequestedWith(com.google.protobuf.ByteString value) { if (value == null) { throw new NullPointerException(); } @@ -6659,7 +5635,7 @@ public final class BussFlowWebOuterClass { return this; } /** - * string x_requested_with = 44; + * bytes x_requested_with = 44; * @return This builder for chaining. */ public Builder clearXRequestedWith() { @@ -6668,76 +5644,30 @@ public final class BussFlowWebOuterClass { onChanged(); return this; } - /** - * string x_requested_with = 44; - * @param value The bytes for xRequestedWith to set. - * @return This builder for chaining. - */ - public Builder setXRequestedWithBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - xRequestedWith_ = value; - onChanged(); - return this; - } - private java.lang.Object operatingSytem_ = ""; + private com.google.protobuf.ByteString operatingSytem_ = com.google.protobuf.ByteString.EMPTY; /** *
        *操作系统
        * 
* - * string operating_sytem = 45; + * bytes operating_sytem = 45; * @return The operatingSytem. */ - public java.lang.String getOperatingSytem() { - java.lang.Object ref = operatingSytem_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - operatingSytem_ = s; - return s; - } else { - return (java.lang.String) ref; - } + @java.lang.Override + public com.google.protobuf.ByteString getOperatingSytem() { + return operatingSytem_; } /** *
        *操作系统
        * 
* - * string operating_sytem = 45; - * @return The bytes for operatingSytem. - */ - public com.google.protobuf.ByteString - getOperatingSytemBytes() { - java.lang.Object ref = operatingSytem_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - operatingSytem_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - *
-       *操作系统
-       * 
- * - * string operating_sytem = 45; + * bytes operating_sytem = 45; * @param value The operatingSytem to set. * @return This builder for chaining. */ - public Builder setOperatingSytem( - java.lang.String value) { + public Builder setOperatingSytem(com.google.protobuf.ByteString value) { if (value == null) { throw new NullPointerException(); } @@ -6751,7 +5681,7 @@ public final class BussFlowWebOuterClass { *操作系统 * * - * string operating_sytem = 45; + * bytes operating_sytem = 45; * @return This builder for chaining. */ public Builder clearOperatingSytem() { @@ -6760,26 +5690,6 @@ public final class BussFlowWebOuterClass { onChanged(); return this; } - /** - *
-       *操作系统
-       * 
- * - * string operating_sytem = 45; - * @param value The bytes for operatingSytem to set. - * @return This builder for chaining. - */ - public Builder setOperatingSytemBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - operatingSytem_ = value; - onChanged(); - return this; - } private int serverResCode_ ; /** @@ -6824,59 +5734,29 @@ public final class BussFlowWebOuterClass { return this; } - private java.lang.Object browser_ = ""; + private com.google.protobuf.ByteString browser_ = com.google.protobuf.ByteString.EMPTY; /** *
        *浏览器名称
        * 
* - * string browser = 47; + * bytes browser = 47; * @return The browser. */ - public java.lang.String getBrowser() { - java.lang.Object ref = browser_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - browser_ = s; - return s; - } else { - return (java.lang.String) ref; - } + @java.lang.Override + public com.google.protobuf.ByteString getBrowser() { + return browser_; } /** *
        *浏览器名称
        * 
* - * string browser = 47; - * @return The bytes for browser. - */ - public com.google.protobuf.ByteString - getBrowserBytes() { - java.lang.Object ref = browser_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - browser_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - *
-       *浏览器名称
-       * 
- * - * string browser = 47; + * bytes browser = 47; * @param value The browser to set. * @return This builder for chaining. */ - public Builder setBrowser( - java.lang.String value) { + public Builder setBrowser(com.google.protobuf.ByteString value) { if (value == null) { throw new NullPointerException(); } @@ -6890,7 +5770,7 @@ public final class BussFlowWebOuterClass { *浏览器名称 * * - * string browser = 47; + * bytes browser = 47; * @return This builder for chaining. */ public Builder clearBrowser() { @@ -6899,26 +5779,6 @@ public final class BussFlowWebOuterClass { onChanged(); return this; } - /** - *
-       *浏览器名称
-       * 
- * - * string browser = 47; - * @param value The bytes for browser to set. - * @return This builder for chaining. - */ - public Builder setBrowserBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - browser_ = value; - onChanged(); - return this; - } private int isUncomplete_ ; /** @@ -7338,59 +6198,29 @@ public final class BussFlowWebOuterClass { return this; } - private java.lang.Object bussinessDetailMesg_ = ""; + private com.google.protobuf.ByteString bussinessDetailMesg_ = com.google.protobuf.ByteString.EMPTY; /** *
        *业务纤细信息
        * 
* - * string bussiness_detail_mesg = 58; + * bytes bussiness_detail_mesg = 58; * @return The bussinessDetailMesg. */ - public java.lang.String getBussinessDetailMesg() { - java.lang.Object ref = bussinessDetailMesg_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - bussinessDetailMesg_ = s; - return s; - } else { - return (java.lang.String) ref; - } + @java.lang.Override + public com.google.protobuf.ByteString getBussinessDetailMesg() { + return bussinessDetailMesg_; } /** *
        *业务纤细信息
        * 
* - * string bussiness_detail_mesg = 58; - * @return The bytes for bussinessDetailMesg. - */ - public com.google.protobuf.ByteString - getBussinessDetailMesgBytes() { - java.lang.Object ref = bussinessDetailMesg_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - bussinessDetailMesg_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - *
-       *业务纤细信息
-       * 
- * - * string bussiness_detail_mesg = 58; + * bytes bussiness_detail_mesg = 58; * @param value The bussinessDetailMesg to set. * @return This builder for chaining. */ - public Builder setBussinessDetailMesg( - java.lang.String value) { + public Builder setBussinessDetailMesg(com.google.protobuf.ByteString value) { if (value == null) { throw new NullPointerException(); } @@ -7404,7 +6234,7 @@ public final class BussFlowWebOuterClass { *业务纤细信息 * * - * string bussiness_detail_mesg = 58; + * bytes bussiness_detail_mesg = 58; * @return This builder for chaining. */ public Builder clearBussinessDetailMesg() { @@ -7413,80 +6243,30 @@ public final class BussFlowWebOuterClass { onChanged(); return this; } - /** - *
-       *业务纤细信息
-       * 
- * - * string bussiness_detail_mesg = 58; - * @param value The bytes for bussinessDetailMesg to set. - * @return This builder for chaining. - */ - public Builder setBussinessDetailMesgBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - bussinessDetailMesg_ = value; - onChanged(); - return this; - } - private java.lang.Object bussinessKeyMesg_ = ""; + private com.google.protobuf.ByteString bussinessKeyMesg_ = com.google.protobuf.ByteString.EMPTY; /** *
        *业务关键字
        * 
* - * string bussiness_key_mesg = 59; + * bytes bussiness_key_mesg = 59; * @return The bussinessKeyMesg. */ - public java.lang.String getBussinessKeyMesg() { - java.lang.Object ref = bussinessKeyMesg_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - bussinessKeyMesg_ = s; - return s; - } else { - return (java.lang.String) ref; - } + @java.lang.Override + public com.google.protobuf.ByteString getBussinessKeyMesg() { + return bussinessKeyMesg_; } /** *
        *业务关键字
        * 
* - * string bussiness_key_mesg = 59; - * @return The bytes for bussinessKeyMesg. - */ - public com.google.protobuf.ByteString - getBussinessKeyMesgBytes() { - java.lang.Object ref = bussinessKeyMesg_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - bussinessKeyMesg_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - *
-       *业务关键字
-       * 
- * - * string bussiness_key_mesg = 59; + * bytes bussiness_key_mesg = 59; * @param value The bussinessKeyMesg to set. * @return This builder for chaining. */ - public Builder setBussinessKeyMesg( - java.lang.String value) { + public Builder setBussinessKeyMesg(com.google.protobuf.ByteString value) { if (value == null) { throw new NullPointerException(); } @@ -7500,7 +6280,7 @@ public final class BussFlowWebOuterClass { *业务关键字 * * - * string bussiness_key_mesg = 59; + * bytes bussiness_key_mesg = 59; * @return This builder for chaining. */ public Builder clearBussinessKeyMesg() { @@ -7509,80 +6289,30 @@ public final class BussFlowWebOuterClass { onChanged(); return this; } - /** - *
-       *业务关键字
-       * 
- * - * string bussiness_key_mesg = 59; - * @param value The bytes for bussinessKeyMesg to set. - * @return This builder for chaining. - */ - public Builder setBussinessKeyMesgBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - bussinessKeyMesg_ = value; - onChanged(); - return this; - } - private java.lang.Object reqData_ = ""; + private com.google.protobuf.ByteString reqData_ = com.google.protobuf.ByteString.EMPTY; /** *
        *请求详情报文
        * 
* - * string req_data = 60; + * bytes req_data = 60; * @return The reqData. */ - public java.lang.String getReqData() { - java.lang.Object ref = reqData_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - reqData_ = s; - return s; - } else { - return (java.lang.String) ref; - } + @java.lang.Override + public com.google.protobuf.ByteString getReqData() { + return reqData_; } /** *
        *请求详情报文
        * 
* - * string req_data = 60; - * @return The bytes for reqData. - */ - public com.google.protobuf.ByteString - getReqDataBytes() { - java.lang.Object ref = reqData_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - reqData_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - *
-       *请求详情报文
-       * 
- * - * string req_data = 60; + * bytes req_data = 60; * @param value The reqData to set. * @return This builder for chaining. */ - public Builder setReqData( - java.lang.String value) { + public Builder setReqData(com.google.protobuf.ByteString value) { if (value == null) { throw new NullPointerException(); } @@ -7596,7 +6326,7 @@ public final class BussFlowWebOuterClass { *请求详情报文 * * - * string req_data = 60; + * bytes req_data = 60; * @return This builder for chaining. */ public Builder clearReqData() { @@ -7605,80 +6335,30 @@ public final class BussFlowWebOuterClass { onChanged(); return this; } - /** - *
-       *请求详情报文
-       * 
- * - * string req_data = 60; - * @param value The bytes for reqData to set. - * @return This builder for chaining. - */ - public Builder setReqDataBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - reqData_ = value; - onChanged(); - return this; - } - private java.lang.Object resData_ = ""; + private com.google.protobuf.ByteString resData_ = com.google.protobuf.ByteString.EMPTY; /** *
        *响应详情报文
        * 
* - * string res_data = 61; + * bytes res_data = 61; * @return The resData. */ - public java.lang.String getResData() { - java.lang.Object ref = resData_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - resData_ = s; - return s; - } else { - return (java.lang.String) ref; - } + @java.lang.Override + public com.google.protobuf.ByteString getResData() { + return resData_; } /** *
        *响应详情报文
        * 
* - * string res_data = 61; - * @return The bytes for resData. - */ - public com.google.protobuf.ByteString - getResDataBytes() { - java.lang.Object ref = resData_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - resData_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - *
-       *响应详情报文
-       * 
- * - * string res_data = 61; + * bytes res_data = 61; * @param value The resData to set. * @return This builder for chaining. */ - public Builder setResData( - java.lang.String value) { + public Builder setResData(com.google.protobuf.ByteString value) { if (value == null) { throw new NullPointerException(); } @@ -7692,7 +6372,7 @@ public final class BussFlowWebOuterClass { *响应详情报文 * * - * string res_data = 61; + * bytes res_data = 61; * @return This builder for chaining. */ public Builder clearResData() { @@ -7701,80 +6381,30 @@ public final class BussFlowWebOuterClass { onChanged(); return this; } - /** - *
-       *响应详情报文
-       * 
- * - * string res_data = 61; - * @param value The bytes for resData to set. - * @return This builder for chaining. - */ - public Builder setResDataBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - resData_ = value; - onChanged(); - return this; - } - private java.lang.Object cookieData_ = ""; + private com.google.protobuf.ByteString cookieData_ = com.google.protobuf.ByteString.EMPTY; /** *
        *cookie详情报文
        * 
* - * string cookie_data = 62; + * bytes cookie_data = 62; * @return The cookieData. */ - public java.lang.String getCookieData() { - java.lang.Object ref = cookieData_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - cookieData_ = s; - return s; - } else { - return (java.lang.String) ref; - } + @java.lang.Override + public com.google.protobuf.ByteString getCookieData() { + return cookieData_; } /** *
        *cookie详情报文
        * 
* - * string cookie_data = 62; - * @return The bytes for cookieData. - */ - public com.google.protobuf.ByteString - getCookieDataBytes() { - java.lang.Object ref = cookieData_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - cookieData_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - *
-       *cookie详情报文
-       * 
- * - * string cookie_data = 62; + * bytes cookie_data = 62; * @param value The cookieData to set. * @return This builder for chaining. */ - public Builder setCookieData( - java.lang.String value) { + public Builder setCookieData(com.google.protobuf.ByteString value) { if (value == null) { throw new NullPointerException(); } @@ -7788,7 +6418,7 @@ public final class BussFlowWebOuterClass { *cookie详情报文 * * - * string cookie_data = 62; + * bytes cookie_data = 62; * @return This builder for chaining. */ public Builder clearCookieData() { @@ -7797,80 +6427,30 @@ public final class BussFlowWebOuterClass { onChanged(); return this; } - /** - *
-       *cookie详情报文
-       * 
- * - * string cookie_data = 62; - * @param value The bytes for cookieData to set. - * @return This builder for chaining. - */ - public Builder setCookieDataBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - cookieData_ = value; - onChanged(); - return this; - } - private java.lang.Object beginUrl_ = ""; + private com.google.protobuf.ByteString beginUrl_ = com.google.protobuf.ByteString.EMPTY; /** *
        *主url详情
        * 
* - * string begin_url = 63; + * bytes begin_url = 63; * @return The beginUrl. */ - public java.lang.String getBeginUrl() { - java.lang.Object ref = beginUrl_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - beginUrl_ = s; - return s; - } else { - return (java.lang.String) ref; - } + @java.lang.Override + public com.google.protobuf.ByteString getBeginUrl() { + return beginUrl_; } /** *
        *主url详情
        * 
* - * string begin_url = 63; - * @return The bytes for beginUrl. - */ - public com.google.protobuf.ByteString - getBeginUrlBytes() { - java.lang.Object ref = beginUrl_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - beginUrl_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - *
-       *主url详情
-       * 
- * - * string begin_url = 63; + * bytes begin_url = 63; * @param value The beginUrl to set. * @return This builder for chaining. */ - public Builder setBeginUrl( - java.lang.String value) { + public Builder setBeginUrl(com.google.protobuf.ByteString value) { if (value == null) { throw new NullPointerException(); } @@ -7884,7 +6464,7 @@ public final class BussFlowWebOuterClass { *主url详情 * * - * string begin_url = 63; + * bytes begin_url = 63; * @return This builder for chaining. */ public Builder clearBeginUrl() { @@ -7893,80 +6473,30 @@ public final class BussFlowWebOuterClass { onChanged(); return this; } - /** - *
-       *主url详情
-       * 
- * - * string begin_url = 63; - * @param value The bytes for beginUrl to set. - * @return This builder for chaining. - */ - public Builder setBeginUrlBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - beginUrl_ = value; - onChanged(); - return this; - } - private java.lang.Object referUrl_ = ""; + private com.google.protobuf.ByteString referUrl_ = com.google.protobuf.ByteString.EMPTY; /** *
        *引用url详情
        * 
* - * string refer_url = 64; + * bytes refer_url = 64; * @return The referUrl. */ - public java.lang.String getReferUrl() { - java.lang.Object ref = referUrl_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - referUrl_ = s; - return s; - } else { - return (java.lang.String) ref; - } + @java.lang.Override + public com.google.protobuf.ByteString getReferUrl() { + return referUrl_; } /** *
        *引用url详情
        * 
* - * string refer_url = 64; - * @return The bytes for referUrl. - */ - public com.google.protobuf.ByteString - getReferUrlBytes() { - java.lang.Object ref = referUrl_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - referUrl_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - *
-       *引用url详情
-       * 
- * - * string refer_url = 64; + * bytes refer_url = 64; * @param value The referUrl to set. * @return This builder for chaining. */ - public Builder setReferUrl( - java.lang.String value) { + public Builder setReferUrl(com.google.protobuf.ByteString value) { if (value == null) { throw new NullPointerException(); } @@ -7980,7 +6510,7 @@ public final class BussFlowWebOuterClass { *引用url详情 * * - * string refer_url = 64; + * bytes refer_url = 64; * @return This builder for chaining. */ public Builder clearReferUrl() { @@ -7989,68 +6519,22 @@ public final class BussFlowWebOuterClass { onChanged(); return this; } - /** - *
-       *引用url详情
-       * 
- * - * string refer_url = 64; - * @param value The bytes for referUrl to set. - * @return This builder for chaining. - */ - public Builder setReferUrlBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - referUrl_ = value; - onChanged(); - return this; - } - private java.lang.Object remainData_ = ""; + private com.google.protobuf.ByteString remainData_ = com.google.protobuf.ByteString.EMPTY; /** - * string remain_data = 65; + * bytes remain_data = 65; * @return The remainData. */ - public java.lang.String getRemainData() { - java.lang.Object ref = remainData_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - remainData_ = s; - return s; - } else { - return (java.lang.String) ref; - } + @java.lang.Override + public com.google.protobuf.ByteString getRemainData() { + return remainData_; } /** - * string remain_data = 65; - * @return The bytes for remainData. - */ - public com.google.protobuf.ByteString - getRemainDataBytes() { - java.lang.Object ref = remainData_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - remainData_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * string remain_data = 65; + * bytes remain_data = 65; * @param value The remainData to set. * @return This builder for chaining. */ - public Builder setRemainData( - java.lang.String value) { + public Builder setRemainData(com.google.protobuf.ByteString value) { if (value == null) { throw new NullPointerException(); } @@ -8060,7 +6544,7 @@ public final class BussFlowWebOuterClass { return this; } /** - * string remain_data = 65; + * bytes remain_data = 65; * @return This builder for chaining. */ public Builder clearRemainData() { @@ -8069,22 +6553,6 @@ public final class BussFlowWebOuterClass { onChanged(); return this; } - /** - * string remain_data = 65; - * @param value The bytes for remainData to set. - * @return This builder for chaining. - */ - public Builder setRemainDataBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - remainData_ = value; - onChanged(); - return this; - } @java.lang.Override public final Builder setUnknownFields( final com.google.protobuf.UnknownFieldSet unknownFields) { @@ -8154,7 +6622,7 @@ public final class BussFlowWebOuterClass { java.lang.String[] descriptorData = { "\n\021BussFlowWeb.proto\022\010dataflow\032\nBase.prot" + "o\"\261\014\n\013BussFlowWeb\022\020\n\010table_id\030\001 \001(\005\022\020\n\010m" + - "sg_type\030\002 \001(\r\022\023\n\013msg_version\030\003 \001(\t\022\017\n\007ms" + + "sg_type\030\002 \001(\r\022\023\n\013msg_version\030\003 \001(\014\022\017\n\007ms" + "g_seq\030\004 \001(\r\022\017\n\007msg_len\030\005 \001(\r\022\017\n\007src_mac\030" + "\006 \001(\004\022\017\n\007dst_mac\030\007 \001(\004\022\017\n\007vlan_id\030\010 \001(\r\022" + "\013\n\003tos\030\t \001(\r\022\024\n\014retran_count\030\n \001(\r\022\023\n\013re" + @@ -8162,10 +6630,10 @@ public final class BussFlowWebOuterClass { "\n\010protocol\030\r \001(\r\022\026\n\016response_bytes\030\016 \001(\r" + "\022\025\n\rrequest_bytes\030\017 \001(\r\022\030\n\020response_pack" + "ets\030\020 \001(\r\022\027\n\017request_packets\030\021 \001(\r\022\017\n\007se" + - "q_ack\030\022 \001(\t\022\024\n\014recog_status\030\023 \001(\r\022\022\n\nreq" + - "_method\030\024 \001(\r\022\024\n\014content_type\030\025 \001(\t\022\016\n\006a" + - "ccept\030\026 \001(\t\022\020\n\010probe_if\030\027 \001(\r\022\017\n\007channel" + - "\030\030 \001(\t\022\021\n\tsessionid\030\031 \001(\t\022\'\n\nrequest_ip\030" + + "q_ack\030\022 \001(\014\022\024\n\014recog_status\030\023 \001(\r\022\022\n\nreq" + + "_method\030\024 \001(\r\022\024\n\014content_type\030\025 \001(\014\022\016\n\006a" + + "ccept\030\026 \001(\014\022\020\n\010probe_if\030\027 \001(\r\022\017\n\007channel" + + "\030\030 \001(\014\022\021\n\tsessionid\030\031 \001(\014\022\'\n\nrequest_ip\030" + "\032 \001(\0132\023.dataflow.IPAddress\022\024\n\014request_po" + "rt\030\033 \001(\r\022(\n\013response_ip\030\034 \001(\0132\023.dataflow" + ".IPAddress\022\025\n\rresponse_port\030\035 \001(\r\022\031\n\021sta" + @@ -8181,18 +6649,18 @@ public final class BussFlowWebOuterClass { "\003\022$\n\034locate_server_translate_time\030) \001(\003\022" + "#\n\033locate_server_response_time\030* \001(\003\022$\n\034" + "locate_client_translate_time\030+ \001(\003\022\030\n\020x_" + - "requested_with\030, \001(\t\022\027\n\017operating_sytem\030" + - "- \001(\t\022\027\n\017server_res_code\030. \001(\r\022\017\n\007browse" + - "r\030/ \001(\t\022\025\n\ris_uncomplete\0300 \001(\005\022\021\n\ttime_f" + + "requested_with\030, \001(\014\022\027\n\017operating_sytem\030" + + "- \001(\014\022\027\n\017server_res_code\030. \001(\r\022\017\n\007browse" + + "r\030/ \001(\014\022\025\n\ris_uncomplete\0300 \001(\005\022\021\n\ttime_f" + "lag\0301 \001(\r\022\026\n\016detail_msg_len\0302 \001(\r\022\023\n\013key" + "_msg_len\0303 \001(\r\022\017\n\007req_len\0304 \001(\r\022\017\n\007res_l" + "en\0305 \001(\r\022\022\n\ncookie_len\0306 \001(\r\022\025\n\rbegin_ur" + "l_len\0307 \001(\r\022\025\n\rrefer_url_len\0308 \001(\r\022\022\n\nre" + "main_len\0309 \001(\r\022\035\n\025bussiness_detail_mesg\030" + - ": \001(\t\022\032\n\022bussiness_key_mesg\030; \001(\t\022\020\n\010req" + - "_data\030< \001(\t\022\020\n\010res_data\030= \001(\t\022\023\n\013cookie_" + - "data\030> \001(\t\022\021\n\tbegin_url\030? \001(\t\022\021\n\trefer_u" + - "rl\030@ \001(\t\022\023\n\013remain_data\030A \001(\tB<\n#com.yua" + + ": \001(\014\022\032\n\022bussiness_key_mesg\030; \001(\014\022\020\n\010req" + + "_data\030< \001(\014\022\020\n\010res_data\030= \001(\014\022\023\n\013cookie_" + + "data\030> \001(\014\022\021\n\tbegin_url\030? \001(\014\022\021\n\trefer_u" + + "rl\030@ \001(\014\022\023\n\013remain_data\030A \001(\014B<\n#com.yua" + "ndian.dataflow.proto.msgtypeP\000Z\023../grpc-" + "gen;grpcgenb\006proto3" }; diff --git a/src/main/java/com/yuandian/dataflow/proto/msgtype/UsrFlowOuterClass.java b/src/main/java/com/yuandian/dataflow/proto/msgtype/UsrFlowOuterClass.java index a829cdc..096b9ca 100644 --- a/src/main/java/com/yuandian/dataflow/proto/msgtype/UsrFlowOuterClass.java +++ b/src/main/java/com/yuandian/dataflow/proto/msgtype/UsrFlowOuterClass.java @@ -131,28 +131,16 @@ public final class UsrFlowOuterClass { int getAppGroupId(); /** - * string request_url = 16; + * bytes request_url = 16; * @return The requestUrl. */ - java.lang.String getRequestUrl(); - /** - * string request_url = 16; - * @return The bytes for requestUrl. - */ - com.google.protobuf.ByteString - getRequestUrlBytes(); + com.google.protobuf.ByteString getRequestUrl(); /** - * string referer_url = 17; + * bytes referer_url = 17; * @return The refererUrl. */ - java.lang.String getRefererUrl(); - /** - * string referer_url = 17; - * @return The bytes for refererUrl. - */ - com.google.protobuf.ByteString - getRefererUrlBytes(); + com.google.protobuf.ByteString getRefererUrl(); /** * uint32 return_code = 18; @@ -209,28 +197,16 @@ public final class UsrFlowOuterClass { int getServerPackets(); /** - * string user_agent = 27; + * bytes user_agent = 27; * @return The userAgent. */ - java.lang.String getUserAgent(); - /** - * string user_agent = 27; - * @return The bytes for userAgent. - */ - com.google.protobuf.ByteString - getUserAgentBytes(); + com.google.protobuf.ByteString getUserAgent(); /** - * string content_type = 28; + * bytes content_type = 28; * @return The contentType. */ - java.lang.String getContentType(); - /** - * string content_type = 28; - * @return The bytes for contentType. - */ - com.google.protobuf.ByteString - getContentTypeBytes(); + com.google.protobuf.ByteString getContentType(); /** * uint32 request_transfer_tm = 29; @@ -257,10 +233,10 @@ public final class UsrFlowOuterClass { super(builder); } private UsrFlow() { - requestUrl_ = ""; - refererUrl_ = ""; - userAgent_ = ""; - contentType_ = ""; + requestUrl_ = com.google.protobuf.ByteString.EMPTY; + refererUrl_ = com.google.protobuf.ByteString.EMPTY; + userAgent_ = com.google.protobuf.ByteString.EMPTY; + contentType_ = com.google.protobuf.ByteString.EMPTY; } @java.lang.Override @@ -385,15 +361,13 @@ public final class UsrFlowOuterClass { break; } case 130: { - java.lang.String s = input.readStringRequireUtf8(); - requestUrl_ = s; + requestUrl_ = input.readBytes(); break; } case 138: { - java.lang.String s = input.readStringRequireUtf8(); - refererUrl_ = s; + refererUrl_ = input.readBytes(); break; } case 144: { @@ -442,15 +416,13 @@ public final class UsrFlowOuterClass { break; } case 218: { - java.lang.String s = input.readStringRequireUtf8(); - userAgent_ = s; + userAgent_ = input.readBytes(); break; } case 226: { - java.lang.String s = input.readStringRequireUtf8(); - contentType_ = s; + contentType_ = input.readBytes(); break; } case 232: { @@ -697,79 +669,25 @@ public final class UsrFlowOuterClass { } public static final int REQUEST_URL_FIELD_NUMBER = 16; - private volatile java.lang.Object requestUrl_; + private com.google.protobuf.ByteString requestUrl_; /** - * string request_url = 16; + * bytes request_url = 16; * @return The requestUrl. */ @java.lang.Override - public java.lang.String getRequestUrl() { - java.lang.Object ref = requestUrl_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - requestUrl_ = s; - return s; - } - } - /** - * string request_url = 16; - * @return The bytes for requestUrl. - */ - @java.lang.Override - public com.google.protobuf.ByteString - getRequestUrlBytes() { - java.lang.Object ref = requestUrl_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - requestUrl_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } + public com.google.protobuf.ByteString getRequestUrl() { + return requestUrl_; } public static final int REFERER_URL_FIELD_NUMBER = 17; - private volatile java.lang.Object refererUrl_; + private com.google.protobuf.ByteString refererUrl_; /** - * string referer_url = 17; + * bytes referer_url = 17; * @return The refererUrl. */ @java.lang.Override - public java.lang.String getRefererUrl() { - java.lang.Object ref = refererUrl_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - refererUrl_ = s; - return s; - } - } - /** - * string referer_url = 17; - * @return The bytes for refererUrl. - */ - @java.lang.Override - public com.google.protobuf.ByteString - getRefererUrlBytes() { - java.lang.Object ref = refererUrl_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - refererUrl_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } + public com.google.protobuf.ByteString getRefererUrl() { + return refererUrl_; } public static final int RETURN_CODE_FIELD_NUMBER = 18; @@ -872,79 +790,25 @@ public final class UsrFlowOuterClass { } public static final int USER_AGENT_FIELD_NUMBER = 27; - private volatile java.lang.Object userAgent_; + private com.google.protobuf.ByteString userAgent_; /** - * string user_agent = 27; + * bytes user_agent = 27; * @return The userAgent. */ @java.lang.Override - public java.lang.String getUserAgent() { - java.lang.Object ref = userAgent_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - userAgent_ = s; - return s; - } - } - /** - * string user_agent = 27; - * @return The bytes for userAgent. - */ - @java.lang.Override - public com.google.protobuf.ByteString - getUserAgentBytes() { - java.lang.Object ref = userAgent_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - userAgent_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } + public com.google.protobuf.ByteString getUserAgent() { + return userAgent_; } public static final int CONTENT_TYPE_FIELD_NUMBER = 28; - private volatile java.lang.Object contentType_; + private com.google.protobuf.ByteString contentType_; /** - * string content_type = 28; + * bytes content_type = 28; * @return The contentType. */ @java.lang.Override - public java.lang.String getContentType() { - java.lang.Object ref = contentType_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - contentType_ = s; - return s; - } - } - /** - * string content_type = 28; - * @return The bytes for contentType. - */ - @java.lang.Override - public com.google.protobuf.ByteString - getContentTypeBytes() { - java.lang.Object ref = contentType_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - contentType_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } + public com.google.protobuf.ByteString getContentType() { + return contentType_; } public static final int REQUEST_TRANSFER_TM_FIELD_NUMBER = 29; @@ -1028,11 +892,11 @@ public final class UsrFlowOuterClass { if (appGroupId_ != 0) { output.writeUInt32(15, appGroupId_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(requestUrl_)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 16, requestUrl_); + if (!requestUrl_.isEmpty()) { + output.writeBytes(16, requestUrl_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(refererUrl_)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 17, refererUrl_); + if (!refererUrl_.isEmpty()) { + output.writeBytes(17, refererUrl_); } if (returnCode_ != 0) { output.writeUInt32(18, returnCode_); @@ -1061,11 +925,11 @@ public final class UsrFlowOuterClass { if (serverPackets_ != 0) { output.writeUInt32(26, serverPackets_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(userAgent_)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 27, userAgent_); + if (!userAgent_.isEmpty()) { + output.writeBytes(27, userAgent_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(contentType_)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 28, contentType_); + if (!contentType_.isEmpty()) { + output.writeBytes(28, contentType_); } if (requestTransferTm_ != 0) { output.writeUInt32(29, requestTransferTm_); @@ -1142,11 +1006,13 @@ public final class UsrFlowOuterClass { size += com.google.protobuf.CodedOutputStream .computeUInt32Size(15, appGroupId_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(requestUrl_)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(16, requestUrl_); + if (!requestUrl_.isEmpty()) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(16, requestUrl_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(refererUrl_)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(17, refererUrl_); + if (!refererUrl_.isEmpty()) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(17, refererUrl_); } if (returnCode_ != 0) { size += com.google.protobuf.CodedOutputStream @@ -1184,11 +1050,13 @@ public final class UsrFlowOuterClass { size += com.google.protobuf.CodedOutputStream .computeUInt32Size(26, serverPackets_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(userAgent_)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(27, userAgent_); + if (!userAgent_.isEmpty()) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(27, userAgent_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(contentType_)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(28, contentType_); + if (!contentType_.isEmpty()) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(28, contentType_); } if (requestTransferTm_ != 0) { size += com.google.protobuf.CodedOutputStream @@ -1525,9 +1393,9 @@ public final class UsrFlowOuterClass { appGroupId_ = 0; - requestUrl_ = ""; + requestUrl_ = com.google.protobuf.ByteString.EMPTY; - refererUrl_ = ""; + refererUrl_ = com.google.protobuf.ByteString.EMPTY; returnCode_ = 0; @@ -1547,9 +1415,9 @@ public final class UsrFlowOuterClass { serverPackets_ = 0; - userAgent_ = ""; + userAgent_ = com.google.protobuf.ByteString.EMPTY; - contentType_ = ""; + contentType_ = com.google.protobuf.ByteString.EMPTY; requestTransferTm_ = 0; @@ -1712,13 +1580,11 @@ public final class UsrFlowOuterClass { if (other.getAppGroupId() != 0) { setAppGroupId(other.getAppGroupId()); } - if (!other.getRequestUrl().isEmpty()) { - requestUrl_ = other.requestUrl_; - onChanged(); + if (other.getRequestUrl() != com.google.protobuf.ByteString.EMPTY) { + setRequestUrl(other.getRequestUrl()); } - if (!other.getRefererUrl().isEmpty()) { - refererUrl_ = other.refererUrl_; - onChanged(); + if (other.getRefererUrl() != com.google.protobuf.ByteString.EMPTY) { + setRefererUrl(other.getRefererUrl()); } if (other.getReturnCode() != 0) { setReturnCode(other.getReturnCode()); @@ -1747,13 +1613,11 @@ public final class UsrFlowOuterClass { if (other.getServerPackets() != 0) { setServerPackets(other.getServerPackets()); } - if (!other.getUserAgent().isEmpty()) { - userAgent_ = other.userAgent_; - onChanged(); + if (other.getUserAgent() != com.google.protobuf.ByteString.EMPTY) { + setUserAgent(other.getUserAgent()); } - if (!other.getContentType().isEmpty()) { - contentType_ = other.contentType_; - onChanged(); + if (other.getContentType() != com.google.protobuf.ByteString.EMPTY) { + setContentType(other.getContentType()); } if (other.getRequestTransferTm() != 0) { setRequestTransferTm(other.getRequestTransferTm()); @@ -2443,47 +2307,21 @@ public final class UsrFlowOuterClass { return this; } - private java.lang.Object requestUrl_ = ""; + private com.google.protobuf.ByteString requestUrl_ = com.google.protobuf.ByteString.EMPTY; /** - * string request_url = 16; + * bytes request_url = 16; * @return The requestUrl. */ - public java.lang.String getRequestUrl() { - java.lang.Object ref = requestUrl_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - requestUrl_ = s; - return s; - } else { - return (java.lang.String) ref; - } + @java.lang.Override + public com.google.protobuf.ByteString getRequestUrl() { + return requestUrl_; } /** - * string request_url = 16; - * @return The bytes for requestUrl. - */ - public com.google.protobuf.ByteString - getRequestUrlBytes() { - java.lang.Object ref = requestUrl_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - requestUrl_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * string request_url = 16; + * bytes request_url = 16; * @param value The requestUrl to set. * @return This builder for chaining. */ - public Builder setRequestUrl( - java.lang.String value) { + public Builder setRequestUrl(com.google.protobuf.ByteString value) { if (value == null) { throw new NullPointerException(); } @@ -2493,7 +2331,7 @@ public final class UsrFlowOuterClass { return this; } /** - * string request_url = 16; + * bytes request_url = 16; * @return This builder for chaining. */ public Builder clearRequestUrl() { @@ -2502,64 +2340,22 @@ public final class UsrFlowOuterClass { onChanged(); return this; } - /** - * string request_url = 16; - * @param value The bytes for requestUrl to set. - * @return This builder for chaining. - */ - public Builder setRequestUrlBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - requestUrl_ = value; - onChanged(); - return this; - } - private java.lang.Object refererUrl_ = ""; + private com.google.protobuf.ByteString refererUrl_ = com.google.protobuf.ByteString.EMPTY; /** - * string referer_url = 17; + * bytes referer_url = 17; * @return The refererUrl. */ - public java.lang.String getRefererUrl() { - java.lang.Object ref = refererUrl_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - refererUrl_ = s; - return s; - } else { - return (java.lang.String) ref; - } + @java.lang.Override + public com.google.protobuf.ByteString getRefererUrl() { + return refererUrl_; } /** - * string referer_url = 17; - * @return The bytes for refererUrl. - */ - public com.google.protobuf.ByteString - getRefererUrlBytes() { - java.lang.Object ref = refererUrl_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - refererUrl_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * string referer_url = 17; + * bytes referer_url = 17; * @param value The refererUrl to set. * @return This builder for chaining. */ - public Builder setRefererUrl( - java.lang.String value) { + public Builder setRefererUrl(com.google.protobuf.ByteString value) { if (value == null) { throw new NullPointerException(); } @@ -2569,7 +2365,7 @@ public final class UsrFlowOuterClass { return this; } /** - * string referer_url = 17; + * bytes referer_url = 17; * @return This builder for chaining. */ public Builder clearRefererUrl() { @@ -2578,22 +2374,6 @@ public final class UsrFlowOuterClass { onChanged(); return this; } - /** - * string referer_url = 17; - * @param value The bytes for refererUrl to set. - * @return This builder for chaining. - */ - public Builder setRefererUrlBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - refererUrl_ = value; - onChanged(); - return this; - } private int returnCode_ ; /** @@ -2874,47 +2654,21 @@ public final class UsrFlowOuterClass { return this; } - private java.lang.Object userAgent_ = ""; + private com.google.protobuf.ByteString userAgent_ = com.google.protobuf.ByteString.EMPTY; /** - * string user_agent = 27; + * bytes user_agent = 27; * @return The userAgent. */ - public java.lang.String getUserAgent() { - java.lang.Object ref = userAgent_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - userAgent_ = s; - return s; - } else { - return (java.lang.String) ref; - } + @java.lang.Override + public com.google.protobuf.ByteString getUserAgent() { + return userAgent_; } /** - * string user_agent = 27; - * @return The bytes for userAgent. - */ - public com.google.protobuf.ByteString - getUserAgentBytes() { - java.lang.Object ref = userAgent_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - userAgent_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * string user_agent = 27; + * bytes user_agent = 27; * @param value The userAgent to set. * @return This builder for chaining. */ - public Builder setUserAgent( - java.lang.String value) { + public Builder setUserAgent(com.google.protobuf.ByteString value) { if (value == null) { throw new NullPointerException(); } @@ -2924,7 +2678,7 @@ public final class UsrFlowOuterClass { return this; } /** - * string user_agent = 27; + * bytes user_agent = 27; * @return This builder for chaining. */ public Builder clearUserAgent() { @@ -2933,64 +2687,22 @@ public final class UsrFlowOuterClass { onChanged(); return this; } - /** - * string user_agent = 27; - * @param value The bytes for userAgent to set. - * @return This builder for chaining. - */ - public Builder setUserAgentBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - userAgent_ = value; - onChanged(); - return this; - } - private java.lang.Object contentType_ = ""; + private com.google.protobuf.ByteString contentType_ = com.google.protobuf.ByteString.EMPTY; /** - * string content_type = 28; + * bytes content_type = 28; * @return The contentType. */ - public java.lang.String getContentType() { - java.lang.Object ref = contentType_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - contentType_ = s; - return s; - } else { - return (java.lang.String) ref; - } + @java.lang.Override + public com.google.protobuf.ByteString getContentType() { + return contentType_; } /** - * string content_type = 28; - * @return The bytes for contentType. - */ - public com.google.protobuf.ByteString - getContentTypeBytes() { - java.lang.Object ref = contentType_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - contentType_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * string content_type = 28; + * bytes content_type = 28; * @param value The contentType to set. * @return This builder for chaining. */ - public Builder setContentType( - java.lang.String value) { + public Builder setContentType(com.google.protobuf.ByteString value) { if (value == null) { throw new NullPointerException(); } @@ -3000,7 +2712,7 @@ public final class UsrFlowOuterClass { return this; } /** - * string content_type = 28; + * bytes content_type = 28; * @return This builder for chaining. */ public Builder clearContentType() { @@ -3009,22 +2721,6 @@ public final class UsrFlowOuterClass { onChanged(); return this; } - /** - * string content_type = 28; - * @param value The bytes for contentType to set. - * @return This builder for chaining. - */ - public Builder setContentTypeBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - contentType_ = value; - onChanged(); - return this; - } private int requestTransferTm_ ; /** @@ -3163,14 +2859,14 @@ public final class UsrFlowOuterClass { " \001(\r\022\021\n\ts_tv_usec\030\t \001(\r\022\020\n\010e_tv_sec\030\n \001(" + "\r\022\021\n\te_tv_usec\030\013 \001(\r\022\024\n\014server_think\030\014 \001" + "(\r\022\021\n\tpage_size\030\r \001(\r\022\016\n\006app_id\030\016 \001(\r\022\024\n" + - "\014app_group_id\030\017 \001(\r\022\023\n\013request_url\030\020 \001(\t" + - "\022\023\n\013referer_url\030\021 \001(\t\022\023\n\013return_code\030\022 \001" + + "\014app_group_id\030\017 \001(\r\022\023\n\013request_url\030\020 \001(\014" + + "\022\023\n\013referer_url\030\021 \001(\014\022\023\n\013return_code\030\022 \001" + "(\r\022\022\n\nerr_tv_sec\030\023 \001(\r\022\023\n\013err_tv_usec\030\024 " + "\001(\r\022\027\n\017client_loss_pkt\030\025 \001(\r\022\027\n\017server_l" + "oss_pkt\030\026 \001(\r\022\024\n\014client_bytes\030\027 \001(\r\022\024\n\014s" + "erver_bytes\030\030 \001(\r\022\026\n\016client_packets\030\031 \001(" + "\r\022\026\n\016server_packets\030\032 \001(\r\022\022\n\nuser_agent\030" + - "\033 \001(\t\022\024\n\014content_type\030\034 \001(\t\022\033\n\023request_t" + + "\033 \001(\014\022\024\n\014content_type\030\034 \001(\014\022\033\n\023request_t" + "ransfer_tm\030\035 \001(\r\022\021\n\ttime_flag\030\036 \001(\rB<\n#c" + "om.yuandian.dataflow.proto.msgtypeP\000Z\023.." + "/grpc-gen;grpcgenb\006proto3" diff --git a/src/main/proto b/src/main/proto index bc99744..f6e1792 160000 --- a/src/main/proto +++ b/src/main/proto @@ -1 +1 @@ -Subproject commit bc997440f085ce75fadc071803b0b359bbf6ccb3 +Subproject commit f6e1792ff1747e23ad9963910991be43e96bd2bd From aa7749f924ed402bd670095cea0fe31658658027 Mon Sep 17 00:00:00 2001 From: huangsimin Date: Wed, 13 Jul 2022 13:33:00 +0800 Subject: [PATCH 03/37] =?UTF-8?q?=E5=AE=8C=E6=88=90=E7=8A=B6=E6=80=81?= =?UTF-8?q?=E6=9C=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/yuandian/dataflow/Server.java | 6 +- .../yuandian/dataflow/controller/TaskLog.java | 56 ++++++++------- .../dataflow/statemachine/RaftClosure.java | 27 ------- .../dataflow/statemachine/StateServer.java | 2 +- .../statemachine/SyncDataClosure.java | 45 ++++++++++++ .../dataflow/statemachine/rpc/SMResponse.java | 36 ++++++++++ .../dataflow/statemachine/rpc/SyncData.java | 72 +------------------ .../statemachine/rpc/SyncDataProcessor.java | 13 +++- .../dataflow/statemachine/rpc/TaskState.java | 42 +++++++++++ 9 files changed, 169 insertions(+), 130 deletions(-) delete mode 100644 src/main/java/com/yuandian/dataflow/statemachine/RaftClosure.java create mode 100644 src/main/java/com/yuandian/dataflow/statemachine/SyncDataClosure.java create mode 100644 src/main/java/com/yuandian/dataflow/statemachine/rpc/SMResponse.java create mode 100644 src/main/java/com/yuandian/dataflow/statemachine/rpc/TaskState.java diff --git a/src/main/java/com/yuandian/dataflow/Server.java b/src/main/java/com/yuandian/dataflow/Server.java index 9a0d35a..2962f3c 100644 --- a/src/main/java/com/yuandian/dataflow/Server.java +++ b/src/main/java/com/yuandian/dataflow/Server.java @@ -14,7 +14,7 @@ import com.alipay.sofa.jraft.RaftGroupService; import com.alipay.sofa.jraft.conf.Configuration; import com.alipay.sofa.jraft.entity.PeerId; import com.alipay.sofa.jraft.option.NodeOptions; -import com.yuandian.dataflow.statemachine.RaftClosure; +import com.yuandian.dataflow.statemachine.SyncDataClosure; import com.yuandian.dataflow.statemachine.StateMachine; import com.yuandian.dataflow.statemachine.StateServer; import com.yuandian.dataflow.statemachine.rpc.SyncDataProcessor; @@ -34,14 +34,14 @@ public class Server { @Autowired public static Node node; - public static RaftClosure done; + public static SyncDataClosure done; private static StateServer stateServer; public static Node GetNode() { return node; } - public static RaftClosure GetDone() { + public static SyncDataClosure GetDone() { return done; } diff --git a/src/main/java/com/yuandian/dataflow/controller/TaskLog.java b/src/main/java/com/yuandian/dataflow/controller/TaskLog.java index ed07bc8..e6cf27a 100644 --- a/src/main/java/com/yuandian/dataflow/controller/TaskLog.java +++ b/src/main/java/com/yuandian/dataflow/controller/TaskLog.java @@ -2,14 +2,15 @@ package com.yuandian.dataflow.controller; import java.nio.ByteBuffer; +import com.alibaba.nacos.api.naming.pojo.Cluster; +import com.alibaba.nacos.common.remote.client.RpcClientFactory; import com.alipay.sofa.jraft.Closure; import com.alipay.sofa.jraft.entity.Task; - -import com.google.protobuf.util.JsonFormat; +import com.alipay.sofa.jraft.rpc.RpcClient; +import com.alipay.sofa.jraft.rpc.impl.BoltRpcClient; import com.yuandian.dataflow.Server; -import com.yuandian.dataflow.grpc.MongodbTest; import com.yuandian.dataflow.projo.Response; -import com.yuandian.dataflow.proto.msgtype.BacktrackingFlowOuterClass; +import com.yuandian.dataflow.statemachine.SyncDataClosure; import lombok.extern.slf4j.Slf4j; @@ -25,40 +26,41 @@ import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestParam; + import com.alipay.sofa.jraft.Node; @Slf4j @Controller public class TaskLog { - // private static final Logger log = LoggerFactory.getLogger(TaskLog.class); private static Node node = Server.GetNode(); - @PostMapping(path = "/test") - public ResponseEntity Processing(@RequestBody String json) { + @GetMapping(path = "/test") + public ResponseEntity Processing() { - /*Task task = new Task(); + + log.info("node.isLeader {} {} node.getNodeId() {}", node.getNodeState(), node.getLeaderId(), node.getNodeId()); + if(node.isLeader()) { + // Task task = new Task(); - log.error(node.toString()); + // // 处理状态机 + // RaftClosure done = new RaftClosure(); + // task.setData(ByteBuffer.wrap("hello".getBytes())); + // task.setDone(done); + + // log.error("{} {} {}",node, node.toString(), task); + // node.apply(task); + + // log.error("{}", "RaftClosure"); - RaftClosure done = new RaftClosure(); - task.setData(ByteBuffer.wrap("hello".getBytes())); - task.setDone(done); - Server.GetNode().apply(task);*/ + + + } + - try { - // 1、类型转换 - BacktrackingFlowOuterClass.BacktrackingFlow.Builder builder = BacktrackingFlowOuterClass.BacktrackingFlow.newBuilder(); - JsonFormat.parser().merge(json, builder); - BacktrackingFlowOuterClass.BacktrackingFlow backtrackingFlow = builder.build(); - - // 2、业务处理 - - // 3、数据保存到 mongoDB - MongodbTest.insertMsgToMongoDB(backtrackingFlow); - } catch (Exception e) { - e.printStackTrace(); - } + + Response response = new Response(); response.Code = HttpStatus.OK; @@ -67,7 +69,7 @@ public class TaskLog { } @GetMapping(path = "/test2") - public ResponseEntity MongodbTest(@RequestBody int status) { + public ResponseEntity MongodbTest(@RequestParam int status) { Response response = new Response(); return new ResponseEntity(response, HttpStatus.OK); diff --git a/src/main/java/com/yuandian/dataflow/statemachine/RaftClosure.java b/src/main/java/com/yuandian/dataflow/statemachine/RaftClosure.java deleted file mode 100644 index 779a1a2..0000000 --- a/src/main/java/com/yuandian/dataflow/statemachine/RaftClosure.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.yuandian.dataflow.statemachine; - -import com.alipay.sofa.jraft.Closure; -import com.alipay.sofa.jraft.Status; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class RaftClosure implements Closure { - - private static final Logger LOG = LoggerFactory.getLogger(StateMachine.class); - - @Override - public void run(Status status) { - - LOG.info("Task completed with status"+status.getCode()); - LOG.info("Task completed with "+status.getErrorMsg()); - LOG.info("Task completed with "+status.getRaftError()); - - } - -// @Override -// public void onCommitted() { -// System.out.println("Task onCommitted"); -// } - -} diff --git a/src/main/java/com/yuandian/dataflow/statemachine/StateServer.java b/src/main/java/com/yuandian/dataflow/statemachine/StateServer.java index 01e970c..ea617f4 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/StateServer.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/StateServer.java @@ -20,7 +20,7 @@ import com.alipay.sofa.jraft.option.NodeOptions; import com.alipay.sofa.jraft.rpc.InvokeCallback; import com.alipay.sofa.jraft.rpc.impl.BoltRaftRpcFactory; import com.alipay.sofa.jraft.util.Endpoint; -import com.yuandian.dataflow.statemachine.RaftClosure; +import com.yuandian.dataflow.statemachine.SyncDataClosure; import com.yuandian.dataflow.statemachine.StateMachine; import com.yuandian.dataflow.statemachine.rpc.SyncData; import com.yuandian.dataflow.statemachine.rpc.SyncDataProcessor; diff --git a/src/main/java/com/yuandian/dataflow/statemachine/SyncDataClosure.java b/src/main/java/com/yuandian/dataflow/statemachine/SyncDataClosure.java new file mode 100644 index 0000000..d714d2d --- /dev/null +++ b/src/main/java/com/yuandian/dataflow/statemachine/SyncDataClosure.java @@ -0,0 +1,45 @@ +package com.yuandian.dataflow.statemachine; + +import com.alipay.sofa.jraft.Closure; +import com.alipay.sofa.jraft.Status; +import com.yuandian.dataflow.statemachine.rpc.SMResponse; +import com.yuandian.dataflow.statemachine.rpc.TaskState; + +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import lombok.extern.slf4j.Slf4j; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@Slf4j +@Getter +@Setter +@ToString +public abstract class SyncDataClosure implements Closure { + + // 状态机的统一响应 + private SMResponse response; + // 代表任务状态 + private TaskState state; + + + protected void failure(final String errorMsg, final String redirect) { + final SMResponse response = new SMResponse(); + response.setSuccess(false); + response.setMsg(errorMsg); + response.setRedirect(redirect); + setResponse(response); + } + + protected void success(final TaskState value) { + final SMResponse response = new SMResponse(); + response.setState(value); + response.setSuccess(true); + setResponse(response); + } + + + +} diff --git a/src/main/java/com/yuandian/dataflow/statemachine/rpc/SMResponse.java b/src/main/java/com/yuandian/dataflow/statemachine/rpc/SMResponse.java new file mode 100644 index 0000000..62c9182 --- /dev/null +++ b/src/main/java/com/yuandian/dataflow/statemachine/rpc/SMResponse.java @@ -0,0 +1,36 @@ +/** + * description + * + * @author eson + *2022年7月13日-09:07:22 + */ +package com.yuandian.dataflow.statemachine.rpc; + +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import lombok.extern.slf4j.Slf4j; + +/** + * description + * + * @author eson + *2022年7月13日-09:07:22 + */ +@Slf4j +@Getter +@Setter +@ToString +public class SMResponse { + + private TaskState state; + + + private boolean success; + /** + * redirect peer id + */ + private String redirect; + + private String msg; +} diff --git a/src/main/java/com/yuandian/dataflow/statemachine/rpc/SyncData.java b/src/main/java/com/yuandian/dataflow/statemachine/rpc/SyncData.java index 928702a..2a3a4a4 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/rpc/SyncData.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/rpc/SyncData.java @@ -29,76 +29,6 @@ public class SyncData implements Serializable { private static final long serialVersionUID = 1L; - private long queueSize = 0; - - - // @Getter - // @Setter - // public class IncrementAndGetRequest implements Serializable { - // private long delta; - // } - - // public class GetValueRequest implements Serializable { - // private static final long serialVersionUID = 9218253805003988802L; - - // public GetValueRequest() { - // super(); - // } - // } - - - // @Getter - // @Setter - // public class ValueResponse implements Serializable { - - // private static final long serialVersionUID = -4220017686727146773L; - - // private long value; - // private boolean success; - // /** - // * redirect peer id - // */ - // private String redirect; - - // private String errorMsg; - - // } - - // public class IncrementAndAddClosure implements Closure { - // // private CounterServer counterServer; - // private IncrementAndGetRequest request; - // private ValueResponse response; - // private Closure done; // 网络应答callback - - // public IncrementAndAddClosure(CounterServer counterServer, IncrementAndGetRequest request, ValueResponse response, - // Closure done) { - // super(); - // this.counterServer = counterServer; - // this.request = request; - // this.response = response; - // this.done = done; - // } - - // @Override - // public void run(Status status) { - // // 返回应答给客户端 - // if (this.done != null) { - // done.run(status); - // } - // } - - // public IncrementAndGetRequest getRequest() { - // return this.request; - // } - - // public void setRequest(IncrementAndGetRequest request) { - // this.request = request; - // } - - // public ValueResponse getResponse() { - // return this.response; - // } - - // } + private TaskState state; } diff --git a/src/main/java/com/yuandian/dataflow/statemachine/rpc/SyncDataProcessor.java b/src/main/java/com/yuandian/dataflow/statemachine/rpc/SyncDataProcessor.java index a682e27..6f7f149 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/rpc/SyncDataProcessor.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/rpc/SyncDataProcessor.java @@ -6,8 +6,10 @@ */ package com.yuandian.dataflow.statemachine.rpc; +import com.alipay.sofa.jraft.Status; import com.alipay.sofa.jraft.rpc.RpcContext; import com.alipay.sofa.jraft.rpc.RpcProcessor; +import com.yuandian.dataflow.statemachine.SyncDataClosure; import lombok.extern.slf4j.Slf4j; @@ -24,7 +26,16 @@ public class SyncDataProcessor implements RpcProcessor { public void handleRequest(RpcContext rpcCtx, SyncData request) { log.info("{}", rpcCtx); log.info("{}", request); - rpcCtx.sendResponse(null); // + + + final SyncDataClosure closure = new SyncDataClosure() { + @Override + public void run(Status status) { + rpcCtx.sendResponse(getResponse()); + } + }; + + } @Override diff --git a/src/main/java/com/yuandian/dataflow/statemachine/rpc/TaskState.java b/src/main/java/com/yuandian/dataflow/statemachine/rpc/TaskState.java new file mode 100644 index 0000000..f830599 --- /dev/null +++ b/src/main/java/com/yuandian/dataflow/statemachine/rpc/TaskState.java @@ -0,0 +1,42 @@ +/** + * description + * + * @author eson + *2022年7月13日-09:11:26 + */ +package com.yuandian.dataflow.statemachine.rpc; + +import java.io.Serializable; + +import com.alipay.sofa.jraft.entity.PeerId; + +import lombok.Getter; +import lombok.Setter; +import lombok.extern.slf4j.Slf4j; + +import java.lang.management.ManagementFactory; +import java.lang.management.OperatingSystemMXBean; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; + +/** + * 代表任务状态 暂时全局使用这个结构 + * + * @author eson + *2022年7月13日-09:11:26 + */ +@Slf4j +@Getter +@Setter +public class TaskState implements Serializable { + private static final long serialVersionUID = -1L; + + // 节点的对应peerID + private PeerId peerId; + private long taskQueueSize; + + + public static void main(String[] args) { + + } +} From 886a5ffe1aa1774ccd0adfa2ae1aabad0ceaada2 Mon Sep 17 00:00:00 2001 From: huangsimin Date: Thu, 14 Jul 2022 18:19:45 +0800 Subject: [PATCH 04/37] =?UTF-8?q?=E7=8A=B6=E6=80=81=E5=90=8C=E6=AD=A5=20TO?= =?UTF-8?q?DO:=20readIndex?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/yuandian/dataflow/Server.java | 46 ++-- .../yuandian/dataflow/controller/TaskLog.java | 35 ++-- .../proto/msgtype/UsrFlowOuterClass.java | 10 +- .../dataflow/statemachine/StateMachine.java | 42 +++- .../dataflow/statemachine/StateServer.java | 97 --------- .../statemachine/StateServerFactory.java | 198 ++++++++++++++++++ .../statemachine/SyncDataClosure.java | 7 +- .../dataflow/statemachine/rpc/SMResponse.java | 10 +- .../dataflow/statemachine/rpc/SyncData.java | 4 +- .../statemachine/rpc/SyncDataProcessor.java | 24 ++- .../dataflow/statemachine/rpc/TaskState.java | 6 +- src/main/resources/logback.xml | 2 +- .../statemachine/StateMachineTest.java | 74 +++++++ 13 files changed, 392 insertions(+), 163 deletions(-) delete mode 100644 src/main/java/com/yuandian/dataflow/statemachine/StateServer.java create mode 100644 src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java create mode 100644 src/test/java/com/yuandian/dataflow/statemachine/StateMachineTest.java diff --git a/src/main/java/com/yuandian/dataflow/Server.java b/src/main/java/com/yuandian/dataflow/Server.java index 2962f3c..6e210fa 100644 --- a/src/main/java/com/yuandian/dataflow/Server.java +++ b/src/main/java/com/yuandian/dataflow/Server.java @@ -16,10 +16,11 @@ import com.alipay.sofa.jraft.entity.PeerId; import com.alipay.sofa.jraft.option.NodeOptions; import com.yuandian.dataflow.statemachine.SyncDataClosure; import com.yuandian.dataflow.statemachine.StateMachine; -import com.yuandian.dataflow.statemachine.StateServer; +import com.yuandian.dataflow.statemachine.StateServerFactory; import com.yuandian.dataflow.statemachine.rpc.SyncDataProcessor; import lombok.var; +import lombok.extern.slf4j.Slf4j; @@ -28,26 +29,17 @@ import lombok.var; * Hello world! * */ +@Slf4j @SpringBootApplication @SpringBootConfiguration public class Server { - @Autowired - public static Node node; - public static SyncDataClosure done; - private static StateServer stateServer; - - public static Node GetNode() { - return node; - } - - public static SyncDataClosure GetDone() { - return done; - } + - public static void main(String[] args) { + public static void main(String[] args) throws Exception { + String[] peers = new String[]{"localhost:4440","localhost:4441","localhost:4442"}; String[] sprPeers = new String[]{"3440","3441","3442"}; @@ -56,11 +48,35 @@ public class Server { Configuration conf = JRaftUtils.getConfiguration("localhost:4440,localhost:4441,localhost:4442"); - stateServer = new StateServer(peeridstr, conf); + // StateServerFactory.my = new StateServerFactory(peeridstr, conf); + StateServerFactory.InitStateServer(peeridstr, conf); + // Thread printer = new Thread( new Runnable(){ + + // @Override + // public void run() { + // // TODO Auto-generated method stub + // while(true) { + // var state = StateServerFactory.getStateServer().getFsm().getTaskState(); + // log.info("{}", state); + // try { + // Thread.sleep(1000); + // } catch (InterruptedException e) { + // // TODO Auto-generated catch block + // e.printStackTrace(); + // } + // } + // } + + // } ); + + // printer.start(); + System.setProperty("server.port", sprPort); var app = SpringApplication.run(Server.class, args); app.start(); + + } } diff --git a/src/main/java/com/yuandian/dataflow/controller/TaskLog.java b/src/main/java/com/yuandian/dataflow/controller/TaskLog.java index e6cf27a..8ca4f6d 100644 --- a/src/main/java/com/yuandian/dataflow/controller/TaskLog.java +++ b/src/main/java/com/yuandian/dataflow/controller/TaskLog.java @@ -10,8 +10,11 @@ import com.alipay.sofa.jraft.rpc.RpcClient; import com.alipay.sofa.jraft.rpc.impl.BoltRpcClient; import com.yuandian.dataflow.Server; import com.yuandian.dataflow.projo.Response; +import com.yuandian.dataflow.statemachine.StateServerFactory; import com.yuandian.dataflow.statemachine.SyncDataClosure; +import com.yuandian.dataflow.statemachine.rpc.TaskState; +import lombok.var; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang.ObjectUtils.Null; @@ -29,42 +32,32 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestParam; import com.alipay.sofa.jraft.Node; +import com.alipay.sofa.jraft.Status; @Slf4j @Controller public class TaskLog { - private static Node node = Server.GetNode(); + @GetMapping(path = "/test") public ResponseEntity Processing() { - - log.info("node.isLeader {} {} node.getNodeId() {}", node.getNodeState(), node.getLeaderId(), node.getNodeId()); - if(node.isLeader()) { - // Task task = new Task(); - - // // 处理状态机 - // RaftClosure done = new RaftClosure(); - // task.setData(ByteBuffer.wrap("hello".getBytes())); - // task.setDone(done); - - // log.error("{} {} {}",node, node.toString(), task); - // node.apply(task); - - // log.error("{}", "RaftClosure"); - - - - } - + // var state = StateServerFactory.getStateServer().getFsm().getTaskState(); + var c = new SyncDataClosure() { + @Override + public void run(Status status) { + log.info(getTaskState().toString()); + } + }; + StateServerFactory.getStateServer().readIndexState(true, c ); Response response = new Response(); response.Code = HttpStatus.OK; - response.Message = HttpStatus.OK.toString(); + response.Message = "OK"; return new ResponseEntity(response, HttpStatus.OK); } diff --git a/src/main/java/com/yuandian/dataflow/proto/msgtype/UsrFlowOuterClass.java b/src/main/java/com/yuandian/dataflow/proto/msgtype/UsrFlowOuterClass.java index a829cdc..6dbf67e 100644 --- a/src/main/java/com/yuandian/dataflow/proto/msgtype/UsrFlowOuterClass.java +++ b/src/main/java/com/yuandian/dataflow/proto/msgtype/UsrFlowOuterClass.java @@ -20,7 +20,7 @@ public final class UsrFlowOuterClass { /** *
-     *编号19
+     *编号19
      * 
* * int32 table_id = 1; @@ -501,7 +501,7 @@ public final class UsrFlowOuterClass { private int tableId_; /** *
-     *编号19
+     *编号19
      * 
* * int32 table_id = 1; @@ -1793,7 +1793,7 @@ public final class UsrFlowOuterClass { private int tableId_ ; /** *
-       *编号19
+       *编号19
        * 
* * int32 table_id = 1; @@ -1805,7 +1805,7 @@ public final class UsrFlowOuterClass { } /** *
-       *编号19
+       *编号19
        * 
* * int32 table_id = 1; @@ -1820,7 +1820,7 @@ public final class UsrFlowOuterClass { } /** *
-       *编号19
+       *编号19
        * 
* * int32 table_id = 1; diff --git a/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java b/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java index c93f337..454c8ba 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java @@ -3,6 +3,7 @@ package com.yuandian.dataflow.statemachine; import java.io.File; import java.io.IOException; import java.nio.ByteBuffer; +import java.util.concurrent.Executor; import java.util.concurrent.atomic.AtomicLong; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -12,12 +13,22 @@ import com.alipay.sofa.jraft.Closure; import com.alipay.sofa.jraft.Iterator; import com.alipay.sofa.jraft.Status; import com.alipay.sofa.jraft.core.StateMachineAdapter; +import com.alipay.sofa.jraft.entity.PeerId; import com.alipay.sofa.jraft.error.RaftError; import com.alipay.sofa.jraft.error.RaftException; +import com.alipay.sofa.jraft.error.RemotingException; +import com.alipay.sofa.jraft.option.CliOptions; +import com.alipay.sofa.jraft.rpc.InvokeCallback; +import com.alipay.sofa.jraft.rpc.impl.BoltRaftRpcFactory; import com.alipay.sofa.jraft.storage.snapshot.SnapshotReader; import com.alipay.sofa.jraft.storage.snapshot.SnapshotWriter; +import com.alipay.sofa.jraft.util.Endpoint; import com.alipay.sofa.jraft.util.Utils; +import com.yuandian.dataflow.statemachine.rpc.SMResponse; +import com.yuandian.dataflow.statemachine.rpc.SyncData; +import com.yuandian.dataflow.statemachine.rpc.TaskState; +import lombok.var; import lombok.extern.slf4j.Slf4j; /** @@ -28,6 +39,7 @@ import lombok.extern.slf4j.Slf4j; * 2018-Apr-09 4:52:31 PM */ @Slf4j + public class StateMachine extends StateMachineAdapter { // private static final Logger LOG = LoggerFactory.getLogger(StateMachine.class); @@ -35,7 +47,7 @@ public class StateMachine extends StateMachineAdapter { /** * Counter value */ - private final AtomicLong value = new AtomicLong(0); + private TaskState taskState = new TaskState(); /** * Leader term */ @@ -48,8 +60,8 @@ public class StateMachine extends StateMachineAdapter { /** * Returns current value. */ - public long getValue() { - return this.value.get(); + public TaskState getTaskState() { + return taskState; } @Override @@ -59,12 +71,22 @@ public class StateMachine extends StateMachineAdapter { if (iter.done() != null) { // This task is applied by this node, get value from closure to avoid additional // parsing. - - log.error("done:{}",iter.getData().toString()); - + var closure = (SyncDataClosure)iter.done(); + taskState = closure.getTaskState(); + log.info("SyncDataClosure(done) taskState:{} leaderTerm:{}",taskState, this.leaderTerm); + closure.success(taskState); + closure.run(Status.OK()); } else { - // Have to parse FetchAddRequest from this user log. - log.error("null:{}",iter.getData().toString()); + // Have to parse FetchAddRequest from this user log. + final ByteBuffer data = iter.getData(); + try { + taskState = SerializerManager.getSerializer(SerializerManager.Hessian2).deserialize( + data.array(), TaskState.class.getName()); + log.info("SyncDataClosure(null) taskState:{} leaderTerm:{}", taskState, this.leaderTerm); + } catch (CodecException e) { + e.printStackTrace(); + } + } iter.next(); @@ -100,4 +122,8 @@ public class StateMachine extends StateMachineAdapter { super.onLeaderStop(status); } + public static void main(String[] args) throws InterruptedException, RemotingException { + + } + } diff --git a/src/main/java/com/yuandian/dataflow/statemachine/StateServer.java b/src/main/java/com/yuandian/dataflow/statemachine/StateServer.java deleted file mode 100644 index ea617f4..0000000 --- a/src/main/java/com/yuandian/dataflow/statemachine/StateServer.java +++ /dev/null @@ -1,97 +0,0 @@ -/** - * description - * - * @author eson - *2022年7月12日-13:36:24 - */ -package com.yuandian.dataflow.statemachine; - -import java.io.File; - -import com.alibaba.nacos.common.remote.client.RpcClient; -import com.alipay.sofa.jraft.JRaftUtils; -import com.alipay.sofa.jraft.Node; -import com.alipay.sofa.jraft.RaftGroupService; -import com.alipay.sofa.jraft.conf.Configuration; -import com.alipay.sofa.jraft.entity.PeerId; -import com.alipay.sofa.jraft.error.RemotingException; -import com.alipay.sofa.jraft.option.CliOptions; -import com.alipay.sofa.jraft.option.NodeOptions; -import com.alipay.sofa.jraft.rpc.InvokeCallback; -import com.alipay.sofa.jraft.rpc.impl.BoltRaftRpcFactory; -import com.alipay.sofa.jraft.util.Endpoint; -import com.yuandian.dataflow.statemachine.SyncDataClosure; -import com.yuandian.dataflow.statemachine.StateMachine; -import com.yuandian.dataflow.statemachine.rpc.SyncData; -import com.yuandian.dataflow.statemachine.rpc.SyncDataProcessor; - -import lombok.var; -import lombok.extern.slf4j.Slf4j; - -/** - * description - * - * @author eson - *2022年7月12日-13:36:24 - */ -@Slf4j -@var -public class StateServer { - - public Node node; - public RaftGroupService cluster; - public StateMachine fsm; - - private String groupId = "dataflow"; - - public StateServer(String addr, Configuration conf) { - String[] peers = new String[]{"localhost:4440","localhost:4441","localhost:4442"}; - String[] sprPeers = new String[]{"3440","3441","3442"}; - - // var peeridstr = peers[Integer.parseInt(serverId)]; - // var sprPort = sprPeers[Integer.parseInt(args[0])]; - - // String groupId = "jraft"; - - // Configuration conf = JRaftUtils.getConfiguration("localhost:4440,localhost:4441,localhost:4442"); - - PeerId serverId = JRaftUtils.getPeerId(addr); - int port = serverId.getPort(); - - NodeOptions nodeOptions = new NodeOptions(); - nodeOptions.setElectionTimeoutMs(1000); - nodeOptions.setSnapshotLogIndexMargin(3600); - nodeOptions.setInitialConf(conf); - - File RaftDataFile = new File(String.format("./raftdata/%d", port) ); - log.info("{}",RaftDataFile.mkdirs()); - - nodeOptions.setLogUri( String.format("./raftdata/%d/logs", port) ); - nodeOptions.setRaftMetaUri(String.format("./raftdata/%d/rafts", port)); - nodeOptions.setSnapshotUri(String.format("./raftdata/%d/snaps", port)); - fsm = new StateMachine(); // 状态实例初始化 - nodeOptions.setFsm(fsm); - - cluster = new RaftGroupService(groupId, serverId, nodeOptions); - cluster.getRpcServer().registerProcessor(new SyncDataProcessor()); - - - - - node = cluster.start(); - } - - - public static void main(String[] args) throws InterruptedException, RemotingException { - var rpcClient = new BoltRaftRpcFactory().createRpcClient(); - - - rpcClient.init(new CliOptions()); - - var resp = rpcClient.invokeSync(new Endpoint("localhost",4441), new SyncData(), 5000); - log.info("{}", resp); - - // done = new RaftClosure(); - // node.shutdown(done); - } -} diff --git a/src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java b/src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java new file mode 100644 index 0000000..f58b2d8 --- /dev/null +++ b/src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java @@ -0,0 +1,198 @@ +/** + * description + * + * @author eson + *2022年7月12日-13:36:24 + */ +package com.yuandian.dataflow.statemachine; + +import java.io.File; +import java.nio.ByteBuffer; +import java.util.concurrent.Executor; + +import com.alipay.remoting.exception.CodecException; +import com.alipay.remoting.serialization.SerializerManager; +import com.alipay.sofa.jraft.JRaftUtils; +import com.alipay.sofa.jraft.Node; +import com.alipay.sofa.jraft.RaftGroupService; +import com.alipay.sofa.jraft.Status; +import com.alipay.sofa.jraft.closure.ReadIndexClosure; +import com.alipay.sofa.jraft.conf.Configuration; +import com.alipay.sofa.jraft.entity.PeerId; +import com.alipay.sofa.jraft.entity.Task; +import com.alipay.sofa.jraft.error.RaftError; +import com.alipay.sofa.jraft.error.RemotingException; +import com.alipay.sofa.jraft.option.CliOptions; +import com.alipay.sofa.jraft.option.NodeOptions; +import com.alipay.sofa.jraft.rpc.impl.BoltRaftRpcFactory; +import com.alipay.sofa.jraft.util.BytesUtil; +import com.alipay.sofa.jraft.util.Endpoint; +import com.yuandian.dataflow.statemachine.rpc.SMResponse; +import com.yuandian.dataflow.statemachine.rpc.SyncData; +import com.yuandian.dataflow.statemachine.rpc.SyncDataProcessor; +import com.yuandian.dataflow.statemachine.rpc.TaskState; + +import lombok.Getter; +import lombok.Setter; +import lombok.var; +import lombok.extern.slf4j.Slf4j; + +/** + * description + * + * @author eson + *2022年7月12日-13:36:24 + */ +@Slf4j +@var +public class StateServerFactory { + + private static StateServer ss; + // 必须初始化 + public static void InitStateServer(String peerstr, Configuration conf) throws Exception { + if(ss != null) { + throw new Exception("重复初始化 InitStateServer"); + } + ss = new StateServerFactory.StateServer(peerstr, conf); + } + + // 获取状态服务的对象 + public static StateServer getStateServer() { + return ss; + } + + @Getter + @Setter + public static class StateServer { + + private Node node; + private RaftGroupService cluster; + private StateMachine fsm; + + private String groupId = "dataflow"; + private Executor readIndexExecutor; + + public StateServer(String addr, Configuration conf) { + String[] peers = new String[]{"localhost:4440","localhost:4441","localhost:4442"}; + String[] sprPeers = new String[]{"3440","3441","3442"}; + + // var peeridstr = peers[Integer.parseInt(serverId)]; + // var sprPort = sprPeers[Integer.parseInt(args[0])]; + + // String groupId = "jraft"; + + // Configuration conf = JRaftUtils.getConfiguration("localhost:4440,localhost:4441,localhost:4442"); + + PeerId serverId = JRaftUtils.getPeerId(addr); + int port = serverId.getPort(); + + NodeOptions nodeOptions = new NodeOptions(); + nodeOptions.setElectionTimeoutMs(1000); + nodeOptions.setSnapshotLogIndexMargin(3600); + nodeOptions.setInitialConf(conf); + + File RaftDataFile = new File(String.format("./raftdata/%d", port) ); + log.info("{}",RaftDataFile.mkdirs()); + + nodeOptions.setLogUri( String.format("./raftdata/%d/logs", port) ); + nodeOptions.setRaftMetaUri(String.format("./raftdata/%d/rafts", port)); + nodeOptions.setSnapshotUri(String.format("./raftdata/%d/snaps", port)); + fsm = new StateMachine(); // 状态实例初始化 + nodeOptions.setFsm(fsm); + + cluster = new RaftGroupService(groupId, serverId, nodeOptions); + cluster.getRpcServer().registerProcessor(new SyncDataProcessor()); + + + + + node = cluster.start(); + } + + public boolean isLeader() { + return this.fsm.isLeader(); + } + + public TaskState getTaskState() { + return this.fsm.getTaskState(); + } + + public void applyState(TaskState state, SyncDataClosure closure) { + if (!ss.isLeader()) { + ss.handlerNotLeaderError(closure); + return; + } + + try { + closure.setTaskState(state); + final Task task = new Task(); + task.setData(ByteBuffer.wrap(SerializerManager.getSerializer(SerializerManager.Hessian2).serialize(state))); + task.setDone(closure); + StateServerFactory.getStateServer().getNode().apply(task); + } catch (CodecException e) { + String errorMsg = "Fail to encode TaskState"; + log.error(errorMsg, e); + closure.failure(errorMsg, PeerId.emptyPeer()); + closure.run(new Status(RaftError.EINTERNAL, errorMsg)); + } + } + + public void readIndexState(final boolean readOnlySafe, final SyncDataClosure closure) { + + if(!readOnlySafe){ + closure.success(getTaskState()); + closure.run(Status.OK()); + return; + } + + getNode().readIndex(BytesUtil.EMPTY_BYTES, new ReadIndexClosure() { + @Override + public void run(Status status, long index, byte[] reqCtx) { + if(status.isOk()){ + closure.success(getTaskState()); + closure.run(Status.OK()); + return; + } + + readIndexExecutor.execute(() -> { + if(isLeader()){ + log.debug("Fail to get value with 'ReadIndex': {}, try to applying to the state machine.", status); + applyState( getTaskState(), closure); + }else { + handlerNotLeaderError(closure); + } + }); + } + }); + } + + public SMResponse redirect() { + + final SMResponse response = new SMResponse(); + response.setSuccess(false); + if (this.node != null) { + final PeerId leader = this.node.getLeaderId(); + if (leader != null) { + response.setRedirect(leader); + } + } + return response; + + } + + public void handlerNotLeaderError(final SyncDataClosure closure) { + closure.failure("Not leader.", redirect().getRedirect()); + closure.run(new Status(RaftError.EPERM, "Not leader")); + } +} + + + public static void main(String[] args) throws InterruptedException, RemotingException { + var rpcClient = new BoltRaftRpcFactory().createRpcClient(); + + rpcClient.init(new CliOptions()); + + var resp = rpcClient.invokeSync(new Endpoint("localhost",4441), new SyncData(), 5000); + log.info("{}", resp); + } +} diff --git a/src/main/java/com/yuandian/dataflow/statemachine/SyncDataClosure.java b/src/main/java/com/yuandian/dataflow/statemachine/SyncDataClosure.java index d714d2d..f7e1ccf 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/SyncDataClosure.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/SyncDataClosure.java @@ -2,6 +2,7 @@ package com.yuandian.dataflow.statemachine; import com.alipay.sofa.jraft.Closure; import com.alipay.sofa.jraft.Status; +import com.alipay.sofa.jraft.entity.PeerId; import com.yuandian.dataflow.statemachine.rpc.SMResponse; import com.yuandian.dataflow.statemachine.rpc.TaskState; @@ -22,10 +23,10 @@ public abstract class SyncDataClosure implements Closure { // 状态机的统一响应 private SMResponse response; // 代表任务状态 - private TaskState state; + private TaskState taskState; - protected void failure(final String errorMsg, final String redirect) { + public void failure(final String errorMsg, final PeerId redirect) { final SMResponse response = new SMResponse(); response.setSuccess(false); response.setMsg(errorMsg); @@ -33,7 +34,7 @@ public abstract class SyncDataClosure implements Closure { setResponse(response); } - protected void success(final TaskState value) { + public void success(final TaskState value) { final SMResponse response = new SMResponse(); response.setState(value); response.setSuccess(true); diff --git a/src/main/java/com/yuandian/dataflow/statemachine/rpc/SMResponse.java b/src/main/java/com/yuandian/dataflow/statemachine/rpc/SMResponse.java index 62c9182..8a260f2 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/rpc/SMResponse.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/rpc/SMResponse.java @@ -6,6 +6,10 @@ */ package com.yuandian.dataflow.statemachine.rpc; +import java.io.Serializable; + +import com.alipay.sofa.jraft.entity.PeerId; + import lombok.Getter; import lombok.Setter; import lombok.ToString; @@ -21,7 +25,9 @@ import lombok.extern.slf4j.Slf4j; @Getter @Setter @ToString -public class SMResponse { +public class SMResponse implements Serializable { + + private static final long serialVersionUID = 1L; private TaskState state; @@ -30,7 +36,7 @@ public class SMResponse { /** * redirect peer id */ - private String redirect; + private PeerId redirect; private String msg; } diff --git a/src/main/java/com/yuandian/dataflow/statemachine/rpc/SyncData.java b/src/main/java/com/yuandian/dataflow/statemachine/rpc/SyncData.java index 2a3a4a4..e2349e3 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/rpc/SyncData.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/rpc/SyncData.java @@ -29,6 +29,8 @@ public class SyncData implements Serializable { private static final long serialVersionUID = 1L; - private TaskState state; + private TaskState taskState; + + } diff --git a/src/main/java/com/yuandian/dataflow/statemachine/rpc/SyncDataProcessor.java b/src/main/java/com/yuandian/dataflow/statemachine/rpc/SyncDataProcessor.java index 6f7f149..2181cb1 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/rpc/SyncDataProcessor.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/rpc/SyncDataProcessor.java @@ -6,11 +6,23 @@ */ package com.yuandian.dataflow.statemachine.rpc; +import java.nio.ByteBuffer; + +import com.alipay.remoting.exception.CodecException; +import com.alipay.remoting.serialization.SerializerManager; import com.alipay.sofa.jraft.Status; +import com.alipay.sofa.jraft.entity.Task; +import com.alipay.sofa.jraft.error.RaftError; import com.alipay.sofa.jraft.rpc.RpcContext; import com.alipay.sofa.jraft.rpc.RpcProcessor; +import com.yuandian.dataflow.statemachine.StateServerFactory; import com.yuandian.dataflow.statemachine.SyncDataClosure; +import com.yuandian.dataflow.statemachine.StateServerFactory.StateServer; +import com.alipay.sofa.jraft.entity.PeerId; +import org.apache.commons.lang.StringUtils; + +import lombok.var; import lombok.extern.slf4j.Slf4j; /** @@ -24,18 +36,18 @@ public class SyncDataProcessor implements RpcProcessor { @Override public void handleRequest(RpcContext rpcCtx, SyncData request) { - log.info("{}", rpcCtx); - log.info("{}", request); + + log.info("request: {}", request); - final SyncDataClosure closure = new SyncDataClosure() { @Override public void run(Status status) { rpcCtx.sendResponse(getResponse()); + log.info("{}", status); } }; - + StateServerFactory.getStateServer().applyState(request.getTaskState(), closure); } @Override @@ -43,8 +55,6 @@ public class SyncDataProcessor implements RpcProcessor { return SyncData.class.getName(); } - public static void main(String[] args) { - - } + } diff --git a/src/main/java/com/yuandian/dataflow/statemachine/rpc/TaskState.java b/src/main/java/com/yuandian/dataflow/statemachine/rpc/TaskState.java index f830599..af05361 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/rpc/TaskState.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/rpc/TaskState.java @@ -12,6 +12,7 @@ import com.alipay.sofa.jraft.entity.PeerId; import lombok.Getter; import lombok.Setter; +import lombok.ToString; import lombok.extern.slf4j.Slf4j; import java.lang.management.ManagementFactory; @@ -28,6 +29,7 @@ import java.lang.reflect.Modifier; @Slf4j @Getter @Setter +@ToString public class TaskState implements Serializable { private static final long serialVersionUID = -1L; @@ -36,7 +38,5 @@ public class TaskState implements Serializable { private long taskQueueSize; - public static void main(String[] args) { - - } + } diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml index 1a5cfba..269a553 100644 --- a/src/main/resources/logback.xml +++ b/src/main/resources/logback.xml @@ -3,7 +3,7 @@ class="ch.qos.logback.core.ConsoleAppender"> - %d{yyyyMMdd HH:mm:ss.SSS} %-5level%thread\(%file:%line\): %msg%n + %d{yyyyMMdd HH:mm:ss.SSS} %level %thread\(%file:%line\): %msg%n diff --git a/src/test/java/com/yuandian/dataflow/statemachine/StateMachineTest.java b/src/test/java/com/yuandian/dataflow/statemachine/StateMachineTest.java new file mode 100644 index 0000000..b8c37b9 --- /dev/null +++ b/src/test/java/com/yuandian/dataflow/statemachine/StateMachineTest.java @@ -0,0 +1,74 @@ +package com.yuandian.dataflow.statemachine; + +import java.util.concurrent.Executor; + +import org.junit.jupiter.api.Test; + +import com.alipay.sofa.jraft.entity.PeerId; +import com.alipay.sofa.jraft.error.RemotingException; +import com.alipay.sofa.jraft.option.CliOptions; +import com.alipay.sofa.jraft.rpc.InvokeCallback; +import com.alipay.sofa.jraft.rpc.impl.BoltRaftRpcFactory; +import com.alipay.sofa.jraft.util.Endpoint; +import com.yuandian.dataflow.statemachine.rpc.SMResponse; +import com.yuandian.dataflow.statemachine.rpc.SyncData; +import com.yuandian.dataflow.statemachine.rpc.TaskState; + +import lombok.var; +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public class StateMachineTest { + @Test + void testOnApply() throws InterruptedException, RemotingException { + var rpcClient = new BoltRaftRpcFactory().createRpcClient(); + rpcClient.init(new CliOptions()); + + + var fstate = new TaskState(); + var fdata = new SyncData(); + fdata.setTaskState(fstate); + + var leader = new Endpoint("localhost",4441); + SMResponse resp = (SMResponse)rpcClient.invokeSync(leader, fdata + , 5000); + log.info("{}", resp); + if( resp != null && !resp.isSuccess() ) { + leader = resp.getRedirect().getEndpoint(); + resp = (SMResponse)rpcClient.invokeSync(resp.getRedirect().getEndpoint(), fdata + , 5000); + log.info("{}", resp); + } + + + int i = 0 ; + while(true) { + + var state = new TaskState(); + var data = new SyncData(); + data.setTaskState(state); + + state.setPeerId( PeerId.parsePeer("localhost:2222") ); + + state.setTaskQueueSize(i); + + var pi = i ; + i++; + if (i >= 1000) { + break; + } + rpcClient.invokeAsync(leader, data, new InvokeCallback() { + @Override + public void complete(Object result, Throwable err) { + // SMResponse resp = (SMResponse)result; + log.info("{} {} {}", result, err, pi); + } + + @Override + public Executor executor() { + return null; + } + } , 5000); + } + } +} From dce906a7eb7073ac6a8514b3848822e7a4215c4b Mon Sep 17 00:00:00 2001 From: huangsimin Date: Fri, 15 Jul 2022 01:00:22 +0800 Subject: [PATCH 05/37] =?UTF-8?q?=E5=AE=8C=E6=88=90=E7=8A=B6=E6=80=81?= =?UTF-8?q?=E6=9C=BA=E7=9A=84=E8=AF=BB=E5=86=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/yuandian/dataflow/Server.java | 4 -- .../yuandian/dataflow/controller/TaskLog.java | 61 ++++++++----------- .../statemachine/StateServerFactory.java | 17 ++++-- .../statemachine/SyncDataClosure.java | 8 ++- 4 files changed, 46 insertions(+), 44 deletions(-) diff --git a/src/main/java/com/yuandian/dataflow/Server.java b/src/main/java/com/yuandian/dataflow/Server.java index 6e210fa..b59fd1e 100644 --- a/src/main/java/com/yuandian/dataflow/Server.java +++ b/src/main/java/com/yuandian/dataflow/Server.java @@ -33,11 +33,7 @@ import lombok.extern.slf4j.Slf4j; @SpringBootApplication @SpringBootConfiguration public class Server { - - - - public static void main(String[] args) throws Exception { diff --git a/src/main/java/com/yuandian/dataflow/controller/TaskLog.java b/src/main/java/com/yuandian/dataflow/controller/TaskLog.java index 8ca4f6d..78c9dcb 100644 --- a/src/main/java/com/yuandian/dataflow/controller/TaskLog.java +++ b/src/main/java/com/yuandian/dataflow/controller/TaskLog.java @@ -1,14 +1,12 @@ package com.yuandian.dataflow.controller; -import java.nio.ByteBuffer; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; -import com.alibaba.nacos.api.naming.pojo.Cluster; -import com.alibaba.nacos.common.remote.client.RpcClientFactory; -import com.alipay.sofa.jraft.Closure; -import com.alipay.sofa.jraft.entity.Task; -import com.alipay.sofa.jraft.rpc.RpcClient; -import com.alipay.sofa.jraft.rpc.impl.BoltRpcClient; -import com.yuandian.dataflow.Server; +import com.alipay.sofa.jraft.Status; import com.yuandian.dataflow.projo.Response; import com.yuandian.dataflow.statemachine.StateServerFactory; import com.yuandian.dataflow.statemachine.SyncDataClosure; @@ -17,23 +15,6 @@ import com.yuandian.dataflow.statemachine.rpc.TaskState; import lombok.var; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang.ObjectUtils.Null; -import org.apache.commons.logging.Log; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestParam; - -import com.alipay.sofa.jraft.Node; -import com.alipay.sofa.jraft.Status; - @Slf4j @Controller public class TaskLog { @@ -41,23 +22,35 @@ public class TaskLog { @GetMapping(path = "/test") - public ResponseEntity Processing() { + public ResponseEntity Processing() throws InterruptedException { // var state = StateServerFactory.getStateServer().getFsm().getTaskState(); - var c = new SyncDataClosure() { + + + SyncDataClosure closure = new SyncDataClosure() { @Override public void run(Status status) { - log.info(getTaskState().toString()); + synchronized(lockObject) { + lockObject.notify(); + } } - }; - StateServerFactory.getStateServer().readIndexState(true, c ); - - + }; + var state = new TaskState(); + state.setTaskQueueSize(1); + closure.setTaskState(state); + StateServerFactory.getStateServer().readIndexState(true, closure); + + synchronized(closure.lockObject) { + closure.lockObject.wait(); + } + + + - Response response = new Response(); + final Response response = new Response(); response.Code = HttpStatus.OK; - response.Message = "OK"; + response.Message = closure.getTaskState().toString(); return new ResponseEntity(response, HttpStatus.OK); } diff --git a/src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java b/src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java index f58b2d8..25bd435 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java @@ -140,6 +140,8 @@ public class StateServerFactory { public void readIndexState(final boolean readOnlySafe, final SyncDataClosure closure) { if(!readOnlySafe){ + + closure.setTaskState(getTaskState()); closure.success(getTaskState()); closure.run(Status.OK()); return; @@ -149,15 +151,22 @@ public class StateServerFactory { @Override public void run(Status status, long index, byte[] reqCtx) { if(status.isOk()){ - closure.success(getTaskState()); - closure.run(Status.OK()); + + if(closure.getTaskState() != null){ + applyState(closure.getTaskState(), closure); + } else { + closure.setTaskState(getTaskState()); + closure.success(getTaskState()); + closure.run(Status.OK()); + } + return; } readIndexExecutor.execute(() -> { if(isLeader()){ - log.debug("Fail to get value with 'ReadIndex': {}, try to applying to the state machine.", status); - applyState( getTaskState(), closure); + log.info("Fail to get value with 'ReadIndex': {}, try to applying to the state machine.", status); + applyState(getTaskState(), closure); }else { handlerNotLeaderError(closure); } diff --git a/src/main/java/com/yuandian/dataflow/statemachine/SyncDataClosure.java b/src/main/java/com/yuandian/dataflow/statemachine/SyncDataClosure.java index f7e1ccf..7a83439 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/SyncDataClosure.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/SyncDataClosure.java @@ -25,7 +25,13 @@ public abstract class SyncDataClosure implements Closure { // 代表任务状态 private TaskState taskState; + public Object lockObject = new Object(); + public SyncDataClosure() { + + } + + public void failure(final String errorMsg, final PeerId redirect) { final SMResponse response = new SMResponse(); response.setSuccess(false); @@ -41,6 +47,4 @@ public abstract class SyncDataClosure implements Closure { setResponse(response); } - - } From 5a50ce22ef5185e965a2af95501ec56dfb2c1954 Mon Sep 17 00:00:00 2001 From: huangsimin Date: Fri, 15 Jul 2022 18:42:35 +0800 Subject: [PATCH 06/37] todo: next readIndex --- .../java/com/yuandian/dataflow/Server.java | 12 ++- .../yuandian/dataflow/controller/TaskLog.java | 32 +++---- .../dataflow/statemachine/StateMachine.java | 27 +++--- .../statemachine/StateServerFactory.java | 96 +++++++++++++------ .../statemachine/SyncDataClosure.java | 10 +- .../dataflow/statemachine/rpc/SMResponse.java | 3 +- .../statemachine/rpc/SyncDataProcessor.java | 8 +- .../{SyncData.java => SyncDataRequest.java} | 10 +- .../{rpc/TaskState.java => state/State.java} | 15 ++- .../statemachine/state/WorkerState.java | 32 +++++++ .../statemachine/StateMachineTest.java | 23 ++--- start.sh | 2 +- 12 files changed, 165 insertions(+), 105 deletions(-) rename src/main/java/com/yuandian/dataflow/statemachine/rpc/{SyncData.java => SyncDataRequest.java} (65%) rename src/main/java/com/yuandian/dataflow/statemachine/{rpc/TaskState.java => state/State.java} (68%) create mode 100644 src/main/java/com/yuandian/dataflow/statemachine/state/WorkerState.java diff --git a/src/main/java/com/yuandian/dataflow/Server.java b/src/main/java/com/yuandian/dataflow/Server.java index b59fd1e..e1fbba3 100644 --- a/src/main/java/com/yuandian/dataflow/Server.java +++ b/src/main/java/com/yuandian/dataflow/Server.java @@ -8,6 +8,7 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringBootConfiguration; import org.springframework.boot.autoconfigure.SpringBootApplication; +import com.alipay.remoting.serialization.SerializerManager; import com.alipay.sofa.jraft.JRaftUtils; import com.alipay.sofa.jraft.Node; import com.alipay.sofa.jraft.RaftGroupService; @@ -37,14 +38,21 @@ public class Server { public static void main(String[] args) throws Exception { + + String[] peers = new String[]{"localhost:4440","localhost:4441","localhost:4442"}; String[] sprPeers = new String[]{"3440","3441","3442"}; + var peeridstr = peers[ Integer.parseInt(args[0] )]; var sprPort = sprPeers[Integer.parseInt(args[0] )]; + // var peeridstr = peers[2]; + // var sprPort = sprPeers[2]; + + Configuration conf = JRaftUtils.getConfiguration("localhost:4440,localhost:4441,localhost:4442"); - // StateServerFactory.my = new StateServerFactory(peeridstr, conf); + StateServerFactory.InitStateServer(peeridstr, conf); // Thread printer = new Thread( new Runnable(){ @@ -53,7 +61,7 @@ public class Server { // public void run() { // // TODO Auto-generated method stub // while(true) { - // var state = StateServerFactory.getStateServer().getFsm().getTaskState(); + // var state = StateServerFactory.getStateServer().getFsm().getState(); // log.info("{}", state); // try { // Thread.sleep(1000); diff --git a/src/main/java/com/yuandian/dataflow/controller/TaskLog.java b/src/main/java/com/yuandian/dataflow/controller/TaskLog.java index 78c9dcb..59ddb33 100644 --- a/src/main/java/com/yuandian/dataflow/controller/TaskLog.java +++ b/src/main/java/com/yuandian/dataflow/controller/TaskLog.java @@ -10,7 +10,7 @@ import com.alipay.sofa.jraft.Status; import com.yuandian.dataflow.projo.Response; import com.yuandian.dataflow.statemachine.StateServerFactory; import com.yuandian.dataflow.statemachine.SyncDataClosure; -import com.yuandian.dataflow.statemachine.rpc.TaskState; +import com.yuandian.dataflow.statemachine.state.State; import lombok.var; import lombok.extern.slf4j.Slf4j; @@ -23,34 +23,26 @@ public class TaskLog { @GetMapping(path = "/test") public ResponseEntity Processing() throws InterruptedException { - - // var state = StateServerFactory.getStateServer().getFsm().getTaskState(); - - + SyncDataClosure closure = new SyncDataClosure() { @Override public void run(Status status) { - synchronized(lockObject) { - lockObject.notify(); - } + log.info(getState().toString()); } }; - var state = new TaskState(); - state.setTaskQueueSize(1); - closure.setTaskState(state); - StateServerFactory.getStateServer().readIndexState(true, closure); - - synchronized(closure.lockObject) { - closure.lockObject.wait(); - } - - + + var state = new State(); + closure.setState(state); + + log.info(StateServerFactory.getStateServer().getFsm().getState().toString() ); + // state.getWorker().setPeerId(StateServerFactory.getStateServer().getNode().getNodeId().getPeerId()); + // state.getWorker().setTaskQueueSize(1); - + StateServerFactory.getStateServer().readIndexState(true, closure); final Response response = new Response(); response.Code = HttpStatus.OK; - response.Message = closure.getTaskState().toString(); + response.Message = "ok"; return new ResponseEntity(response, HttpStatus.OK); } diff --git a/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java b/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java index 454c8ba..9fc88e3 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java @@ -25,8 +25,8 @@ import com.alipay.sofa.jraft.storage.snapshot.SnapshotWriter; import com.alipay.sofa.jraft.util.Endpoint; import com.alipay.sofa.jraft.util.Utils; import com.yuandian.dataflow.statemachine.rpc.SMResponse; -import com.yuandian.dataflow.statemachine.rpc.SyncData; -import com.yuandian.dataflow.statemachine.rpc.TaskState; +import com.yuandian.dataflow.statemachine.rpc.SyncDataRequest; +import com.yuandian.dataflow.statemachine.state.State; import lombok.var; import lombok.extern.slf4j.Slf4j; @@ -39,15 +39,14 @@ import lombok.extern.slf4j.Slf4j; * 2018-Apr-09 4:52:31 PM */ @Slf4j - public class StateMachine extends StateMachineAdapter { // private static final Logger LOG = LoggerFactory.getLogger(StateMachine.class); /** - * Counter value + * State value 全局使用的唯一状态 */ - private TaskState taskState = new TaskState(); + private State state = new State(); /** * Leader term */ @@ -58,10 +57,10 @@ public class StateMachine extends StateMachineAdapter { } /** - * Returns current value. + * Returns current value. 只有Get 操作状态由协议流程决定 Apply */ - public TaskState getTaskState() { - return taskState; + public State getState() { + return state; } @Override @@ -72,17 +71,17 @@ public class StateMachine extends StateMachineAdapter { // This task is applied by this node, get value from closure to avoid additional // parsing. var closure = (SyncDataClosure)iter.done(); - taskState = closure.getTaskState(); - log.info("SyncDataClosure(done) taskState:{} leaderTerm:{}",taskState, this.leaderTerm); - closure.success(taskState); + state = closure.getState(); + log.info("SyncDataClosure(done) taskState:{} leaderTerm:{}",state, this.leaderTerm); + closure.success(state); closure.run(Status.OK()); } else { // Have to parse FetchAddRequest from this user log. final ByteBuffer data = iter.getData(); try { - taskState = SerializerManager.getSerializer(SerializerManager.Hessian2).deserialize( - data.array(), TaskState.class.getName()); - log.info("SyncDataClosure(null) taskState:{} leaderTerm:{}", taskState, this.leaderTerm); + state = SerializerManager.getSerializer(SerializerManager.Hessian2).deserialize( + data.array(), State.class.getName()); + log.info("SyncDataClosure(null) taskState:{} leaderTerm:{}", state, this.leaderTerm); } catch (CodecException e) { e.printStackTrace(); } diff --git a/src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java b/src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java index 25bd435..a811f2a 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java @@ -9,7 +9,10 @@ package com.yuandian.dataflow.statemachine; import java.io.File; import java.nio.ByteBuffer; import java.util.concurrent.Executor; +import java.util.concurrent.SynchronousQueue; +import java.util.concurrent.ThreadPoolExecutor; +import com.alipay.remoting.NamedThreadFactory; import com.alipay.remoting.exception.CodecException; import com.alipay.remoting.serialization.SerializerManager; import com.alipay.sofa.jraft.JRaftUtils; @@ -27,10 +30,12 @@ import com.alipay.sofa.jraft.option.NodeOptions; import com.alipay.sofa.jraft.rpc.impl.BoltRaftRpcFactory; import com.alipay.sofa.jraft.util.BytesUtil; import com.alipay.sofa.jraft.util.Endpoint; +import com.alipay.sofa.jraft.util.ThreadPoolUtil; import com.yuandian.dataflow.statemachine.rpc.SMResponse; -import com.yuandian.dataflow.statemachine.rpc.SyncData; +import com.yuandian.dataflow.statemachine.rpc.SyncDataRequest; import com.yuandian.dataflow.statemachine.rpc.SyncDataProcessor; -import com.yuandian.dataflow.statemachine.rpc.TaskState; +import com.yuandian.dataflow.statemachine.state.State; +import com.yuandian.dataflow.statemachine.state.WorkerState; import lombok.Getter; import lombok.Setter; @@ -54,6 +59,27 @@ public class StateServerFactory { throw new Exception("重复初始化 InitStateServer"); } ss = new StateServerFactory.StateServer(peerstr, conf); + + + ss.readIndexState(true, new SyncDataClosure() { + @Override + public void run(Status status) { + log.info("add peerid {}", getState()); + var wstate = getState().getWorkers().get(ss.node.getNodeId().getPeerId()); + if(wstate == null) { + wstate = new WorkerState(); + getState().getWorkers().put(ss.node.getNodeId().getPeerId(), wstate); + log.info("update: {}", getState()); + ss.applyState(getState(), new SyncDataClosure() { + @Override + public void run(Status status) { + log.info("{} add workers", ss.node.getNodeId().getPeerId()); + } + } ); + } + } + + }); } // 获取状态服务的对象 @@ -70,7 +96,7 @@ public class StateServerFactory { private StateMachine fsm; private String groupId = "dataflow"; - private Executor readIndexExecutor; + private Executor readIndexExecutor = createReadIndexExecutor(); public StateServer(String addr, Configuration conf) { String[] peers = new String[]{"localhost:4440","localhost:4441","localhost:4442"}; @@ -100,31 +126,32 @@ public class StateServerFactory { fsm = new StateMachine(); // 状态实例初始化 nodeOptions.setFsm(fsm); - cluster = new RaftGroupService(groupId, serverId, nodeOptions); + cluster = new RaftGroupService(groupId, serverId, nodeOptions); cluster.getRpcServer().registerProcessor(new SyncDataProcessor()); - - - - node = cluster.start(); + + if(node.isLeader()) { + + } + } public boolean isLeader() { return this.fsm.isLeader(); } - public TaskState getTaskState() { - return this.fsm.getTaskState(); + public State getState() { + return this.fsm.getState(); } - public void applyState(TaskState state, SyncDataClosure closure) { + public void applyState(State state, SyncDataClosure closure) { if (!ss.isLeader()) { ss.handlerNotLeaderError(closure); return; } try { - closure.setTaskState(state); + closure.setState(state); final Task task = new Task(); task.setData(ByteBuffer.wrap(SerializerManager.getSerializer(SerializerManager.Hessian2).serialize(state))); task.setDone(closure); @@ -140,9 +167,8 @@ public class StateServerFactory { public void readIndexState(final boolean readOnlySafe, final SyncDataClosure closure) { if(!readOnlySafe){ - - closure.setTaskState(getTaskState()); - closure.success(getTaskState()); + closure.setState(getState()); + closure.success(getState()); closure.run(Status.OK()); return; } @@ -150,23 +176,19 @@ public class StateServerFactory { getNode().readIndex(BytesUtil.EMPTY_BYTES, new ReadIndexClosure() { @Override public void run(Status status, long index, byte[] reqCtx) { - if(status.isOk()){ - if(closure.getTaskState() != null){ - applyState(closure.getTaskState(), closure); - } else { - closure.setTaskState(getTaskState()); - closure.success(getTaskState()); - closure.run(Status.OK()); - } - + if(status.isOk()){ + log.info("readIndex {}", getState()); + closure.setState(getState()); + closure.success(getState()); + closure.run(Status.OK()); return; } readIndexExecutor.execute(() -> { if(isLeader()){ log.info("Fail to get value with 'ReadIndex': {}, try to applying to the state machine.", status); - applyState(getTaskState(), closure); + applyState(getState(), closure); }else { handlerNotLeaderError(closure); } @@ -176,7 +198,6 @@ public class StateServerFactory { } public SMResponse redirect() { - final SMResponse response = new SMResponse(); response.setSuccess(false); if (this.node != null) { @@ -186,22 +207,35 @@ public class StateServerFactory { } } return response; - } public void handlerNotLeaderError(final SyncDataClosure closure) { closure.failure("Not leader.", redirect().getRedirect()); closure.run(new Status(RaftError.EPERM, "Not leader")); } + + + private Executor createReadIndexExecutor() { + // final StoreEngineOptions opts = new StoreEngineOptions(); + // return StoreEngineHelper.createReadIndexExecutor(opts.getReadIndexCoreThreads()); + + return ThreadPoolUtil.newBuilder() // + .poolName("CounterPool") // + .enableMetric(true) // + .coreThreads(4) // + .maximumThreads(4) // + .keepAliveSeconds(60L) // + .workQueue(new SynchronousQueue<>()) // + .threadFactory(new NamedThreadFactory("CounterService", true)) // + .rejectedHandler(new ThreadPoolExecutor.AbortPolicy()) // + .build(); + } } - public static void main(String[] args) throws InterruptedException, RemotingException { var rpcClient = new BoltRaftRpcFactory().createRpcClient(); - rpcClient.init(new CliOptions()); - - var resp = rpcClient.invokeSync(new Endpoint("localhost",4441), new SyncData(), 5000); + var resp = rpcClient.invokeSync(new Endpoint("localhost",4441), new SyncDataRequest(), 5000); log.info("{}", resp); } } diff --git a/src/main/java/com/yuandian/dataflow/statemachine/SyncDataClosure.java b/src/main/java/com/yuandian/dataflow/statemachine/SyncDataClosure.java index 7a83439..3d0b891 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/SyncDataClosure.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/SyncDataClosure.java @@ -4,7 +4,7 @@ import com.alipay.sofa.jraft.Closure; import com.alipay.sofa.jraft.Status; import com.alipay.sofa.jraft.entity.PeerId; import com.yuandian.dataflow.statemachine.rpc.SMResponse; -import com.yuandian.dataflow.statemachine.rpc.TaskState; +import com.yuandian.dataflow.statemachine.state.State; import lombok.Getter; import lombok.Setter; @@ -23,15 +23,14 @@ public abstract class SyncDataClosure implements Closure { // 状态机的统一响应 private SMResponse response; // 代表任务状态 - private TaskState taskState; + private State state; - public Object lockObject = new Object(); + public Object locksync = new Object(); public SyncDataClosure() { } - public void failure(final String errorMsg, final PeerId redirect) { final SMResponse response = new SMResponse(); response.setSuccess(false); @@ -40,11 +39,10 @@ public abstract class SyncDataClosure implements Closure { setResponse(response); } - public void success(final TaskState value) { + public void success(final State value) { final SMResponse response = new SMResponse(); response.setState(value); response.setSuccess(true); setResponse(response); } - } diff --git a/src/main/java/com/yuandian/dataflow/statemachine/rpc/SMResponse.java b/src/main/java/com/yuandian/dataflow/statemachine/rpc/SMResponse.java index 8a260f2..8e28092 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/rpc/SMResponse.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/rpc/SMResponse.java @@ -9,6 +9,7 @@ package com.yuandian.dataflow.statemachine.rpc; import java.io.Serializable; import com.alipay.sofa.jraft.entity.PeerId; +import com.yuandian.dataflow.statemachine.state.State; import lombok.Getter; import lombok.Setter; @@ -29,7 +30,7 @@ public class SMResponse implements Serializable { private static final long serialVersionUID = 1L; - private TaskState state; + private State state; private boolean success; diff --git a/src/main/java/com/yuandian/dataflow/statemachine/rpc/SyncDataProcessor.java b/src/main/java/com/yuandian/dataflow/statemachine/rpc/SyncDataProcessor.java index 2181cb1..0e1f4ae 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/rpc/SyncDataProcessor.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/rpc/SyncDataProcessor.java @@ -32,10 +32,10 @@ import lombok.extern.slf4j.Slf4j; *2022年7月12日-11:10:54 */ @Slf4j -public class SyncDataProcessor implements RpcProcessor { +public class SyncDataProcessor implements RpcProcessor { @Override - public void handleRequest(RpcContext rpcCtx, SyncData request) { + public void handleRequest(RpcContext rpcCtx, SyncDataRequest request) { log.info("request: {}", request); @@ -47,12 +47,12 @@ public class SyncDataProcessor implements RpcProcessor { } }; - StateServerFactory.getStateServer().applyState(request.getTaskState(), closure); + StateServerFactory.getStateServer().applyState(request.getState(), closure); } @Override public String interest() { - return SyncData.class.getName(); + return SyncDataRequest.class.getName(); } diff --git a/src/main/java/com/yuandian/dataflow/statemachine/rpc/SyncData.java b/src/main/java/com/yuandian/dataflow/statemachine/rpc/SyncDataRequest.java similarity index 65% rename from src/main/java/com/yuandian/dataflow/statemachine/rpc/SyncData.java rename to src/main/java/com/yuandian/dataflow/statemachine/rpc/SyncDataRequest.java index e2349e3..70e7228 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/rpc/SyncData.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/rpc/SyncDataRequest.java @@ -9,6 +9,7 @@ package com.yuandian.dataflow.statemachine.rpc; import java.io.Serializable; import com.alipay.sofa.jraft.Closure; +import com.yuandian.dataflow.statemachine.state.State; import lombok.Getter; import lombok.Setter; @@ -16,7 +17,7 @@ import lombok.ToString; import lombok.extern.slf4j.Slf4j; /** - * description + * 同步状态时, 需要用的结构类. 新增的状态可以在 State结构里添加 * * @author eson *2022年7月11日-16:01:07 @@ -25,12 +26,9 @@ import lombok.extern.slf4j.Slf4j; @Getter @Setter @ToString -public class SyncData implements Serializable { +public class SyncDataRequest implements Serializable { private static final long serialVersionUID = 1L; + private State state; - private TaskState taskState; - - - } diff --git a/src/main/java/com/yuandian/dataflow/statemachine/rpc/TaskState.java b/src/main/java/com/yuandian/dataflow/statemachine/state/State.java similarity index 68% rename from src/main/java/com/yuandian/dataflow/statemachine/rpc/TaskState.java rename to src/main/java/com/yuandian/dataflow/statemachine/state/State.java index af05361..c48a18f 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/rpc/TaskState.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/state/State.java @@ -4,7 +4,7 @@ * @author eson *2022年7月13日-09:11:26 */ -package com.yuandian.dataflow.statemachine.rpc; +package com.yuandian.dataflow.statemachine.state; import java.io.Serializable; @@ -19,9 +19,10 @@ import java.lang.management.ManagementFactory; import java.lang.management.OperatingSystemMXBean; import java.lang.reflect.Method; import java.lang.reflect.Modifier; +import java.util.HashMap; /** - * 代表任务状态 暂时全局使用这个结构 + * 代表任务状态 暂时全局使用这个结构. 添加新增状态 * * @author eson *2022年7月13日-09:11:26 @@ -30,13 +31,9 @@ import java.lang.reflect.Modifier; @Getter @Setter @ToString -public class TaskState implements Serializable { +public class State implements Serializable { + private static final long serialVersionUID = -1L; - // 节点的对应peerID - private PeerId peerId; - private long taskQueueSize; - - - + private HashMap workers = new HashMap<>(); } diff --git a/src/main/java/com/yuandian/dataflow/statemachine/state/WorkerState.java b/src/main/java/com/yuandian/dataflow/statemachine/state/WorkerState.java new file mode 100644 index 0000000..bc7e058 --- /dev/null +++ b/src/main/java/com/yuandian/dataflow/statemachine/state/WorkerState.java @@ -0,0 +1,32 @@ +/** + * description + * + * @author eson + *2022年7月15日-10:04:00 + */ +package com.yuandian.dataflow.statemachine.state; + +import java.io.Serializable; + +import com.alipay.sofa.jraft.entity.PeerId; + +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; + +/** + * description + * + * @author eson + *2022年7月15日-10:04:00 + */ +@Getter +@Setter +@ToString +public class WorkerState implements Serializable { + + private static final long serialVersionUID = -1L; + // 节点的对应peerID + public PeerId peerId; + public long taskQueueSize; +} diff --git a/src/test/java/com/yuandian/dataflow/statemachine/StateMachineTest.java b/src/test/java/com/yuandian/dataflow/statemachine/StateMachineTest.java index b8c37b9..1384ebe 100644 --- a/src/test/java/com/yuandian/dataflow/statemachine/StateMachineTest.java +++ b/src/test/java/com/yuandian/dataflow/statemachine/StateMachineTest.java @@ -11,8 +11,8 @@ import com.alipay.sofa.jraft.rpc.InvokeCallback; import com.alipay.sofa.jraft.rpc.impl.BoltRaftRpcFactory; import com.alipay.sofa.jraft.util.Endpoint; import com.yuandian.dataflow.statemachine.rpc.SMResponse; -import com.yuandian.dataflow.statemachine.rpc.SyncData; -import com.yuandian.dataflow.statemachine.rpc.TaskState; +import com.yuandian.dataflow.statemachine.rpc.SyncDataRequest; +import com.yuandian.dataflow.statemachine.state.State; import lombok.var; import lombok.extern.slf4j.Slf4j; @@ -25,9 +25,9 @@ public class StateMachineTest { rpcClient.init(new CliOptions()); - var fstate = new TaskState(); - var fdata = new SyncData(); - fdata.setTaskState(fstate); + var fstate = new State(); + var fdata = new SyncDataRequest(); + fdata.setState(fstate); var leader = new Endpoint("localhost",4441); SMResponse resp = (SMResponse)rpcClient.invokeSync(leader, fdata @@ -44,20 +44,21 @@ public class StateMachineTest { int i = 0 ; while(true) { - var state = new TaskState(); - var data = new SyncData(); - data.setTaskState(state); + var state = new State(); + var request = new SyncDataRequest(); // 创建请求 + request.setState(state); // 添加请求的参数 - state.setPeerId( PeerId.parsePeer("localhost:2222") ); + var wstate = state.getWorkers(); - state.setTaskQueueSize(i); + // state.getWorker().setPeerId( PeerId.parsePeer("localhost:2222") ); + // state.getWorker().setTaskQueueSize(i); var pi = i ; i++; if (i >= 1000) { break; } - rpcClient.invokeAsync(leader, data, new InvokeCallback() { + rpcClient.invokeAsync(leader, request, new InvokeCallback() { @Override public void complete(Object result, Throwable err) { // SMResponse resp = (SMResponse)result; diff --git a/start.sh b/start.sh index 5997f9d..66d3c5d 100755 --- a/start.sh +++ b/start.sh @@ -6,4 +6,4 @@ sleep 2 screen -dmS raft-0 -L java -jar target/dataflow-1.0.0-SNAPSHOT.jar 0 screen -dmS raft-1 -L java -jar target/dataflow-1.0.0-SNAPSHOT.jar 1 -screen -dmS raft-2 -L java -jar target/dataflow-1.0.0-SNAPSHOT.jar 2 +screen -dmS raft-2 -L java -jar target/dataflow-1.0.0-SNAPSHOT.jar 2 \ No newline at end of file From 493f3d4907d4b45d9297a3895f4ec6b39e0dcf59 Mon Sep 17 00:00:00 2001 From: huangsimin Date: Mon, 18 Jul 2022 03:07:52 +0800 Subject: [PATCH 07/37] TODO --- pom.xml | 4 +- .../java/com/yuandian/dataflow/Server.java | 26 +--- .../yuandian/dataflow/controller/TaskLog.java | 10 +- .../java/com/yuandian/dataflow/projo/Doc.java | 2 +- .../dataflow/statemachine/StateMachine.java | 8 +- .../statemachine/StateServerFactory.java | 114 ++++++++++-------- ...{SyncDataClosure.java => SyncClosure.java} | 17 ++- .../statemachine/rpc/RequestCondition.java | 21 ++++ ...SyncDataRequest.java => RequestState.java} | 5 +- .../rpc/{SMResponse.java => ResponseSM.java} | 2 +- .../rpc/SyncConditionProcessor.java | 59 +++++++++ ...Processor.java => SyncStateProcessor.java} | 13 +- .../statemachine/StateMachineTest.java | 6 +- start.sh | 10 +- 14 files changed, 188 insertions(+), 109 deletions(-) rename src/main/java/com/yuandian/dataflow/statemachine/{SyncDataClosure.java => SyncClosure.java} (70%) create mode 100644 src/main/java/com/yuandian/dataflow/statemachine/rpc/RequestCondition.java rename src/main/java/com/yuandian/dataflow/statemachine/rpc/{SyncDataRequest.java => RequestState.java} (85%) rename src/main/java/com/yuandian/dataflow/statemachine/rpc/{SMResponse.java => ResponseSM.java} (93%) create mode 100644 src/main/java/com/yuandian/dataflow/statemachine/rpc/SyncConditionProcessor.java rename src/main/java/com/yuandian/dataflow/statemachine/rpc/{SyncDataProcessor.java => SyncStateProcessor.java} (77%) diff --git a/pom.xml b/pom.xml index fc86a3e..384412f 100644 --- a/pom.xml +++ b/pom.xml @@ -192,7 +192,7 @@ 1.6.2 - + org.springframework.boot spring-boot-maven-plugin diff --git a/src/main/java/com/yuandian/dataflow/Server.java b/src/main/java/com/yuandian/dataflow/Server.java index e1fbba3..7702caa 100644 --- a/src/main/java/com/yuandian/dataflow/Server.java +++ b/src/main/java/com/yuandian/dataflow/Server.java @@ -15,10 +15,10 @@ import com.alipay.sofa.jraft.RaftGroupService; import com.alipay.sofa.jraft.conf.Configuration; import com.alipay.sofa.jraft.entity.PeerId; import com.alipay.sofa.jraft.option.NodeOptions; -import com.yuandian.dataflow.statemachine.SyncDataClosure; +import com.yuandian.dataflow.statemachine.SyncClosure; import com.yuandian.dataflow.statemachine.StateMachine; import com.yuandian.dataflow.statemachine.StateServerFactory; -import com.yuandian.dataflow.statemachine.rpc.SyncDataProcessor; +import com.yuandian.dataflow.statemachine.rpc.SyncStateProcessor; import lombok.var; import lombok.extern.slf4j.Slf4j; @@ -54,29 +54,7 @@ public class Server { Configuration conf = JRaftUtils.getConfiguration("localhost:4440,localhost:4441,localhost:4442"); StateServerFactory.InitStateServer(peeridstr, conf); - - // Thread printer = new Thread( new Runnable(){ - - // @Override - // public void run() { - // // TODO Auto-generated method stub - // while(true) { - // var state = StateServerFactory.getStateServer().getFsm().getState(); - // log.info("{}", state); - // try { - // Thread.sleep(1000); - // } catch (InterruptedException e) { - // // TODO Auto-generated catch block - // e.printStackTrace(); - // } - // } - // } - - // } ); - // printer.start(); - - System.setProperty("server.port", sprPort); var app = SpringApplication.run(Server.class, args); app.start(); diff --git a/src/main/java/com/yuandian/dataflow/controller/TaskLog.java b/src/main/java/com/yuandian/dataflow/controller/TaskLog.java index 59ddb33..443ab54 100644 --- a/src/main/java/com/yuandian/dataflow/controller/TaskLog.java +++ b/src/main/java/com/yuandian/dataflow/controller/TaskLog.java @@ -9,7 +9,7 @@ import org.springframework.web.bind.annotation.RequestParam; import com.alipay.sofa.jraft.Status; import com.yuandian.dataflow.projo.Response; import com.yuandian.dataflow.statemachine.StateServerFactory; -import com.yuandian.dataflow.statemachine.SyncDataClosure; +import com.yuandian.dataflow.statemachine.SyncClosure; import com.yuandian.dataflow.statemachine.state.State; import lombok.var; @@ -24,17 +24,17 @@ public class TaskLog { @GetMapping(path = "/test") public ResponseEntity Processing() throws InterruptedException { - SyncDataClosure closure = new SyncDataClosure() { + SyncClosure closure = new SyncClosure() { @Override public void run(Status status) { - log.info(getState().toString()); + log.error("{} {}",getValue().toString(), getValue().getWorkers().size()); } }; var state = new State(); - closure.setState(state); + closure.setValue(state); - log.info(StateServerFactory.getStateServer().getFsm().getState().toString() ); + log.error(StateServerFactory.getStateServer().getFsm().getState().toString() ); // state.getWorker().setPeerId(StateServerFactory.getStateServer().getNode().getNodeId().getPeerId()); // state.getWorker().setTaskQueueSize(1); diff --git a/src/main/java/com/yuandian/dataflow/projo/Doc.java b/src/main/java/com/yuandian/dataflow/projo/Doc.java index 8e56325..502695f 100644 --- a/src/main/java/com/yuandian/dataflow/projo/Doc.java +++ b/src/main/java/com/yuandian/dataflow/projo/Doc.java @@ -19,7 +19,7 @@ import lombok.Setter; -@BsonDiscriminator + @Getter @Setter public final class Doc extends Document { diff --git a/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java b/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java index 9fc88e3..1741024 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java @@ -24,8 +24,8 @@ import com.alipay.sofa.jraft.storage.snapshot.SnapshotReader; import com.alipay.sofa.jraft.storage.snapshot.SnapshotWriter; import com.alipay.sofa.jraft.util.Endpoint; import com.alipay.sofa.jraft.util.Utils; -import com.yuandian.dataflow.statemachine.rpc.SMResponse; -import com.yuandian.dataflow.statemachine.rpc.SyncDataRequest; +import com.yuandian.dataflow.statemachine.rpc.ResponseSM; +import com.yuandian.dataflow.statemachine.rpc.RequestState; import com.yuandian.dataflow.statemachine.state.State; import lombok.var; @@ -70,8 +70,8 @@ public class StateMachine extends StateMachineAdapter { if (iter.done() != null) { // This task is applied by this node, get value from closure to avoid additional // parsing. - var closure = (SyncDataClosure)iter.done(); - state = closure.getState(); + var closure = (SyncClosure)iter.done(); + state = closure.getValue(); log.info("SyncDataClosure(done) taskState:{} leaderTerm:{}",state, this.leaderTerm); closure.success(state); closure.run(Status.OK()); diff --git a/src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java b/src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java index a811f2a..2945937 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java @@ -14,6 +14,7 @@ import java.util.concurrent.ThreadPoolExecutor; import com.alipay.remoting.NamedThreadFactory; import com.alipay.remoting.exception.CodecException; + import com.alipay.remoting.serialization.SerializerManager; import com.alipay.sofa.jraft.JRaftUtils; import com.alipay.sofa.jraft.Node; @@ -27,13 +28,15 @@ import com.alipay.sofa.jraft.error.RaftError; import com.alipay.sofa.jraft.error.RemotingException; import com.alipay.sofa.jraft.option.CliOptions; import com.alipay.sofa.jraft.option.NodeOptions; +import com.alipay.sofa.jraft.rpc.RpcClient; import com.alipay.sofa.jraft.rpc.impl.BoltRaftRpcFactory; import com.alipay.sofa.jraft.util.BytesUtil; import com.alipay.sofa.jraft.util.Endpoint; import com.alipay.sofa.jraft.util.ThreadPoolUtil; -import com.yuandian.dataflow.statemachine.rpc.SMResponse; -import com.yuandian.dataflow.statemachine.rpc.SyncDataRequest; -import com.yuandian.dataflow.statemachine.rpc.SyncDataProcessor; +import com.yuandian.dataflow.statemachine.rpc.ResponseSM; +import com.yuandian.dataflow.statemachine.rpc.RequestCondition; +import com.yuandian.dataflow.statemachine.rpc.RequestState; +import com.yuandian.dataflow.statemachine.rpc.SyncStateProcessor; import com.yuandian.dataflow.statemachine.state.State; import com.yuandian.dataflow.statemachine.state.WorkerState; @@ -53,33 +56,23 @@ import lombok.extern.slf4j.Slf4j; public class StateServerFactory { private static StateServer ss; - // 必须初始化 + public static void InitStateServer(String peerstr, Configuration conf) throws Exception { if(ss != null) { throw new Exception("重复初始化 InitStateServer"); } ss = new StateServerFactory.StateServer(peerstr, conf); + log.error("init peerid {}", ss.node.getNodeId().getPeerId()); + + ss.getNode().join(); + var request = new RequestCondition(); + request.setWorkerState( new WorkerState() ); + request.getWorkerState().setPeerId( ss.cluster.getServerId() ); + log.error("{}", ss.getNode().getNodeMetrics() ); + - - ss.readIndexState(true, new SyncDataClosure() { - @Override - public void run(Status status) { - log.info("add peerid {}", getState()); - var wstate = getState().getWorkers().get(ss.node.getNodeId().getPeerId()); - if(wstate == null) { - wstate = new WorkerState(); - getState().getWorkers().put(ss.node.getNodeId().getPeerId(), wstate); - log.info("update: {}", getState()); - ss.applyState(getState(), new SyncDataClosure() { - @Override - public void run(Status status) { - log.info("{} add workers", ss.node.getNodeId().getPeerId()); - } - } ); - } - } - - }); + ResponseSM resp = (ResponseSM)ss.getRpcClient().invokeSync(ss.getNode().getLeaderId().getEndpoint(), request, 5000); + log.info("{}", resp); } // 获取状态服务的对象 @@ -90,6 +83,10 @@ public class StateServerFactory { @Getter @Setter public static class StateServer { + + RpcClient rpcClient; + + private Node node; private RaftGroupService cluster; @@ -127,31 +124,29 @@ public class StateServerFactory { nodeOptions.setFsm(fsm); cluster = new RaftGroupService(groupId, serverId, nodeOptions); - cluster.getRpcServer().registerProcessor(new SyncDataProcessor()); + cluster.getRpcServer().registerProcessor(new SyncStateProcessor()); node = cluster.start(); - if(node.isLeader()) { - - } - + rpcClient = new BoltRaftRpcFactory().createRpcClient(); + rpcClient.init(new CliOptions()); } public boolean isLeader() { return this.fsm.isLeader(); } - public State getState() { + public State getFSMState() { return this.fsm.getState(); } - public void applyState(State state, SyncDataClosure closure) { + public void applyState(State state, SyncClosure closure) { if (!ss.isLeader()) { ss.handlerNotLeaderError(closure); return; } try { - closure.setState(state); + closure.setValue(state); final Task task = new Task(); task.setData(ByteBuffer.wrap(SerializerManager.getSerializer(SerializerManager.Hessian2).serialize(state))); task.setDone(closure); @@ -164,31 +159,52 @@ public class StateServerFactory { } } - public void readIndexState(final boolean readOnlySafe, final SyncDataClosure closure) { - - if(!readOnlySafe){ - closure.setState(getState()); - closure.success(getState()); - closure.run(Status.OK()); + public void applyWorkerState(WorkerState state, SyncClosure closure) { + if (!ss.isLeader()) { + ss.handlerNotLeaderError(closure); return; } + var wmap = getFSMState().getWorkers(); + var wstate = wmap.get(ss.node.getNodeId().getPeerId()); + if(wstate == null) { + wstate = new WorkerState(); + wmap.put(ss.node.getNodeId().getPeerId(), wstate); + log.error("update: {}", wmap.size()); + ss.applyState(getFSMState(), new SyncClosure() { + @Override + public void run(Status status) { + log.error("{} add workers", ss.node.getNodeId().getPeerId()); + } + } ); + } + } + + public void readIndexState(final boolean readOnlySafe, final SyncClosure closure) { + + closure.setValue(getFSMState()); + if(!readOnlySafe){ + + closure.success(getFSMState()); + closure.run(Status.OK()); + return; + } + getNode().readIndex(BytesUtil.EMPTY_BYTES, new ReadIndexClosure() { @Override public void run(Status status, long index, byte[] reqCtx) { if(status.isOk()){ - log.info("readIndex {}", getState()); - closure.setState(getState()); - closure.success(getState()); + log.error("readIndex {}", getFSMState()); + closure.success(getFSMState()); closure.run(Status.OK()); return; } readIndexExecutor.execute(() -> { if(isLeader()){ - log.info("Fail to get value with 'ReadIndex': {}, try to applying to the state machine.", status); - applyState(getState(), closure); + log.error("Fail to get value with 'ReadIndex': {}, try to applying to the state machine.", status); + applyState(getFSMState(), closure); }else { handlerNotLeaderError(closure); } @@ -197,8 +213,8 @@ public class StateServerFactory { }); } - public SMResponse redirect() { - final SMResponse response = new SMResponse(); + public ResponseSM redirect() { + final ResponseSM response = new ResponseSM(); response.setSuccess(false); if (this.node != null) { final PeerId leader = this.node.getLeaderId(); @@ -209,7 +225,7 @@ public class StateServerFactory { return response; } - public void handlerNotLeaderError(final SyncDataClosure closure) { + public void handlerNotLeaderError(final SyncClosure closure) { closure.failure("Not leader.", redirect().getRedirect()); closure.run(new Status(RaftError.EPERM, "Not leader")); } @@ -220,13 +236,13 @@ public class StateServerFactory { // return StoreEngineHelper.createReadIndexExecutor(opts.getReadIndexCoreThreads()); return ThreadPoolUtil.newBuilder() // - .poolName("CounterPool") // + .poolName("ReadIndexPool") // .enableMetric(true) // .coreThreads(4) // .maximumThreads(4) // .keepAliveSeconds(60L) // .workQueue(new SynchronousQueue<>()) // - .threadFactory(new NamedThreadFactory("CounterService", true)) // + .threadFactory(new NamedThreadFactory("ReadIndexService", true)) // .rejectedHandler(new ThreadPoolExecutor.AbortPolicy()) // .build(); } @@ -235,7 +251,7 @@ public class StateServerFactory { public static void main(String[] args) throws InterruptedException, RemotingException { var rpcClient = new BoltRaftRpcFactory().createRpcClient(); rpcClient.init(new CliOptions()); - var resp = rpcClient.invokeSync(new Endpoint("localhost",4441), new SyncDataRequest(), 5000); + var resp = rpcClient.invokeSync(new Endpoint("localhost",4441), new RequestState(), 5000); log.info("{}", resp); } } diff --git a/src/main/java/com/yuandian/dataflow/statemachine/SyncDataClosure.java b/src/main/java/com/yuandian/dataflow/statemachine/SyncClosure.java similarity index 70% rename from src/main/java/com/yuandian/dataflow/statemachine/SyncDataClosure.java rename to src/main/java/com/yuandian/dataflow/statemachine/SyncClosure.java index 3d0b891..f19f155 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/SyncDataClosure.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/SyncClosure.java @@ -3,7 +3,7 @@ package com.yuandian.dataflow.statemachine; import com.alipay.sofa.jraft.Closure; import com.alipay.sofa.jraft.Status; import com.alipay.sofa.jraft.entity.PeerId; -import com.yuandian.dataflow.statemachine.rpc.SMResponse; +import com.yuandian.dataflow.statemachine.rpc.ResponseSM; import com.yuandian.dataflow.statemachine.state.State; import lombok.Getter; @@ -18,21 +18,20 @@ import org.slf4j.LoggerFactory; @Getter @Setter @ToString -public abstract class SyncDataClosure implements Closure { +public abstract class SyncClosure implements Closure { // 状态机的统一响应 - private SMResponse response; + private ResponseSM response; // 代表任务状态 - private State state; + private T value; - public Object locksync = new Object(); - - public SyncDataClosure() { + + public SyncClosure() { } public void failure(final String errorMsg, final PeerId redirect) { - final SMResponse response = new SMResponse(); + final ResponseSM response = new ResponseSM(); response.setSuccess(false); response.setMsg(errorMsg); response.setRedirect(redirect); @@ -40,7 +39,7 @@ public abstract class SyncDataClosure implements Closure { } public void success(final State value) { - final SMResponse response = new SMResponse(); + final ResponseSM response = new ResponseSM(); response.setState(value); response.setSuccess(true); setResponse(response); diff --git a/src/main/java/com/yuandian/dataflow/statemachine/rpc/RequestCondition.java b/src/main/java/com/yuandian/dataflow/statemachine/rpc/RequestCondition.java new file mode 100644 index 0000000..2c67e0c --- /dev/null +++ b/src/main/java/com/yuandian/dataflow/statemachine/rpc/RequestCondition.java @@ -0,0 +1,21 @@ +package com.yuandian.dataflow.statemachine.rpc; + +import java.io.Serializable; + +import com.yuandian.dataflow.statemachine.state.WorkerState; + +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import lombok.extern.slf4j.Slf4j; + +@Slf4j +@Getter +@Setter +@ToString +public class RequestCondition implements Serializable { + + private static final long serialVersionUID = 1L; + + private WorkerState workerState; +} diff --git a/src/main/java/com/yuandian/dataflow/statemachine/rpc/SyncDataRequest.java b/src/main/java/com/yuandian/dataflow/statemachine/rpc/RequestState.java similarity index 85% rename from src/main/java/com/yuandian/dataflow/statemachine/rpc/SyncDataRequest.java rename to src/main/java/com/yuandian/dataflow/statemachine/rpc/RequestState.java index 70e7228..f9fb594 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/rpc/SyncDataRequest.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/rpc/RequestState.java @@ -9,6 +9,7 @@ package com.yuandian.dataflow.statemachine.rpc; import java.io.Serializable; import com.alipay.sofa.jraft.Closure; +import com.alipay.sofa.jraft.entity.PeerId; import com.yuandian.dataflow.statemachine.state.State; import lombok.Getter; @@ -26,9 +27,9 @@ import lombok.extern.slf4j.Slf4j; @Getter @Setter @ToString -public class SyncDataRequest implements Serializable { +public class RequestState implements Serializable { private static final long serialVersionUID = 1L; + private State state; - } diff --git a/src/main/java/com/yuandian/dataflow/statemachine/rpc/SMResponse.java b/src/main/java/com/yuandian/dataflow/statemachine/rpc/ResponseSM.java similarity index 93% rename from src/main/java/com/yuandian/dataflow/statemachine/rpc/SMResponse.java rename to src/main/java/com/yuandian/dataflow/statemachine/rpc/ResponseSM.java index 8e28092..5e4694f 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/rpc/SMResponse.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/rpc/ResponseSM.java @@ -26,7 +26,7 @@ import lombok.extern.slf4j.Slf4j; @Getter @Setter @ToString -public class SMResponse implements Serializable { +public class ResponseSM implements Serializable { private static final long serialVersionUID = 1L; diff --git a/src/main/java/com/yuandian/dataflow/statemachine/rpc/SyncConditionProcessor.java b/src/main/java/com/yuandian/dataflow/statemachine/rpc/SyncConditionProcessor.java new file mode 100644 index 0000000..89ca91d --- /dev/null +++ b/src/main/java/com/yuandian/dataflow/statemachine/rpc/SyncConditionProcessor.java @@ -0,0 +1,59 @@ +/** + * description + * + * @author eson + *2022年7月12日-11:10:54 + */ +package com.yuandian.dataflow.statemachine.rpc; + +import java.nio.ByteBuffer; + +import com.alipay.remoting.exception.CodecException; +import com.alipay.remoting.serialization.SerializerManager; +import com.alipay.sofa.jraft.Status; +import com.alipay.sofa.jraft.entity.Task; +import com.alipay.sofa.jraft.error.RaftError; +import com.alipay.sofa.jraft.rpc.RpcContext; +import com.alipay.sofa.jraft.rpc.RpcProcessor; +import com.yuandian.dataflow.statemachine.StateServerFactory; +import com.yuandian.dataflow.statemachine.SyncClosure; +import com.yuandian.dataflow.statemachine.StateServerFactory.StateServer; +import com.alipay.sofa.jraft.entity.PeerId; + +import org.apache.commons.lang.StringUtils; + +import lombok.var; +import lombok.extern.slf4j.Slf4j; + +/** + * description + * + * @author eson + *2022年7月12日-11:10:54 + */ +@Slf4j +public class SyncConditionProcessor implements RpcProcessor { + + @Override + public void handleRequest(RpcContext rpcCtx, RequestCondition request) { + + log.info("request: {}", request); + final SyncClosure closure = new SyncClosure() { + @Override + public void run(Status status) { + rpcCtx.sendResponse(getResponse()); + log.info("{}", status); + } + }; + + StateServerFactory.getStateServer().applyWorkerState(request.getWorkerState(), closure); + } + + @Override + public String interest() { + return RequestState.class.getName(); + } + + + +} diff --git a/src/main/java/com/yuandian/dataflow/statemachine/rpc/SyncDataProcessor.java b/src/main/java/com/yuandian/dataflow/statemachine/rpc/SyncStateProcessor.java similarity index 77% rename from src/main/java/com/yuandian/dataflow/statemachine/rpc/SyncDataProcessor.java rename to src/main/java/com/yuandian/dataflow/statemachine/rpc/SyncStateProcessor.java index 0e1f4ae..ade1afd 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/rpc/SyncDataProcessor.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/rpc/SyncStateProcessor.java @@ -16,8 +16,9 @@ import com.alipay.sofa.jraft.error.RaftError; import com.alipay.sofa.jraft.rpc.RpcContext; import com.alipay.sofa.jraft.rpc.RpcProcessor; import com.yuandian.dataflow.statemachine.StateServerFactory; -import com.yuandian.dataflow.statemachine.SyncDataClosure; +import com.yuandian.dataflow.statemachine.SyncClosure; import com.yuandian.dataflow.statemachine.StateServerFactory.StateServer; +import com.yuandian.dataflow.statemachine.state.State; import com.alipay.sofa.jraft.entity.PeerId; import org.apache.commons.lang.StringUtils; @@ -32,14 +33,14 @@ import lombok.extern.slf4j.Slf4j; *2022年7月12日-11:10:54 */ @Slf4j -public class SyncDataProcessor implements RpcProcessor { +public class SyncStateProcessor implements RpcProcessor { @Override - public void handleRequest(RpcContext rpcCtx, SyncDataRequest request) { + public void handleRequest(RpcContext rpcCtx, RequestState request) { log.info("request: {}", request); - - final SyncDataClosure closure = new SyncDataClosure() { + + final SyncClosure closure = new SyncClosure() { @Override public void run(Status status) { rpcCtx.sendResponse(getResponse()); @@ -52,7 +53,7 @@ public class SyncDataProcessor implements RpcProcessor { @Override public String interest() { - return SyncDataRequest.class.getName(); + return RequestState.class.getName(); } diff --git a/src/test/java/com/yuandian/dataflow/statemachine/StateMachineTest.java b/src/test/java/com/yuandian/dataflow/statemachine/StateMachineTest.java index 1384ebe..d4dcc53 100644 --- a/src/test/java/com/yuandian/dataflow/statemachine/StateMachineTest.java +++ b/src/test/java/com/yuandian/dataflow/statemachine/StateMachineTest.java @@ -11,7 +11,7 @@ import com.alipay.sofa.jraft.rpc.InvokeCallback; import com.alipay.sofa.jraft.rpc.impl.BoltRaftRpcFactory; import com.alipay.sofa.jraft.util.Endpoint; import com.yuandian.dataflow.statemachine.rpc.SMResponse; -import com.yuandian.dataflow.statemachine.rpc.SyncDataRequest; +import com.yuandian.dataflow.statemachine.rpc.RequestState; import com.yuandian.dataflow.statemachine.state.State; import lombok.var; @@ -26,7 +26,7 @@ public class StateMachineTest { var fstate = new State(); - var fdata = new SyncDataRequest(); + var fdata = new RequestState(); fdata.setState(fstate); var leader = new Endpoint("localhost",4441); @@ -45,7 +45,7 @@ public class StateMachineTest { while(true) { var state = new State(); - var request = new SyncDataRequest(); // 创建请求 + var request = new RequestState(); // 创建请求 request.setState(state); // 添加请求的参数 var wstate = state.getWorkers(); diff --git a/start.sh b/start.sh index 66d3c5d..003f772 100755 --- a/start.sh +++ b/start.sh @@ -4,6 +4,10 @@ screen -S raft-2 -X quit sleep 2 -screen -dmS raft-0 -L java -jar target/dataflow-1.0.0-SNAPSHOT.jar 0 -screen -dmS raft-1 -L java -jar target/dataflow-1.0.0-SNAPSHOT.jar 1 -screen -dmS raft-2 -L java -jar target/dataflow-1.0.0-SNAPSHOT.jar 2 \ No newline at end of file +screen -dmS raft-0 -L java -jar target/dataflow-1.0.0-SNAPSHOT.jar 0 +screen -dmS raft-1 -L java -jar target/dataflow-1.0.0-SNAPSHOT.jar 1 +screen -dmS raft-2 -L java -jar target/dataflow-1.0.0-SNAPSHOT.jar 2 + +screen -S raft-0 -X logfile flush 1 +screen -S raft-1 -X logfile flush 1 +screen -S raft-2 -X logfile flush 1 \ No newline at end of file From 18d329910d61dadb7314b466a6e97c091ba78100 Mon Sep 17 00:00:00 2001 From: huangsimin Date: Mon, 18 Jul 2022 15:22:20 +0800 Subject: [PATCH 08/37] Save --- .../yuandian/dataflow/controller/TaskLog.java | 8 +- .../dataflow/statemachine/StateMachine.java | 56 ++++++- .../statemachine/StateServerFactory.java | 157 ++++++++++++------ .../rpc/SyncConditionProcessor.java | 6 +- .../statemachine/rpc/SyncStateProcessor.java | 2 +- .../statemachine/StateMachineTest.java | 8 +- start.sh | 9 +- 7 files changed, 176 insertions(+), 70 deletions(-) diff --git a/src/main/java/com/yuandian/dataflow/controller/TaskLog.java b/src/main/java/com/yuandian/dataflow/controller/TaskLog.java index 443ab54..06254c7 100644 --- a/src/main/java/com/yuandian/dataflow/controller/TaskLog.java +++ b/src/main/java/com/yuandian/dataflow/controller/TaskLog.java @@ -19,8 +19,6 @@ import lombok.extern.slf4j.Slf4j; @Controller public class TaskLog { - - @GetMapping(path = "/test") public ResponseEntity Processing() throws InterruptedException { @@ -33,8 +31,12 @@ public class TaskLog { var state = new State(); closure.setValue(state); + StateServerFactory.getStateServer().useState((fsmState)->{ + log.error(fsmState.toString() ); + return fsmState; + }); - log.error(StateServerFactory.getStateServer().getFsm().getState().toString() ); + // state.getWorker().setPeerId(StateServerFactory.getStateServer().getNode().getNodeId().getPeerId()); // state.getWorker().setTaskQueueSize(1); diff --git a/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java b/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java index 1741024..91234ed 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java @@ -5,6 +5,8 @@ import java.io.IOException; import java.nio.ByteBuffer; import java.util.concurrent.Executor; import java.util.concurrent.atomic.AtomicLong; +import java.util.function.Function; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.alipay.remoting.exception.CodecException; @@ -13,6 +15,7 @@ import com.alipay.sofa.jraft.Closure; import com.alipay.sofa.jraft.Iterator; import com.alipay.sofa.jraft.Status; import com.alipay.sofa.jraft.core.StateMachineAdapter; +import com.alipay.sofa.jraft.entity.LeaderChangeContext; import com.alipay.sofa.jraft.entity.PeerId; import com.alipay.sofa.jraft.error.RaftError; import com.alipay.sofa.jraft.error.RaftException; @@ -25,8 +28,10 @@ import com.alipay.sofa.jraft.storage.snapshot.SnapshotWriter; import com.alipay.sofa.jraft.util.Endpoint; import com.alipay.sofa.jraft.util.Utils; import com.yuandian.dataflow.statemachine.rpc.ResponseSM; +import com.yuandian.dataflow.statemachine.rpc.RequestCondition; import com.yuandian.dataflow.statemachine.rpc.RequestState; import com.yuandian.dataflow.statemachine.state.State; +import com.yuandian.dataflow.statemachine.state.WorkerState; import lombok.var; import lombok.extern.slf4j.Slf4j; @@ -59,11 +64,33 @@ public class StateMachine extends StateMachineAdapter { /** * Returns current value. 只有Get 操作状态由协议流程决定 Apply */ - public State getState() { - return state; + // public State getState() { + // return state; + // } + + + /** + * Returns current value. 读取修改都在这个函数域内进行 + */ + public void useState(Function dofunc) { + synchronized(this.state) { + dofunc.apply(this.state); + } + } + + /** + * Returns current value. 读取修改都在这个函数域内进行 + */ + public void updateState(Function dofunc) { + synchronized(this.state) { + var newstate = dofunc.apply(this.state); + this.state = newstate; + } } + @Override + // @SuppressWarnings("unchecked") public void onApply(final Iterator iter) { while (iter.hasNext()) { @@ -82,6 +109,7 @@ public class StateMachine extends StateMachineAdapter { state = SerializerManager.getSerializer(SerializerManager.Hessian2).deserialize( data.array(), State.class.getName()); log.info("SyncDataClosure(null) taskState:{} leaderTerm:{}", state, this.leaderTerm); + } catch (CodecException e) { e.printStackTrace(); } @@ -113,6 +141,30 @@ public class StateMachine extends StateMachineAdapter { this.leaderTerm.set(term); super.onLeaderStart(term); + + + } + + @Override + public void onStartFollowing(LeaderChangeContext ctx) { + // TODO Auto-generated method stub + super.onStartFollowing(ctx); + + var ss = StateServerFactory.getStateServer(); + var node = ss.getNode(); + + try { + var request = new RequestCondition(); + request.setWorkerState( new WorkerState() ); + request.getWorkerState().setPeerId( ss.getCluster().getServerId() ); + log.error("------------ leader id {}", node.getLeaderId()); + ResponseSM resp; + resp = (ResponseSM)StateServerFactory.getStateServer().getRpcClient().invokeSync(node.getLeaderId().getEndpoint(), request, 5000); + log.error("{}", resp); + } catch (InterruptedException | RemotingException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } } @Override diff --git a/src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java b/src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java index 2945937..0b54ff8 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java @@ -11,10 +11,10 @@ import java.nio.ByteBuffer; import java.util.concurrent.Executor; import java.util.concurrent.SynchronousQueue; import java.util.concurrent.ThreadPoolExecutor; +import java.util.function.Function; import com.alipay.remoting.NamedThreadFactory; import com.alipay.remoting.exception.CodecException; - import com.alipay.remoting.serialization.SerializerManager; import com.alipay.sofa.jraft.JRaftUtils; import com.alipay.sofa.jraft.Node; @@ -33,9 +33,9 @@ import com.alipay.sofa.jraft.rpc.impl.BoltRaftRpcFactory; import com.alipay.sofa.jraft.util.BytesUtil; import com.alipay.sofa.jraft.util.Endpoint; import com.alipay.sofa.jraft.util.ThreadPoolUtil; -import com.yuandian.dataflow.statemachine.rpc.ResponseSM; -import com.yuandian.dataflow.statemachine.rpc.RequestCondition; import com.yuandian.dataflow.statemachine.rpc.RequestState; +import com.yuandian.dataflow.statemachine.rpc.ResponseSM; +import com.yuandian.dataflow.statemachine.rpc.SyncConditionProcessor; import com.yuandian.dataflow.statemachine.rpc.SyncStateProcessor; import com.yuandian.dataflow.statemachine.state.State; import com.yuandian.dataflow.statemachine.state.WorkerState; @@ -63,16 +63,7 @@ public class StateServerFactory { } ss = new StateServerFactory.StateServer(peerstr, conf); log.error("init peerid {}", ss.node.getNodeId().getPeerId()); - - ss.getNode().join(); - var request = new RequestCondition(); - request.setWorkerState( new WorkerState() ); - request.getWorkerState().setPeerId( ss.cluster.getServerId() ); - log.error("{}", ss.getNode().getNodeMetrics() ); - - ResponseSM resp = (ResponseSM)ss.getRpcClient().invokeSync(ss.getNode().getLeaderId().getEndpoint(), request, 5000); - log.info("{}", resp); } // 获取状态服务的对象 @@ -86,8 +77,6 @@ public class StateServerFactory { RpcClient rpcClient; - - private Node node; private RaftGroupService cluster; private StateMachine fsm; @@ -125,6 +114,7 @@ public class StateServerFactory { cluster = new RaftGroupService(groupId, serverId, nodeOptions); cluster.getRpcServer().registerProcessor(new SyncStateProcessor()); + cluster.getRpcServer().registerProcessor(new SyncConditionProcessor()); node = cluster.start(); rpcClient = new BoltRaftRpcFactory().createRpcClient(); @@ -135,8 +125,46 @@ public class StateServerFactory { return this.fsm.isLeader(); } - public State getFSMState() { - return this.fsm.getState(); + + public void useState(Function dofunc) { + + this.fsm.useState((fsmState)->{ + + + + SyncClosure closure = new SyncClosure() { + @Override + public void run(Status status) { + + } + }; + + + getNode().readIndex(BytesUtil.EMPTY_BYTES, new ReadIndexClosure() { + @Override + public void run(Status status, long index, byte[] reqCtx) { + if(status.isOk()){ + log.error("readIndex {}", fsmState); + closure.success(fsmState); + closure.run(Status.OK()); + return; + } + + readIndexExecutor.execute(() -> { + if(isLeader()){ + log.error("Fail to get value with 'ReadIndex': {}, try to applying to the state machine.", status); + applyState(fsmState, closure); + }else { + handlerNotLeaderError(closure); + } + }); + } + }); + + + + return null; + }); } public void applyState(State state, SyncClosure closure) { @@ -151,6 +179,7 @@ public class StateServerFactory { task.setData(ByteBuffer.wrap(SerializerManager.getSerializer(SerializerManager.Hessian2).serialize(state))); task.setDone(closure); StateServerFactory.getStateServer().getNode().apply(task); + } catch (CodecException e) { String errorMsg = "Fail to encode TaskState"; log.error(errorMsg, e); @@ -165,52 +194,72 @@ public class StateServerFactory { return; } - var wmap = getFSMState().getWorkers(); - var wstate = wmap.get(ss.node.getNodeId().getPeerId()); - if(wstate == null) { - wstate = new WorkerState(); - wmap.put(ss.node.getNodeId().getPeerId(), wstate); - log.error("update: {}", wmap.size()); - ss.applyState(getFSMState(), new SyncClosure() { - @Override - public void run(Status status) { - log.error("{} add workers", ss.node.getNodeId().getPeerId()); + useState((fsmState)->{ + var wmap = fsmState.getWorkers(); + var wstate = wmap.get(state.getPeerId()); + + if(wstate == null) { + wmap.put(state.getPeerId(), state); + try { + final Task task = new Task(); + log.error("{}", fsmState); + task.setData(ByteBuffer.wrap(SerializerManager.getSerializer(SerializerManager.Hessian2).serialize(fsmState))); + task.setDone(closure); + StateServerFactory.getStateServer().getNode().apply(task); + } catch (CodecException e) { + String errorMsg = "Fail to encode TaskState"; + log.error(errorMsg, e); + closure.failure(errorMsg, PeerId.emptyPeer()); + closure.run(new Status(RaftError.EINTERNAL, errorMsg)); } - } ); - } + } + + return fsmState; + }); + + + + } public void readIndexState(final boolean readOnlySafe, final SyncClosure closure) { - closure.setValue(getFSMState()); - if(!readOnlySafe){ - - closure.success(getFSMState()); - closure.run(Status.OK()); - return; - } - - getNode().readIndex(BytesUtil.EMPTY_BYTES, new ReadIndexClosure() { - @Override - public void run(Status status, long index, byte[] reqCtx) { - if(status.isOk()){ - log.error("readIndex {}", getFSMState()); - closure.success(getFSMState()); - closure.run(Status.OK()); - return; - } - - readIndexExecutor.execute(() -> { - if(isLeader()){ - log.error("Fail to get value with 'ReadIndex': {}, try to applying to the state machine.", status); - applyState(getFSMState(), closure); - }else { - handlerNotLeaderError(closure); - } - }); + useState((fsmState)->{ + closure.setValue(fsmState); + if(!readOnlySafe){ + + closure.success(fsmState); + closure.run(Status.OK()); + return fsmState; } + + getNode().readIndex(BytesUtil.EMPTY_BYTES, new ReadIndexClosure() { + @Override + public void run(Status status, long index, byte[] reqCtx) { + + if(status.isOk()){ + log.error("readIndex {}", fsmState); + closure.success(fsmState); + closure.run(Status.OK()); + return; + } + + readIndexExecutor.execute(() -> { + if(isLeader()){ + log.error("Fail to get value with 'ReadIndex': {}, try to applying to the state machine.", status); + applyState(fsmState, closure); + }else { + handlerNotLeaderError(closure); + } + }); + } + }); + + return fsmState; }); + + } public ResponseSM redirect() { diff --git a/src/main/java/com/yuandian/dataflow/statemachine/rpc/SyncConditionProcessor.java b/src/main/java/com/yuandian/dataflow/statemachine/rpc/SyncConditionProcessor.java index 89ca91d..fefff27 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/rpc/SyncConditionProcessor.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/rpc/SyncConditionProcessor.java @@ -15,9 +15,11 @@ import com.alipay.sofa.jraft.entity.Task; import com.alipay.sofa.jraft.error.RaftError; import com.alipay.sofa.jraft.rpc.RpcContext; import com.alipay.sofa.jraft.rpc.RpcProcessor; +import com.lmax.disruptor.WorkProcessor; import com.yuandian.dataflow.statemachine.StateServerFactory; import com.yuandian.dataflow.statemachine.SyncClosure; import com.yuandian.dataflow.statemachine.StateServerFactory.StateServer; +import com.yuandian.dataflow.statemachine.state.WorkerState; import com.alipay.sofa.jraft.entity.PeerId; import org.apache.commons.lang.StringUtils; @@ -38,7 +40,7 @@ public class SyncConditionProcessor implements RpcProcessor { public void handleRequest(RpcContext rpcCtx, RequestCondition request) { log.info("request: {}", request); - final SyncClosure closure = new SyncClosure() { + final SyncClosure closure = new SyncClosure() { @Override public void run(Status status) { rpcCtx.sendResponse(getResponse()); @@ -51,7 +53,7 @@ public class SyncConditionProcessor implements RpcProcessor { @Override public String interest() { - return RequestState.class.getName(); + return RequestCondition.class.getName(); } diff --git a/src/main/java/com/yuandian/dataflow/statemachine/rpc/SyncStateProcessor.java b/src/main/java/com/yuandian/dataflow/statemachine/rpc/SyncStateProcessor.java index ade1afd..5d97764 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/rpc/SyncStateProcessor.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/rpc/SyncStateProcessor.java @@ -40,7 +40,7 @@ public class SyncStateProcessor implements RpcProcessor { log.info("request: {}", request); - final SyncClosure closure = new SyncClosure() { + final SyncClosure closure = new SyncClosure() { @Override public void run(Status status) { rpcCtx.sendResponse(getResponse()); diff --git a/src/test/java/com/yuandian/dataflow/statemachine/StateMachineTest.java b/src/test/java/com/yuandian/dataflow/statemachine/StateMachineTest.java index d4dcc53..809cb28 100644 --- a/src/test/java/com/yuandian/dataflow/statemachine/StateMachineTest.java +++ b/src/test/java/com/yuandian/dataflow/statemachine/StateMachineTest.java @@ -10,7 +10,7 @@ import com.alipay.sofa.jraft.option.CliOptions; import com.alipay.sofa.jraft.rpc.InvokeCallback; import com.alipay.sofa.jraft.rpc.impl.BoltRaftRpcFactory; import com.alipay.sofa.jraft.util.Endpoint; -import com.yuandian.dataflow.statemachine.rpc.SMResponse; +import com.yuandian.dataflow.statemachine.rpc.ResponseSM; import com.yuandian.dataflow.statemachine.rpc.RequestState; import com.yuandian.dataflow.statemachine.state.State; @@ -30,12 +30,12 @@ public class StateMachineTest { fdata.setState(fstate); var leader = new Endpoint("localhost",4441); - SMResponse resp = (SMResponse)rpcClient.invokeSync(leader, fdata + ResponseSM resp = (ResponseSM)rpcClient.invokeSync(leader, fdata , 5000); log.info("{}", resp); if( resp != null && !resp.isSuccess() ) { leader = resp.getRedirect().getEndpoint(); - resp = (SMResponse)rpcClient.invokeSync(resp.getRedirect().getEndpoint(), fdata + resp = (ResponseSM)rpcClient.invokeSync(resp.getRedirect().getEndpoint(), fdata , 5000); log.info("{}", resp); } @@ -61,7 +61,7 @@ public class StateMachineTest { rpcClient.invokeAsync(leader, request, new InvokeCallback() { @Override public void complete(Object result, Throwable err) { - // SMResponse resp = (SMResponse)result; + // ResponseSM resp = (ResponseSM)result; log.info("{} {} {}", result, err, pi); } diff --git a/start.sh b/start.sh index 003f772..42bed0d 100755 --- a/start.sh +++ b/start.sh @@ -2,12 +2,13 @@ screen -S raft-0 -X quit screen -S raft-1 -X quit screen -S raft-2 -X quit -sleep 2 +sleep 1 screen -dmS raft-0 -L java -jar target/dataflow-1.0.0-SNAPSHOT.jar 0 screen -dmS raft-1 -L java -jar target/dataflow-1.0.0-SNAPSHOT.jar 1 screen -dmS raft-2 -L java -jar target/dataflow-1.0.0-SNAPSHOT.jar 2 -screen -S raft-0 -X logfile flush 1 -screen -S raft-1 -X logfile flush 1 -screen -S raft-2 -X logfile flush 1 \ No newline at end of file + +screen -S raft-0 -X logfile flush 0 +screen -S raft-1 -X logfile flush 0 +screen -S raft-2 -X logfile flush 0 \ No newline at end of file From ad78dd261389e10ec850774245f53aaafaa70026 Mon Sep 17 00:00:00 2001 From: huangsimin Date: Mon, 18 Jul 2022 17:54:37 +0800 Subject: [PATCH 09/37] =?UTF-8?q?TODO:=20=E6=9B=B4=E5=A5=BD=E8=AE=BE?= =?UTF-8?q?=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yuandian/dataflow/controller/TaskLog.java | 4 +- .../dataflow/statemachine/StateMachine.java | 20 +++--- .../statemachine/StateServerFactory.java | 72 +++++++++++-------- 3 files changed, 54 insertions(+), 42 deletions(-) diff --git a/src/main/java/com/yuandian/dataflow/controller/TaskLog.java b/src/main/java/com/yuandian/dataflow/controller/TaskLog.java index 06254c7..1360774 100644 --- a/src/main/java/com/yuandian/dataflow/controller/TaskLog.java +++ b/src/main/java/com/yuandian/dataflow/controller/TaskLog.java @@ -31,9 +31,9 @@ public class TaskLog { var state = new State(); closure.setValue(state); - StateServerFactory.getStateServer().useState((fsmState)->{ + StateServerFactory.getStateServer().useFsmState((fsmState)->{ log.error(fsmState.toString() ); - return fsmState; + return null; }); diff --git a/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java b/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java index 91234ed..969eac1 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java @@ -64,9 +64,9 @@ public class StateMachine extends StateMachineAdapter { /** * Returns current value. 只有Get 操作状态由协议流程决定 Apply */ - // public State getState() { - // return state; - // } + public State getState() { + return state; + } /** @@ -106,10 +106,12 @@ public class StateMachine extends StateMachineAdapter { // Have to parse FetchAddRequest from this user log. final ByteBuffer data = iter.getData(); try { - state = SerializerManager.getSerializer(SerializerManager.Hessian2).deserialize( - data.array(), State.class.getName()); - log.info("SyncDataClosure(null) taskState:{} leaderTerm:{}", state, this.leaderTerm); - + + state = SerializerManager.getSerializer(SerializerManager.Hessian2).deserialize( + data.array(), State.class.getName()); + log.info("SyncDataClosure(null) taskState:{} leaderTerm:{}", state, this.leaderTerm); + + } catch (CodecException e) { e.printStackTrace(); } @@ -147,7 +149,7 @@ public class StateMachine extends StateMachineAdapter { @Override public void onStartFollowing(LeaderChangeContext ctx) { - // TODO Auto-generated method stub + super.onStartFollowing(ctx); var ss = StateServerFactory.getStateServer(); @@ -162,7 +164,7 @@ public class StateMachine extends StateMachineAdapter { resp = (ResponseSM)StateServerFactory.getStateServer().getRpcClient().invokeSync(node.getLeaderId().getEndpoint(), request, 5000); log.error("{}", resp); } catch (InterruptedException | RemotingException e) { - // TODO Auto-generated catch block + e.printStackTrace(); } } diff --git a/src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java b/src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java index 0b54ff8..9d0f091 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java @@ -126,48 +126,54 @@ public class StateServerFactory { } - public void useState(Function dofunc) { - - this.fsm.useState((fsmState)->{ - - - + public void useFsmState(Function dofunc) { + + SyncClosure closure = new SyncClosure() { @Override public void run(Status status) { - + } }; - + getNode().readIndex(BytesUtil.EMPTY_BYTES, new ReadIndexClosure() { @Override public void run(Status status, long index, byte[] reqCtx) { - if(status.isOk()){ - log.error("readIndex {}", fsmState); - closure.success(fsmState); - closure.run(Status.OK()); - return; - } - - readIndexExecutor.execute(() -> { - if(isLeader()){ - log.error("Fail to get value with 'ReadIndex': {}, try to applying to the state machine.", status); - applyState(fsmState, closure); - }else { - handlerNotLeaderError(closure); + + getFsm().useState((fsmState)->{ + if(status.isOk()){ + log.error("readIndex {}", fsmState); + closure.success(fsmState); + closure.run(Status.OK()); + dofunc.apply(fsmState); + return null; } + + readIndexExecutor.execute(() -> { + if(isLeader()){ + log.error("Fail to get value with 'ReadIndex': {}, try to applying to the state machine.", status); + applyState(fsmState, closure); + }else { + handlerNotLeaderError(closure); + } + }); + return null; }); + + } }); - return null; - }); + return ; + } + public void applyState(State state, SyncClosure closure) { + // 所有的提交都必须再leader进行 if (!ss.isLeader()) { ss.handlerNotLeaderError(closure); return; @@ -177,7 +183,7 @@ public class StateServerFactory { closure.setValue(state); final Task task = new Task(); task.setData(ByteBuffer.wrap(SerializerManager.getSerializer(SerializerManager.Hessian2).serialize(state))); - task.setDone(closure); + task.setDone(closure); // 确认所有数据 一致, 不需要加锁 StateServerFactory.getStateServer().getNode().apply(task); } catch (CodecException e) { @@ -194,7 +200,9 @@ public class StateServerFactory { return; } - useState((fsmState)->{ + + useFsmState((fsmState)->{ + var wmap = fsmState.getWorkers(); var wstate = wmap.get(state.getPeerId()); @@ -205,16 +213,18 @@ public class StateServerFactory { log.error("{}", fsmState); task.setData(ByteBuffer.wrap(SerializerManager.getSerializer(SerializerManager.Hessian2).serialize(fsmState))); task.setDone(closure); - StateServerFactory.getStateServer().getNode().apply(task); + StateServerFactory.getStateServer().getNode().apply(task); // 提交数据 } catch (CodecException e) { String errorMsg = "Fail to encode TaskState"; log.error(errorMsg, e); closure.failure(errorMsg, PeerId.emptyPeer()); closure.run(new Status(RaftError.EINTERNAL, errorMsg)); } + } else { + closure.success(fsmState); + closure.run(Status.OK()); } - - return fsmState; + return null; }); @@ -225,13 +235,13 @@ public class StateServerFactory { public void readIndexState(final boolean readOnlySafe, final SyncClosure closure) { - useState((fsmState)->{ + useFsmState((fsmState)->{ closure.setValue(fsmState); if(!readOnlySafe){ closure.success(fsmState); closure.run(Status.OK()); - return fsmState; + return null; } getNode().readIndex(BytesUtil.EMPTY_BYTES, new ReadIndexClosure() { @@ -256,7 +266,7 @@ public class StateServerFactory { } }); - return fsmState; + return null; }); From 36fe0e6428e65f9c167f7310bdcc1d32061a0c61 Mon Sep 17 00:00:00 2001 From: huangsimin Date: Mon, 18 Jul 2022 18:04:21 +0800 Subject: [PATCH 10/37] =?UTF-8?q?TODO:=20=E8=AE=BE=E8=AE=A1=E4=B8=80?= =?UTF-8?q?=E4=B8=AA=E7=AE=80=E5=8D=95=E6=98=93=E6=87=82api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/yuandian/dataflow/controller/TaskLog.java | 12 ++---------- .../yuandian/dataflow/statemachine/StateMachine.java | 4 ++-- .../dataflow/statemachine/StateServerFactory.java | 1 - 3 files changed, 4 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/yuandian/dataflow/controller/TaskLog.java b/src/main/java/com/yuandian/dataflow/controller/TaskLog.java index 1360774..bfba04e 100644 --- a/src/main/java/com/yuandian/dataflow/controller/TaskLog.java +++ b/src/main/java/com/yuandian/dataflow/controller/TaskLog.java @@ -22,15 +22,7 @@ public class TaskLog { @GetMapping(path = "/test") public ResponseEntity Processing() throws InterruptedException { - SyncClosure closure = new SyncClosure() { - @Override - public void run(Status status) { - log.error("{} {}",getValue().toString(), getValue().getWorkers().size()); - } - }; - - var state = new State(); - closure.setValue(state); + StateServerFactory.getStateServer().useFsmState((fsmState)->{ log.error(fsmState.toString() ); return null; @@ -40,7 +32,7 @@ public class TaskLog { // state.getWorker().setPeerId(StateServerFactory.getStateServer().getNode().getNodeId().getPeerId()); // state.getWorker().setTaskQueueSize(1); - StateServerFactory.getStateServer().readIndexState(true, closure); + final Response response = new Response(); response.Code = HttpStatus.OK; diff --git a/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java b/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java index 969eac1..aae79a4 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java @@ -97,7 +97,7 @@ public class StateMachine extends StateMachineAdapter { if (iter.done() != null) { // This task is applied by this node, get value from closure to avoid additional // parsing. - var closure = (SyncClosure)iter.done(); + var closure = (SyncClosure)iter.done(); // 只支持单一个State. 全状态机只支持一种提交 state = closure.getValue(); log.info("SyncDataClosure(done) taskState:{} leaderTerm:{}",state, this.leaderTerm); closure.success(state); @@ -109,7 +109,7 @@ public class StateMachine extends StateMachineAdapter { state = SerializerManager.getSerializer(SerializerManager.Hessian2).deserialize( data.array(), State.class.getName()); - log.info("SyncDataClosure(null) taskState:{} leaderTerm:{}", state, this.leaderTerm); + log.info("SyncDataClosure(null) taskState:{} leaderTerm:{}", state, this.leaderTerm); } catch (CodecException e) { diff --git a/src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java b/src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java index 9d0f091..e1cac63 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java @@ -185,7 +185,6 @@ public class StateServerFactory { task.setData(ByteBuffer.wrap(SerializerManager.getSerializer(SerializerManager.Hessian2).serialize(state))); task.setDone(closure); // 确认所有数据 一致, 不需要加锁 StateServerFactory.getStateServer().getNode().apply(task); - } catch (CodecException e) { String errorMsg = "Fail to encode TaskState"; log.error(errorMsg, e); From 20e50d142d1c385d19409cbd034777057d84ec1e Mon Sep 17 00:00:00 2001 From: huangsimin Date: Tue, 19 Jul 2022 00:04:59 +0800 Subject: [PATCH 11/37] finish --- .../java/com/yuandian/dataflow/Server.java | 3 +- .../yuandian/dataflow/controller/TaskLog.java | 12 ++++++- .../java/com/yuandian/dataflow/projo/Doc.java | 22 ++++-------- .../dataflow/statemachine/StateMachine.java | 36 +++++++++++++++---- .../statemachine/StateServerFactory.java | 10 ++++-- .../rpc/SyncConditionProcessor.java | 3 +- .../com/yuandian/dataflow}/MongodbTest.java | 2 +- .../statemachine/StateMachineTest.java | 6 ++-- 8 files changed, 61 insertions(+), 33 deletions(-) rename src/{main/java/com/yuandian/dataflow/grpc => test/java/com/yuandian/dataflow}/MongodbTest.java (98%) diff --git a/src/main/java/com/yuandian/dataflow/Server.java b/src/main/java/com/yuandian/dataflow/Server.java index 7702caa..89ce643 100644 --- a/src/main/java/com/yuandian/dataflow/Server.java +++ b/src/main/java/com/yuandian/dataflow/Server.java @@ -7,6 +7,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringBootConfiguration; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration; import com.alipay.remoting.serialization.SerializerManager; import com.alipay.sofa.jraft.JRaftUtils; @@ -31,7 +32,7 @@ import lombok.extern.slf4j.Slf4j; * */ @Slf4j -@SpringBootApplication +@SpringBootApplication(exclude = {MongoAutoConfiguration.class}) @SpringBootConfiguration public class Server { diff --git a/src/main/java/com/yuandian/dataflow/controller/TaskLog.java b/src/main/java/com/yuandian/dataflow/controller/TaskLog.java index bfba04e..4fbf2c8 100644 --- a/src/main/java/com/yuandian/dataflow/controller/TaskLog.java +++ b/src/main/java/com/yuandian/dataflow/controller/TaskLog.java @@ -7,10 +7,13 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestParam; import com.alipay.sofa.jraft.Status; +import com.alipay.sofa.jraft.entity.PeerId; +import com.alipay.sofa.jraft.error.RemotingException; import com.yuandian.dataflow.projo.Response; import com.yuandian.dataflow.statemachine.StateServerFactory; import com.yuandian.dataflow.statemachine.SyncClosure; import com.yuandian.dataflow.statemachine.state.State; +import com.yuandian.dataflow.statemachine.state.WorkerState; import lombok.var; import lombok.extern.slf4j.Slf4j; @@ -20,7 +23,7 @@ import lombok.extern.slf4j.Slf4j; public class TaskLog { @GetMapping(path = "/test") - public ResponseEntity Processing() throws InterruptedException { + public ResponseEntity Processing() throws InterruptedException, RemotingException { StateServerFactory.getStateServer().useFsmState((fsmState)->{ @@ -31,6 +34,13 @@ public class TaskLog { // state.getWorker().setPeerId(StateServerFactory.getStateServer().getNode().getNodeId().getPeerId()); // state.getWorker().setTaskQueueSize(1); + + StateServerFactory.getStateServer().updateFsmState((fsmState)->{ + log.error(fsmState.toString() ); + fsmState.getWorkers().put(new PeerId(), new WorkerState()); + return fsmState; + }); + diff --git a/src/main/java/com/yuandian/dataflow/projo/Doc.java b/src/main/java/com/yuandian/dataflow/projo/Doc.java index 502695f..e1389a1 100644 --- a/src/main/java/com/yuandian/dataflow/projo/Doc.java +++ b/src/main/java/com/yuandian/dataflow/projo/Doc.java @@ -2,27 +2,20 @@ package com.yuandian.dataflow.projo; -import java.io.Serializable; -import java.lang.annotation.Documented; import java.time.LocalDateTime; import org.bson.Document; -import org.bson.codecs.pojo.annotations.BsonCreator; -import org.bson.codecs.pojo.annotations.BsonDiscriminator; import org.bson.codecs.pojo.annotations.BsonProperty; import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.databind.util.JSONPObject; import lombok.Getter; import lombok.Setter; - - -@Getter @Setter -public final class Doc extends Document { +@Getter +public final class Doc extends Document { @JsonProperty("code") @BsonProperty("code") @@ -33,14 +26,11 @@ public final class Doc extends Document { public LocalDateTime TS; @JsonProperty("desc") - @BsonProperty("desc") + @BsonProperty("desc") public String Desc; @JsonProperty("data") - @BsonProperty("data") - public Document Data; - - - - + @BsonProperty("data") + public Document Data; + } diff --git a/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java b/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java index aae79a4..ec27c09 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java @@ -80,11 +80,32 @@ public class StateMachine extends StateMachineAdapter { /** * Returns current value. 读取修改都在这个函数域内进行 + * @throws RemotingException + * @throws InterruptedException */ - public void updateState(Function dofunc) { + public void updateState(Function dofunc) throws InterruptedException, RemotingException { synchronized(this.state) { var newstate = dofunc.apply(this.state); - this.state = newstate; + var ss = StateServerFactory.getStateServer(); + if(!isLeader()) { + var request = new RequestState(); + request.setState(newstate); + var result = ss.getRpcClient().invokeSync(ss.getNode().getLeaderId().getEndpoint(), request, 5000); + log.info("{}", result); + return; + } + + // this.state = newstate; + if(newstate != null) { + var colsure = new SyncClosure() { + @Override + public void run(Status status) { + + } + }; + colsure.setValue(newstate); + StateServerFactory.getStateServer().applyState(newstate, colsure); + } } } @@ -98,19 +119,22 @@ public class StateMachine extends StateMachineAdapter { // This task is applied by this node, get value from closure to avoid additional // parsing. var closure = (SyncClosure)iter.done(); // 只支持单一个State. 全状态机只支持一种提交 - state = closure.getValue(); - log.info("SyncDataClosure(done) taskState:{} leaderTerm:{}",state, this.leaderTerm); + log.info("SyncDataClosure(done) taskState:{} leaderTerm:{} {}",this.state, this.leaderTerm, closure); + synchronized(this.state) { + this.state = closure.getValue(); + } + closure.success(state); closure.run(Status.OK()); } else { // Have to parse FetchAddRequest from this user log. final ByteBuffer data = iter.getData(); try { - + synchronized(state) { state = SerializerManager.getSerializer(SerializerManager.Hessian2).deserialize( data.array(), State.class.getName()); log.info("SyncDataClosure(null) taskState:{} leaderTerm:{}", state, this.leaderTerm); - + } } catch (CodecException e) { e.printStackTrace(); diff --git a/src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java b/src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java index e1cac63..edcc8aa 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java @@ -171,6 +171,10 @@ public class StateServerFactory { } + public void updateFsmState(Function dofunc) throws InterruptedException, RemotingException { + this.getFsm().updateState(dofunc); + } + public void applyState(State state, SyncClosure closure) { // 所有的提交都必须再leader进行 @@ -193,7 +197,7 @@ public class StateServerFactory { } } - public void applyWorkerState(WorkerState state, SyncClosure closure) { + public void applyWorkerState(WorkerState state, SyncClosure closure) { if (!ss.isLeader()) { ss.handlerNotLeaderError(closure); return; @@ -209,13 +213,13 @@ public class StateServerFactory { wmap.put(state.getPeerId(), state); try { final Task task = new Task(); - log.error("{}", fsmState); + closure.setValue(fsmState); task.setData(ByteBuffer.wrap(SerializerManager.getSerializer(SerializerManager.Hessian2).serialize(fsmState))); task.setDone(closure); StateServerFactory.getStateServer().getNode().apply(task); // 提交数据 } catch (CodecException e) { String errorMsg = "Fail to encode TaskState"; - log.error(errorMsg, e); + log.error("{}:{}",errorMsg, e); closure.failure(errorMsg, PeerId.emptyPeer()); closure.run(new Status(RaftError.EINTERNAL, errorMsg)); } diff --git a/src/main/java/com/yuandian/dataflow/statemachine/rpc/SyncConditionProcessor.java b/src/main/java/com/yuandian/dataflow/statemachine/rpc/SyncConditionProcessor.java index fefff27..263a63d 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/rpc/SyncConditionProcessor.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/rpc/SyncConditionProcessor.java @@ -19,6 +19,7 @@ import com.lmax.disruptor.WorkProcessor; import com.yuandian.dataflow.statemachine.StateServerFactory; import com.yuandian.dataflow.statemachine.SyncClosure; import com.yuandian.dataflow.statemachine.StateServerFactory.StateServer; +import com.yuandian.dataflow.statemachine.state.State; import com.yuandian.dataflow.statemachine.state.WorkerState; import com.alipay.sofa.jraft.entity.PeerId; @@ -40,7 +41,7 @@ public class SyncConditionProcessor implements RpcProcessor { public void handleRequest(RpcContext rpcCtx, RequestCondition request) { log.info("request: {}", request); - final SyncClosure closure = new SyncClosure() { + final SyncClosure closure = new SyncClosure< State>() { @Override public void run(Status status) { rpcCtx.sendResponse(getResponse()); diff --git a/src/main/java/com/yuandian/dataflow/grpc/MongodbTest.java b/src/test/java/com/yuandian/dataflow/MongodbTest.java similarity index 98% rename from src/main/java/com/yuandian/dataflow/grpc/MongodbTest.java rename to src/test/java/com/yuandian/dataflow/MongodbTest.java index d250df0..73e1ed9 100644 --- a/src/main/java/com/yuandian/dataflow/grpc/MongodbTest.java +++ b/src/test/java/com/yuandian/dataflow/MongodbTest.java @@ -1,4 +1,4 @@ -package com.yuandian.dataflow.grpc; +package com.yuandian.dataflow; import com.mongodb.MongoClient; import com.mongodb.MongoCredential; diff --git a/src/test/java/com/yuandian/dataflow/statemachine/StateMachineTest.java b/src/test/java/com/yuandian/dataflow/statemachine/StateMachineTest.java index 809cb28..329abfa 100644 --- a/src/test/java/com/yuandian/dataflow/statemachine/StateMachineTest.java +++ b/src/test/java/com/yuandian/dataflow/statemachine/StateMachineTest.java @@ -23,8 +23,7 @@ public class StateMachineTest { void testOnApply() throws InterruptedException, RemotingException { var rpcClient = new BoltRaftRpcFactory().createRpcClient(); rpcClient.init(new CliOptions()); - - + var fstate = new State(); var fdata = new RequestState(); fdata.setState(fstate); @@ -39,8 +38,7 @@ public class StateMachineTest { , 5000); log.info("{}", resp); } - - + int i = 0 ; while(true) { From 6f743686a141423036e1304250930837cbd25ee4 Mon Sep 17 00:00:00 2001 From: huangsimin Date: Tue, 19 Jul 2022 10:15:54 +0800 Subject: [PATCH 12/37] =?UTF-8?q?=E9=80=BB=E8=BE=91=E8=B7=91=E9=80=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yuandian/dataflow/controller/TaskLog.java | 7 +--- .../com/yuandian/dataflow/master/Header.java | 10 ++--- .../dataflow/statemachine/StateMachine.java | 37 ++++++++++++------- .../statemachine/StateServerFactory.java | 18 +++++---- src/main/resources/logback.xml | 15 +++++++- 5 files changed, 55 insertions(+), 32 deletions(-) diff --git a/src/main/java/com/yuandian/dataflow/controller/TaskLog.java b/src/main/java/com/yuandian/dataflow/controller/TaskLog.java index 4fbf2c8..01ae05a 100644 --- a/src/main/java/com/yuandian/dataflow/controller/TaskLog.java +++ b/src/main/java/com/yuandian/dataflow/controller/TaskLog.java @@ -27,7 +27,7 @@ public class TaskLog { StateServerFactory.getStateServer().useFsmState((fsmState)->{ - log.error(fsmState.toString() ); + log.debug(fsmState.toString() ); return null; }); @@ -36,14 +36,11 @@ public class TaskLog { // state.getWorker().setTaskQueueSize(1); StateServerFactory.getStateServer().updateFsmState((fsmState)->{ - log.error(fsmState.toString() ); + log.debug(fsmState.toString() ); fsmState.getWorkers().put(new PeerId(), new WorkerState()); return fsmState; }); - - - final Response response = new Response(); response.Code = HttpStatus.OK; response.Message = "ok"; diff --git a/src/main/java/com/yuandian/dataflow/master/Header.java b/src/main/java/com/yuandian/dataflow/master/Header.java index f1df546..d31fdc6 100644 --- a/src/main/java/com/yuandian/dataflow/master/Header.java +++ b/src/main/java/com/yuandian/dataflow/master/Header.java @@ -44,12 +44,12 @@ public class Header { var out = new DataOutputStream(sock.getOutputStream()); // 发送验证字符串 // out.write("public".getBytes()); - // log.error("{}", PacketHeader.PacketCode(in)); + // log.debug("{}", PacketHeader.PacketCode(in)); // var pheader = new PacketHeader(in); - // log.error("{}", pheader); + // log.debug("{}", pheader); // var pbase = PacketBase.createPacketBase(pheader); - // log.error("{}",pbase); + // log.debug("{}",pbase); // //60010流需要解压 @@ -74,7 +74,7 @@ public class Header { // var length = ByteBuffer.wrap(in.readNBytes(4)).order(ByteOrder.LITTLE_ENDIAN).getInt(); // if (length <= 13) { - // log.error("[{}:{}][数据总条数:{}][当前解析第{}条][length<13][探针发包有问题]"); + // log.debug("[{}:{}][数据总条数:{}][当前解析第{}条][length<13][探针发包有问题]"); // throw new Exception("数据解析异常"); // } @@ -90,7 +90,7 @@ public class Header { // if (length <= 13) { - // log.error("[{}:{}][数据总条数:{}][当前解析第{}条][length<13][探针发包有问题]"); + // log.debug("[{}:{}][数据总条数:{}][当前解析第{}条][length<13][探针发包有问题]"); // throw new Exception("数据解析异常"); // } diff --git a/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java b/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java index ec27c09..8019d81 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java @@ -153,7 +153,7 @@ public class StateMachine extends StateMachineAdapter { @Override public void onError(final RaftException e) { - log.error("Raft error: {}", e, e); + log.debug("Raft error: {}", e, e); } @Override @@ -167,30 +167,41 @@ public class StateMachine extends StateMachineAdapter { this.leaderTerm.set(term); super.onLeaderStart(term); - - + var ss = StateServerFactory.getStateServer(); + var ws = new WorkerState(); + ws.setPeerId(ss.getCluster().getServerId()); + final SyncClosure closure = new SyncClosure< State>() { + @Override + public void run(Status status) { + log.debug("leader set WorkerState {} ", status); + } + }; + ss.applyWorkerState(ws, closure); + return; } @Override public void onStartFollowing(LeaderChangeContext ctx) { super.onStartFollowing(ctx); - - var ss = StateServerFactory.getStateServer(); - var node = ss.getNode(); - try { + var ss = StateServerFactory.getStateServer(); + var ws = new WorkerState(); + ws.setPeerId(ss.getCluster().getServerId()); var request = new RequestCondition(); - request.setWorkerState( new WorkerState() ); - request.getWorkerState().setPeerId( ss.getCluster().getServerId() ); - log.error("------------ leader id {}", node.getLeaderId()); + request.setWorkerState(ws); + log.debug("my: {} leader id {}",ss.getCluster().getServerId(), ss.getNode().getLeaderId()); ResponseSM resp; - resp = (ResponseSM)StateServerFactory.getStateServer().getRpcClient().invokeSync(node.getLeaderId().getEndpoint(), request, 5000); - log.error("{}", resp); + resp = (ResponseSM)StateServerFactory.getStateServer().getRpcClient().invokeSync(ss.getNode().getLeaderId().getEndpoint(), request, 5000); + if(resp == null) { + log.error("{} set WorkerState is error", resp); + } + log.debug("WorkerState is {}", resp); + return; } catch (InterruptedException | RemotingException e) { - e.printStackTrace(); } + } @Override diff --git a/src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java b/src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java index edcc8aa..93173ea 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java @@ -62,7 +62,7 @@ public class StateServerFactory { throw new Exception("重复初始化 InitStateServer"); } ss = new StateServerFactory.StateServer(peerstr, conf); - log.error("init peerid {}", ss.node.getNodeId().getPeerId()); + log.debug("init peerid {}", ss.node.getNodeId().getPeerId()); } @@ -143,7 +143,7 @@ public class StateServerFactory { getFsm().useState((fsmState)->{ if(status.isOk()){ - log.error("readIndex {}", fsmState); + log.debug("readIndex {}", fsmState); closure.success(fsmState); closure.run(Status.OK()); dofunc.apply(fsmState); @@ -152,7 +152,7 @@ public class StateServerFactory { readIndexExecutor.execute(() -> { if(isLeader()){ - log.error("Fail to get value with 'ReadIndex': {}, try to applying to the state machine.", status); + log.debug("Fail to get value with 'ReadIndex': {}, try to applying to the state machine.", getNode()); applyState(fsmState, closure); }else { handlerNotLeaderError(closure); @@ -176,6 +176,8 @@ public class StateServerFactory { } + + public void applyState(State state, SyncClosure closure) { // 所有的提交都必须再leader进行 if (!ss.isLeader()) { @@ -191,7 +193,7 @@ public class StateServerFactory { StateServerFactory.getStateServer().getNode().apply(task); } catch (CodecException e) { String errorMsg = "Fail to encode TaskState"; - log.error(errorMsg, e); + log.debug(errorMsg, e); closure.failure(errorMsg, PeerId.emptyPeer()); closure.run(new Status(RaftError.EINTERNAL, errorMsg)); } @@ -219,7 +221,7 @@ public class StateServerFactory { StateServerFactory.getStateServer().getNode().apply(task); // 提交数据 } catch (CodecException e) { String errorMsg = "Fail to encode TaskState"; - log.error("{}:{}",errorMsg, e); + log.debug("{}:{}",errorMsg, e); closure.failure(errorMsg, PeerId.emptyPeer()); closure.run(new Status(RaftError.EINTERNAL, errorMsg)); } @@ -252,7 +254,7 @@ public class StateServerFactory { public void run(Status status, long index, byte[] reqCtx) { if(status.isOk()){ - log.error("readIndex {}", fsmState); + log.debug("readIndex {}", fsmState); closure.success(fsmState); closure.run(Status.OK()); return; @@ -260,7 +262,7 @@ public class StateServerFactory { readIndexExecutor.execute(() -> { if(isLeader()){ - log.error("Fail to get value with 'ReadIndex': {}, try to applying to the state machine.", status); + log.debug("Fail to get value with 'ReadIndex': {}, try to applying to the state machine.", status); applyState(fsmState, closure); }else { handlerNotLeaderError(closure); @@ -310,6 +312,8 @@ public class StateServerFactory { } } + + public static void main(String[] args) throws InterruptedException, RemotingException { var rpcClient = new BoltRaftRpcFactory().createRpcClient(); rpcClient.init(new CliOptions()); diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml index 269a553..fe5dcb1 100644 --- a/src/main/resources/logback.xml +++ b/src/main/resources/logback.xml @@ -6,8 +6,19 @@ %d{yyyyMMdd HH:mm:ss.SSS} %level %thread\(%file:%line\): %msg%n + + DEBUG + ACCEPT + DENY + - + + + + + + + \ No newline at end of file From 9e6159ee16d3f7d7fd114d51d81bc200b9272415 Mon Sep 17 00:00:00 2001 From: huangsimin Date: Tue, 19 Jul 2022 12:06:03 +0800 Subject: [PATCH 13/37] =?UTF-8?q?=E5=AE=8C=E6=88=90=E5=90=8C=E6=AD=A5?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=9A=84api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yuandian/dataflow/controller/TaskLog.java | 17 +- .../dataflow/statemachine/StateMachine.java | 27 ++-- .../statemachine/StateServerFactory.java | 150 +++++++++++------- .../dataflow/statemachine/SyncClosure.java | 4 +- .../statemachine/state/WorkerState.java | 4 + 5 files changed, 123 insertions(+), 79 deletions(-) diff --git a/src/main/java/com/yuandian/dataflow/controller/TaskLog.java b/src/main/java/com/yuandian/dataflow/controller/TaskLog.java index 01ae05a..216a65c 100644 --- a/src/main/java/com/yuandian/dataflow/controller/TaskLog.java +++ b/src/main/java/com/yuandian/dataflow/controller/TaskLog.java @@ -25,25 +25,18 @@ public class TaskLog { @GetMapping(path = "/test") public ResponseEntity Processing() throws InterruptedException, RemotingException { - + + var ws = new WorkerState(new PeerId()); + StateServerFactory.getStateServer().updateFsmWorkerState(ws); + final Response response = new Response(); StateServerFactory.getStateServer().useFsmState((fsmState)->{ log.debug(fsmState.toString() ); + response.Message = fsmState.toString(); return null; }); - // state.getWorker().setPeerId(StateServerFactory.getStateServer().getNode().getNodeId().getPeerId()); - // state.getWorker().setTaskQueueSize(1); - - StateServerFactory.getStateServer().updateFsmState((fsmState)->{ - log.debug(fsmState.toString() ); - fsmState.getWorkers().put(new PeerId(), new WorkerState()); - return fsmState; - }); - - final Response response = new Response(); response.Code = HttpStatus.OK; - response.Message = "ok"; return new ResponseEntity(response, HttpStatus.OK); } diff --git a/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java b/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java index 8019d81..ede6e55 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java @@ -167,16 +167,19 @@ public class StateMachine extends StateMachineAdapter { this.leaderTerm.set(term); super.onLeaderStart(term); - var ss = StateServerFactory.getStateServer(); - var ws = new WorkerState(); - ws.setPeerId(ss.getCluster().getServerId()); - final SyncClosure closure = new SyncClosure< State>() { - @Override - public void run(Status status) { - log.debug("leader set WorkerState {} ", status); - } - }; - ss.applyWorkerState(ws, closure); + try { + updateState((state)->{ + var ws = new WorkerState(StateServerFactory.getStateServer().getCluster().getServerId()); + state.getWorkers().put(ws.peerId, ws); + return state; + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } catch (RemotingException e) { + e.printStackTrace(); + } + + return; } @@ -184,10 +187,10 @@ public class StateMachine extends StateMachineAdapter { public void onStartFollowing(LeaderChangeContext ctx) { super.onStartFollowing(ctx); + try { var ss = StateServerFactory.getStateServer(); - var ws = new WorkerState(); - ws.setPeerId(ss.getCluster().getServerId()); + var ws = new WorkerState(ss.getCluster().getServerId()); var request = new RequestCondition(); request.setWorkerState(ws); log.debug("my: {} leader id {}",ss.getCluster().getServerId(), ss.getNode().getLeaderId()); diff --git a/src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java b/src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java index 93173ea..3e6338c 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java @@ -33,6 +33,7 @@ import com.alipay.sofa.jraft.rpc.impl.BoltRaftRpcFactory; import com.alipay.sofa.jraft.util.BytesUtil; import com.alipay.sofa.jraft.util.Endpoint; import com.alipay.sofa.jraft.util.ThreadPoolUtil; +import com.yuandian.dataflow.statemachine.rpc.RequestCondition; import com.yuandian.dataflow.statemachine.rpc.RequestState; import com.yuandian.dataflow.statemachine.rpc.ResponseSM; import com.yuandian.dataflow.statemachine.rpc.SyncConditionProcessor; @@ -126,9 +127,12 @@ public class StateServerFactory { } + /** + * 同步 可以使用follow使用, 但是可能延迟于leader. 只读 + * @param dofunc + */ public void useFsmState(Function dofunc) { - - + SyncClosure closure = new SyncClosure() { @Override public void run(Status status) { @@ -136,17 +140,18 @@ public class StateServerFactory { } }; - + getNode().readIndex(BytesUtil.EMPTY_BYTES, new ReadIndexClosure() { @Override public void run(Status status, long index, byte[] reqCtx) { getFsm().useState((fsmState)->{ if(status.isOk()){ - log.debug("readIndex {}", fsmState); closure.success(fsmState); closure.run(Status.OK()); - dofunc.apply(fsmState); + synchronized(dofunc) { + dofunc.apply(fsmState); + } return null; } @@ -160,22 +165,99 @@ public class StateServerFactory { }); return null; }); - - + + synchronized(dofunc) { + log.debug("dofunc notify"); + dofunc.notify(); + } } }); - - - + + try { + synchronized(dofunc) { + log.debug("dofunc wait"); + dofunc.wait(5000); + log.debug("dofunc unwait"); + } + } catch (InterruptedException e) { + e.printStackTrace(); + } return ; } - public void updateFsmState(Function dofunc) throws InterruptedException, RemotingException { - this.getFsm().updateState(dofunc); - } + /** + * 同步更新 WorkerState + * @param dofunc + * @throws InterruptedException + * @throws RemotingException + */ + public void updateFsmWorkerState(WorkerState ws) throws InterruptedException, RemotingException { - + if(isLeader()) { + var closure = new SyncClosure() { + @Override + public void run(Status status) { + log.debug("leader {}", status); + this.synclock.notify(); + } + }; + StateServerFactory.getStateServer().applyWorkerState(ws, closure); + closure.synclock.wait(5000); + return; + } + + try { + var ss = StateServerFactory.getStateServer(); + var request = new RequestCondition(); + request.setWorkerState(ws); + log.debug("my: {} leader id {}",ss.getCluster().getServerId(), ss.getNode().getLeaderId()); + ResponseSM resp; + resp = (ResponseSM)StateServerFactory.getStateServer().getRpcClient().invokeSync(ss.getNode().getLeaderId().getEndpoint(), request, 5000); + if(resp == null) { + log.error("{} set WorkerState is error", resp); + } + log.debug("follow is {}", resp); + return; + } catch (InterruptedException | RemotingException e) { + e.printStackTrace(); + } + } + + /** + * 同步更新整个State + * @param s + * @throws InterruptedException + * @throws RemotingException + */ + public void updateFsmState(State s) throws InterruptedException, RemotingException { + if(isLeader()) { + var closure = new SyncClosure() { + @Override + public void run(Status status) { + log.debug("leader {}", status); + synclock.notify(); + } + }; + StateServerFactory.getStateServer().applyState(s, closure); + closure.synclock.wait(5000); + + return; + } + + var ss = StateServerFactory.getStateServer(); + var request = new RequestState(); + request.setState(s); + log.debug("my: {} leader id {}",ss.getCluster().getServerId(), ss.getNode().getLeaderId()); + ResponseSM resp; + resp = (ResponseSM)StateServerFactory.getStateServer().getRpcClient().invokeSync(ss.getNode().getLeaderId().getEndpoint(), request, 5000); + if(resp == null) { + log.error("{} set State is error", resp); + } + log.debug("follow is {}", resp); + return; + + } public void applyState(State state, SyncClosure closure) { @@ -235,46 +317,6 @@ public class StateServerFactory { - } - - public void readIndexState(final boolean readOnlySafe, final SyncClosure closure) { - - - useFsmState((fsmState)->{ - closure.setValue(fsmState); - if(!readOnlySafe){ - - closure.success(fsmState); - closure.run(Status.OK()); - return null; - } - - getNode().readIndex(BytesUtil.EMPTY_BYTES, new ReadIndexClosure() { - @Override - public void run(Status status, long index, byte[] reqCtx) { - - if(status.isOk()){ - log.debug("readIndex {}", fsmState); - closure.success(fsmState); - closure.run(Status.OK()); - return; - } - - readIndexExecutor.execute(() -> { - if(isLeader()){ - log.debug("Fail to get value with 'ReadIndex': {}, try to applying to the state machine.", status); - applyState(fsmState, closure); - }else { - handlerNotLeaderError(closure); - } - }); - } - }); - - return null; - }); - - } public ResponseSM redirect() { diff --git a/src/main/java/com/yuandian/dataflow/statemachine/SyncClosure.java b/src/main/java/com/yuandian/dataflow/statemachine/SyncClosure.java index f19f155..40ba6d9 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/SyncClosure.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/SyncClosure.java @@ -25,7 +25,9 @@ public abstract class SyncClosure implements Closure { // 代表任务状态 private T value; - + public Object synclock = new Object(); + + public SyncClosure() { } diff --git a/src/main/java/com/yuandian/dataflow/statemachine/state/WorkerState.java b/src/main/java/com/yuandian/dataflow/statemachine/state/WorkerState.java index bc7e058..2d46d94 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/state/WorkerState.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/state/WorkerState.java @@ -29,4 +29,8 @@ public class WorkerState implements Serializable { // 节点的对应peerID public PeerId peerId; public long taskQueueSize; + + public WorkerState(PeerId pid) { + this.peerId = pid; + } } From d7cd8ed7580b2c985b3a1c78f2cb735e4be09503 Mon Sep 17 00:00:00 2001 From: huangsimin Date: Tue, 19 Jul 2022 18:26:56 +0800 Subject: [PATCH 14/37] =?UTF-8?q?TODO:=20=E5=90=84=E4=B8=AA=E8=8A=82?= =?UTF-8?q?=E7=82=B9=E7=9A=84=E9=94=80=E6=AF=81=E5=85=B3=E7=B3=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/yuandian/dataflow/Server.java | 7 +- .../yuandian/dataflow/controller/TaskLog.java | 28 +++++--- .../dataflow/statemachine/StateMachine.java | 45 ++++++++----- .../statemachine/StateServerFactory.java | 66 +++++++++++++++++-- src/main/resources/logback.xml | 4 +- .../java/com/yuandian/dataflow/AppTest.java | 1 + start.sh | 3 +- 7 files changed, 115 insertions(+), 39 deletions(-) diff --git a/src/main/java/com/yuandian/dataflow/Server.java b/src/main/java/com/yuandian/dataflow/Server.java index 89ce643..4a49a81 100644 --- a/src/main/java/com/yuandian/dataflow/Server.java +++ b/src/main/java/com/yuandian/dataflow/Server.java @@ -38,8 +38,7 @@ public class Server { public static void main(String[] args) throws Exception { - - + String[] peers = new String[]{"localhost:4440","localhost:4441","localhost:4442"}; String[] sprPeers = new String[]{"3440","3441","3442"}; @@ -54,12 +53,10 @@ public class Server { Configuration conf = JRaftUtils.getConfiguration("localhost:4440,localhost:4441,localhost:4442"); - StateServerFactory.InitStateServer(peeridstr, conf); + StateServerFactory.initStateServer(peeridstr, conf); System.setProperty("server.port", sprPort); var app = SpringApplication.run(Server.class, args); app.start(); - - } } diff --git a/src/main/java/com/yuandian/dataflow/controller/TaskLog.java b/src/main/java/com/yuandian/dataflow/controller/TaskLog.java index 216a65c..4a48904 100644 --- a/src/main/java/com/yuandian/dataflow/controller/TaskLog.java +++ b/src/main/java/com/yuandian/dataflow/controller/TaskLog.java @@ -24,26 +24,36 @@ public class TaskLog { @GetMapping(path = "/test") public ResponseEntity Processing() throws InterruptedException, RemotingException { - - - var ws = new WorkerState(new PeerId()); - StateServerFactory.getStateServer().updateFsmWorkerState(ws); - final Response response = new Response(); + // var ws = new WorkerState(new PeerId()); + // StateServerFactory.getStateServer().updateFsmWorkerState(ws); + Response response = new Response(); StateServerFactory.getStateServer().useFsmState((fsmState)->{ log.debug(fsmState.toString() ); + log.debug( StateServerFactory.getNode().getLeaderId().toString() ); response.Message = fsmState.toString(); return null; }); - - response.Code = HttpStatus.OK; return new ResponseEntity(response, HttpStatus.OK); } @GetMapping(path = "/test2") - public ResponseEntity MongodbTest(@RequestParam int status) { - + public ResponseEntity MongodbTest() { Response response = new Response(); + StateServerFactory.getStateServer().useFsmStateAsync((fsmState)->{ + log.debug("{} {}", fsmState.toString()); + // response.Message = fsmState.toString(); + return null; + }); + + return new ResponseEntity(response, HttpStatus.OK); + } + + + @GetMapping(path = "/test3") + public ResponseEntity RemoveLeader() { + Response response = new Response(); + StateServerFactory.getNode().shutdown(); return new ResponseEntity(response, HttpStatus.OK); } } diff --git a/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java b/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java index ede6e55..4d292da 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java @@ -111,7 +111,7 @@ public class StateMachine extends StateMachineAdapter { @Override - // @SuppressWarnings("unchecked") + @SuppressWarnings("unchecked") public void onApply(final Iterator iter) { while (iter.hasNext()) { @@ -131,7 +131,7 @@ public class StateMachine extends StateMachineAdapter { final ByteBuffer data = iter.getData(); try { synchronized(state) { - state = SerializerManager.getSerializer(SerializerManager.Hessian2).deserialize( + state = SerializerManager.getSerializer(SerializerManager.Hessian2).deserialize( data.array(), State.class.getName()); log.info("SyncDataClosure(null) taskState:{} leaderTerm:{}", state, this.leaderTerm); } @@ -153,20 +153,17 @@ public class StateMachine extends StateMachineAdapter { @Override public void onError(final RaftException e) { - log.debug("Raft error: {}", e, e); + log.error("Raft error: {}", e, e); } @Override public boolean onSnapshotLoad(final SnapshotReader reader) { - return true; } @Override public void onLeaderStart(final long term) { this.leaderTerm.set(term); - super.onLeaderStart(term); - try { updateState((state)->{ var ws = new WorkerState(StateServerFactory.getStateServer().getCluster().getServerId()); @@ -178,15 +175,31 @@ public class StateMachine extends StateMachineAdapter { } catch (RemotingException e) { e.printStackTrace(); } - - - return; + super.onLeaderStart(term); } + @Override + public void onLeaderStop(final Status status) { + this.leaderTerm.set(-1); + super.onLeaderStop(status); + + try { + updateState((state)->{ + state.getWorkers().remove( StateServerFactory.getServerId() ); + return state; + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } catch (RemotingException e) { + e.printStackTrace(); + } + } + + @Override public void onStartFollowing(LeaderChangeContext ctx) { - super.onStartFollowing(ctx); + try { var ss = StateServerFactory.getStateServer(); @@ -204,15 +217,15 @@ public class StateMachine extends StateMachineAdapter { } catch (InterruptedException | RemotingException e) { e.printStackTrace(); } - + + super.onStartFollowing(ctx); } - @Override - public void onLeaderStop(final Status status) { - this.leaderTerm.set(-1); - super.onLeaderStop(status); - } + + + + public static void main(String[] args) throws InterruptedException, RemotingException { } diff --git a/src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java b/src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java index 3e6338c..5f01dc3 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java @@ -58,13 +58,28 @@ public class StateServerFactory { private static StateServer ss; - public static void InitStateServer(String peerstr, Configuration conf) throws Exception { + public static void initStateServer(String peerstr, Configuration conf) throws Exception { if(ss != null) { throw new Exception("重复初始化 InitStateServer"); } ss = new StateServerFactory.StateServer(peerstr, conf); log.debug("init peerid {}", ss.node.getNodeId().getPeerId()); + } + public static PeerId getServerId() { + return ss.getCluster().getServerId(); + } + + public static Node getNode() { + return ss.getNode() ; + } + + public static RpcClient getRpcClient() { + return ss.getRpcClient(); + } + + public static RaftGroupService getCluster() { + return ss.getCluster(); } // 获取状态服务的对象 @@ -136,11 +151,11 @@ public class StateServerFactory { SyncClosure closure = new SyncClosure() { @Override public void run(Status status) { - + } }; - + getNode().readIndex(BytesUtil.EMPTY_BYTES, new ReadIndexClosure() { @Override public void run(Status status, long index, byte[] reqCtx) { @@ -167,7 +182,7 @@ public class StateServerFactory { }); synchronized(dofunc) { - log.debug("dofunc notify"); + // log.debug("dofunc notify {}", getNode()); dofunc.notify(); } } @@ -175,9 +190,9 @@ public class StateServerFactory { try { synchronized(dofunc) { - log.debug("dofunc wait"); + // log.debug("dofunc wait"); dofunc.wait(5000); - log.debug("dofunc unwait"); + // log.debug("dofunc unwait"); } } catch (InterruptedException e) { e.printStackTrace(); @@ -186,6 +201,43 @@ public class StateServerFactory { } + public void useFsmStateAsync(Function dofunc) { + + SyncClosure closure = new SyncClosure() { + @Override + public void run(Status status) { + dofunc.apply(this.getValue()); + } + }; + + getNode().readIndex(BytesUtil.EMPTY_BYTES, new ReadIndexClosure() { + @Override + public void run(Status status, long index, byte[] reqCtx) { + + getFsm().useState((fsmState)->{ + if(status.isOk()){ + closure.setValue(fsmState); + closure.success(fsmState); + closure.run(Status.OK()); + return null; + } + + readIndexExecutor.execute(() -> { + if(isLeader()){ + log.info("Fail to get value with 'ReadIndex': {}, try to applying to the state machine.", getNode()); + applyState(fsmState, closure); + }else { + handlerNotLeaderError(closure); + } + }); + return null; + }); + } + }); + + return ; + } + /** * 同步更新 WorkerState * @param dofunc @@ -194,6 +246,7 @@ public class StateServerFactory { */ public void updateFsmWorkerState(WorkerState ws) throws InterruptedException, RemotingException { + // leader就直接提交 if(isLeader()) { var closure = new SyncClosure() { @Override @@ -208,6 +261,7 @@ public class StateServerFactory { } try { + // 非leader就 rpc请求 var ss = StateServerFactory.getStateServer(); var request = new RequestCondition(); request.setWorkerState(ws); diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml index fe5dcb1..4b84335 100644 --- a/src/main/resources/logback.xml +++ b/src/main/resources/logback.xml @@ -6,11 +6,11 @@ %d{yyyyMMdd HH:mm:ss.SSS} %level %thread\(%file:%line\): %msg%n - + diff --git a/src/test/java/com/yuandian/dataflow/AppTest.java b/src/test/java/com/yuandian/dataflow/AppTest.java index 14a9c6b..0d6d478 100644 --- a/src/test/java/com/yuandian/dataflow/AppTest.java +++ b/src/test/java/com/yuandian/dataflow/AppTest.java @@ -41,6 +41,7 @@ import lombok.extern.slf4j.Slf4j; @Slf4j public class AppTest { + @FunctionalInterface public interface FuncReturn { public float Execute(); diff --git a/start.sh b/start.sh index 42bed0d..748c796 100755 --- a/start.sh +++ b/start.sh @@ -1,6 +1,6 @@ screen -S raft-0 -X quit screen -S raft-1 -X quit -screen -S raft-2 -X quit +screen -S raft-2 -X quit sleep 1 @@ -8,6 +8,7 @@ screen -dmS raft-0 -L java -jar target/dataflow-1.0.0-SNAPSHOT.jar 0 screen -dmS raft-1 -L java -jar target/dataflow-1.0.0-SNAPSHOT.jar 1 screen -dmS raft-2 -L java -jar target/dataflow-1.0.0-SNAPSHOT.jar 2 +sleep 1 screen -S raft-0 -X logfile flush 0 screen -S raft-1 -X logfile flush 0 From 62dd411739e7533295eeeefe4804864648573e4b Mon Sep 17 00:00:00 2001 From: huangsimin Date: Wed, 20 Jul 2022 01:47:49 +0800 Subject: [PATCH 15/37] =?UTF-8?q?TODO:=20=E6=96=B0=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/yuandian/dataflow/Server.java | 5 +- .../yuandian/dataflow/controller/TaskLog.java | 7 +- .../dataflow/statemachine/StateMachine.java | 54 +++++++++++--- .../statemachine/StateServerFactory.java | 74 +++++++++++++++++-- src/main/resources/logback.xml | 8 +- 5 files changed, 124 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/yuandian/dataflow/Server.java b/src/main/java/com/yuandian/dataflow/Server.java index 4a49a81..6258617 100644 --- a/src/main/java/com/yuandian/dataflow/Server.java +++ b/src/main/java/com/yuandian/dataflow/Server.java @@ -8,6 +8,7 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringBootConfiguration; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration; +import org.springframework.context.ConfigurableApplicationContext; import com.alipay.remoting.serialization.SerializerManager; import com.alipay.sofa.jraft.JRaftUtils; @@ -49,14 +50,14 @@ public class Server { // var peeridstr = peers[2]; // var sprPort = sprPeers[2]; - + Configuration conf = JRaftUtils.getConfiguration("localhost:4440,localhost:4441,localhost:4442"); StateServerFactory.initStateServer(peeridstr, conf); System.setProperty("server.port", sprPort); - var app = SpringApplication.run(Server.class, args); + ConfigurableApplicationContext app = SpringApplication.run(Server.class, args); app.start(); } } diff --git a/src/main/java/com/yuandian/dataflow/controller/TaskLog.java b/src/main/java/com/yuandian/dataflow/controller/TaskLog.java index 4a48904..4589103 100644 --- a/src/main/java/com/yuandian/dataflow/controller/TaskLog.java +++ b/src/main/java/com/yuandian/dataflow/controller/TaskLog.java @@ -53,7 +53,12 @@ public class TaskLog { @GetMapping(path = "/test3") public ResponseEntity RemoveLeader() { Response response = new Response(); - StateServerFactory.getNode().shutdown(); + try { + StateServerFactory.getNode().shutdown(); + } catch (Exception e) { + e.printStackTrace(); + } + return new ResponseEntity(response, HttpStatus.OK); } } diff --git a/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java b/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java index 4d292da..90eddb4 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java @@ -9,11 +9,14 @@ import java.util.function.Function; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.boot.SpringApplication; + import com.alipay.remoting.exception.CodecException; import com.alipay.remoting.serialization.SerializerManager; import com.alipay.sofa.jraft.Closure; import com.alipay.sofa.jraft.Iterator; import com.alipay.sofa.jraft.Status; +import com.alipay.sofa.jraft.conf.Configuration; import com.alipay.sofa.jraft.core.StateMachineAdapter; import com.alipay.sofa.jraft.entity.LeaderChangeContext; import com.alipay.sofa.jraft.entity.PeerId; @@ -153,7 +156,7 @@ public class StateMachine extends StateMachineAdapter { @Override public void onError(final RaftException e) { - log.error("Raft error: {}", e, e); + log.debug("Raft error: {}", e, e); } @Override @@ -163,6 +166,7 @@ public class StateMachine extends StateMachineAdapter { @Override public void onLeaderStart(final long term) { + log.debug("onLeaderStart {}", StateServerFactory.getCluster().getServerId()); this.leaderTerm.set(term); try { updateState((state)->{ @@ -180,6 +184,7 @@ public class StateMachine extends StateMachineAdapter { @Override public void onLeaderStop(final Status status) { + log.debug("onLeaderStop {}", StateServerFactory.getCluster().getServerId()); this.leaderTerm.set(-1); super.onLeaderStop(status); @@ -188,19 +193,39 @@ public class StateMachine extends StateMachineAdapter { state.getWorkers().remove( StateServerFactory.getServerId() ); return state; }); + } catch (InterruptedException e) { e.printStackTrace(); } catch (RemotingException e) { e.printStackTrace(); } } + + + + @Override + public void onShutdown() { + log.debug("onShutdown"); + try { + updateState((state)->{ + state.getWorkers().remove( StateServerFactory.getServerId() ); + return state; + }); + + } catch (InterruptedException e) { + e.printStackTrace(); + } catch (RemotingException e) { + e.printStackTrace(); + } + + super.onShutdown(); + + } @Override public void onStartFollowing(LeaderChangeContext ctx) { - - - + log.debug("{} {}", ctx, StateServerFactory.getCluster().getServerId()); try { var ss = StateServerFactory.getStateServer(); var ws = new WorkerState(ss.getCluster().getServerId()); @@ -210,7 +235,7 @@ public class StateMachine extends StateMachineAdapter { ResponseSM resp; resp = (ResponseSM)StateServerFactory.getStateServer().getRpcClient().invokeSync(ss.getNode().getLeaderId().getEndpoint(), request, 5000); if(resp == null) { - log.error("{} set WorkerState is error", resp); + log.debug("{} set WorkerState is error", resp); } log.debug("WorkerState is {}", resp); return; @@ -221,13 +246,22 @@ public class StateMachine extends StateMachineAdapter { super.onStartFollowing(ctx); } - + @Override + public void onConfigurationCommitted(Configuration conf) { + // TODO Auto-generated method stub + super.onConfigurationCommitted(conf); + } + + @Override + public void onStopFollowing(LeaderChangeContext ctx) { + log.debug("{} {}",ctx, StateServerFactory.getCluster().getServerId()); + super.onStopFollowing(ctx); + } - - public static void main(String[] args) throws InterruptedException, RemotingException { - - } + + + } diff --git a/src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java b/src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java index 5f01dc3..5fc2b2e 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java @@ -13,6 +13,8 @@ import java.util.concurrent.SynchronousQueue; import java.util.concurrent.ThreadPoolExecutor; import java.util.function.Function; +import org.springframework.context.ConfigurableApplicationContext; + import com.alipay.remoting.NamedThreadFactory; import com.alipay.remoting.exception.CodecException; import com.alipay.remoting.serialization.SerializerManager; @@ -28,6 +30,7 @@ import com.alipay.sofa.jraft.error.RaftError; import com.alipay.sofa.jraft.error.RemotingException; import com.alipay.sofa.jraft.option.CliOptions; import com.alipay.sofa.jraft.option.NodeOptions; +import com.alipay.sofa.jraft.rpc.InvokeCallback; import com.alipay.sofa.jraft.rpc.RpcClient; import com.alipay.sofa.jraft.rpc.impl.BoltRaftRpcFactory; import com.alipay.sofa.jraft.util.BytesUtil; @@ -57,6 +60,7 @@ import lombok.extern.slf4j.Slf4j; public class StateServerFactory { private static StateServer ss; + private static ConfigurableApplicationContext appCxt; public static void initStateServer(String peerstr, Configuration conf) throws Exception { if(ss != null) { @@ -66,6 +70,15 @@ public class StateServerFactory { log.debug("init peerid {}", ss.node.getNodeId().getPeerId()); } + public static void setAppCxt(ConfigurableApplicationContext cxt) { + appCxt = cxt; + } + + public static ConfigurableApplicationContext getAppCxt() { + return appCxt; + } + + public static PeerId getServerId() { return ss.getCluster().getServerId(); } @@ -132,6 +145,8 @@ public class StateServerFactory { cluster.getRpcServer().registerProcessor(new SyncStateProcessor()); cluster.getRpcServer().registerProcessor(new SyncConditionProcessor()); node = cluster.start(); + + rpcClient = new BoltRaftRpcFactory().createRpcClient(); rpcClient.init(new CliOptions()); @@ -206,7 +221,9 @@ public class StateServerFactory { SyncClosure closure = new SyncClosure() { @Override public void run(Status status) { - dofunc.apply(this.getValue()); + if(status.isOk()) { + dofunc.apply(this.getValue()); + } } }; @@ -251,7 +268,7 @@ public class StateServerFactory { var closure = new SyncClosure() { @Override public void run(Status status) { - log.debug("leader {}", status); + // log.debug("leader {}", status); this.synclock.notify(); } }; @@ -267,11 +284,11 @@ public class StateServerFactory { request.setWorkerState(ws); log.debug("my: {} leader id {}",ss.getCluster().getServerId(), ss.getNode().getLeaderId()); ResponseSM resp; - resp = (ResponseSM)StateServerFactory.getStateServer().getRpcClient().invokeSync(ss.getNode().getLeaderId().getEndpoint(), request, 5000); + resp = (ResponseSM)StateServerFactory.getRpcClient().invokeSync(StateServerFactory.getNode().getLeaderId().getEndpoint(), request, 5000); if(resp == null) { log.error("{} set WorkerState is error", resp); } - log.debug("follow is {}", resp); + // log.debug("follow is {}", resp); return; } catch (InterruptedException | RemotingException e) { e.printStackTrace(); @@ -289,13 +306,12 @@ public class StateServerFactory { var closure = new SyncClosure() { @Override public void run(Status status) { - log.debug("leader {}", status); + // log.debug("leader update {}", status); synclock.notify(); } }; StateServerFactory.getStateServer().applyState(s, closure); closure.synclock.wait(5000); - return; } @@ -308,7 +324,51 @@ public class StateServerFactory { if(resp == null) { log.error("{} set State is error", resp); } - log.debug("follow is {}", resp); + // log.debug("follow is {}", resp); + return; + + } + + + public void updateFsmStateAsync(State s, Function onCompleted) throws InterruptedException, RemotingException { + if(isLeader()) { + var closure = new SyncClosure() { + @Override + public void run(Status status) { + // log.debug("leader update {}", status); + if(status.isOk()) { + onCompleted.apply(status); + } + } + }; + StateServerFactory.getStateServer().applyState(s, closure); + return; + } + + var ss = StateServerFactory.getStateServer(); + var request = new RequestState(); + request.setState(s); + log.debug("my: {} leader id {}",ss.getCluster().getServerId(), ss.getNode().getLeaderId()); + + StateServerFactory + .getStateServer() + .getRpcClient() + .invokeAsync(ss.getNode().getLeaderId().getEndpoint(), request, new InvokeCallback() { + + @Override + public void complete(Object result, Throwable err) { + if(result != null){ + onCompleted.apply(Status.OK()); + } else { + var status = new Status(10000, "rpc invokeAsync with request: {}", request); + log.debug("{}", status); + onCompleted.apply(status); + } + } + + }, 5000); + + // log.debug("follow is {}", resp); return; } diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml index 4b84335..f3f6718 100644 --- a/src/main/resources/logback.xml +++ b/src/main/resources/logback.xml @@ -14,11 +14,11 @@ - + - + \ No newline at end of file From 182d38595f714a5f7fc5728aef6fc3b9d134e3c1 Mon Sep 17 00:00:00 2001 From: huangsimin Date: Wed, 20 Jul 2022 18:27:00 +0800 Subject: [PATCH 16/37] =?UTF-8?q?=E5=8E=BB=E9=99=A4Spring=20Boot?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assembly.xml | 44 ++++++++ pom.xml | 103 +++++++++++++++++- .../java/com/yuandian/dataflow/Server.java | 53 ++++----- .../yuandian/dataflow/controller/TaskLog.java | 89 ++++++++------- .../dataflow/grpc/CollectPackets.java | 18 +-- .../com/yuandian/dataflow/projo/Response.java | 4 +- .../dataflow/statemachine/StateMachine.java | 43 ++++---- .../statemachine/StateServerFactory.java | 88 +++------------ .../statemachine/state/StateFactory.java | 78 +++++++++++++ .../statemachine/state/WorkerState.java | 13 ++- src/main/resources/logback.xml | 12 +- .../java/com/yuandian/dataflow/AppTest.java | 2 +- start.sh | 9 +- 13 files changed, 363 insertions(+), 193 deletions(-) create mode 100644 assembly.xml create mode 100644 src/main/java/com/yuandian/dataflow/statemachine/state/StateFactory.java diff --git a/assembly.xml b/assembly.xml new file mode 100644 index 0000000..d0a0aa8 --- /dev/null +++ b/assembly.xml @@ -0,0 +1,44 @@ + + + bin + + dir + tar.gz + + false + + + true + lib + runtime + + + + + unix + 0755 + + bin/** + config/** + + + **/src/** + **/target/** + **/.*/** + + + + + + + lib/ + false + + + lib + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 384412f..b6954ae 100644 --- a/pom.xml +++ b/pom.xml @@ -21,8 +21,8 @@ 2.3.0 1.32.3 1.7.36 - 1.3.10 - 2.7.0 + 1.3.11 + 2.7.1 3.12.11 2.1.0 1.30 @@ -47,6 +47,20 @@ ${yuandian.common.config.version} + + + + + ch.qos.logback + logback-classic + 1.2.11 + + + + ch.qos.logback + logback-core + 1.2.11 + org.slf4j @@ -54,6 +68,27 @@ ${slf4j.version} + + + + + + + + + + + + + org.yaml @@ -77,11 +112,11 @@ - + @@ -214,7 +249,7 @@ --> - + + + + org.apache.maven.plugins + maven-jar-plugin + + + + true + com.yuandian.dataflow.Server + + + + + org.apache.maven.plugins + maven-assembly-plugin + + + make-assembly + package + + single + + + + + + assembly.xml + + + + + + + + + org.apache.maven.plugins diff --git a/src/main/java/com/yuandian/dataflow/Server.java b/src/main/java/com/yuandian/dataflow/Server.java index 6258617..86232a4 100644 --- a/src/main/java/com/yuandian/dataflow/Server.java +++ b/src/main/java/com/yuandian/dataflow/Server.java @@ -1,26 +1,10 @@ package com.yuandian.dataflow; -import java.io.File; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.SpringBootConfiguration; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration; -import org.springframework.context.ConfigurableApplicationContext; - -import com.alipay.remoting.serialization.SerializerManager; import com.alipay.sofa.jraft.JRaftUtils; -import com.alipay.sofa.jraft.Node; -import com.alipay.sofa.jraft.RaftGroupService; import com.alipay.sofa.jraft.conf.Configuration; -import com.alipay.sofa.jraft.entity.PeerId; -import com.alipay.sofa.jraft.option.NodeOptions; -import com.yuandian.dataflow.statemachine.SyncClosure; -import com.yuandian.dataflow.statemachine.StateMachine; import com.yuandian.dataflow.statemachine.StateServerFactory; -import com.yuandian.dataflow.statemachine.rpc.SyncStateProcessor; import lombok.var; import lombok.extern.slf4j.Slf4j; @@ -33,31 +17,38 @@ import lombok.extern.slf4j.Slf4j; * */ @Slf4j -@SpringBootApplication(exclude = {MongoAutoConfiguration.class}) -@SpringBootConfiguration public class Server { - - public static void main(String[] args) throws Exception { - + public static String peeridstr; + public static String sprPort; + public static Configuration conf ; + public static void main(String[] args) throws Exception { + String[] peers = new String[]{"localhost:4440","localhost:4441","localhost:4442"}; String[] sprPeers = new String[]{"3440","3441","3442"}; - var peeridstr = peers[ Integer.parseInt(args[0] )]; - var sprPort = sprPeers[Integer.parseInt(args[0] )]; - + var peeridx = Integer.parseInt(args[0]); + var peeridstr = peers[ peeridx ]; + var sprPort = sprPeers[ peeridx ]; // var peeridstr = peers[2]; // var sprPort = sprPeers[2]; - + log.info("{} {}", peeridstr, sprPort); - Configuration conf = JRaftUtils.getConfiguration("localhost:4440,localhost:4441,localhost:4442"); - - StateServerFactory.initStateServer(peeridstr, conf); + conf = JRaftUtils.getConfiguration(String.join(",", peers)); + StateServerFactory.startStateServer(peeridstr, conf); + + // System.setProperty("server.port", sprPort); + // ConfigurableApplicationContext app = SpringApplication.run(Server.class, args); + // StateServerFactory.setAppCxt(app); + // app.addApplicationListener(new SpringReadyEvent()); + // app.start(); - System.setProperty("server.port", sprPort); - ConfigurableApplicationContext app = SpringApplication.run(Server.class, args); - app.start(); } + + + + + } diff --git a/src/main/java/com/yuandian/dataflow/controller/TaskLog.java b/src/main/java/com/yuandian/dataflow/controller/TaskLog.java index 4589103..626217a 100644 --- a/src/main/java/com/yuandian/dataflow/controller/TaskLog.java +++ b/src/main/java/com/yuandian/dataflow/controller/TaskLog.java @@ -1,10 +1,13 @@ package com.yuandian.dataflow.controller; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestParam; +// import org.springframework.http.HttpStatus; +// import org.springframework.http.MediaType; +// import org.springframework.http.ResponseEntity; +// import org.springframework.stereotype.Controller; +// import org.springframework.web.bind.annotation.GetMapping; +// import org.springframework.web.bind.annotation.PostMapping; +// import org.springframework.web.bind.annotation.RequestBody; +// import org.springframework.web.bind.annotation.RequestParam; import com.alipay.sofa.jraft.Status; import com.alipay.sofa.jraft.entity.PeerId; @@ -19,46 +22,52 @@ import lombok.var; import lombok.extern.slf4j.Slf4j; @Slf4j -@Controller +// @Controller public class TaskLog { - @GetMapping(path = "/test") - public ResponseEntity Processing() throws InterruptedException, RemotingException { - // var ws = new WorkerState(new PeerId()); - // StateServerFactory.getStateServer().updateFsmWorkerState(ws); - Response response = new Response(); - StateServerFactory.getStateServer().useFsmState((fsmState)->{ - log.debug(fsmState.toString() ); - log.debug( StateServerFactory.getNode().getLeaderId().toString() ); - response.Message = fsmState.toString(); - return null; - }); - response.Code = HttpStatus.OK; - return new ResponseEntity(response, HttpStatus.OK); - } + // @PostMapping(path = "/test", produces={MediaType.APPLICATION_JSON_VALUE}) + // public ResponseEntity Processing(@RequestBody String Count) throws InterruptedException, RemotingException { + // // var ws = new WorkerState(new PeerId()); + // // StateServerFactory.getStateServer().updateFsmWorkerState(ws); + // log.debug("{}", Count); + // Response response = new Response(); + // synchronized(response) { + // StateServerFactory.getStateServer().useFsmStateAsync((fsmState)->{ + // log.debug("http: {}",StateServerFactory.getServerId() ); + // response.Message = fsmState.toString(); + // response.notify(); + // return null; + // }); + // } + + // response.Code = HttpStatus.OK; + // return new ResponseEntity(response, HttpStatus.OK); + // } - @GetMapping(path = "/test2") - public ResponseEntity MongodbTest() { - Response response = new Response(); - StateServerFactory.getStateServer().useFsmStateAsync((fsmState)->{ - log.debug("{} {}", fsmState.toString()); - // response.Message = fsmState.toString(); - return null; - }); + // @GetMapping(path = "/test2") + // public ResponseEntity MongodbTest() { + // Response response = new Response(); + // StateServerFactory.getStateServer().useFsmStateAsync((fsmState)->{ + // log.debug("{} {}", fsmState.toString()); + // // response.Message = fsmState.toString(); + // return null; + // }); - return new ResponseEntity(response, HttpStatus.OK); - } + // return new ResponseEntity(response, HttpStatus.OK); + // } - @GetMapping(path = "/test3") - public ResponseEntity RemoveLeader() { - Response response = new Response(); - try { - StateServerFactory.getNode().shutdown(); - } catch (Exception e) { - e.printStackTrace(); - } + // @GetMapping(path = "/test3") + // public ResponseEntity RemoveLeader() { + // Response response = new Response(); + // try { + // StateServerFactory.getNode().shutdown(); + // } catch (Exception e) { + // e.printStackTrace(); + // response.Message = e.getMessage(); + // return new ResponseEntity(response, HttpStatus.INTERNAL_SERVER_ERROR); + // } - return new ResponseEntity(response, HttpStatus.OK); - } + // return new ResponseEntity(response, HttpStatus.OK); + // } } diff --git a/src/main/java/com/yuandian/dataflow/grpc/CollectPackets.java b/src/main/java/com/yuandian/dataflow/grpc/CollectPackets.java index 45ce4ea..74b3a8b 100644 --- a/src/main/java/com/yuandian/dataflow/grpc/CollectPackets.java +++ b/src/main/java/com/yuandian/dataflow/grpc/CollectPackets.java @@ -28,8 +28,8 @@ import com.yuandian.dataflow.proto.msgtype.*; import io.grpc.ManagedChannelBuilder; import lombok.var; import lombok.extern.slf4j.Slf4j; -import org.springframework.http.*; -import org.springframework.web.client.RestTemplate; +// import org.springframework.http.*; +// import org.springframework.web.client.RestTemplate; /** * description @@ -121,15 +121,15 @@ public class CollectPackets extends CollectPacketsServerImplBase { var result = p.unpack(BacktrackingFlowOuterClass.BacktrackingFlow.class); System.out.println(result.getClass().toString() + " ,val: " + JsonFormat.printer().print(result)); - RestTemplate client = new RestTemplate(); - HttpHeaders headers = new HttpHeaders(); - headers.setContentType(MediaType.APPLICATION_JSON); + // RestTemplate client = new RestTemplate(); + // HttpHeaders headers = new HttpHeaders(); + // headers.setContentType(MediaType.APPLICATION_JSON); - HttpEntity requestEntity = new HttpEntity<>(JsonFormat.printer().print(result), headers); - String url = "http://localhost:3440/test"; - ResponseEntity response = client.exchange(url, HttpMethod.POST, requestEntity, Response.class); + // HttpEntity requestEntity = new HttpEntity<>(JsonFormat.printer().print(result), headers); + // String url = "http://localhost:3440/test"; + // ResponseEntity response = client.exchange(url, HttpMethod.POST, requestEntity, Response.class); - System.out.println("result:" + response.getBody()); + // System.out.println("result:" + response.getBody()); } catch (InvalidProtocolBufferException e) { e.printStackTrace(); } diff --git a/src/main/java/com/yuandian/dataflow/projo/Response.java b/src/main/java/com/yuandian/dataflow/projo/Response.java index 8936a92..05bfe65 100644 --- a/src/main/java/com/yuandian/dataflow/projo/Response.java +++ b/src/main/java/com/yuandian/dataflow/projo/Response.java @@ -1,12 +1,12 @@ package com.yuandian.dataflow.projo; -import org.springframework.http.HttpStatus; +import org.apache.http.HttpStatus; import com.fasterxml.jackson.annotation.JsonProperty; public class Response { @JsonProperty("code") - public HttpStatus Code; + public org.apache.http.HttpStatus Code; @JsonProperty("message") public String Message; @JsonProperty("data") diff --git a/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java b/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java index 90eddb4..f4e6595 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java @@ -9,7 +9,7 @@ import java.util.function.Function; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.boot.SpringApplication; + import com.alipay.remoting.exception.CodecException; import com.alipay.remoting.serialization.SerializerManager; @@ -34,6 +34,7 @@ import com.yuandian.dataflow.statemachine.rpc.ResponseSM; import com.yuandian.dataflow.statemachine.rpc.RequestCondition; import com.yuandian.dataflow.statemachine.rpc.RequestState; import com.yuandian.dataflow.statemachine.state.State; +import com.yuandian.dataflow.statemachine.state.StateFactory; import com.yuandian.dataflow.statemachine.state.WorkerState; import lombok.var; @@ -76,9 +77,7 @@ public class StateMachine extends StateMachineAdapter { * Returns current value. 读取修改都在这个函数域内进行 */ public void useState(Function dofunc) { - synchronized(this.state) { - dofunc.apply(this.state); - } + dofunc.apply(this.state); } /** @@ -87,7 +86,7 @@ public class StateMachine extends StateMachineAdapter { * @throws InterruptedException */ public void updateState(Function dofunc) throws InterruptedException, RemotingException { - synchronized(this.state) { + var newstate = dofunc.apply(this.state); var ss = StateServerFactory.getStateServer(); if(!isLeader()) { @@ -109,7 +108,7 @@ public class StateMachine extends StateMachineAdapter { colsure.setValue(newstate); StateServerFactory.getStateServer().applyState(newstate, colsure); } - } + } @@ -123,9 +122,9 @@ public class StateMachine extends StateMachineAdapter { // parsing. var closure = (SyncClosure)iter.done(); // 只支持单一个State. 全状态机只支持一种提交 log.info("SyncDataClosure(done) taskState:{} leaderTerm:{} {}",this.state, this.leaderTerm, closure); - synchronized(this.state) { + this.state = closure.getValue(); - } + closure.success(state); closure.run(Status.OK()); @@ -174,6 +173,9 @@ public class StateMachine extends StateMachineAdapter { state.getWorkers().put(ws.peerId, ws); return state; }); + if(!StateFactory.getMasterExecute().isAlive()) { + StateFactory.getMasterExecute().start(); + } } catch (InterruptedException e) { e.printStackTrace(); } catch (RemotingException e) { @@ -188,6 +190,10 @@ public class StateMachine extends StateMachineAdapter { this.leaderTerm.set(-1); super.onLeaderStop(status); + if(StateFactory.getMasterExecute().isAlive()) { + StateFactory.getMasterExecute().interrupt(); + } + try { updateState((state)->{ state.getWorkers().remove( StateServerFactory.getServerId() ); @@ -206,27 +212,19 @@ public class StateMachine extends StateMachineAdapter { @Override public void onShutdown() { log.debug("onShutdown"); - try { - updateState((state)->{ - state.getWorkers().remove( StateServerFactory.getServerId() ); - return state; - }); - - } catch (InterruptedException e) { - e.printStackTrace(); - } catch (RemotingException e) { - e.printStackTrace(); - } - super.onShutdown(); - } @Override public void onStartFollowing(LeaderChangeContext ctx) { - log.debug("{} {}", ctx, StateServerFactory.getCluster().getServerId()); + log.debug("[onStartFollowing] {} {}", ctx, StateServerFactory.getCluster().getServerId()); try { + + if(StateFactory.getMasterExecute().isAlive()) { + StateFactory.getMasterExecute().interrupt(); + } + var ss = StateServerFactory.getStateServer(); var ws = new WorkerState(ss.getCluster().getServerId()); var request = new RequestCondition(); @@ -248,7 +246,6 @@ public class StateMachine extends StateMachineAdapter { @Override public void onConfigurationCommitted(Configuration conf) { - // TODO Auto-generated method stub super.onConfigurationCommitted(conf); } diff --git a/src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java b/src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java index 5fc2b2e..d7d28ab 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java @@ -13,7 +13,7 @@ import java.util.concurrent.SynchronousQueue; import java.util.concurrent.ThreadPoolExecutor; import java.util.function.Function; -import org.springframework.context.ConfigurableApplicationContext; + import com.alipay.remoting.NamedThreadFactory; import com.alipay.remoting.exception.CodecException; @@ -60,23 +60,20 @@ import lombok.extern.slf4j.Slf4j; public class StateServerFactory { private static StateServer ss; - private static ConfigurableApplicationContext appCxt; - public static void initStateServer(String peerstr, Configuration conf) throws Exception { + private static String myPeerStr; + private static Configuration raftConf; + + public static void startStateServer(String peerstr, Configuration conf) throws Exception { if(ss != null) { throw new Exception("重复初始化 InitStateServer"); } ss = new StateServerFactory.StateServer(peerstr, conf); - log.debug("init peerid {}", ss.node.getNodeId().getPeerId()); } - public static void setAppCxt(ConfigurableApplicationContext cxt) { - appCxt = cxt; - } + - public static ConfigurableApplicationContext getAppCxt() { - return appCxt; - } + public static PeerId getServerId() { @@ -114,15 +111,15 @@ public class StateServerFactory { private Executor readIndexExecutor = createReadIndexExecutor(); public StateServer(String addr, Configuration conf) { - String[] peers = new String[]{"localhost:4440","localhost:4441","localhost:4442"}; - String[] sprPeers = new String[]{"3440","3441","3442"}; + // String[] peers = new String[]{"localhost:4440","localhost:4441","localhost:4442"}; + // String[] sprPeers = new String[]{"3440","3441","3442"}; // var peeridstr = peers[Integer.parseInt(serverId)]; // var sprPort = sprPeers[Integer.parseInt(args[0])]; // String groupId = "jraft"; - // Configuration conf = JRaftUtils.getConfiguration("localhost:4440,localhost:4441,localhost:4442"); + // conf = JRaftUtils.getConfiguration("localhost:4440,localhost:4441,localhost:4442"); PeerId serverId = JRaftUtils.getPeerId(addr); int port = serverId.getPort(); @@ -146,76 +143,17 @@ public class StateServerFactory { cluster.getRpcServer().registerProcessor(new SyncConditionProcessor()); node = cluster.start(); - - rpcClient = new BoltRaftRpcFactory().createRpcClient(); rpcClient.init(new CliOptions()); } + + public boolean isLeader() { return this.fsm.isLeader(); } - - /** - * 同步 可以使用follow使用, 但是可能延迟于leader. 只读 - * @param dofunc - */ - public void useFsmState(Function dofunc) { - - SyncClosure closure = new SyncClosure() { - @Override - public void run(Status status) { - - } - }; - - getNode().readIndex(BytesUtil.EMPTY_BYTES, new ReadIndexClosure() { - @Override - public void run(Status status, long index, byte[] reqCtx) { - - getFsm().useState((fsmState)->{ - if(status.isOk()){ - closure.success(fsmState); - closure.run(Status.OK()); - synchronized(dofunc) { - dofunc.apply(fsmState); - } - return null; - } - - readIndexExecutor.execute(() -> { - if(isLeader()){ - log.debug("Fail to get value with 'ReadIndex': {}, try to applying to the state machine.", getNode()); - applyState(fsmState, closure); - }else { - handlerNotLeaderError(closure); - } - }); - return null; - }); - - synchronized(dofunc) { - // log.debug("dofunc notify {}", getNode()); - dofunc.notify(); - } - } - }); - - try { - synchronized(dofunc) { - // log.debug("dofunc wait"); - dofunc.wait(5000); - // log.debug("dofunc unwait"); - } - } catch (InterruptedException e) { - e.printStackTrace(); - } - return ; - - } - public void useFsmStateAsync(Function dofunc) { SyncClosure closure = new SyncClosure() { @@ -402,7 +340,7 @@ public class StateServerFactory { } - useFsmState((fsmState)->{ + useFsmStateAsync((fsmState)->{ var wmap = fsmState.getWorkers(); var wstate = wmap.get(state.getPeerId()); diff --git a/src/main/java/com/yuandian/dataflow/statemachine/state/StateFactory.java b/src/main/java/com/yuandian/dataflow/statemachine/state/StateFactory.java new file mode 100644 index 0000000..6f49539 --- /dev/null +++ b/src/main/java/com/yuandian/dataflow/statemachine/state/StateFactory.java @@ -0,0 +1,78 @@ +/** + * description + * + * @author eson + *2022年7月20日-10:00:05 + */ +package com.yuandian.dataflow.statemachine.state; + + +import com.alibaba.nacos.api.cmdb.pojo.Entity; +import com.yuandian.dataflow.statemachine.StateServerFactory; + +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import lombok.var; +import lombok.extern.slf4j.Slf4j; + +/** + * description + * + * @author eson + *2022年7月20日-10:00:05 + */ +@Slf4j +@Getter +@Setter +@ToString +public class StateFactory { + + public static Thread masterExecute = new Thread(new Runnable() { + @Override + public void run() { + try { + while(true) { + log.debug("master execute {}", StateServerFactory.getServerId()); + var alivePeers = StateServerFactory.getCluster().getRaftNode().listAlivePeers(); + log.debug("master execute {}", StateServerFactory.getCluster().getRaftNode().listAlivePeers()); + if(alivePeers != null) { + synchronized(alivePeers) { + StateServerFactory.getStateServer().useFsmStateAsync((state)->{ + alivePeers.forEach((peer)->{ + var ws = state.getWorkers().get(peer); + if(ws != null) { + var cap = 10000 - ws.getTaskQueueSize(); + if(cap > 0) { + log.debug("{}", cap); + + + } + } + }); + alivePeers.notify(); + return null; + }); + } + + } + + Thread.sleep(2000); + } + } catch (InterruptedException e) { + e.printStackTrace(); + } + + } + }); + + public static Thread getMasterExecute() { + return masterExecute; + } + + public static void Init() { + + } + + +} diff --git a/src/main/java/com/yuandian/dataflow/statemachine/state/WorkerState.java b/src/main/java/com/yuandian/dataflow/statemachine/state/WorkerState.java index 2d46d94..5e16daf 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/state/WorkerState.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/state/WorkerState.java @@ -7,6 +7,7 @@ package com.yuandian.dataflow.statemachine.state; import java.io.Serializable; +import java.time.Instant; import com.alipay.sofa.jraft.entity.PeerId; @@ -26,9 +27,19 @@ import lombok.ToString; public class WorkerState implements Serializable { private static final long serialVersionUID = -1L; - // 节点的对应peerID + + /** + * 节点的对应peerID + */ public PeerId peerId; + /** + * 任务队列的数量 + */ public long taskQueueSize; + /** + * 更新时间 + */ + public Instant updateAt; public WorkerState(PeerId pid) { this.peerId = pid; diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml index f3f6718..85b4e0c 100644 --- a/src/main/resources/logback.xml +++ b/src/main/resources/logback.xml @@ -10,15 +10,21 @@ DEBUG ACCEPT DENY + + + + ERROR + ACCEPT + DENY --> - + - + \ No newline at end of file diff --git a/src/test/java/com/yuandian/dataflow/AppTest.java b/src/test/java/com/yuandian/dataflow/AppTest.java index 0d6d478..1117839 100644 --- a/src/test/java/com/yuandian/dataflow/AppTest.java +++ b/src/test/java/com/yuandian/dataflow/AppTest.java @@ -21,7 +21,7 @@ import javax.swing.text.AbstractDocument.BranchElement; import org.bson.Document; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import org.springframework.expression.spel.ast.FunctionReference; +// import org.springframework.expression.spel.ast.FunctionReference; import com.mongodb.MongoClient; import com.mongodb.client.model.InsertManyOptions; diff --git a/start.sh b/start.sh index 748c796..366b3f1 100755 --- a/start.sh +++ b/start.sh @@ -2,11 +2,14 @@ screen -S raft-0 -X quit screen -S raft-1 -X quit screen -S raft-2 -X quit + +version=1.0.0-SNAPSHOT + sleep 1 -screen -dmS raft-0 -L java -jar target/dataflow-1.0.0-SNAPSHOT.jar 0 -screen -dmS raft-1 -L java -jar target/dataflow-1.0.0-SNAPSHOT.jar 1 -screen -dmS raft-2 -L java -jar target/dataflow-1.0.0-SNAPSHOT.jar 2 +screen -dmS raft-0 -L java -cp target/dataflow-${version}.jar-bin/lib/*jar -jar target/dataflow-${version}.jar 0 +screen -dmS raft-1 -L java -cp target/dataflow-${version}.jar-bin/lib/*jar -jar target/dataflow-${version}.jar 1 +screen -dmS raft-2 -L java -cp target/dataflow-${version}.jar-bin/lib/*jar -jar target/dataflow-${version}.jar 2 sleep 1 From 8d79341e2305b61c8277b9b9eda88d0024ef4cbc Mon Sep 17 00:00:00 2001 From: huangsimin Date: Thu, 21 Jul 2022 01:43:25 +0800 Subject: [PATCH 17/37] =?UTF-8?q?=E5=88=A0=E9=99=A4springboot=E6=89=93?= =?UTF-8?q?=E5=8C=85=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 4 +- assembly.xml | 24 +++++------ pom.xml | 120 ++++++++++++++++----------------------------------- restart.sh | 2 + start.sh | 9 ++-- stop.sh | 1 + 6 files changed, 59 insertions(+), 101 deletions(-) create mode 100755 restart.sh diff --git a/.gitignore b/.gitignore index 674db64..ffc6ed1 100644 --- a/.gitignore +++ b/.gitignore @@ -79,7 +79,7 @@ local.properties .classpath # Annotation Processing -.apt_generated +.apt_generated* .sts4-cache/ @@ -202,4 +202,4 @@ README.html raftdata -screenlog.* \ No newline at end of file +screenlog.* diff --git a/assembly.xml b/assembly.xml index d0a0aa8..e1c5d6e 100644 --- a/assembly.xml +++ b/assembly.xml @@ -13,25 +13,25 @@ runtime + + + + - unix - 0755 - - bin/** - config/** - - - **/src/** - **/target/** - **/.*/** - + 0664 + ${project.build.directory} + + + *.jar + + - lib/ + ${project.directory} false diff --git a/pom.xml b/pom.xml index b6954ae..c0e9190 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ 3.12.11 2.1.0 1.30 - + 1.2.11 1.0.4 @@ -53,13 +53,13 @@ ch.qos.logback logback-classic - 1.2.11 + ${logback.version} ch.qos.logback logback-core - 1.2.11 + ${logback.version} @@ -67,27 +67,6 @@ slf4j-api ${slf4j.version} - - - - - - - - - - - - - @@ -227,66 +206,63 @@ 1.6.2 - - + org.apache.maven.plugins maven-jar-plugin + true + lib/ com.yuandian.dataflow.Server - + + org.apache.maven.plugins + maven-dependency-plugin + + + copy-dependencies + prepare-package + + copy-dependencies + + + false + false + true + ${project.build.directory}/lib + + + + + + + + org.apache.maven.plugins maven-assembly-plugin make-assembly - package + assembly single + false + + + com.yuandian.dataflow.Server + + assembly.xml @@ -294,29 +270,7 @@ - - + diff --git a/restart.sh b/restart.sh new file mode 100755 index 0000000..3bb4f6e --- /dev/null +++ b/restart.sh @@ -0,0 +1,2 @@ +#! /bin/bash +sh stop.sh & rm raftdata/ -rf && mvn -T4 package && truncate -s 0 screenlog.0 && sh start.sh diff --git a/start.sh b/start.sh index 366b3f1..2b4c76e 100755 --- a/start.sh +++ b/start.sh @@ -1,15 +1,16 @@ +#! /bin/bash screen -S raft-0 -X quit screen -S raft-1 -X quit screen -S raft-2 -X quit -version=1.0.0-SNAPSHOT +VERSION=1.0.0-SNAPSHOT sleep 1 -screen -dmS raft-0 -L java -cp target/dataflow-${version}.jar-bin/lib/*jar -jar target/dataflow-${version}.jar 0 -screen -dmS raft-1 -L java -cp target/dataflow-${version}.jar-bin/lib/*jar -jar target/dataflow-${version}.jar 1 -screen -dmS raft-2 -L java -cp target/dataflow-${version}.jar-bin/lib/*jar -jar target/dataflow-${version}.jar 2 +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 sleep 1 diff --git a/stop.sh b/stop.sh index e34e95a..12f7ef1 100755 --- a/stop.sh +++ b/stop.sh @@ -1,3 +1,4 @@ +#! /bin/bash screen -S raft-0 -X quit screen -S raft-1 -X quit screen -S raft-2 -X quit From b24ac05920097fd7047f47094deb319bfe7e4906 Mon Sep 17 00:00:00 2001 From: huangsimin Date: Thu, 21 Jul 2022 15:48:59 +0800 Subject: [PATCH 18/37] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20raft=E5=A4=84?= =?UTF-8?q?=E7=90=86=E7=9A=84=E6=B3=A8=E8=A7=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 13 +-- .../dataflow/controller/PacketsProcessor.java | 59 ++++++++++++++ .../dataflow/grpc/CollectPackets.java | 2 +- .../master/{Header.java => Master.java} | 2 +- .../dataflow/statemachine/StateMachine.java | 23 +----- .../statemachine/StateServerFactory.java | 25 ++++-- .../statemachine/rpc/RequestCondition.java | 21 ----- .../statemachine/rpc/RequestState.java | 35 -------- .../rpc/SyncConditionProcessor.java | 18 ++++- .../statemachine/rpc/SyncStateProcessor.java | 26 +++++- .../rpc/annotations/ProcessorRaft.java | 24 ++++++ .../statemachine/state/StateFactory.java | 80 +++++++++++++------ src/main/resources/logback.xml | 4 +- 13 files changed, 212 insertions(+), 120 deletions(-) create mode 100644 src/main/java/com/yuandian/dataflow/controller/PacketsProcessor.java rename src/main/java/com/yuandian/dataflow/master/{Header.java => Master.java} (99%) delete mode 100644 src/main/java/com/yuandian/dataflow/statemachine/rpc/RequestCondition.java delete mode 100644 src/main/java/com/yuandian/dataflow/statemachine/rpc/RequestState.java create mode 100644 src/main/java/com/yuandian/dataflow/statemachine/rpc/annotations/ProcessorRaft.java diff --git a/pom.xml b/pom.xml index c0e9190..6aa74f6 100644 --- a/pom.xml +++ b/pom.xml @@ -89,8 +89,13 @@ ${mongo.driver.version} - - + + + org.reflections + reflections + 0.10.2 + + From 08fbedecccb6d50c05bcae4a285b4bb8358a0752 Mon Sep 17 00:00:00 2001 From: huangsimin Date: Thu, 21 Jul 2022 15:49:48 +0800 Subject: [PATCH 19/37] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=8D=95=E5=85=83?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E7=9A=84=E7=B1=BB=E5=9E=8B=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/yuandian/dataflow/statemachine/StateMachineTest.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/test/java/com/yuandian/dataflow/statemachine/StateMachineTest.java b/src/test/java/com/yuandian/dataflow/statemachine/StateMachineTest.java index 329abfa..565a0f2 100644 --- a/src/test/java/com/yuandian/dataflow/statemachine/StateMachineTest.java +++ b/src/test/java/com/yuandian/dataflow/statemachine/StateMachineTest.java @@ -4,14 +4,13 @@ import java.util.concurrent.Executor; import org.junit.jupiter.api.Test; -import com.alipay.sofa.jraft.entity.PeerId; import com.alipay.sofa.jraft.error.RemotingException; import com.alipay.sofa.jraft.option.CliOptions; import com.alipay.sofa.jraft.rpc.InvokeCallback; import com.alipay.sofa.jraft.rpc.impl.BoltRaftRpcFactory; import com.alipay.sofa.jraft.util.Endpoint; import com.yuandian.dataflow.statemachine.rpc.ResponseSM; -import com.yuandian.dataflow.statemachine.rpc.RequestState; +import com.yuandian.dataflow.statemachine.rpc.SyncStateProcessor.RequestState; import com.yuandian.dataflow.statemachine.state.State; import lombok.var; From 761a8dd664f293b2234a0c694617143dab2e70bd Mon Sep 17 00:00:00 2001 From: huangsimin Date: Thu, 21 Jul 2022 16:32:48 +0800 Subject: [PATCH 20/37] =?UTF-8?q?TODO:=20=E6=9B=B4=E6=96=B0=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E7=9A=84=20=E9=87=8D=E6=96=B0=E8=AE=BE=E8=AE=A1=20?= =?UTF-8?q?=E9=81=BF=E5=85=8D=E8=87=AA=E9=94=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dataflow/controller/PacketsProcessor.java | 1 + .../statemachine/StateServerFactory.java | 4 +- .../statemachine/state/StateFactory.java | 80 +++++++++++-------- src/main/resources/logback.xml | 6 +- 4 files changed, 54 insertions(+), 37 deletions(-) diff --git a/src/main/java/com/yuandian/dataflow/controller/PacketsProcessor.java b/src/main/java/com/yuandian/dataflow/controller/PacketsProcessor.java index c8a3162..ff00dc9 100644 --- a/src/main/java/com/yuandian/dataflow/controller/PacketsProcessor.java +++ b/src/main/java/com/yuandian/dataflow/controller/PacketsProcessor.java @@ -45,6 +45,7 @@ public class PacketsProcessor implements RpcProcessor> scans = new Reflections("com.yuandian.dataflow").getTypesAnnotatedWith(ProcessorRaft.class); scans.forEach((pRaftClass)->{ diff --git a/src/main/java/com/yuandian/dataflow/statemachine/state/StateFactory.java b/src/main/java/com/yuandian/dataflow/statemachine/state/StateFactory.java index 6d9c165..0c21e5c 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/state/StateFactory.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/state/StateFactory.java @@ -6,13 +6,16 @@ */ package com.yuandian.dataflow.statemachine.state; - +import java.time.Instant; + import com.alibaba.nacos.shaded.io.grpc.netty.shaded.io.netty.handler.codec.http.HttpContentEncoder.Result; +import com.alipay.sofa.jraft.Status; import com.alipay.sofa.jraft.error.RemotingException; import com.google.protobuf.Any; import com.yuandian.dataflow.controller.PacketsProcessor.PacketsRequest; import com.yuandian.dataflow.proto.msgtype.BacktrackingFlowOuterClass; import com.yuandian.dataflow.statemachine.StateServerFactory; +import com.yuandian.dataflow.statemachine.SyncClosure; import lombok.Getter; import lombok.Setter; @@ -43,47 +46,58 @@ public class StateFactory { if (alivePeers != null) { var ss = StateServerFactory.getStateServer(); StateServerFactory.getStateServer().useFsmStateAsync((state) -> { - synchronized(alivePeers){ - alivePeers.forEach((peer) -> { - var ws = state.getWorkers().get(peer); - if (ws != null) { - var cap = 100 - ws.getTaskQueueSize(); - if (cap > 0) { - log.debug("{}", cap); - var request = new PacketsRequest(); - for(int i = 0; i < cap ; i++ ) { - var p = Any.pack( - BacktrackingFlowOuterClass.BacktrackingFlow.newBuilder() - .setTableId(10086) - .build() - ); + synchronized (alivePeers) { + alivePeers.forEach((peer) -> { + WorkerState ws = state.getWorkers().get(peer); + if (ws != null) { + var cap = 100 - ws.getTaskQueueSize(); + if (cap > 0) { + log.debug("{}", cap); + var request = new PacketsRequest(); + for (int i = 0; i < cap; i++) { + var p = Any.pack( + BacktrackingFlowOuterClass.BacktrackingFlow.newBuilder() + .setTableId(10086) + .build()); request.getPackets().add(p); - } - - try { - var result = ss.getRpcClient().invokeSync(ws.getPeerId().getEndpoint(), request, 5000); - log.info("{}", result); - } catch (InterruptedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (RemotingException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + } + + try { + var result = ss.getRpcClient().invokeSync(ws.getPeerId().getEndpoint(), + request, 5000); + log.info("{}", result); + ws.setUpdateAt( Instant.now() ); + ws.setTaskQueueSize(ws.getTaskQueueSize() - cap); + + + + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (RemotingException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } } } - } - alivePeers.notifyAll(); - }); - } - + + ss.applyState(state, new SyncClosure() { + public void run(Status status) { + log.debug("{}", status); + }; + } ); + alivePeers.notifyAll(); + }); + } + return null; }); - synchronized(alivePeers){ + synchronized (alivePeers) { alivePeers.wait(5000); } - + } Thread.sleep(2000); diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml index 77df777..e67372b 100644 --- a/src/main/resources/logback.xml +++ b/src/main/resources/logback.xml @@ -20,11 +20,11 @@ - - - + + \ No newline at end of file From 3f8e3d5ad7f5ac91704067b996b3a1e63612632f Mon Sep 17 00:00:00 2001 From: huangsimin Date: Thu, 21 Jul 2022 16:44:39 +0800 Subject: [PATCH 21/37] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dataflow/statemachine/rpc/annotations/ProcessorRaft.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/yuandian/dataflow/statemachine/rpc/annotations/ProcessorRaft.java b/src/main/java/com/yuandian/dataflow/statemachine/rpc/annotations/ProcessorRaft.java index 71dda04..86426ef 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/rpc/annotations/ProcessorRaft.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/rpc/annotations/ProcessorRaft.java @@ -12,7 +12,7 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** - * raft自动装配 + * raft自定注册到全局唯一raft服务上 * * @author eson *2022年7月21日-14:27:49 From d35d161f4173e36eb36cfca13c8ae004d6960c0f Mon Sep 17 00:00:00 2001 From: huangsimin Date: Thu, 21 Jul 2022 16:45:30 +0800 Subject: [PATCH 22/37] =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=A4=9A=E4=BD=99?= =?UTF-8?q?=E7=9A=84=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yuandian/dataflow/controller/TaskLog.java | 73 ---------- .../com/yuandian/dataflow/master/Master.java | 137 ------------------ 2 files changed, 210 deletions(-) delete mode 100644 src/main/java/com/yuandian/dataflow/controller/TaskLog.java delete mode 100644 src/main/java/com/yuandian/dataflow/master/Master.java diff --git a/src/main/java/com/yuandian/dataflow/controller/TaskLog.java b/src/main/java/com/yuandian/dataflow/controller/TaskLog.java deleted file mode 100644 index 626217a..0000000 --- a/src/main/java/com/yuandian/dataflow/controller/TaskLog.java +++ /dev/null @@ -1,73 +0,0 @@ -package com.yuandian.dataflow.controller; - -// import org.springframework.http.HttpStatus; -// import org.springframework.http.MediaType; -// import org.springframework.http.ResponseEntity; -// import org.springframework.stereotype.Controller; -// import org.springframework.web.bind.annotation.GetMapping; -// import org.springframework.web.bind.annotation.PostMapping; -// import org.springframework.web.bind.annotation.RequestBody; -// import org.springframework.web.bind.annotation.RequestParam; - -import com.alipay.sofa.jraft.Status; -import com.alipay.sofa.jraft.entity.PeerId; -import com.alipay.sofa.jraft.error.RemotingException; -import com.yuandian.dataflow.projo.Response; -import com.yuandian.dataflow.statemachine.StateServerFactory; -import com.yuandian.dataflow.statemachine.SyncClosure; -import com.yuandian.dataflow.statemachine.state.State; -import com.yuandian.dataflow.statemachine.state.WorkerState; - -import lombok.var; -import lombok.extern.slf4j.Slf4j; - -@Slf4j -// @Controller -public class TaskLog { - - // @PostMapping(path = "/test", produces={MediaType.APPLICATION_JSON_VALUE}) - // public ResponseEntity Processing(@RequestBody String Count) throws InterruptedException, RemotingException { - // // var ws = new WorkerState(new PeerId()); - // // StateServerFactory.getStateServer().updateFsmWorkerState(ws); - // log.debug("{}", Count); - // Response response = new Response(); - // synchronized(response) { - // StateServerFactory.getStateServer().useFsmStateAsync((fsmState)->{ - // log.debug("http: {}",StateServerFactory.getServerId() ); - // response.Message = fsmState.toString(); - // response.notify(); - // return null; - // }); - // } - - // response.Code = HttpStatus.OK; - // return new ResponseEntity(response, HttpStatus.OK); - // } - - // @GetMapping(path = "/test2") - // public ResponseEntity MongodbTest() { - // Response response = new Response(); - // StateServerFactory.getStateServer().useFsmStateAsync((fsmState)->{ - // log.debug("{} {}", fsmState.toString()); - // // response.Message = fsmState.toString(); - // return null; - // }); - - // return new ResponseEntity(response, HttpStatus.OK); - // } - - - // @GetMapping(path = "/test3") - // public ResponseEntity RemoveLeader() { - // Response response = new Response(); - // try { - // StateServerFactory.getNode().shutdown(); - // } catch (Exception e) { - // e.printStackTrace(); - // response.Message = e.getMessage(); - // return new ResponseEntity(response, HttpStatus.INTERNAL_SERVER_ERROR); - // } - - // return new ResponseEntity(response, HttpStatus.OK); - // } -} diff --git a/src/main/java/com/yuandian/dataflow/master/Master.java b/src/main/java/com/yuandian/dataflow/master/Master.java deleted file mode 100644 index 62b0d6f..0000000 --- a/src/main/java/com/yuandian/dataflow/master/Master.java +++ /dev/null @@ -1,137 +0,0 @@ -package com.yuandian.dataflow.master; - -import java.io.ByteArrayInputStream; -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.net.InetSocketAddress; -import java.net.Socket; -import java.net.SocketException; -import java.nio.Buffer; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.util.ArrayList; - -// import com.yuandian.dataflow.proto.decode.PacketBase; -// import com.yuandian.dataflow.proto.decode.PacketHeader; -// import com.yuandian.dataflow.proto.decode.utils; - -import io.netty.handler.codec.compression.ZlibDecoder; -import lombok.Cleanup; -import lombok.Getter; -import lombok.Setter; -import lombok.var; -import lombok.extern.slf4j.Slf4j; - -/** - * Header - */ -@Slf4j - -public class Master { - - public static void main(String[] args) throws Exception { - - var addr = new InetSocketAddress("192.168.1.248", 60001); - @Cleanup - var sock = new Socket(); - sock.setReceiveBufferSize(10 * 1024 * 1024);// socket接收缓存 - sock.setSoTimeout(1000 * 30); - // 设置超时 - sock.connect(addr, 10 * 1000); - var in = new DataInputStream(sock.getInputStream()); - var out = new DataOutputStream(sock.getOutputStream()); - // 发送验证字符串 - // out.write("public".getBytes()); - // log.debug("{}", PacketHeader.PacketCode(in)); - // var pheader = new PacketHeader(in); - - // log.debug("{}", pheader); - // var pbase = PacketBase.createPacketBase(pheader); - // log.debug("{}",pbase); - - - // //60010流需要解压 - // byte[] unzipbodydata = null; - // if (pheader.getTableID() == 20) { - // pheader.parseNextHeader_60010(in); - // byte[] zipbodydata = in.readNBytes(pheader.getMsgLen()); - // unzipbodydata = utils.Inflate(zipbodydata); - // } - - // for (int i = 0; i < pheader.getRecCount(); i++) { - // PacketBase dataBean = null; - - // if (pheader.getTableID() >= 22 && pheader.getTableID() <= 24) { - // // 读取具体数据头信息,获取前四个字段值,第四个字段为整条数据的长度 字段长度分别为 4 1 4 4 - // // bodyhead = new byte[13]; - // // readTillLength(bodyhead, 13); - - // var p1 = ByteBuffer.wrap(in.readNBytes(4)).order(ByteOrder.LITTLE_ENDIAN).getInt(); - // var p2 = ByteBuffer.wrap(in.readNBytes(1)).order(ByteOrder.LITTLE_ENDIAN).getInt(); - // var p3 = ByteBuffer.wrap(in.readNBytes(4)).order(ByteOrder.LITTLE_ENDIAN).getInt(); - // var length = ByteBuffer.wrap(in.readNBytes(4)).order(ByteOrder.LITTLE_ENDIAN).getInt(); - - // if (length <= 13) { - // log.debug("[{}:{}][数据总条数:{}][当前解析第{}条][length<13][探针发包有问题]"); - // throw new Exception("数据解析异常"); - // } - - // // 解析数据 - // dataBean = pbase.Parse(pheader, ByteBuffer.wrap(in.readNBytes(length - 13))); - // } else if (pheader.getTableID() == 25) { - - // var nowtype = ByteBuffer.wrap(in.readNBytes(4)).order(ByteOrder.LITTLE_ENDIAN).getInt(); - // var p2 = ByteBuffer.wrap(in.readNBytes(1)).order(ByteOrder.LITTLE_ENDIAN).getInt(); - // var p3 = ByteBuffer.wrap(in.readNBytes(4)).order(ByteOrder.LITTLE_ENDIAN).getInt(); - // var length = ByteBuffer.wrap(in.readNBytes(4)).order(ByteOrder.LITTLE_ENDIAN).getInt(); - // pheader.setNowType(nowtype); - - - // if (length <= 13) { - // log.debug("[{}:{}][数据总条数:{}][当前解析第{}条][length<13][探针发包有问题]"); - // throw new Exception("数据解析异常"); - // } - - // // 读取具体数据体信息 - // byte[] bodydata = new byte[length - 13]; - // readTillLength(bodydata, length - 13); - - // // 解析数据 - // dataBean = instance.Parse(pheader, bodydata, 0); - // } else if (pheader.getTableID() == 28 || pheader.getTableID() == 29) { //28或29为Apm流统计 - - // if (pheader.getTableID() == 28) { - // length = ApmBaseDataFlow.SIZE; - // } else { - // length = BasicTrafficFlow.SIZE; - // } - - // byte[] bodydata = new byte[length]; - // readTillLength(bodydata, length); - // dataBean = instance.Parse(pheader, bodydata, 0); - - // } else if (pheader.getTableID() == 17 || pheader.getTableID() == 18) { //18 为网络性能流 - // if (pheader.getTableID() == 17) { - // length = AppFlow.SIZE; - // } else if (pheader.getTableID() == 18) { - // length = QoeFlow.SIZE; - // } - // byte[] bodydata = new byte[length]; - // readTillLength(bodydata, length); - // dataBean = instance.Parse(pheader, bodydata, 0); - // } else if (pheader.getTableID() == 20) { - // int offset = i * SstFlow.SIZE; - // dataBean = instance.Parse(pheader, unzipbodydata, offset); - // } else { - // logger.info("不需要的数据类型:" + pheader.getTableID()); - // break; - // } - // if (dataBean != null) { - // tempBaseDatas.add(dataBean); - // } - // } - - } -} From f7dbbb35cbc85a2446882dbc348a2d3b3eff8eb2 Mon Sep 17 00:00:00 2001 From: huangsimin Date: Mon, 25 Jul 2022 17:04:45 +0800 Subject: [PATCH 23/37] =?UTF-8?q?TODO:=20=E8=A7=A3=E5=86=B3=20=E4=B8=BB?= =?UTF-8?q?=E4=BB=8E=E6=93=8D=E4=BD=9C=20=E6=9B=B4=E6=96=B0=E6=B7=B7?= =?UTF-8?q?=E4=B9=B1=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 3 +- .../dataflow/controller/PacketsProcessor.java | 69 ++++++- .../dataflow/statemachine/StateMachine.java | 112 ++++------- .../statemachine/StateServerFactory.java | 185 ++---------------- .../dataflow/statemachine/SyncClosure.java | 8 +- .../{ResponseSM.java => RaftResponse.java} | 2 +- ...sor.java => SyncWorkerStateProcessor.java} | 8 +- .../rpc/annotations/ProcessorRaft.java | 1 - .../statemachine/state/StateFactory.java | 107 +++++----- .../statemachine/StateMachineTest.java | 6 +- 10 files changed, 191 insertions(+), 310 deletions(-) rename src/main/java/com/yuandian/dataflow/statemachine/rpc/{ResponseSM.java => RaftResponse.java} (93%) rename src/main/java/com/yuandian/dataflow/statemachine/rpc/{SyncConditionProcessor.java => SyncWorkerStateProcessor.java} (85%) diff --git a/pom.xml b/pom.xml index 6aa74f6..d35d4da 100644 --- a/pom.xml +++ b/pom.xml @@ -147,13 +147,14 @@ ${grpc.version} - + org.projectlombok lombok 1.18.24 provided + diff --git a/src/main/java/com/yuandian/dataflow/controller/PacketsProcessor.java b/src/main/java/com/yuandian/dataflow/controller/PacketsProcessor.java index ff00dc9..df20041 100644 --- a/src/main/java/com/yuandian/dataflow/controller/PacketsProcessor.java +++ b/src/main/java/com/yuandian/dataflow/controller/PacketsProcessor.java @@ -7,15 +7,23 @@ package com.yuandian.dataflow.controller; import java.io.Serializable; +import java.time.Instant; import java.util.ArrayList; +import com.alipay.sofa.jraft.Status; import com.alipay.sofa.jraft.entity.PeerId; +import com.alipay.sofa.jraft.error.RemotingException; +import com.alipay.sofa.jraft.rpc.InvokeCallback; import com.alipay.sofa.jraft.rpc.RpcContext; import com.alipay.sofa.jraft.rpc.RpcProcessor; import com.google.protobuf.Any; import com.yuandian.dataflow.statemachine.StateServerFactory; -import com.yuandian.dataflow.statemachine.rpc.ResponseSM; +import com.yuandian.dataflow.statemachine.SyncClosure; +import com.yuandian.dataflow.statemachine.rpc.RaftResponse; +import com.yuandian.dataflow.statemachine.rpc.SyncStateProcessor; +import com.yuandian.dataflow.statemachine.rpc.SyncWorkerStateProcessor; import com.yuandian.dataflow.statemachine.rpc.annotations.ProcessorRaft; +import com.yuandian.dataflow.statemachine.state.State; import lombok.Getter; import lombok.Setter; @@ -42,19 +50,62 @@ public class PacketsProcessor implements RpcProcessor{ + + var work = state.getWorkers().get( ss.getCluster().getServerId()); + + + work.setTaskQueueSize( work.getTaskQueueSize() - request.packets.size()); + work.setUpdateAt(Instant.now()); + + if(!ss.isLeader()) { + var requestUpdateState = new SyncWorkerStateProcessor.RequestWorkerState(); + requestUpdateState.setWorkerState(work); + log.info("转发 {}", work); + try { + ss.getRpcClient().invokeAsync(StateServerFactory.getNode().getLeaderId().getEndpoint(), + requestUpdateState, new InvokeCallback() { + @Override + public void complete(Object result, Throwable err) { + if (err != null) { + err.printStackTrace(); + } else { + log.debug("转发 udate workerState {}", result); + } + rpcCtx.sendResponse(resp); + }}, 5000); + } catch (InterruptedException | RemotingException e) { + e.printStackTrace(); + } + return; + } + + + StateServerFactory.getStateServer().applyWorkerState(work, new SyncClosure() { + @Override + public void run(Status status) { + log.debug("finsh tasks size {}, size: {}", status, request.packets.size()); + rpcCtx.sendResponse(resp); + } + + }); + }); + + } @Override public String interest() { - // TODO Auto-generated method stub return PacketsRequest.class.getName(); } - - - } diff --git a/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java b/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java index 59afa42..5cba656 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java @@ -16,8 +16,8 @@ import com.alipay.sofa.jraft.error.RaftException; import com.alipay.sofa.jraft.error.RemotingException; import com.alipay.sofa.jraft.storage.snapshot.SnapshotReader; import com.alipay.sofa.jraft.storage.snapshot.SnapshotWriter; -import com.yuandian.dataflow.statemachine.rpc.ResponseSM; -import com.yuandian.dataflow.statemachine.rpc.SyncConditionProcessor.RequestCondition; +import com.yuandian.dataflow.statemachine.rpc.RaftResponse; +import com.yuandian.dataflow.statemachine.rpc.SyncWorkerStateProcessor.RequestWorkerState; import com.yuandian.dataflow.statemachine.rpc.SyncStateProcessor.RequestState; import com.yuandian.dataflow.statemachine.state.State; import com.yuandian.dataflow.statemachine.state.StateFactory; @@ -58,46 +58,9 @@ public class StateMachine extends StateMachineAdapter { return state; } - - /** - * Returns current value. 读取修改都在这个函数域内进行 - */ - public void useState(Function dofunc) { - dofunc.apply(this.state); - } - /** - * Returns current value. 读取修改都在这个函数域内进行 - * @throws RemotingException - * @throws InterruptedException - */ - public void updateState(Function dofunc) throws InterruptedException, RemotingException { - - var newstate = dofunc.apply(this.state); - var ss = StateServerFactory.getStateServer(); - if(!isLeader()) { - var request = new RequestState(); - request.setState(newstate); - var result = ss.getRpcClient().invokeSync(ss.getNode().getLeaderId().getEndpoint(), request, 5000); - log.info("{}", result); - return; - } - - // this.state = newstate; - if(newstate != null) { - var colsure = new SyncClosure() { - @Override - public void run(Status status) { - - } - }; - colsure.setValue(newstate); - StateServerFactory.getStateServer().applyState(newstate, colsure); - } - - } - - + + @Override @SuppressWarnings("unchecked") public void onApply(final Iterator iter) { @@ -107,7 +70,7 @@ public class StateMachine extends StateMachineAdapter { // This task is applied by this node, get value from closure to avoid additional // parsing. var closure = (SyncClosure)iter.done(); // 只支持单一个State. 全状态机只支持一种提交 - log.info("SyncDataClosure(done) taskState:{} leaderTerm:{} {}",this.state, this.leaderTerm, closure); + // log.info("SyncDataClosure(done) taskState:{} leaderTerm:{} {}",this.state, this.leaderTerm, closure); this.state = closure.getValue(); closure.success(state); closure.run(Status.OK()); @@ -115,11 +78,11 @@ public class StateMachine extends StateMachineAdapter { // Have to parse FetchAddRequest from this user log. final ByteBuffer data = iter.getData(); try { - synchronized(state) { - state = SerializerManager.getSerializer(SerializerManager.Hessian2).deserialize( - data.array(), State.class.getName()); - log.info("SyncDataClosure(null) taskState:{} leaderTerm:{}", state, this.leaderTerm); - } + + state = SerializerManager.getSerializer(SerializerManager.Hessian2).deserialize( + data.array(), State.class.getName()); + // log.info("SyncDataClosure(null) taskState:{} leaderTerm:{}", state, this.leaderTerm); + } catch (CodecException e) { e.printStackTrace(); @@ -150,20 +113,31 @@ public class StateMachine extends StateMachineAdapter { public void onLeaderStart(final long term) { log.debug("onLeaderStart {}", StateServerFactory.getCluster().getServerId()); this.leaderTerm.set(term); - try { - updateState((state)->{ - var ws = new WorkerState(StateServerFactory.getStateServer().getCluster().getServerId()); - state.getWorkers().put(ws.peerId, ws); - return state; - }); - if(!StateFactory.getMasterExecute().isAlive()) { - StateFactory.getMasterExecute().start(); - } - } catch (InterruptedException e) { - e.printStackTrace(); - } catch (RemotingException e) { - e.printStackTrace(); + + if(StateFactory.getMasterExecute().isAlive()) { + StateFactory.getMasterExecute().interrupt(); } + + var ss = StateServerFactory.getStateServer(); + ss.useFsmStateNotLock((state)->{ + var ws = state.getWorkers().get( ss.getCluster().getServerId() ); + if(ws == null) { + ws = new WorkerState(ss.getCluster().getServerId()); + state.getWorkers().put(ss.getCluster().getServerId(), ws); + } + + ss.applyState(state, new SyncClosure() { + @Override + public void run(Status status) { + log.debug("master update workerstate: {}", status); + } + + }); + + }); + + StateFactory.getMasterExecute().start(); + super.onLeaderStart(term); } @@ -177,17 +151,7 @@ public class StateMachine extends StateMachineAdapter { StateFactory.getMasterExecute().interrupt(); } - try { - updateState((state)->{ - state.getWorkers().remove( StateServerFactory.getServerId() ); - return state; - }); - - } catch (InterruptedException e) { - e.printStackTrace(); - } catch (RemotingException e) { - e.printStackTrace(); - } + } @@ -210,11 +174,11 @@ public class StateMachine extends StateMachineAdapter { var ss = StateServerFactory.getStateServer(); var ws = new WorkerState(ss.getCluster().getServerId()); - var request = new RequestCondition(); + var request = new RequestWorkerState(); request.setWorkerState(ws); log.debug("my: {} leader id {}",ss.getCluster().getServerId(), ss.getNode().getLeaderId()); - ResponseSM resp; - resp = (ResponseSM)StateServerFactory.getStateServer().getRpcClient().invokeSync(ss.getNode().getLeaderId().getEndpoint(), request, 5000); + RaftResponse resp; + resp = (RaftResponse)StateServerFactory.getStateServer().getRpcClient().invokeSync(ss.getNode().getLeaderId().getEndpoint(), request, 5000); if(resp == null) { log.debug("{} set WorkerState is error", resp); } diff --git a/src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java b/src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java index 4f47e9e..cef50ce 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java @@ -12,6 +12,7 @@ import java.util.Set; import java.util.concurrent.Executor; import java.util.concurrent.SynchronousQueue; import java.util.concurrent.ThreadPoolExecutor; +import java.util.function.Consumer; import java.util.function.Function; import org.reflections.Reflections; @@ -38,8 +39,8 @@ import com.alipay.sofa.jraft.rpc.impl.BoltRaftRpcFactory; import com.alipay.sofa.jraft.util.BytesUtil; import com.alipay.sofa.jraft.util.Endpoint; import com.alipay.sofa.jraft.util.ThreadPoolUtil; -import com.yuandian.dataflow.statemachine.rpc.ResponseSM; -import com.yuandian.dataflow.statemachine.rpc.SyncConditionProcessor.RequestCondition; +import com.yuandian.dataflow.statemachine.rpc.RaftResponse; +import com.yuandian.dataflow.statemachine.rpc.SyncWorkerStateProcessor.RequestWorkerState; import com.yuandian.dataflow.statemachine.rpc.SyncStateProcessor.RequestState; import com.yuandian.dataflow.statemachine.rpc.annotations.ProcessorRaft; import com.yuandian.dataflow.statemachine.state.State; @@ -166,164 +167,21 @@ public class StateServerFactory { return this.fsm.isLeader(); } - - public void useFsmStateAsync(Function dofunc) { - - SyncClosure closure = new SyncClosure() { - @Override - public void run(Status status) { - if(status.isOk()) { - dofunc.apply(this.getValue()); - } - } - }; - - getNode().readIndex(BytesUtil.EMPTY_BYTES, new ReadIndexClosure() { - @Override - public void run(Status status, long index, byte[] reqCtx) { - - getFsm().useState((fsmState)->{ - if(status.isOk()){ - closure.setValue(fsmState); - closure.success(fsmState); - closure.run(Status.OK()); - return null; - } - - readIndexExecutor.execute(() -> { - if(isLeader()){ - log.info("Fail to get value with 'ReadIndex': {}, try to applying to the state machine.", getNode()); - applyState(fsmState, closure); - }else { - handlerNotLeaderError(closure); - } - }); - return null; - }); - } - }); - - return ; - } - - /** - * 同步更新 WorkerState - * @param dofunc - * @throws InterruptedException - * @throws RemotingException - */ - public void updateFsmWorkerState(WorkerState ws) throws InterruptedException, RemotingException { - - // leader就直接提交 - if(isLeader()) { - var closure = new SyncClosure() { - @Override - public void run(Status status) { - // log.debug("leader {}", status); - this.synclock.notify(); - } - }; - StateServerFactory.getStateServer().applyWorkerState(ws, closure); - closure.synclock.wait(5000); - return; - } - - try { - // 非leader就 rpc请求 - var ss = StateServerFactory.getStateServer(); - var request = new RequestCondition(); - request.setWorkerState(ws); - log.debug("my: {} leader id {}",ss.getCluster().getServerId(), ss.getNode().getLeaderId()); - ResponseSM resp; - resp = (ResponseSM)StateServerFactory.getRpcClient().invokeSync(StateServerFactory.getNode().getLeaderId().getEndpoint(), request, 5000); - if(resp == null) { - log.error("{} set WorkerState is error", resp); - } - // log.debug("follow is {}", resp); - return; - } catch (InterruptedException | RemotingException e) { - e.printStackTrace(); - } - } - - /** - * 同步更新整个State - * @param s - * @throws InterruptedException - * @throws RemotingException - */ - public void updateFsmState(State s) throws InterruptedException, RemotingException { - if(isLeader()) { - var closure = new SyncClosure() { - @Override - public void run(Status status) { - // log.debug("leader update {}", status); - synclock.notify(); - } - }; - StateServerFactory.getStateServer().applyState(s, closure); - closure.synclock.wait(5000); - return; - } - - var ss = StateServerFactory.getStateServer(); - var request = new RequestState(); - request.setState(s); - log.debug("my: {} leader id {}",ss.getCluster().getServerId(), ss.getNode().getLeaderId()); - ResponseSM resp; - resp = (ResponseSM)StateServerFactory.getStateServer().getRpcClient().invokeSync(ss.getNode().getLeaderId().getEndpoint(), request, 5000); - if(resp == null) { - log.error("{} set State is error", resp); - } - // log.debug("follow is {}", resp); - return; - - } - - - public void updateFsmStateAsync(State s, Function onCompleted) throws InterruptedException, RemotingException { - if(isLeader()) { - var closure = new SyncClosure() { - @Override - public void run(Status status) { - // log.debug("leader update {}", status); - if(status.isOk()) { - onCompleted.apply(status); - } - } - }; - StateServerFactory.getStateServer().applyState(s, closure); - return; - } - - var ss = StateServerFactory.getStateServer(); - var request = new RequestState(); - request.setState(s); - log.debug("my: {} leader id {}",ss.getCluster().getServerId(), ss.getNode().getLeaderId()); - StateServerFactory - .getStateServer() - .getRpcClient() - .invokeAsync(ss.getNode().getLeaderId().getEndpoint(), request, new InvokeCallback() { - @Override - public void complete(Object result, Throwable err) { - if(result != null){ - onCompleted.apply(Status.OK()); - } else { - var status = new Status(10000, "rpc invokeAsync with request: {}", request); - log.debug("{}", status); - onCompleted.apply(status); - } - } - - }, 5000); - - // log.debug("follow is {}", resp); - return; - + public void useFsmState(Consumer dofunc) { + var state = ss.fsm.getState(); + synchronized(state) { + dofunc.accept(state); + } } + public void useFsmStateNotLock(Consumer dofunc) { + var state = ss.fsm.getState(); + dofunc.accept(state); + } + + public void applyState(State state, SyncClosure closure) { // 所有的提交都必须再leader进行 @@ -351,10 +209,8 @@ public class StateServerFactory { ss.handlerNotLeaderError(closure); return; } - - - useFsmStateAsync((fsmState)->{ - + + StateServerFactory.getStateServer().useFsmStateNotLock((fsmState)->{ var wmap = fsmState.getWorkers(); var wstate = wmap.get(state.getPeerId()); @@ -376,16 +232,13 @@ public class StateServerFactory { closure.success(fsmState); closure.run(Status.OK()); } - return null; }); - - - + } - public ResponseSM redirect() { - final ResponseSM response = new ResponseSM(); + public RaftResponse redirect() { + final RaftResponse response = new RaftResponse(); response.setSuccess(false); if (this.node != null) { final PeerId leader = this.node.getLeaderId(); diff --git a/src/main/java/com/yuandian/dataflow/statemachine/SyncClosure.java b/src/main/java/com/yuandian/dataflow/statemachine/SyncClosure.java index 40ba6d9..19ab8a7 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/SyncClosure.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/SyncClosure.java @@ -3,7 +3,7 @@ package com.yuandian.dataflow.statemachine; import com.alipay.sofa.jraft.Closure; import com.alipay.sofa.jraft.Status; import com.alipay.sofa.jraft.entity.PeerId; -import com.yuandian.dataflow.statemachine.rpc.ResponseSM; +import com.yuandian.dataflow.statemachine.rpc.RaftResponse; import com.yuandian.dataflow.statemachine.state.State; import lombok.Getter; @@ -21,7 +21,7 @@ import org.slf4j.LoggerFactory; public abstract class SyncClosure implements Closure { // 状态机的统一响应 - private ResponseSM response; + private RaftResponse response; // 代表任务状态 private T value; @@ -33,7 +33,7 @@ public abstract class SyncClosure implements Closure { } public void failure(final String errorMsg, final PeerId redirect) { - final ResponseSM response = new ResponseSM(); + final RaftResponse response = new RaftResponse(); response.setSuccess(false); response.setMsg(errorMsg); response.setRedirect(redirect); @@ -41,7 +41,7 @@ public abstract class SyncClosure implements Closure { } public void success(final State value) { - final ResponseSM response = new ResponseSM(); + final RaftResponse response = new RaftResponse(); response.setState(value); response.setSuccess(true); setResponse(response); diff --git a/src/main/java/com/yuandian/dataflow/statemachine/rpc/ResponseSM.java b/src/main/java/com/yuandian/dataflow/statemachine/rpc/RaftResponse.java similarity index 93% rename from src/main/java/com/yuandian/dataflow/statemachine/rpc/ResponseSM.java rename to src/main/java/com/yuandian/dataflow/statemachine/rpc/RaftResponse.java index 5e4694f..f2769d8 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/rpc/ResponseSM.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/rpc/RaftResponse.java @@ -26,7 +26,7 @@ import lombok.extern.slf4j.Slf4j; @Getter @Setter @ToString -public class ResponseSM implements Serializable { +public class RaftResponse implements Serializable { private static final long serialVersionUID = 1L; diff --git a/src/main/java/com/yuandian/dataflow/statemachine/rpc/SyncConditionProcessor.java b/src/main/java/com/yuandian/dataflow/statemachine/rpc/SyncWorkerStateProcessor.java similarity index 85% rename from src/main/java/com/yuandian/dataflow/statemachine/rpc/SyncConditionProcessor.java rename to src/main/java/com/yuandian/dataflow/statemachine/rpc/SyncWorkerStateProcessor.java index 4bd0352..252f473 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/rpc/SyncConditionProcessor.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/rpc/SyncWorkerStateProcessor.java @@ -41,12 +41,12 @@ import lombok.extern.slf4j.Slf4j; */ @Slf4j @ProcessorRaft -public class SyncConditionProcessor implements RpcProcessor { +public class SyncWorkerStateProcessor implements RpcProcessor { @Getter @Setter @ToString - public static class RequestCondition implements Serializable { + public static class RequestWorkerState implements Serializable { private static final long serialVersionUID = 1L; @@ -54,7 +54,7 @@ public class SyncConditionProcessor implements RpcProcessor closure = new SyncClosure< State>() { @@ -70,7 +70,7 @@ public class SyncConditionProcessor implements RpcProcessor { - synchronized (alivePeers) { - alivePeers.forEach((peer) -> { - WorkerState ws = state.getWorkers().get(peer); - if (ws != null) { - var cap = 100 - ws.getTaskQueueSize(); - if (cap > 0) { - log.debug("{}", cap); - var request = new PacketsRequest(); - for (int i = 0; i < cap; i++) { - var p = Any.pack( - BacktrackingFlowOuterClass.BacktrackingFlow.newBuilder() - .setTableId(10086) - .build()); + // var state = ss.getFsm().getState(); + ss.useFsmStateNotLock((state) -> { + alivePeers.forEach((peer) -> { + WorkerState ws = state.getWorkers().get(peer); - request.getPackets().add(p); - - } - - try { - var result = ss.getRpcClient().invokeSync(ws.getPeerId().getEndpoint(), - request, 5000); - log.info("{}", result); - ws.setUpdateAt( Instant.now() ); - ws.setTaskQueueSize(ws.getTaskQueueSize() - cap); - - - - } catch (InterruptedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (RemotingException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } + if (ws != null) { + var cap = 100 - ws.getTaskQueueSize(); + log.debug("cap :{} peer: {}", cap, peer); + if (cap <= 0) { + return ; } - ss.applyState(state, new SyncClosure() { - public void run(Status status) { - log.debug("{}", status); - }; - } ); - alivePeers.notifyAll(); - }); - } + var request = new PacketsRequest(); + for (int i = 0; i < cap; i++) { + var p = Any.pack( + BacktrackingFlowOuterClass.BacktrackingFlow.newBuilder() + .setTableId(10086) + .build()); + request.getPackets().add(p); + } - return null; + + try { + log.debug("rpc {}", peer); + ss.getRpcClient().invokeAsync(peer.getEndpoint(), + request, new InvokeCallback() { + @Override + public void complete(Object result, Throwable err) { + if (err != null) { + err.printStackTrace(); + } else { + log.info("{} peer result", result); + } + } + + }, 5000); + } catch (InterruptedException | RemotingException e) { + e.printStackTrace(); + } + ws.setUpdateAt(Instant.now()); + ws.setTaskQueueSize(100); + } + }); + + ss.applyState(state, new SyncClosure() { + @Override + public void run(Status status) { + log.info("任务队列更新成功 {}", this.getValue().getWorkers()); + } + }); + + }); - synchronized (alivePeers) { - alivePeers.wait(5000); - } + + + + // ss.applyState(state, new SyncClosure() { + // public void run(Status status) { + // log.debug("{}", status); + // }; + // }); } diff --git a/src/test/java/com/yuandian/dataflow/statemachine/StateMachineTest.java b/src/test/java/com/yuandian/dataflow/statemachine/StateMachineTest.java index 565a0f2..a5e0146 100644 --- a/src/test/java/com/yuandian/dataflow/statemachine/StateMachineTest.java +++ b/src/test/java/com/yuandian/dataflow/statemachine/StateMachineTest.java @@ -9,7 +9,7 @@ import com.alipay.sofa.jraft.option.CliOptions; import com.alipay.sofa.jraft.rpc.InvokeCallback; import com.alipay.sofa.jraft.rpc.impl.BoltRaftRpcFactory; import com.alipay.sofa.jraft.util.Endpoint; -import com.yuandian.dataflow.statemachine.rpc.ResponseSM; +import com.yuandian.dataflow.statemachine.rpc.RaftResponse; import com.yuandian.dataflow.statemachine.rpc.SyncStateProcessor.RequestState; import com.yuandian.dataflow.statemachine.state.State; @@ -28,12 +28,12 @@ public class StateMachineTest { fdata.setState(fstate); var leader = new Endpoint("localhost",4441); - ResponseSM resp = (ResponseSM)rpcClient.invokeSync(leader, fdata + RaftResponse resp = (RaftResponse)rpcClient.invokeSync(leader, fdata , 5000); log.info("{}", resp); if( resp != null && !resp.isSuccess() ) { leader = resp.getRedirect().getEndpoint(); - resp = (ResponseSM)rpcClient.invokeSync(resp.getRedirect().getEndpoint(), fdata + resp = (RaftResponse)rpcClient.invokeSync(resp.getRedirect().getEndpoint(), fdata , 5000); log.info("{}", resp); } From 644e65603fe9a6a1a393911e36904ffa7a0fe4ed Mon Sep 17 00:00:00 2001 From: huangsimin Date: Mon, 25 Jul 2022 17:55:23 +0800 Subject: [PATCH 24/37] =?UTF-8?q?TODO:=20=E9=87=8D=E6=96=B0=E8=AE=BE?= =?UTF-8?q?=E8=AE=A1=20=E5=9D=87=E8=A1=A1=E5=A4=84=E7=90=86=E6=96=B9?= =?UTF-8?q?=E6=A1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dataflow/controller/PacketsProcessor.java | 1 - .../statemachine/StateServerFactory.java | 30 +++--- .../rpc/SyncWorkerStateProcessor.java | 2 +- .../statemachine/state/StateFactory.java | 94 +++++++++++++------ 4 files changed, 79 insertions(+), 48 deletions(-) diff --git a/src/main/java/com/yuandian/dataflow/controller/PacketsProcessor.java b/src/main/java/com/yuandian/dataflow/controller/PacketsProcessor.java index df20041..450d47f 100644 --- a/src/main/java/com/yuandian/dataflow/controller/PacketsProcessor.java +++ b/src/main/java/com/yuandian/dataflow/controller/PacketsProcessor.java @@ -97,7 +97,6 @@ public class PacketsProcessor implements RpcProcessor closure) { + log.debug("applyWorkerState"); if (!ss.isLeader()) { ss.handlerNotLeaderError(closure); return; @@ -213,24 +214,21 @@ public class StateServerFactory { StateServerFactory.getStateServer().useFsmStateNotLock((fsmState)->{ var wmap = fsmState.getWorkers(); var wstate = wmap.get(state.getPeerId()); - if(wstate == null) { wmap.put(state.getPeerId(), state); - try { - final Task task = new Task(); - closure.setValue(fsmState); - task.setData(ByteBuffer.wrap(SerializerManager.getSerializer(SerializerManager.Hessian2).serialize(fsmState))); - task.setDone(closure); - StateServerFactory.getStateServer().getNode().apply(task); // 提交数据 - } catch (CodecException e) { - String errorMsg = "Fail to encode TaskState"; - log.debug("{}:{}",errorMsg, e); - closure.failure(errorMsg, PeerId.emptyPeer()); - closure.run(new Status(RaftError.EINTERNAL, errorMsg)); - } - } else { - closure.success(fsmState); - closure.run(Status.OK()); + } + + try { + final Task task = new Task(); + closure.setValue(fsmState); + task.setData(ByteBuffer.wrap(SerializerManager.getSerializer(SerializerManager.Hessian2).serialize(fsmState))); + task.setDone(closure); + StateServerFactory.getStateServer().getNode().apply(task); // 提交数据 + } catch (CodecException e) { + String errorMsg = "Fail to encode TaskState"; + log.debug("{}:{}",errorMsg, e); + closure.failure(errorMsg, PeerId.emptyPeer()); + closure.run(new Status(RaftError.EINTERNAL, errorMsg)); } }); diff --git a/src/main/java/com/yuandian/dataflow/statemachine/rpc/SyncWorkerStateProcessor.java b/src/main/java/com/yuandian/dataflow/statemachine/rpc/SyncWorkerStateProcessor.java index 252f473..a7212c6 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/rpc/SyncWorkerStateProcessor.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/rpc/SyncWorkerStateProcessor.java @@ -56,7 +56,7 @@ public class SyncWorkerStateProcessor implements RpcProcessor closure = new SyncClosure< State>() { @Override public void run(Status status) { diff --git a/src/main/java/com/yuandian/dataflow/statemachine/state/StateFactory.java b/src/main/java/com/yuandian/dataflow/statemachine/state/StateFactory.java index 30b8808..8c8ab68 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/state/StateFactory.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/state/StateFactory.java @@ -7,11 +7,13 @@ package com.yuandian.dataflow.statemachine.state; import java.time.Instant; +import java.util.ArrayList; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import com.alibaba.nacos.shaded.io.grpc.netty.shaded.io.netty.handler.codec.http.HttpContentEncoder.Result; import com.alipay.sofa.jraft.Status; +import com.alipay.sofa.jraft.entity.PeerId; import com.alipay.sofa.jraft.error.RemotingException; import com.alipay.sofa.jraft.rpc.InvokeCallback; import com.google.protobuf.Any; @@ -38,6 +40,18 @@ import lombok.extern.slf4j.Slf4j; @ToString public class StateFactory { + @Getter + @Setter + @ToString + public static class PeerIdCap { + private PeerId peer; + private long cap; + public PeerIdCap(PeerId pid, long cap) { + this.peer = pid; + this.cap = cap; + } + } + public static Thread masterExecute = new Thread(new Runnable() { @Override public void run() { @@ -50,46 +64,24 @@ public class StateFactory { var ss = StateServerFactory.getStateServer(); // var state = ss.getFsm().getState(); + + ArrayList pclist = new ArrayList(); + ss.useFsmStateNotLock((state) -> { alivePeers.forEach((peer) -> { WorkerState ws = state.getWorkers().get(peer); - if (ws != null) { var cap = 100 - ws.getTaskQueueSize(); log.debug("cap :{} peer: {}", cap, peer); if (cap <= 0) { return ; } - - var request = new PacketsRequest(); - for (int i = 0; i < cap; i++) { - var p = Any.pack( - BacktrackingFlowOuterClass.BacktrackingFlow.newBuilder() - .setTableId(10086) - .build()); - request.getPackets().add(p); - } - - - try { - log.debug("rpc {}", peer); - ss.getRpcClient().invokeAsync(peer.getEndpoint(), - request, new InvokeCallback() { - @Override - public void complete(Object result, Throwable err) { - if (err != null) { - err.printStackTrace(); - } else { - log.info("{} peer result", result); - } - } - - }, 5000); - } catch (InterruptedException | RemotingException e) { - e.printStackTrace(); - } ws.setUpdateAt(Instant.now()); ws.setTaskQueueSize(100); + var pc = new PeerIdCap(peer, cap); + pc.setCap(cap); + ; + pclist.add(pc); } }); @@ -97,6 +89,48 @@ public class StateFactory { @Override public void run(Status status) { log.info("任务队列更新成功 {}", this.getValue().getWorkers()); + + pclist.forEach((peer) -> { + + + + + + + if (peer.getCap() <= 0) { + return ; + } + + var request = new PacketsRequest(); + for (int i = 0; i < peer.getCap(); i++) { + var p = Any.pack( + BacktrackingFlowOuterClass.BacktrackingFlow.newBuilder() + .setTableId(10086) + .build()); + request.getPackets().add(p); + } + + + try { + log.debug("rpc {}", peer); + ss.getRpcClient().invokeAsync(peer.peer.getEndpoint() , + request, new InvokeCallback() { + @Override + public void complete(Object result, Throwable err) { + if (err != null) { + err.printStackTrace(); + } else { + log.info("{} peer result", result); + } + } + + }, 5000); + } catch (InterruptedException | RemotingException e) { + e.printStackTrace(); + } + + + }); } }); @@ -113,7 +147,7 @@ public class StateFactory { } - Thread.sleep(2000); + Thread.sleep(5000); } } catch (InterruptedException e) { e.printStackTrace(); From bf415d45e819d83994909a8f040337f9ba136ad6 Mon Sep 17 00:00:00 2001 From: huangsimin Date: Tue, 26 Jul 2022 00:25:56 +0800 Subject: [PATCH 25/37] =?UTF-8?q?TODO:=20=E5=88=86=E7=89=87=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F=E5=A4=84=E7=90=86=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dataflow/controller/PacketsProcessor.java | 16 ++++++---------- .../statemachine/StateServerFactory.java | 16 +++++++++++++++- .../statemachine/state/StateFactory.java | 17 ++++++----------- 3 files changed, 27 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/yuandian/dataflow/controller/PacketsProcessor.java b/src/main/java/com/yuandian/dataflow/controller/PacketsProcessor.java index 450d47f..84d6536 100644 --- a/src/main/java/com/yuandian/dataflow/controller/PacketsProcessor.java +++ b/src/main/java/com/yuandian/dataflow/controller/PacketsProcessor.java @@ -54,20 +54,17 @@ public class PacketsProcessor implements RpcProcessor{ var work = state.getWorkers().get( ss.getCluster().getServerId()); - - + + work.setTaskQueueSize( work.getTaskQueueSize() - request.packets.size()); work.setUpdateAt(Instant.now()); - + log.debug("workerState taskQueueSize: {} psize: {}", work.getTaskQueueSize(), request.packets.size()); if(!ss.isLeader()) { var requestUpdateState = new SyncWorkerStateProcessor.RequestWorkerState(); requestUpdateState.setWorkerState(work); @@ -80,7 +77,7 @@ public class PacketsProcessor implements RpcProcessor() { @Override public void run(Status status) { diff --git a/src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java b/src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java index 6f888d1..be327a4 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java @@ -177,8 +177,22 @@ public class StateServerFactory { } public void useFsmStateNotLock(Consumer dofunc) { + var state = ss.fsm.getState(); - dofunc.accept(state); + synchronized(state) { + dofunc.accept(state); + } + + // getNode().readIndex(BytesUtil.EMPTY_BYTES, new ReadIndexClosure() { + + // @Override + // public void run(Status status, long index, byte[] reqCtx) { + // var state = ss.fsm.getState(); + // dofunc.accept(state); + // } + + // } ); + } diff --git a/src/main/java/com/yuandian/dataflow/statemachine/state/StateFactory.java b/src/main/java/com/yuandian/dataflow/statemachine/state/StateFactory.java index 8c8ab68..c95931f 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/state/StateFactory.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/state/StateFactory.java @@ -90,19 +90,14 @@ public class StateFactory { public void run(Status status) { log.info("任务队列更新成功 {}", this.getValue().getWorkers()); - pclist.forEach((peer) -> { - - - - - - - if (peer.getCap() <= 0) { + pclist.forEach((peercap) -> { + + if (peercap.getCap() <= 0) { return ; } var request = new PacketsRequest(); - for (int i = 0; i < peer.getCap(); i++) { + for (int i = 0; i < peercap.getCap(); i++) { var p = Any.pack( BacktrackingFlowOuterClass.BacktrackingFlow.newBuilder() .setTableId(10086) @@ -112,8 +107,8 @@ public class StateFactory { try { - log.debug("rpc {}", peer); - ss.getRpcClient().invokeAsync(peer.peer.getEndpoint() , + log.debug("rpc {}", peercap); + ss.getRpcClient().invokeAsync(peercap.peer.getEndpoint() , request, new InvokeCallback() { @Override public void complete(Object result, Throwable err) { From 849821fd8b65802b289b4b4b3af1bde221ecb393 Mon Sep 17 00:00:00 2001 From: huangsimin <474420502@qq.com> Date: Tue, 26 Jul 2022 16:59:00 +0800 Subject: [PATCH 26/37] =?UTF-8?q?TODO:=20=E8=A7=A3=E5=86=B3=E5=A4=84?= =?UTF-8?q?=E7=90=86packets=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dataflow/controller/PacketsProcessor.java | 39 +++---- .../dataflow/grpc/CollectPackets.java | 26 ++--- .../{SyncClosure.java => OperateClosure.java} | 13 +-- .../dataflow/statemachine/StateMachine.java | 102 +++++++++++++----- .../statemachine/StateServerFactory.java | 71 ++++-------- .../statemachine/operate/Operate.java | 82 ++++++++++++++ ...teProcessor.java => OperateProcessor.java} | 17 +-- .../statemachine/rpc/RaftResponse.java | 3 +- .../rpc/SyncWorkerStateProcessor.java | 78 -------------- .../statemachine/state/StateFactory.java | 93 +++++++--------- .../com/yuandian/dataflow/MongodbTest.java | 6 +- .../statemachine/StateMachineTest.java | 82 +++++++------- 12 files changed, 307 insertions(+), 305 deletions(-) rename src/main/java/com/yuandian/dataflow/statemachine/{SyncClosure.java => OperateClosure.java} (79%) create mode 100644 src/main/java/com/yuandian/dataflow/statemachine/operate/Operate.java rename src/main/java/com/yuandian/dataflow/statemachine/rpc/{SyncStateProcessor.java => OperateProcessor.java} (74%) delete mode 100644 src/main/java/com/yuandian/dataflow/statemachine/rpc/SyncWorkerStateProcessor.java diff --git a/src/main/java/com/yuandian/dataflow/controller/PacketsProcessor.java b/src/main/java/com/yuandian/dataflow/controller/PacketsProcessor.java index 84d6536..a19e406 100644 --- a/src/main/java/com/yuandian/dataflow/controller/PacketsProcessor.java +++ b/src/main/java/com/yuandian/dataflow/controller/PacketsProcessor.java @@ -18,10 +18,12 @@ import com.alipay.sofa.jraft.rpc.RpcContext; import com.alipay.sofa.jraft.rpc.RpcProcessor; import com.google.protobuf.Any; import com.yuandian.dataflow.statemachine.StateServerFactory; -import com.yuandian.dataflow.statemachine.SyncClosure; +import com.yuandian.dataflow.statemachine.operate.Operate; +import com.yuandian.dataflow.statemachine.operate.Operate.OperateType; +import com.yuandian.dataflow.statemachine.OperateClosure; import com.yuandian.dataflow.statemachine.rpc.RaftResponse; -import com.yuandian.dataflow.statemachine.rpc.SyncStateProcessor; -import com.yuandian.dataflow.statemachine.rpc.SyncWorkerStateProcessor; +import com.yuandian.dataflow.statemachine.rpc.OperateProcessor; + import com.yuandian.dataflow.statemachine.rpc.annotations.ProcessorRaft; import com.yuandian.dataflow.statemachine.state.State; @@ -65,34 +67,17 @@ public class PacketsProcessor implements RpcProcessor() { @Override public void run(Status status) { - log.debug("finsh tasks size {}, size: {}", status, request.packets.size()); - rpcCtx.sendResponse(resp); + log.info("{}", this.getResponse()); + rpcCtx.sendResponse(this.getResponse()); } + }); }); diff --git a/src/main/java/com/yuandian/dataflow/grpc/CollectPackets.java b/src/main/java/com/yuandian/dataflow/grpc/CollectPackets.java index f751c86..0395897 100644 --- a/src/main/java/com/yuandian/dataflow/grpc/CollectPackets.java +++ b/src/main/java/com/yuandian/dataflow/grpc/CollectPackets.java @@ -81,7 +81,7 @@ public class CollectPackets extends CollectPacketsServerImplBase { log.info("次序:{} 条数: {}, {}:ms", count, i, Duration.between(now, Instant.now()).toMillis()); } } catch (Exception e) { - e.printStackTrace(); + log.info("{}", e.toString()); } finally { channel.shutdown().awaitTermination(1, TimeUnit.SECONDS); } @@ -99,7 +99,7 @@ public class CollectPackets extends CollectPacketsServerImplBase { // MongodbTest.insertMsgToMongoDB(result); } catch (InvalidProtocolBufferException e) { - e.printStackTrace(); + log.info("{}", e.toString()); } return null; }); @@ -110,7 +110,7 @@ public class CollectPackets extends CollectPacketsServerImplBase { // MongodbTest.insertMsgToMongoDB(result); } catch (InvalidProtocolBufferException e) { - e.printStackTrace(); + log.info("{}", e.toString()); } return null; });*/ @@ -131,7 +131,7 @@ public class CollectPackets extends CollectPacketsServerImplBase { // System.out.println("result:" + response.getBody()); } catch (InvalidProtocolBufferException e) { - e.printStackTrace(); + log.info("{}", e.toString()); } return null; }); @@ -143,7 +143,7 @@ public class CollectPackets extends CollectPacketsServerImplBase { // MongodbTest.insertMsgToMongoDB(result); } catch (InvalidProtocolBufferException e) { - e.printStackTrace(); + log.info("{}", e.toString()); } return null; }); @@ -154,7 +154,7 @@ public class CollectPackets extends CollectPacketsServerImplBase { // MongodbTest.insertMsgToMongoDB(result); } catch (InvalidProtocolBufferException e) { - e.printStackTrace(); + log.info("{}", e.toString()); } return null; }); @@ -165,7 +165,7 @@ public class CollectPackets extends CollectPacketsServerImplBase { // MongodbTest.insertMsgToMongoDB(result); } catch (InvalidProtocolBufferException e) { - e.printStackTrace(); + log.info("{}", e.toString()); } return null; }); @@ -176,7 +176,7 @@ public class CollectPackets extends CollectPacketsServerImplBase { // MongodbTest.insertMsgToMongoDB(result); } catch (InvalidProtocolBufferException e) { - e.printStackTrace(); + log.info("{}", e.toString()); } return null; }); @@ -187,7 +187,7 @@ public class CollectPackets extends CollectPacketsServerImplBase { // MongodbTest.insertMsgToMongoDB(result); } catch (InvalidProtocolBufferException e) { - e.printStackTrace(); + log.info("{}", e.toString()); } return null; }); @@ -198,7 +198,7 @@ public class CollectPackets extends CollectPacketsServerImplBase { // MongodbTest.insertMsgToMongoDB(result); } catch (InvalidProtocolBufferException e) { - e.printStackTrace(); + log.info("{}", e.toString()); } return null; }); @@ -209,7 +209,7 @@ public class CollectPackets extends CollectPacketsServerImplBase { // MongodbTest.insertMsgToMongoDB(result); } catch (InvalidProtocolBufferException e) { - e.printStackTrace(); + log.info("{}", e.toString()); } return null; }); @@ -220,7 +220,7 @@ public class CollectPackets extends CollectPacketsServerImplBase { // MongodbTest.insertMsgToMongoDB(result); } catch (InvalidProtocolBufferException e) { - e.printStackTrace(); + log.info("{}", e.toString()); } return null; }); @@ -231,7 +231,7 @@ public class CollectPackets extends CollectPacketsServerImplBase { // MongodbTest.insertMsgToMongoDB(result); } catch (InvalidProtocolBufferException e) { - e.printStackTrace(); + log.info("{}", e.toString()); } return null; });*/ diff --git a/src/main/java/com/yuandian/dataflow/statemachine/SyncClosure.java b/src/main/java/com/yuandian/dataflow/statemachine/OperateClosure.java similarity index 79% rename from src/main/java/com/yuandian/dataflow/statemachine/SyncClosure.java rename to src/main/java/com/yuandian/dataflow/statemachine/OperateClosure.java index 19ab8a7..69a10e7 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/SyncClosure.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/OperateClosure.java @@ -3,6 +3,7 @@ package com.yuandian.dataflow.statemachine; import com.alipay.sofa.jraft.Closure; import com.alipay.sofa.jraft.Status; import com.alipay.sofa.jraft.entity.PeerId; +import com.yuandian.dataflow.statemachine.operate.Operate; import com.yuandian.dataflow.statemachine.rpc.RaftResponse; import com.yuandian.dataflow.statemachine.state.State; @@ -18,17 +19,17 @@ import org.slf4j.LoggerFactory; @Getter @Setter @ToString -public abstract class SyncClosure implements Closure { +public abstract class OperateClosure implements Closure { // 状态机的统一响应 private RaftResponse response; // 代表任务状态 - private T value; + private Operate value; - public Object synclock = new Object(); + - public SyncClosure() { + public OperateClosure() { } @@ -40,9 +41,9 @@ public abstract class SyncClosure implements Closure { setResponse(response); } - public void success(final State value) { + public void success(final Operate value) { final RaftResponse response = new RaftResponse(); - response.setState(value); + response.setOperate(value); response.setSuccess(true); setResponse(response); } diff --git a/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java b/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java index 5cba656..78589c1 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java @@ -16,9 +16,11 @@ import com.alipay.sofa.jraft.error.RaftException; import com.alipay.sofa.jraft.error.RemotingException; import com.alipay.sofa.jraft.storage.snapshot.SnapshotReader; import com.alipay.sofa.jraft.storage.snapshot.SnapshotWriter; +import com.yuandian.dataflow.statemachine.operate.Operate; +import com.yuandian.dataflow.statemachine.operate.Operate.OperateType; import com.yuandian.dataflow.statemachine.rpc.RaftResponse; -import com.yuandian.dataflow.statemachine.rpc.SyncWorkerStateProcessor.RequestWorkerState; -import com.yuandian.dataflow.statemachine.rpc.SyncStateProcessor.RequestState; + +import com.yuandian.dataflow.statemachine.rpc.OperateProcessor.RequestOperate; import com.yuandian.dataflow.statemachine.state.State; import com.yuandian.dataflow.statemachine.state.StateFactory; import com.yuandian.dataflow.statemachine.state.WorkerState; @@ -58,38 +60,64 @@ public class StateMachine extends StateMachineAdapter { return state; } - - - @Override @SuppressWarnings("unchecked") public void onApply(final Iterator iter) { while (iter.hasNext()) { + Operate op = null; + OperateClosure closure = null; if (iter.done() != null) { // This task is applied by this node, get value from closure to avoid additional // parsing. - var closure = (SyncClosure)iter.done(); // 只支持单一个State. 全状态机只支持一种提交 + closure = (OperateClosure)iter.done(); // 只支持单一个State. 全状态机只支持一种提交 // log.info("SyncDataClosure(done) taskState:{} leaderTerm:{} {}",this.state, this.leaderTerm, closure); - this.state = closure.getValue(); - closure.success(state); - closure.run(Status.OK()); + op = closure.getValue(); + } else { // Have to parse FetchAddRequest from this user log. final ByteBuffer data = iter.getData(); try { - state = SerializerManager.getSerializer(SerializerManager.Hessian2).deserialize( - data.array(), State.class.getName()); + op = SerializerManager.getSerializer(SerializerManager.Hessian2).deserialize( + data.array(),Operate.class.getName()); // log.info("SyncDataClosure(null) taskState:{} leaderTerm:{}", state, this.leaderTerm); - + } catch (CodecException e) { - e.printStackTrace(); + log.info("{}", e.toString()); } } + if(op != null) { + switch(op.getType()) { + case PUT: + WorkerState ws = op.getValue(); + state.getWorkers().put(ws.peerId, ws); + if(closure != null) { + closure.success(op); + closure.run(Status.OK()); + } + break; + case REMOVE: + + + if(closure != null) { + closure.success(op); + closure.run(Status.OK()); + } + break; + default: + break; + + } + } else { + + } + + + iter.next(); } } @@ -123,15 +151,16 @@ public class StateMachine extends StateMachineAdapter { var ws = state.getWorkers().get( ss.getCluster().getServerId() ); if(ws == null) { ws = new WorkerState(ss.getCluster().getServerId()); - state.getWorkers().put(ss.getCluster().getServerId(), ws); + // state.getWorkers().put(ss.getCluster().getServerId(), ws); } - ss.applyState(state, new SyncClosure() { + Operate op = new Operate(OperateType.PUT); + op.setValue(ws); + ss.applyOperate(op, new OperateClosure() { @Override public void run(Status status) { log.debug("master update workerstate: {}", status); } - }); }); @@ -174,18 +203,22 @@ public class StateMachine extends StateMachineAdapter { var ss = StateServerFactory.getStateServer(); var ws = new WorkerState(ss.getCluster().getServerId()); - var request = new RequestWorkerState(); - request.setWorkerState(ws); + log.debug("my: {} leader id {}",ss.getCluster().getServerId(), ss.getNode().getLeaderId()); - RaftResponse resp; - resp = (RaftResponse)StateServerFactory.getStateServer().getRpcClient().invokeSync(ss.getNode().getLeaderId().getEndpoint(), request, 5000); - if(resp == null) { - log.debug("{} set WorkerState is error", resp); - } - log.debug("WorkerState is {}", resp); + + var op = new Operate(OperateType.PUT); + op.setValue(ws); + + Operate.CallOperate(op, new OperateClosure() { + @Override + public void run(Status status) { + log.info("{} {}", status, this.getResponse()); + } + }); + return; - } catch (InterruptedException | RemotingException e) { - e.printStackTrace(); + } catch (Exception e) { + log.info("{}", e.toString()); } super.onStartFollowing(ctx); @@ -199,6 +232,23 @@ public class StateMachine extends StateMachineAdapter { @Override public void onStopFollowing(LeaderChangeContext ctx) { log.debug("{} {}",ctx, StateServerFactory.getCluster().getServerId()); + + var ss = StateServerFactory.getStateServer(); + var ws = new WorkerState(ss.getCluster().getServerId()); + + log.debug("my: {} leader id {}",ss.getCluster().getServerId(), ss.getNode().getLeaderId()); + + var op = new Operate(OperateType.PUT); + op.setValue(ws); + + Operate.CallOperate(op, new OperateClosure() { + @Override + public void run(Status status) { + log.info("{} {}", status, this.getResponse()); + } + }); + + super.onStopFollowing(ctx); } diff --git a/src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java b/src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java index be327a4..69ddde0 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java @@ -39,9 +39,10 @@ import com.alipay.sofa.jraft.rpc.impl.BoltRaftRpcFactory; import com.alipay.sofa.jraft.util.BytesUtil; import com.alipay.sofa.jraft.util.Endpoint; import com.alipay.sofa.jraft.util.ThreadPoolUtil; +import com.yuandian.dataflow.statemachine.operate.Operate; import com.yuandian.dataflow.statemachine.rpc.RaftResponse; -import com.yuandian.dataflow.statemachine.rpc.SyncWorkerStateProcessor.RequestWorkerState; -import com.yuandian.dataflow.statemachine.rpc.SyncStateProcessor.RequestState; + +import com.yuandian.dataflow.statemachine.rpc.OperateProcessor.RequestOperate; import com.yuandian.dataflow.statemachine.rpc.annotations.ProcessorRaft; import com.yuandian.dataflow.statemachine.state.State; import com.yuandian.dataflow.statemachine.state.WorkerState; @@ -150,9 +151,9 @@ public class StateServerFactory { try { cluster.getRpcServer().registerProcessor((RpcProcessor) pRaftClass.newInstance()); } catch (InstantiationException e) { - e.printStackTrace(); + log.info("{}", e.toString()); } catch (IllegalAccessException e) { - e.printStackTrace(); + log.info("{}", e.toString()); } }); node = cluster.start(); @@ -178,26 +179,24 @@ public class StateServerFactory { public void useFsmStateNotLock(Consumer dofunc) { - var state = ss.fsm.getState(); - synchronized(state) { - dofunc.accept(state); - } + + - // getNode().readIndex(BytesUtil.EMPTY_BYTES, new ReadIndexClosure() { + getNode().readIndex(BytesUtil.EMPTY_BYTES, new ReadIndexClosure() { - // @Override - // public void run(Status status, long index, byte[] reqCtx) { - // var state = ss.fsm.getState(); - // dofunc.accept(state); - // } + @Override + public void run(Status status, long index, byte[] reqCtx) { + var state = ss.fsm.getState(); + dofunc.accept(state); + } - // } ); + } ); } - public void applyState(State state, SyncClosure closure) { + public void applyOperate(Operate op, OperateClosure closure) { // 所有的提交都必须再leader进行 if (!ss.isLeader()) { ss.handlerNotLeaderError(closure); @@ -205,9 +204,10 @@ public class StateServerFactory { } try { - closure.setValue(state); + + closure.setValue(op); final Task task = new Task(); - task.setData(ByteBuffer.wrap(SerializerManager.getSerializer(SerializerManager.Hessian2).serialize(state))); + task.setData(ByteBuffer.wrap(SerializerManager.getSerializer(SerializerManager.Hessian2).serialize(op))); task.setDone(closure); // 确认所有数据 一致, 不需要加锁 StateServerFactory.getStateServer().getNode().apply(task); } catch (CodecException e) { @@ -218,36 +218,7 @@ public class StateServerFactory { } } - public void applyWorkerState(WorkerState state, SyncClosure closure) { - log.debug("applyWorkerState"); - if (!ss.isLeader()) { - ss.handlerNotLeaderError(closure); - return; - } - - StateServerFactory.getStateServer().useFsmStateNotLock((fsmState)->{ - var wmap = fsmState.getWorkers(); - var wstate = wmap.get(state.getPeerId()); - if(wstate == null) { - wmap.put(state.getPeerId(), state); - } - - try { - final Task task = new Task(); - closure.setValue(fsmState); - task.setData(ByteBuffer.wrap(SerializerManager.getSerializer(SerializerManager.Hessian2).serialize(fsmState))); - task.setDone(closure); - StateServerFactory.getStateServer().getNode().apply(task); // 提交数据 - } catch (CodecException e) { - String errorMsg = "Fail to encode TaskState"; - log.debug("{}:{}",errorMsg, e); - closure.failure(errorMsg, PeerId.emptyPeer()); - closure.run(new Status(RaftError.EINTERNAL, errorMsg)); - } - }); - - - } + public RaftResponse redirect() { final RaftResponse response = new RaftResponse(); @@ -261,7 +232,7 @@ public class StateServerFactory { return response; } - public void handlerNotLeaderError(final SyncClosure closure) { + public void handlerNotLeaderError(final OperateClosure closure) { closure.failure("Not leader.", redirect().getRedirect()); closure.run(new Status(RaftError.EPERM, "Not leader")); } @@ -289,7 +260,7 @@ public class StateServerFactory { public static void main(String[] args) throws InterruptedException, RemotingException { var rpcClient = new BoltRaftRpcFactory().createRpcClient(); rpcClient.init(new CliOptions()); - var resp = rpcClient.invokeSync(new Endpoint("localhost",4441), new RequestState(), 5000); + var resp = rpcClient.invokeSync(new Endpoint("localhost",4441), new RequestOperate(), 5000); log.info("{}", resp); } } diff --git a/src/main/java/com/yuandian/dataflow/statemachine/operate/Operate.java b/src/main/java/com/yuandian/dataflow/statemachine/operate/Operate.java new file mode 100644 index 0000000..d798fdf --- /dev/null +++ b/src/main/java/com/yuandian/dataflow/statemachine/operate/Operate.java @@ -0,0 +1,82 @@ +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.projo.Response; +import com.yuandian.dataflow.statemachine.OperateClosure; +import com.yuandian.dataflow.statemachine.StateServerFactory; +import com.yuandian.dataflow.statemachine.rpc.OperateProcessor; +import com.yuandian.dataflow.statemachine.rpc.RaftResponse; +import com.yuandian.dataflow.statemachine.state.StateFactory; + + +import lombok.Data; +import lombok.var; +import lombok.extern.slf4j.Slf4j; + +/** + * 操作 + * + * @author eson + */ +@Slf4j +@Data +@var +public class Operate implements Serializable { + + public static enum OperateType { + PUT, REMOVE; + } + + private OperateType type; + private Object value; + + public Operate(OperateType t) { + this.type = t; + } + + public T getValue() { + return (T) this.value; + }; + + public void setValue(T value) { + this.value = value; + return; + }; + + public static void CallOperate(Operate op, OperateClosure closure) { + + var ss = StateServerFactory.getStateServer(); + if (StateServerFactory.getStateServer().isLeader()) { + ss.applyOperate(op, closure); + return; + } + + var request = new OperateProcessor.RequestOperate(); + request.setOperate(op); + + var leaderId = StateServerFactory.getStateServer().getNode().getLeaderId(); + try { + ss.getRpcClient().invokeAsync(leaderId.getEndpoint(), + request, new InvokeCallback() { + + @Override + public void complete(Object result, Throwable err) { + log.info("{}", result); + var resp = (RaftResponse)result; + closure.setResponse(resp); + closure.success(resp.getOperate()); + } + + }, 5000); + } catch (InterruptedException | RemotingException e) { + // TODO Auto-generated catch block + closure.failure("failure", null); + log.info("{}", e.toString()); + } + + } +} diff --git a/src/main/java/com/yuandian/dataflow/statemachine/rpc/SyncStateProcessor.java b/src/main/java/com/yuandian/dataflow/statemachine/rpc/OperateProcessor.java similarity index 74% rename from src/main/java/com/yuandian/dataflow/statemachine/rpc/SyncStateProcessor.java rename to src/main/java/com/yuandian/dataflow/statemachine/rpc/OperateProcessor.java index 6bd48e8..6c96a28 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/rpc/SyncStateProcessor.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/rpc/OperateProcessor.java @@ -17,8 +17,9 @@ import com.alipay.sofa.jraft.error.RaftError; import com.alipay.sofa.jraft.rpc.RpcContext; import com.alipay.sofa.jraft.rpc.RpcProcessor; import com.yuandian.dataflow.statemachine.StateServerFactory; -import com.yuandian.dataflow.statemachine.SyncClosure; +import com.yuandian.dataflow.statemachine.OperateClosure; import com.yuandian.dataflow.statemachine.StateServerFactory.StateServer; +import com.yuandian.dataflow.statemachine.operate.Operate; import com.yuandian.dataflow.statemachine.rpc.annotations.ProcessorRaft; import com.yuandian.dataflow.statemachine.state.State; import com.alipay.sofa.jraft.entity.PeerId; @@ -39,7 +40,7 @@ import lombok.extern.slf4j.Slf4j; */ @Slf4j @ProcessorRaft -public class SyncStateProcessor implements RpcProcessor { +public class OperateProcessor implements RpcProcessor { /** * 同步状态时, 需要用的结构类. 新增的状态可以在 State结构里添加 @@ -51,20 +52,20 @@ public class SyncStateProcessor implements RpcProcessor closure = new SyncClosure() { + final OperateClosure closure = new OperateClosure() { @Override public void run(Status status) { rpcCtx.sendResponse(getResponse()); @@ -72,12 +73,12 @@ public class SyncStateProcessor implements RpcProcessor { - - @Getter - @Setter - @ToString - public static class RequestWorkerState implements Serializable { - - private static final long serialVersionUID = 1L; - - private WorkerState workerState; - } - - @Override - public void handleRequest(RpcContext rpcCtx, RequestWorkerState request) { - - log.info("RequestWorkerState: {}", request); - final SyncClosure closure = new SyncClosure< State>() { - @Override - public void run(Status status) { - rpcCtx.sendResponse(getResponse()); - log.info("{}", status); - } - }; - - StateServerFactory.getStateServer().applyWorkerState(request.getWorkerState(), closure); - } - - @Override - public String interest() { - return RequestWorkerState.class.getName(); - } - - - -} diff --git a/src/main/java/com/yuandian/dataflow/statemachine/state/StateFactory.java b/src/main/java/com/yuandian/dataflow/statemachine/state/StateFactory.java index c95931f..d6068a0 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/state/StateFactory.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/state/StateFactory.java @@ -20,7 +20,9 @@ import com.google.protobuf.Any; import com.yuandian.dataflow.controller.PacketsProcessor.PacketsRequest; import com.yuandian.dataflow.proto.msgtype.BacktrackingFlowOuterClass; import com.yuandian.dataflow.statemachine.StateServerFactory; -import com.yuandian.dataflow.statemachine.SyncClosure; +import com.yuandian.dataflow.statemachine.operate.Operate; +import com.yuandian.dataflow.statemachine.operate.Operate.OperateType; +import com.yuandian.dataflow.statemachine.OperateClosure; import lombok.Getter; import lombok.Setter; @@ -43,9 +45,10 @@ public class StateFactory { @Getter @Setter @ToString - public static class PeerIdCap { + public static class PeerIdCap { private PeerId peer; private long cap; + public PeerIdCap(PeerId pid, long cap) { this.peer = pid; this.cap = cap; @@ -61,12 +64,10 @@ public class StateFactory { var alivePeers = StateServerFactory.getCluster().getRaftNode().listAlivePeers(); log.debug("master execute {}", StateServerFactory.getCluster().getRaftNode().listAlivePeers()); if (alivePeers != null) { - + var ss = StateServerFactory.getStateServer(); // var state = ss.getFsm().getState(); - ArrayList pclist = new ArrayList(); - ss.useFsmStateNotLock((state) -> { alivePeers.forEach((peer) -> { WorkerState ws = state.getWorkers().get(peer); @@ -74,70 +75,54 @@ public class StateFactory { var cap = 100 - ws.getTaskQueueSize(); log.debug("cap :{} peer: {}", cap, peer); if (cap <= 0) { - return ; + return; } ws.setUpdateAt(Instant.now()); ws.setTaskQueueSize(100); - var pc = new PeerIdCap(peer, cap); - pc.setCap(cap); - ; - pclist.add(pc); - } - }); - ss.applyState(state, new SyncClosure() { - @Override - public void run(Status status) { - log.info("任务队列更新成功 {}", this.getValue().getWorkers()); + var op = new Operate(OperateType.PUT); + op.setValue(ws); - pclist.forEach((peercap) -> { - - if (peercap.getCap() <= 0) { - return ; - } - - var request = new PacketsRequest(); - for (int i = 0; i < peercap.getCap(); i++) { - var p = Any.pack( - BacktrackingFlowOuterClass.BacktrackingFlow.newBuilder() - .setTableId(10086) - .build()); - request.getPackets().add(p); - } - - - try { - log.debug("rpc {}", peercap); - ss.getRpcClient().invokeAsync(peercap.peer.getEndpoint() , + var request = new PacketsRequest(); + for (int i = 0; i < cap; i++) { + var p = Any.pack( + BacktrackingFlowOuterClass.BacktrackingFlow.newBuilder() + .setTableId(10086) + .build()); + request.getPackets().add(p); + } + + // Operate.CallOperate(op, new OperateClosure() { + // @Override + // public void run(Status status) { + // // TODO Auto-generated method stub + // log.info("{}", status); + // } + // }); + + try { + ss.getRpcClient().invokeAsync(peer.getEndpoint(), request, new InvokeCallback() { + @Override public void complete(Object result, Throwable err) { - if (err != null) { - err.printStackTrace(); - } else { - log.info("{} peer result", result); - } + log.info("{}", result); } - + }, 5000); - } catch (InterruptedException | RemotingException e) { - e.printStackTrace(); - } - - - }); + } catch (InterruptedException | RemotingException e) { + log.info("error send packets {}", e.toString()); + } + } }); - }); - - // ss.applyState(state, new SyncClosure() { - // public void run(Status status) { - // log.debug("{}", status); - // }; + // public void run(Status status) { + // log.debug("{}", status); + // }; // }); } @@ -145,7 +130,7 @@ public class StateFactory { Thread.sleep(5000); } } catch (InterruptedException e) { - e.printStackTrace(); + log.info("{}", e.toString()); } } diff --git a/src/test/java/com/yuandian/dataflow/MongodbTest.java b/src/test/java/com/yuandian/dataflow/MongodbTest.java index 73e1ed9..7822bd7 100644 --- a/src/test/java/com/yuandian/dataflow/MongodbTest.java +++ b/src/test/java/com/yuandian/dataflow/MongodbTest.java @@ -5,12 +5,16 @@ import com.mongodb.MongoCredential; import com.mongodb.ServerAddress; import com.mongodb.client.MongoCollection; import com.mongodb.client.MongoDatabase; + +import lombok.extern.slf4j.Slf4j; + import org.bson.Document; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.List; +@Slf4j public class MongodbTest { public static void insertMsgToMongoDB(T obj) { @@ -34,7 +38,7 @@ public class MongodbTest { System.err.println("insert success"); } catch (Exception e) { - e.printStackTrace(); + log.info("{}", e.toString()); } } diff --git a/src/test/java/com/yuandian/dataflow/statemachine/StateMachineTest.java b/src/test/java/com/yuandian/dataflow/statemachine/StateMachineTest.java index a5e0146..eed9347 100644 --- a/src/test/java/com/yuandian/dataflow/statemachine/StateMachineTest.java +++ b/src/test/java/com/yuandian/dataflow/statemachine/StateMachineTest.java @@ -10,7 +10,7 @@ import com.alipay.sofa.jraft.rpc.InvokeCallback; import com.alipay.sofa.jraft.rpc.impl.BoltRaftRpcFactory; import com.alipay.sofa.jraft.util.Endpoint; import com.yuandian.dataflow.statemachine.rpc.RaftResponse; -import com.yuandian.dataflow.statemachine.rpc.SyncStateProcessor.RequestState; +import com.yuandian.dataflow.statemachine.rpc.OperateProcessor.RequestOperate; import com.yuandian.dataflow.statemachine.state.State; import lombok.var; @@ -20,53 +20,53 @@ import lombok.extern.slf4j.Slf4j; public class StateMachineTest { @Test void testOnApply() throws InterruptedException, RemotingException { - var rpcClient = new BoltRaftRpcFactory().createRpcClient(); - rpcClient.init(new CliOptions()); + // var rpcClient = new BoltRaftRpcFactory().createRpcClient(); + // rpcClient.init(new CliOptions()); - var fstate = new State(); - var fdata = new RequestState(); - fdata.setState(fstate); + // var fstate = new State(); + // var fdata = new RequestOperate(); + // fdata.setOperate(fstate); - var leader = new Endpoint("localhost",4441); - RaftResponse resp = (RaftResponse)rpcClient.invokeSync(leader, fdata - , 5000); - log.info("{}", resp); - if( resp != null && !resp.isSuccess() ) { - leader = resp.getRedirect().getEndpoint(); - resp = (RaftResponse)rpcClient.invokeSync(resp.getRedirect().getEndpoint(), fdata - , 5000); - log.info("{}", resp); - } + // var leader = new Endpoint("localhost",4441); + // RaftResponse resp = (RaftResponse)rpcClient.invokeSync(leader, fdata + // , 5000); + // log.info("{}", resp); + // if( resp != null && !resp.isSuccess() ) { + // leader = resp.getRedirect().getEndpoint(); + // resp = (RaftResponse)rpcClient.invokeSync(resp.getRedirect().getEndpoint(), fdata + // , 5000); + // log.info("{}", resp); + // } - int i = 0 ; - while(true) { + // int i = 0 ; + // while(true) { - var state = new State(); - var request = new RequestState(); // 创建请求 - request.setState(state); // 添加请求的参数 + // var state = new State(); + // var request = new RequestOperate(); // 创建请求 + // request.setState(state); // 添加请求的参数 - var wstate = state.getWorkers(); + // var wstate = state.getWorkers(); - // state.getWorker().setPeerId( PeerId.parsePeer("localhost:2222") ); - // state.getWorker().setTaskQueueSize(i); + // // state.getWorker().setPeerId( PeerId.parsePeer("localhost:2222") ); + // // state.getWorker().setTaskQueueSize(i); - var pi = i ; - i++; - if (i >= 1000) { - break; - } - rpcClient.invokeAsync(leader, request, new InvokeCallback() { - @Override - public void complete(Object result, Throwable err) { - // ResponseSM resp = (ResponseSM)result; - log.info("{} {} {}", result, err, pi); - } + // var pi = i ; + // i++; + // if (i >= 1000) { + // break; + // } + // rpcClient.invokeAsync(leader, request, new InvokeCallback() { + // @Override + // public void complete(Object result, Throwable err) { + // // ResponseSM resp = (ResponseSM)result; + // log.info("{} {} {}", result, err, pi); + // } - @Override - public Executor executor() { - return null; - } - } , 5000); - } + // @Override + // public Executor executor() { + // return null; + // } + // } , 5000); + // } } } From 159e25ddc67ae7408840ee424b7c969dcf54fecd Mon Sep 17 00:00:00 2001 From: huangsimin <474420502@qq.com> Date: Tue, 26 Jul 2022 17:32:51 +0800 Subject: [PATCH 27/37] =?UTF-8?q?TODO:=20=E5=AE=8C=E5=96=84=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dataflow/controller/PacketsProcessor.java | 7 +++- .../statemachine/state/StateFactory.java | 41 +++++++++---------- 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/src/main/java/com/yuandian/dataflow/controller/PacketsProcessor.java b/src/main/java/com/yuandian/dataflow/controller/PacketsProcessor.java index a19e406..f2db24b 100644 --- a/src/main/java/com/yuandian/dataflow/controller/PacketsProcessor.java +++ b/src/main/java/com/yuandian/dataflow/controller/PacketsProcessor.java @@ -52,13 +52,14 @@ public class PacketsProcessor implements RpcProcessor{ var work = state.getWorkers().get( ss.getCluster().getServerId()); @@ -75,7 +76,9 @@ public class PacketsProcessor implements RpcProcessor Date: Tue, 26 Jul 2022 17:52:58 +0800 Subject: [PATCH 28/37] =?UTF-8?q?=E5=87=8F=E5=B0=91=E5=9B=9E=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/yuandian/dataflow/controller/PacketsProcessor.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/yuandian/dataflow/controller/PacketsProcessor.java b/src/main/java/com/yuandian/dataflow/controller/PacketsProcessor.java index f2db24b..e9f6d0a 100644 --- a/src/main/java/com/yuandian/dataflow/controller/PacketsProcessor.java +++ b/src/main/java/com/yuandian/dataflow/controller/PacketsProcessor.java @@ -67,17 +67,16 @@ public class PacketsProcessor implements RpcProcessor Date: Wed, 27 Jul 2022 00:02:25 +0800 Subject: [PATCH 29/37] =?UTF-8?q?=E5=A4=8D=E6=9D=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dataflow/controller/PacketsProcessor.java | 35 ++++++------- .../dataflow/grpc/CollectPackets.java | 1 - .../com/yuandian/dataflow/projo/Response.java | 14 ------ .../dataflow/statemachine/StateMachine.java | 24 ++++----- .../statemachine/StateServerFactory.java | 49 +++++++++---------- .../statemachine/operate/Operate.java | 20 ++++---- .../statemachine/rpc/OperateProcessor.java | 11 ++--- .../statemachine/state/StateFactory.java | 6 +-- .../statemachine/StateMachineTest.java | 2 +- 9 files changed, 68 insertions(+), 94 deletions(-) delete mode 100644 src/main/java/com/yuandian/dataflow/projo/Response.java diff --git a/src/main/java/com/yuandian/dataflow/controller/PacketsProcessor.java b/src/main/java/com/yuandian/dataflow/controller/PacketsProcessor.java index e9f6d0a..a35b520 100644 --- a/src/main/java/com/yuandian/dataflow/controller/PacketsProcessor.java +++ b/src/main/java/com/yuandian/dataflow/controller/PacketsProcessor.java @@ -55,31 +55,32 @@ public class PacketsProcessor implements RpcProcessor{ + log.info("{} handler request.packets.size(): {}", StateServerFactory.getServerId(), request.packets.size()); + ss.readIndexState((state)->{ - var work = state.getWorkers().get( ss.getCluster().getServerId()); - - - work.setTaskQueueSize( work.getTaskQueueSize() - request.packets.size()); - work.setUpdateAt(Instant.now()); - log.debug("workerState taskQueueSize: {} psize: {} state {}", work.getTaskQueueSize(), request.packets.size(), state.getWorkers().size()); - var op = new Operate(OperateType.PUT); - op.setValue(work); - Operate.CallOperate(op, new OperateClosure() { + var ws = state.getWorkers().get(StateServerFactory.getServerId()); + ws.setTaskQueueSize( ws.getTaskQueueSize() - request.packets.size()); + ws.setUpdateAt(Instant.now()); + + log.debug("workerState taskQueueSize: {} psize: {} state {}", ws.getTaskQueueSize(), request.packets.size(), state.getWorkers().size()); + + Operate.CallOperate(new Operate(OperateType.PUT,ws), new OperateClosure() { @Override public void run(Status status) { - log.info("{}", this.getResponse()); - var resp = new RaftResponse(); - resp.setSuccess(true); - // resp.setRedirect(StateServerFactory.getStateServer().getNode().getLeaderId()); + var resp = this.getResponse(); + if(status.isOk()) { + resp.setSuccess(true); + log.info("{}", resp); + } else { + resp.setSuccess(false); + } + rpcCtx.sendResponse(resp); } - }); }); diff --git a/src/main/java/com/yuandian/dataflow/grpc/CollectPackets.java b/src/main/java/com/yuandian/dataflow/grpc/CollectPackets.java index 0395897..17215ad 100644 --- a/src/main/java/com/yuandian/dataflow/grpc/CollectPackets.java +++ b/src/main/java/com/yuandian/dataflow/grpc/CollectPackets.java @@ -16,7 +16,6 @@ import java.util.stream.Collectors; import com.google.protobuf.*; import com.google.protobuf.util.JsonFormat; import com.yuandian.common.Config; -import com.yuandian.dataflow.projo.Response; import com.yuandian.dataflow.proto.CollectPacketsServerGrpc; diff --git a/src/main/java/com/yuandian/dataflow/projo/Response.java b/src/main/java/com/yuandian/dataflow/projo/Response.java deleted file mode 100644 index 05bfe65..0000000 --- a/src/main/java/com/yuandian/dataflow/projo/Response.java +++ /dev/null @@ -1,14 +0,0 @@ - package com.yuandian.dataflow.projo; - -import org.apache.http.HttpStatus; - -import com.fasterxml.jackson.annotation.JsonProperty; - -public class Response { - @JsonProperty("code") - public org.apache.http.HttpStatus Code; - @JsonProperty("message") - public String Message; - @JsonProperty("data") - public Object Data; -} diff --git a/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java b/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java index 78589c1..3a75347 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java @@ -20,7 +20,7 @@ import com.yuandian.dataflow.statemachine.operate.Operate; import com.yuandian.dataflow.statemachine.operate.Operate.OperateType; import com.yuandian.dataflow.statemachine.rpc.RaftResponse; -import com.yuandian.dataflow.statemachine.rpc.OperateProcessor.RequestOperate; +import com.yuandian.dataflow.statemachine.rpc.OperateProcessor.OperateRequest; import com.yuandian.dataflow.statemachine.state.State; import com.yuandian.dataflow.statemachine.state.StateFactory; import com.yuandian.dataflow.statemachine.state.WorkerState; @@ -147,15 +147,14 @@ public class StateMachine extends StateMachineAdapter { } var ss = StateServerFactory.getStateServer(); - ss.useFsmStateNotLock((state)->{ - var ws = state.getWorkers().get( ss.getCluster().getServerId() ); + ss.readIndexState((state)->{ + var ws = state.getWorkers().get( StateServerFactory.getServerId() ); if(ws == null) { - ws = new WorkerState(ss.getCluster().getServerId()); + ws = new WorkerState(StateServerFactory.getServerId()); // state.getWorkers().put(ss.getCluster().getServerId(), ws); } - Operate op = new Operate(OperateType.PUT); - op.setValue(ws); + Operate op = new Operate(OperateType.PUT, ws); ss.applyOperate(op, new OperateClosure() { @Override public void run(Status status) { @@ -204,10 +203,9 @@ public class StateMachine extends StateMachineAdapter { var ss = StateServerFactory.getStateServer(); var ws = new WorkerState(ss.getCluster().getServerId()); - log.debug("my: {} leader id {}",ss.getCluster().getServerId(), ss.getNode().getLeaderId()); + log.debug("my: {} leader id {}",StateServerFactory.getServerId(), StateServerFactory.getLeaderId()); - var op = new Operate(OperateType.PUT); - op.setValue(ws); + var op = new Operate(OperateType.PUT, ws); Operate.CallOperate(op, new OperateClosure() { @Override @@ -234,13 +232,11 @@ public class StateMachine extends StateMachineAdapter { log.debug("{} {}",ctx, StateServerFactory.getCluster().getServerId()); var ss = StateServerFactory.getStateServer(); - var ws = new WorkerState(ss.getCluster().getServerId()); + var ws = new WorkerState(StateServerFactory.getServerId()); - log.debug("my: {} leader id {}",ss.getCluster().getServerId(), ss.getNode().getLeaderId()); - - var op = new Operate(OperateType.PUT); - op.setValue(ws); + log.debug("my: {} leader id {}",StateServerFactory.getServerId(), StateServerFactory.getLeaderId()); + var op = new Operate(OperateType.PUT, ws); Operate.CallOperate(op, new OperateClosure() { @Override public void run(Status status) { diff --git a/src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java b/src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java index 69ddde0..66cad64 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java @@ -42,7 +42,7 @@ import com.alipay.sofa.jraft.util.ThreadPoolUtil; import com.yuandian.dataflow.statemachine.operate.Operate; import com.yuandian.dataflow.statemachine.rpc.RaftResponse; -import com.yuandian.dataflow.statemachine.rpc.OperateProcessor.RequestOperate; +import com.yuandian.dataflow.statemachine.rpc.OperateProcessor.OperateRequest; import com.yuandian.dataflow.statemachine.rpc.annotations.ProcessorRaft; import com.yuandian.dataflow.statemachine.state.State; import com.yuandian.dataflow.statemachine.state.WorkerState; @@ -64,9 +64,6 @@ public class StateServerFactory { private static StateServer ss; - private static String myPeerStr; - private static Configuration raftConf; - public static void startStateServer(String peerstr, Configuration conf) throws Exception { if(ss != null) { throw new Exception("重复初始化 InitStateServer"); @@ -75,9 +72,14 @@ public class StateServerFactory { } + public static boolean isLeader() { + return ss.getNode().isLeader() ; + } - + public static PeerId getLeaderId() { + return ss.node.getLeaderId() ; + } public static PeerId getServerId() { return ss.getCluster().getServerId(); @@ -177,21 +179,15 @@ public class StateServerFactory { } } - public void useFsmStateNotLock(Consumer dofunc) { - - - - + public void readIndexState(Consumer dofunc) { getNode().readIndex(BytesUtil.EMPTY_BYTES, new ReadIndexClosure() { - @Override public void run(Status status, long index, byte[] reqCtx) { - var state = ss.fsm.getState(); - dofunc.accept(state); + if( status.isOk()) { + dofunc.accept(ss.fsm.getState()); + } } - } ); - } @@ -204,7 +200,6 @@ public class StateServerFactory { } try { - closure.setValue(op); final Task task = new Task(); task.setData(ByteBuffer.wrap(SerializerManager.getSerializer(SerializerManager.Hessian2).serialize(op))); @@ -242,16 +237,16 @@ public class StateServerFactory { // final StoreEngineOptions opts = new StoreEngineOptions(); // return StoreEngineHelper.createReadIndexExecutor(opts.getReadIndexCoreThreads()); - return ThreadPoolUtil.newBuilder() // - .poolName("ReadIndexPool") // - .enableMetric(true) // - .coreThreads(4) // - .maximumThreads(4) // - .keepAliveSeconds(60L) // - .workQueue(new SynchronousQueue<>()) // - .threadFactory(new NamedThreadFactory("ReadIndexService", true)) // - .rejectedHandler(new ThreadPoolExecutor.AbortPolicy()) // - .build(); + return ThreadPoolUtil.newBuilder() // + .poolName("ReadIndexPool") // + .enableMetric(true) // + .coreThreads(4) // + .maximumThreads(4) // + .keepAliveSeconds(60L) // + .workQueue(new SynchronousQueue<>()) // + .threadFactory(new NamedThreadFactory("ReadIndexService", true)) // + .rejectedHandler(new ThreadPoolExecutor.AbortPolicy()) // + .build(); } } @@ -260,7 +255,7 @@ public class StateServerFactory { public static void main(String[] args) throws InterruptedException, RemotingException { var rpcClient = new BoltRaftRpcFactory().createRpcClient(); rpcClient.init(new CliOptions()); - var resp = rpcClient.invokeSync(new Endpoint("localhost",4441), new RequestOperate(), 5000); + var resp = rpcClient.invokeSync(new Endpoint("localhost",4441), new OperateRequest(), 5000); log.info("{}", resp); } } diff --git a/src/main/java/com/yuandian/dataflow/statemachine/operate/Operate.java b/src/main/java/com/yuandian/dataflow/statemachine/operate/Operate.java index d798fdf..bab840a 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/operate/Operate.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/operate/Operate.java @@ -2,17 +2,14 @@ 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.projo.Response; import com.yuandian.dataflow.statemachine.OperateClosure; import com.yuandian.dataflow.statemachine.StateServerFactory; import com.yuandian.dataflow.statemachine.rpc.OperateProcessor; import com.yuandian.dataflow.statemachine.rpc.RaftResponse; -import com.yuandian.dataflow.statemachine.state.StateFactory; +import com.yuandian.dataflow.statemachine.state.WorkerState; - import lombok.Data; import lombok.var; import lombok.extern.slf4j.Slf4j; @@ -34,8 +31,9 @@ public class Operate implements Serializable { private OperateType type; private Object value; - public Operate(OperateType t) { + public Operate(OperateType t, WorkerState ws) { this.type = t; + this.value = ws; } public T getValue() { @@ -48,17 +46,17 @@ public class Operate implements Serializable { }; public static void CallOperate(Operate op, OperateClosure closure) { - + var ss = StateServerFactory.getStateServer(); - if (StateServerFactory.getStateServer().isLeader()) { + if (StateServerFactory.isLeader()) { ss.applyOperate(op, closure); return; } - var request = new OperateProcessor.RequestOperate(); + var request = new OperateProcessor.OperateRequest(); request.setOperate(op); - var leaderId = StateServerFactory.getStateServer().getNode().getLeaderId(); + var leaderId = StateServerFactory.getLeaderId(); try { ss.getRpcClient().invokeAsync(leaderId.getEndpoint(), request, new InvokeCallback() { @@ -66,7 +64,7 @@ public class Operate implements Serializable { @Override public void complete(Object result, Throwable err) { log.info("{}", result); - var resp = (RaftResponse)result; + var resp = (RaftResponse) result; closure.setResponse(resp); closure.success(resp.getOperate()); } @@ -75,7 +73,7 @@ public class Operate implements Serializable { } catch (InterruptedException | RemotingException e) { // TODO Auto-generated catch block closure.failure("failure", null); - log.info("{}", e.toString()); + log.info("{}", e.toString()); } } diff --git a/src/main/java/com/yuandian/dataflow/statemachine/rpc/OperateProcessor.java b/src/main/java/com/yuandian/dataflow/statemachine/rpc/OperateProcessor.java index 6c96a28..b8b4c8a 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/rpc/OperateProcessor.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/rpc/OperateProcessor.java @@ -40,19 +40,18 @@ import lombok.extern.slf4j.Slf4j; */ @Slf4j @ProcessorRaft -public class OperateProcessor implements RpcProcessor { +public class OperateProcessor implements RpcProcessor { /** - * 同步状态时, 需要用的结构类. 新增的状态可以在 State结构里添加 + * 同步状态时, 需要用的结构类. 新增的状态可以在 Operate结构里添加 * * @author eson *2022年7月11日-16:01:07 */ - @Getter @Setter @ToString - public static class RequestOperate implements Serializable { + public static class OperateRequest implements Serializable { private static final long serialVersionUID = 1L; @@ -61,7 +60,7 @@ public class OperateProcessor implements RpcProcessor { + ss.readIndexState((state) -> { alivePeers.forEach((peer) -> { WorkerState ws = state.getWorkers().get(peer); if (ws != null) { @@ -89,8 +89,8 @@ public class StateFactory { request.getPackets().add(p); } - var op = new Operate(OperateType.PUT); - op.setValue(ws); + var op = new Operate(OperateType.PUT, ws); + Operate.CallOperate(op, new OperateClosure() { @Override public void run(Status status) { diff --git a/src/test/java/com/yuandian/dataflow/statemachine/StateMachineTest.java b/src/test/java/com/yuandian/dataflow/statemachine/StateMachineTest.java index eed9347..5e117a0 100644 --- a/src/test/java/com/yuandian/dataflow/statemachine/StateMachineTest.java +++ b/src/test/java/com/yuandian/dataflow/statemachine/StateMachineTest.java @@ -10,7 +10,7 @@ import com.alipay.sofa.jraft.rpc.InvokeCallback; import com.alipay.sofa.jraft.rpc.impl.BoltRaftRpcFactory; import com.alipay.sofa.jraft.util.Endpoint; import com.yuandian.dataflow.statemachine.rpc.RaftResponse; -import com.yuandian.dataflow.statemachine.rpc.OperateProcessor.RequestOperate; +import com.yuandian.dataflow.statemachine.rpc.OperateProcessor.OperateRequest; import com.yuandian.dataflow.statemachine.state.State; import lombok.var; From 4fa9035983f5d185908e42870b64174f39b404e0 Mon Sep 17 00:00:00 2001 From: huangsimin <474420502@qq.com> Date: Wed, 27 Jul 2022 12:37:32 +0800 Subject: [PATCH 30/37] =?UTF-8?q?=E6=B7=BB=E5=8A=A0mongodb=E4=BE=8B?= =?UTF-8?q?=E5=AD=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 16 +- .../dataflow/controller/PacketsProcessor.java | 55 +++---- .../java/com/yuandian/dataflow/projo/Doc.java | 59 +++++-- .../dataflow/statemachine/MasterFactory.java | 124 +++++++++++++++ .../dataflow/statemachine/StateMachine.java | 77 +++++---- .../statemachine/StateServerFactory.java | 20 ++- .../GenericClosure.java} | 21 ++- .../statemachine/closure/StateClosure.java | 5 + .../statemachine/operate/Operate.java | 19 ++- .../statemachine/rpc/OperateProcessor.java | 4 +- .../statemachine/rpc/RaftResponse.java | 4 +- .../statemachine/state/StateFactory.java | 146 ------------------ .../java/com/yuandian/dataflow/AppTest.java | 107 ++++++------- .../com/yuandian/dataflow/MongodbTest.java | 122 +++++++-------- 14 files changed, 406 insertions(+), 373 deletions(-) create mode 100644 src/main/java/com/yuandian/dataflow/statemachine/MasterFactory.java rename src/main/java/com/yuandian/dataflow/statemachine/{OperateClosure.java => closure/GenericClosure.java} (67%) create mode 100644 src/main/java/com/yuandian/dataflow/statemachine/closure/StateClosure.java delete mode 100644 src/main/java/com/yuandian/dataflow/statemachine/state/StateFactory.java diff --git a/pom.xml b/pom.xml index d35d4da..480ac89 100644 --- a/pom.xml +++ b/pom.xml @@ -23,7 +23,7 @@ 1.7.36 1.3.11 2.7.1 - 3.12.11 + 4.7.0 2.1.0 1.30 1.2.11 @@ -83,11 +83,15 @@ - - org.mongodb - mongo-java-driver - ${mongo.driver.version} - + + + + + org.mongodb + mongodb-driver-sync + ${mongo.driver.version} + + diff --git a/src/main/java/com/yuandian/dataflow/controller/PacketsProcessor.java b/src/main/java/com/yuandian/dataflow/controller/PacketsProcessor.java index a35b520..14edd27 100644 --- a/src/main/java/com/yuandian/dataflow/controller/PacketsProcessor.java +++ b/src/main/java/com/yuandian/dataflow/controller/PacketsProcessor.java @@ -18,9 +18,9 @@ import com.alipay.sofa.jraft.rpc.RpcContext; import com.alipay.sofa.jraft.rpc.RpcProcessor; import com.google.protobuf.Any; import com.yuandian.dataflow.statemachine.StateServerFactory; +import com.yuandian.dataflow.statemachine.closure.GenericClosure; import com.yuandian.dataflow.statemachine.operate.Operate; import com.yuandian.dataflow.statemachine.operate.Operate.OperateType; -import com.yuandian.dataflow.statemachine.OperateClosure; import com.yuandian.dataflow.statemachine.rpc.RaftResponse; import com.yuandian.dataflow.statemachine.rpc.OperateProcessor; @@ -52,37 +52,38 @@ public class PacketsProcessor implements RpcProcessor{ - - var ws = state.getWorkers().get(StateServerFactory.getServerId()); - ws.setTaskQueueSize( ws.getTaskQueueSize() - request.packets.size()); - ws.setUpdateAt(Instant.now()); + ss.readIndexState( new GenericClosure() { - log.debug("workerState taskQueueSize: {} psize: {} state {}", ws.getTaskQueueSize(), request.packets.size(), state.getWorkers().size()); - - Operate.CallOperate(new Operate(OperateType.PUT,ws), new OperateClosure() { - @Override - public void run(Status status) { - var resp = this.getResponse(); - if(status.isOk()) { - resp.setSuccess(true); - log.info("{}", resp); - } else { - resp.setSuccess(false); + @Override + public void run(Status status) { + + var state = this.getValue(); + var ws = state.getWorkers().get(StateServerFactory.getServerId()); + ws.setTaskQueueSize( ws.getTaskQueueSize() - request.packets.size()); + ws.setUpdateAt(Instant.now()); + + log.debug("workerState taskQueueSize: {} psize: {} state {}", ws.getTaskQueueSize(), request.packets.size(), state.getWorkers().size()); + + Operate.CallOperate(new Operate(OperateType.PUT,ws), new GenericClosure() { + @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); } - - rpcCtx.sendResponse(resp); - } - }); - }); + }); + } + + } ); } diff --git a/src/main/java/com/yuandian/dataflow/projo/Doc.java b/src/main/java/com/yuandian/dataflow/projo/Doc.java index e1389a1..3d073fd 100644 --- a/src/main/java/com/yuandian/dataflow/projo/Doc.java +++ b/src/main/java/com/yuandian/dataflow/projo/Doc.java @@ -4,33 +4,66 @@ package com.yuandian.dataflow.projo; import java.time.LocalDateTime; +import org.bson.BsonDocument; +import org.bson.BsonInt64; +import org.bson.BsonValue; import org.bson.Document; +import org.bson.codecs.configuration.CodecProvider; +import org.bson.codecs.configuration.CodecRegistry; +import org.bson.codecs.pojo.PojoCodecProvider; +import static com.mongodb.MongoClientSettings.getDefaultCodecRegistry; +import static org.bson.codecs.configuration.CodecRegistries.fromProviders; +import static org.bson.codecs.configuration.CodecRegistries.fromRegistries; import org.bson.codecs.pojo.annotations.BsonProperty; +import org.bson.conversions.Bson; +import org.bson.types.ObjectId; import com.fasterxml.jackson.annotation.JsonProperty; +import com.mongodb.client.FindIterable; +import com.mongodb.client.MongoClient; +import com.mongodb.client.MongoClients; +import com.mongodb.client.MongoCollection; +import com.mongodb.client.MongoDatabase; +import com.mongodb.client.model.Filters; import lombok.Getter; import lombok.Setter; +import lombok.ToString; +import lombok.extern.slf4j.Slf4j; +@Slf4j @Setter @Getter -public final class Doc extends Document { +@ToString +public final class Doc { - @JsonProperty("code") - @BsonProperty("code") - public int Code ; + @BsonProperty("retryPackets") + public int retryPackets ; - @JsonProperty("ts") - @BsonProperty("ts") - public LocalDateTime TS; + @BsonProperty("serverResponseTime") + public int serverResponseTime ; - @JsonProperty("desc") - @BsonProperty("desc") - public String Desc; + @BsonProperty("requestBytes") + public int requestBytes ; - @JsonProperty("data") - @BsonProperty("data") - public Document Data; + @BsonProperty("businessName") + public String businessName ; + + @BsonProperty("responseIp") + public int responseIp ; + + + + + public static void main(String[] args) { + MongoClient mgo = MongoClients.create("mongodb://yuandian:yuandian123@192.168.1.113:27017"); + CodecProvider pojoCodecProvider = PojoCodecProvider.builder().register("com.yuandian.dataflow.projo").build(); + CodecRegistry pojoCodecRegistry = fromRegistries(getDefaultCodecRegistry(),fromProviders(pojoCodecProvider)); + + MongoDatabase oriDatabase = mgo.getDatabase("ori-database").withCodecRegistry(pojoCodecRegistry); + MongoCollection db = oriDatabase.getCollection("network_performace_flow_2022072400", Doc.class); + log.debug("{}", db.countDocuments( new BsonDocument("serverResponseTime", new BsonDocument("$gt", new BsonInt64(2083478517) )) )); + } } diff --git a/src/main/java/com/yuandian/dataflow/statemachine/MasterFactory.java b/src/main/java/com/yuandian/dataflow/statemachine/MasterFactory.java new file mode 100644 index 0000000..9263085 --- /dev/null +++ b/src/main/java/com/yuandian/dataflow/statemachine/MasterFactory.java @@ -0,0 +1,124 @@ +/** + * description + * + * @author eson + *2022年7月20日-10:00:05 + */ +package com.yuandian.dataflow.statemachine; + +import java.time.Instant; + +import com.alipay.sofa.jraft.Status; +import com.alipay.sofa.jraft.error.RemotingException; +import com.alipay.sofa.jraft.rpc.InvokeCallback; +import com.google.protobuf.Any; +import com.yuandian.dataflow.controller.PacketsProcessor.PacketsRequest; +import com.yuandian.dataflow.proto.msgtype.BacktrackingFlowOuterClass; +import com.yuandian.dataflow.statemachine.closure.GenericClosure; +import com.yuandian.dataflow.statemachine.operate.Operate; +import com.yuandian.dataflow.statemachine.operate.Operate.OperateType; +import com.yuandian.dataflow.statemachine.state.State; +import com.yuandian.dataflow.statemachine.state.WorkerState; + +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import lombok.var; +import lombok.extern.slf4j.Slf4j; + +/** + * Master主线程, 用于接收packets + * + * @author eson + * 2022年7月20日-10:00:05 + */ +@Slf4j +@Getter +@Setter +@ToString +public class MasterFactory { + + public static final int MAX_TASKS = 100; + + public static Thread masterExecute = new Thread(new Runnable() { + @Override + public void run() { + try { + while (true) { + log.debug("master execute {}", StateServerFactory.getServerId()); + var alivePeers = StateServerFactory.getRaftNode().listAlivePeers(); + log.debug("master execute {}", StateServerFactory.getRaftNode().listAlivePeers()); + if (alivePeers != null) { + + var ss = StateServerFactory.getStateServer(); + // 读一致性 + ss.readIndexState( new GenericClosure() { + + @Override + public void run(Status status) { + var state = this.getValue(); + + alivePeers.forEach((peer) -> { + WorkerState ws = state.getWorkers().get(peer); + if (ws != null) { + // + var canDealTasks = MAX_TASKS - ws.getTaskQueueSize(); + log.debug("cap :{} peer: {}", canDealTasks, peer); + if (canDealTasks <= 0) { + return; + } + ws.setUpdateAt(Instant.now()); + ws.setTaskQueueSize(MAX_TASKS); + + var request = new PacketsRequest(); + for (int i = 0; i < canDealTasks; i++) { + var p = Any.pack(BacktrackingFlowOuterClass.BacktrackingFlow + .newBuilder() + .setTableId(10086) + .build()); + request.getPackets().add(p); + } + + Operate.CallOperate(new Operate(OperateType.PUT, ws), new GenericClosure() { + @Override + public void run(Status status) { + + log.info("{}", status); + try { + ss.getRpcClient().invokeAsync(peer.getEndpoint(), request, + new InvokeCallback() { + @Override + public void complete(Object result, Throwable err) { + log.info("PacketsRequest: {}", result); + } + }, 5000); + } catch (InterruptedException | RemotingException e) { + log.info("error send packets {}", e.toString()); + } + } + }); + } + }); + } + + } ); + } + + Thread.sleep(5000); + } + } catch (InterruptedException e) { + log.info("{}", e.toString()); + } + + } + }); + + public static Thread getMasterExecute() { + return masterExecute; + } + + public static void Init() { + + } + +} diff --git a/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java b/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java index 3a75347..cf3b6c1 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java @@ -16,13 +16,13 @@ import com.alipay.sofa.jraft.error.RaftException; import com.alipay.sofa.jraft.error.RemotingException; import com.alipay.sofa.jraft.storage.snapshot.SnapshotReader; import com.alipay.sofa.jraft.storage.snapshot.SnapshotWriter; +import com.yuandian.dataflow.statemachine.closure.GenericClosure; import com.yuandian.dataflow.statemachine.operate.Operate; import com.yuandian.dataflow.statemachine.operate.Operate.OperateType; import com.yuandian.dataflow.statemachine.rpc.RaftResponse; import com.yuandian.dataflow.statemachine.rpc.OperateProcessor.OperateRequest; import com.yuandian.dataflow.statemachine.state.State; -import com.yuandian.dataflow.statemachine.state.StateFactory; import com.yuandian.dataflow.statemachine.state.WorkerState; import lombok.var; @@ -66,12 +66,11 @@ public class StateMachine extends StateMachineAdapter { while (iter.hasNext()) { Operate op = null; - OperateClosure closure = null; + GenericClosure closure = null; if (iter.done() != null) { // This task is applied by this node, get value from closure to avoid additional // parsing. - closure = (OperateClosure)iter.done(); // 只支持单一个State. 全状态机只支持一种提交 - // log.info("SyncDataClosure(done) taskState:{} leaderTerm:{} {}",this.state, this.leaderTerm, closure); + closure = (GenericClosure)iter.done(); // 只支持单一个State. 全状态机只支持一种提交 op = closure.getValue(); } else { @@ -79,11 +78,7 @@ public class StateMachine extends StateMachineAdapter { final ByteBuffer data = iter.getData(); try { - op = SerializerManager.getSerializer(SerializerManager.Hessian2).deserialize( - data.array(),Operate.class.getName()); - // log.info("SyncDataClosure(null) taskState:{} leaderTerm:{}", state, this.leaderTerm); - - + op = SerializerManager.getSerializer(SerializerManager.Hessian2).deserialize(data.array(),Operate.class.getName()); } catch (CodecException e) { log.info("{}", e.toString()); } @@ -101,8 +96,6 @@ public class StateMachine extends StateMachineAdapter { } break; case REMOVE: - - if(closure != null) { closure.success(op); closure.run(Status.OK()); @@ -139,33 +132,39 @@ public class StateMachine extends StateMachineAdapter { @Override public void onLeaderStart(final long term) { - log.debug("onLeaderStart {}", StateServerFactory.getCluster().getServerId()); + log.debug("onLeaderStart {}", StateServerFactory.getServerId()); this.leaderTerm.set(term); - if(StateFactory.getMasterExecute().isAlive()) { - StateFactory.getMasterExecute().interrupt(); + // 判断是否Master线程还在跑, 如果存在则中断 + if(MasterFactory.getMasterExecute().isAlive()) { + MasterFactory.getMasterExecute().interrupt(); } var ss = StateServerFactory.getStateServer(); - ss.readIndexState((state)->{ - var ws = state.getWorkers().get( StateServerFactory.getServerId() ); - if(ws == null) { - ws = new WorkerState(StateServerFactory.getServerId()); - // state.getWorkers().put(ss.getCluster().getServerId(), ws); - } + ss.readIndexState( new GenericClosure() { - Operate op = new Operate(OperateType.PUT, ws); - ss.applyOperate(op, new OperateClosure() { - @Override - public void run(Status status) { - log.debug("master update workerstate: {}", status); + @Override + public void run(Status status) { + + var ws = state.getWorkers().get( StateServerFactory.getServerId() ); + if(ws == null) { + ws = new WorkerState(StateServerFactory.getServerId()); } - }); - + + Operate op = new Operate(OperateType.PUT, ws); + ss.applyOperate(op, new GenericClosure() { + @Override + public void run(Status status) { + log.debug("master update workerstate: {}", status); + } + }); + } + }); - StateFactory.getMasterExecute().start(); - + // 当成为master时候 必须启动 + MasterFactory.getMasterExecute().start(); + super.onLeaderStart(term); } @@ -175,8 +174,9 @@ public class StateMachine extends StateMachineAdapter { this.leaderTerm.set(-1); super.onLeaderStop(status); - if(StateFactory.getMasterExecute().isAlive()) { - StateFactory.getMasterExecute().interrupt(); + // 判断是否Master线程还在跑, 如果存在则中断 + if(MasterFactory.getMasterExecute().isAlive()) { + MasterFactory.getMasterExecute().interrupt(); } @@ -196,18 +196,17 @@ public class StateMachine extends StateMachineAdapter { log.debug("[onStartFollowing] {} {}", ctx, StateServerFactory.getCluster().getServerId()); try { - if(StateFactory.getMasterExecute().isAlive()) { - StateFactory.getMasterExecute().interrupt(); + // 判断是否Master线程还在跑, 如果存在则中断 + if(MasterFactory.getMasterExecute().isAlive()) { + MasterFactory.getMasterExecute().interrupt(); } - - var ss = StateServerFactory.getStateServer(); - var ws = new WorkerState(ss.getCluster().getServerId()); - + + var ws = new WorkerState(StateServerFactory.getServerId()); log.debug("my: {} leader id {}",StateServerFactory.getServerId(), StateServerFactory.getLeaderId()); var op = new Operate(OperateType.PUT, ws); - Operate.CallOperate(op, new OperateClosure() { + Operate.CallOperate(op, new GenericClosure() { @Override public void run(Status status) { log.info("{} {}", status, this.getResponse()); @@ -237,7 +236,7 @@ public class StateMachine extends StateMachineAdapter { log.debug("my: {} leader id {}",StateServerFactory.getServerId(), StateServerFactory.getLeaderId()); var op = new Operate(OperateType.PUT, ws); - Operate.CallOperate(op, new OperateClosure() { + Operate.CallOperate(op, new GenericClosure() { @Override public void run(Status status) { log.info("{} {}", status, this.getResponse()); diff --git a/src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java b/src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java index 66cad64..c5d724a 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java @@ -39,6 +39,7 @@ import com.alipay.sofa.jraft.rpc.impl.BoltRaftRpcFactory; import com.alipay.sofa.jraft.util.BytesUtil; import com.alipay.sofa.jraft.util.Endpoint; import com.alipay.sofa.jraft.util.ThreadPoolUtil; +import com.yuandian.dataflow.statemachine.closure.GenericClosure; import com.yuandian.dataflow.statemachine.operate.Operate; import com.yuandian.dataflow.statemachine.rpc.RaftResponse; @@ -73,7 +74,7 @@ public class StateServerFactory { public static boolean isLeader() { - return ss.getNode().isLeader() ; + return ss.node.isLeader() ; } @@ -82,11 +83,15 @@ public class StateServerFactory { } public static PeerId getServerId() { - return ss.getCluster().getServerId(); + return ss.cluster.getServerId(); } public static Node getNode() { - return ss.getNode() ; + return ss.node ; + } + + public static Node getRaftNode() { + return ss.cluster.getRaftNode() ; } public static RpcClient getRpcClient() { @@ -179,12 +184,13 @@ public class StateServerFactory { } } - public void readIndexState(Consumer dofunc) { + public void readIndexState(GenericClosure closure) { getNode().readIndex(BytesUtil.EMPTY_BYTES, new ReadIndexClosure() { @Override public void run(Status status, long index, byte[] reqCtx) { if( status.isOk()) { - dofunc.accept(ss.fsm.getState()); + closure.success(ss.fsm.getState()); + closure.run(status); } } } ); @@ -192,7 +198,7 @@ public class StateServerFactory { - public void applyOperate(Operate op, OperateClosure closure) { + public void applyOperate(Operate op, GenericClosure closure) { // 所有的提交都必须再leader进行 if (!ss.isLeader()) { ss.handlerNotLeaderError(closure); @@ -227,7 +233,7 @@ public class StateServerFactory { return response; } - public void handlerNotLeaderError(final OperateClosure closure) { + public void handlerNotLeaderError(final GenericClosure closure) { closure.failure("Not leader.", redirect().getRedirect()); closure.run(new Status(RaftError.EPERM, "Not leader")); } diff --git a/src/main/java/com/yuandian/dataflow/statemachine/OperateClosure.java b/src/main/java/com/yuandian/dataflow/statemachine/closure/GenericClosure.java similarity index 67% rename from src/main/java/com/yuandian/dataflow/statemachine/OperateClosure.java rename to src/main/java/com/yuandian/dataflow/statemachine/closure/GenericClosure.java index 69a10e7..002bed1 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/OperateClosure.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/closure/GenericClosure.java @@ -1,4 +1,4 @@ -package com.yuandian.dataflow.statemachine; +package com.yuandian.dataflow.statemachine.closure; import com.alipay.sofa.jraft.Closure; import com.alipay.sofa.jraft.Status; @@ -19,31 +19,28 @@ import org.slf4j.LoggerFactory; @Getter @Setter @ToString -public abstract class OperateClosure implements Closure { +public abstract class GenericClosure implements Closure { // 状态机的统一响应 - private RaftResponse response; + private RaftResponse response; // 代表任务状态 - private Operate value; + private T value; - - - - public OperateClosure() { + public GenericClosure() { } public void failure(final String errorMsg, final PeerId redirect) { - final RaftResponse response = new RaftResponse(); + final RaftResponse response = new RaftResponse(); response.setSuccess(false); response.setMsg(errorMsg); response.setRedirect(redirect); setResponse(response); } - public void success(final Operate value) { - final RaftResponse response = new RaftResponse(); - response.setOperate(value); + public void success(final T value) { + final RaftResponse response = new RaftResponse(); + response.setValue(value); response.setSuccess(true); setResponse(response); } diff --git a/src/main/java/com/yuandian/dataflow/statemachine/closure/StateClosure.java b/src/main/java/com/yuandian/dataflow/statemachine/closure/StateClosure.java new file mode 100644 index 0000000..e49a805 --- /dev/null +++ b/src/main/java/com/yuandian/dataflow/statemachine/closure/StateClosure.java @@ -0,0 +1,5 @@ +package com.yuandian.dataflow.statemachine.closure; + +public class StateClosure { + +} diff --git a/src/main/java/com/yuandian/dataflow/statemachine/operate/Operate.java b/src/main/java/com/yuandian/dataflow/statemachine/operate/Operate.java index bab840a..0194b1a 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/operate/Operate.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/operate/Operate.java @@ -4,8 +4,8 @@ import java.io.Serializable; import com.alipay.sofa.jraft.error.RemotingException; import com.alipay.sofa.jraft.rpc.InvokeCallback; -import com.yuandian.dataflow.statemachine.OperateClosure; import com.yuandian.dataflow.statemachine.StateServerFactory; +import com.yuandian.dataflow.statemachine.closure.GenericClosure; import com.yuandian.dataflow.statemachine.rpc.OperateProcessor; import com.yuandian.dataflow.statemachine.rpc.RaftResponse; import com.yuandian.dataflow.statemachine.state.WorkerState; @@ -45,14 +45,21 @@ public class Operate implements Serializable { return; }; - public static void CallOperate(Operate op, OperateClosure closure) { + /** + * 调用操作设置 + * @param op 传入的操作类 + * @param closure 回调函数. Operate为返回值 + */ + public static void CallOperate(Operate op, GenericClosure closure) { var ss = StateServerFactory.getStateServer(); - if (StateServerFactory.isLeader()) { + // 如果是leader 就直接提交 + if (StateServerFactory.isLeader()) { ss.applyOperate(op, closure); return; } + // 非leader 转发请求 统一有leader处理 var request = new OperateProcessor.OperateRequest(); request.setOperate(op); @@ -64,14 +71,14 @@ public class Operate implements Serializable { @Override public void complete(Object result, Throwable err) { log.info("{}", result); - var resp = (RaftResponse) result; + //TODO: 解决回调的次序问题 + var resp = (RaftResponse) result; closure.setResponse(resp); - closure.success(resp.getOperate()); + closure.success(resp.getValue()); } }, 5000); } catch (InterruptedException | RemotingException e) { - // TODO Auto-generated catch block closure.failure("failure", null); log.info("{}", e.toString()); } diff --git a/src/main/java/com/yuandian/dataflow/statemachine/rpc/OperateProcessor.java b/src/main/java/com/yuandian/dataflow/statemachine/rpc/OperateProcessor.java index b8b4c8a..96a825a 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/rpc/OperateProcessor.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/rpc/OperateProcessor.java @@ -17,8 +17,8 @@ import com.alipay.sofa.jraft.error.RaftError; import com.alipay.sofa.jraft.rpc.RpcContext; import com.alipay.sofa.jraft.rpc.RpcProcessor; import com.yuandian.dataflow.statemachine.StateServerFactory; -import com.yuandian.dataflow.statemachine.OperateClosure; import com.yuandian.dataflow.statemachine.StateServerFactory.StateServer; +import com.yuandian.dataflow.statemachine.closure.GenericClosure; import com.yuandian.dataflow.statemachine.operate.Operate; import com.yuandian.dataflow.statemachine.rpc.annotations.ProcessorRaft; import com.yuandian.dataflow.statemachine.state.State; @@ -64,7 +64,7 @@ public class OperateProcessor implements RpcProcessor implements Serializable { private static final long serialVersionUID = 1L; - private Operate operate; + private T value; private boolean success; diff --git a/src/main/java/com/yuandian/dataflow/statemachine/state/StateFactory.java b/src/main/java/com/yuandian/dataflow/statemachine/state/StateFactory.java deleted file mode 100644 index 65e5cb2..0000000 --- a/src/main/java/com/yuandian/dataflow/statemachine/state/StateFactory.java +++ /dev/null @@ -1,146 +0,0 @@ -/** - * description - * - * @author eson - *2022年7月20日-10:00:05 - */ -package com.yuandian.dataflow.statemachine.state; - -import java.time.Instant; -import java.util.ArrayList; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; - -import com.alibaba.nacos.shaded.io.grpc.netty.shaded.io.netty.handler.codec.http.HttpContentEncoder.Result; -import com.alipay.sofa.jraft.Status; -import com.alipay.sofa.jraft.entity.PeerId; -import com.alipay.sofa.jraft.error.RemotingException; -import com.alipay.sofa.jraft.rpc.InvokeCallback; -import com.google.protobuf.Any; -import com.yuandian.dataflow.controller.PacketsProcessor.PacketsRequest; -import com.yuandian.dataflow.proto.msgtype.BacktrackingFlowOuterClass; -import com.yuandian.dataflow.statemachine.StateServerFactory; -import com.yuandian.dataflow.statemachine.operate.Operate; -import com.yuandian.dataflow.statemachine.operate.Operate.OperateType; -import com.yuandian.dataflow.statemachine.OperateClosure; - -import lombok.Getter; -import lombok.Setter; -import lombok.ToString; -import lombok.var; -import lombok.extern.slf4j.Slf4j; - -/** - * description - * - * @author eson - * 2022年7月20日-10:00:05 - */ -@Slf4j -@Getter -@Setter -@ToString -public class StateFactory { - - @Getter - @Setter - @ToString - public static class PeerIdCap { - private PeerId peer; - private long cap; - - public PeerIdCap(PeerId pid, long cap) { - this.peer = pid; - this.cap = cap; - } - } - - public static Thread masterExecute = new Thread(new Runnable() { - @Override - public void run() { - try { - while (true) { - log.debug("master execute {}", StateServerFactory.getServerId()); - var alivePeers = StateServerFactory.getCluster().getRaftNode().listAlivePeers(); - log.debug("master execute {}", StateServerFactory.getCluster().getRaftNode().listAlivePeers()); - if (alivePeers != null) { - - var ss = StateServerFactory.getStateServer(); - // var state = ss.getFsm().getState(); - - ss.readIndexState((state) -> { - alivePeers.forEach((peer) -> { - WorkerState ws = state.getWorkers().get(peer); - if (ws != null) { - var cap = 100 - ws.getTaskQueueSize(); - log.debug("cap :{} peer: {}", cap, peer); - if (cap <= 0) { - return; - } - ws.setUpdateAt(Instant.now()); - ws.setTaskQueueSize(100); - - var request = new PacketsRequest(); - for (int i = 0; i < cap; i++) { - var p = Any.pack( - BacktrackingFlowOuterClass.BacktrackingFlow.newBuilder() - .setTableId(10086) - .build()); - request.getPackets().add(p); - } - - var op = new Operate(OperateType.PUT, ws); - - Operate.CallOperate(op, new OperateClosure() { - @Override - public void run(Status status) { - - log.info("{}", status); - - try { - ss.getRpcClient().invokeAsync(peer.getEndpoint(), - request, new InvokeCallback() { - - @Override - public void complete(Object result, Throwable err) { - log.info("{}", result); - } - - }, 5000); - } catch (InterruptedException | RemotingException e) { - log.info("error send packets {}", e.toString()); - } - } - }); - - } - }); - - }); - - // ss.applyState(state, new SyncClosure() { - // public void run(Status status) { - // log.debug("{}", status); - // }; - // }); - - } - - Thread.sleep(5000); - } - } catch (InterruptedException e) { - log.info("{}", e.toString()); - } - - } - }); - - public static Thread getMasterExecute() { - return masterExecute; - } - - public static void Init() { - - } - -} diff --git a/src/test/java/com/yuandian/dataflow/AppTest.java b/src/test/java/com/yuandian/dataflow/AppTest.java index 1117839..88cdb2f 100644 --- a/src/test/java/com/yuandian/dataflow/AppTest.java +++ b/src/test/java/com/yuandian/dataflow/AppTest.java @@ -23,7 +23,8 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; // import org.springframework.expression.spel.ast.FunctionReference; -import com.mongodb.MongoClient; +import com.mongodb.client.MongoClient; +import com.mongodb.client.MongoClients; import com.mongodb.client.model.InsertManyOptions; import com.yuandian.dataflow.projo.Doc; @@ -122,75 +123,77 @@ public class AppTest { } } - @Test - public void Mongodb() throws InterruptedException { + // @Test + // public void Mongodb() throws InterruptedException { - ArrayList execs = new ArrayList<>(); + // ArrayList execs = new ArrayList<>(); - final Metric metric = new Metric(); - metric.start(); - for (int c = 0; c < 10; c++) { - Thread exec = new Thread(() -> { + // final Metric metric = new Metric(); + // metric.start(); + // for (int c = 0; c < 10; c++) { + // Thread exec = new Thread(() -> { - @Cleanup - MongoClient mgo = new MongoClient("localhost", 27017); + // @Cleanup + // MongoClient mgo = MongoClients.create("mongodb://yuandian:yuandian123@192.168.1.113:27017"); + + - log.info("msg"); + // log.info("msg"); - long LoopNumber = 5; - long BatchSize = 20000; + // long LoopNumber = 5; + // long BatchSize = 20000; - var db = mgo.getDatabase("yuandian"); - var cltdoc = db.getCollection("doc"); + // var db = mgo.getDatabase("yuandian"); + // var cltdoc = db.getCollection("doc"); - for (int n = 0; n < LoopNumber; n++) { + // for (int n = 0; n < LoopNumber; n++) { - metric.push(() -> { + // metric.push(() -> { - List documents = new ArrayList<>(); - Random r = new Random(); + // List documents = new ArrayList<>(); + // Random r = new Random(); - for (int i = 0; i < BatchSize; i++) { + // for (int i = 0; i < BatchSize; i++) { - var doc = new Doc(); - var datadoc = new Document(); + // var doc = new Doc(); + // var datadoc = new Document(); - doc.append("code", r.nextInt(100)); - doc.append("desc", "desc"); - doc.append("ts", Instant.now()); + // doc.append("code", r.nextInt(100)); + // doc.append("desc", "desc"); + // doc.append("ts", Instant.now()); - for (int ii = 0; ii < 24; ii++) { - UUID uid = UUID.randomUUID(); - datadoc - .append(uid.toString(), uid.toString()); - } + // for (int ii = 0; ii < 24; ii++) { + // UUID uid = UUID.randomUUID(); + // datadoc + // .append(uid.toString(), uid.toString()); + // } - doc.append("data", datadoc); - documents.add(doc); - } + // doc.append("data", datadoc); + // documents.add(doc); + // } - var opt = new InsertManyOptions(); - cltdoc.insertMany(documents, opt); - return BatchSize; - }); - } - }); - exec.start(); - execs.add(exec); - } - ; + // var opt = new InsertManyOptions(); + // cltdoc.insertMany(documents, opt); + // return BatchSize; + // }); + // } + // }); + // exec.start(); + // execs.add(exec); + // } + // ; - execs.forEach((e) -> { - try { - e.join(); - } catch (InterruptedException e1) { - e1.printStackTrace(); - } - }); + // execs.forEach((e) -> { + // try { + // e.join(); + // } catch (InterruptedException e1) { + // e1.printStackTrace(); + // } + // }); - metric.close(); + // metric.close(); - } + // } diff --git a/src/test/java/com/yuandian/dataflow/MongodbTest.java b/src/test/java/com/yuandian/dataflow/MongodbTest.java index 7822bd7..424ed9e 100644 --- a/src/test/java/com/yuandian/dataflow/MongodbTest.java +++ b/src/test/java/com/yuandian/dataflow/MongodbTest.java @@ -1,6 +1,6 @@ package com.yuandian.dataflow; -import com.mongodb.MongoClient; + import com.mongodb.MongoCredential; import com.mongodb.ServerAddress; import com.mongodb.client.MongoCollection; @@ -18,73 +18,73 @@ import java.util.List; public class MongodbTest { public static void insertMsgToMongoDB(T obj) { - try { - ServerAddress serverAddress = new ServerAddress("192.168.1.113", 27017); - List addrs = new ArrayList<>(); - addrs.add(serverAddress); + // try { + // ServerAddress serverAddress = new ServerAddress("192.168.1.113", 27017); + // List addrs = new ArrayList<>(); + // addrs.add(serverAddress); - MongoCredential credential = MongoCredential.createScramSha1Credential("yd-rw", "admin", "yuandian123".toCharArray()); - List credentials = new ArrayList<>(); - credentials.add(credential); + // MongoCredential credential = MongoCredential.createScramSha1Credential("yd-rw", "admin", "yuandian123".toCharArray()); + // List credentials = new ArrayList<>(); + // credentials.add(credential); - MongoClient mongoClient = new MongoClient(addrs, credentials); + // MongoClient mongoClient = new MongoClient(addrs, credentials); - MongoDatabase db = mongoClient.getDatabase("yd-base"); + // MongoDatabase db = mongoClient.getDatabase("yd-base"); - // todo 修改名字 - MongoCollection collection = db.getCollection("lxy-test"); + // // todo 修改名字 + // MongoCollection collection = db.getCollection("lxy-test"); - collection.insertOne(obj2Doc(obj)); + // collection.insertOne(obj2Doc(obj)); - System.err.println("insert success"); - } catch (Exception e) { - log.info("{}", e.toString()); - } - } + // System.err.println("insert success"); + // } catch (Exception e) { + // log.info("{}", e.toString()); + // } + // } - public static Document obj2Doc(T obj) throws Exception { - Document doc = new Document(); - Field[] fields = obj.getClass().getDeclaredFields(); - for (Field field : fields) { - String varName = field.getName(); - boolean accessFlag = field.isAccessible(); - if (!accessFlag) { - field.setAccessible(true); - } - Object param = field.get(obj); - if (param == null) { - continue; - } else if (param instanceof Integer) { - int value = ((Integer) param).intValue(); - doc.put(varName, value); - } else if (param instanceof String) { - String value = (String) param; - doc.put(varName, value); - } else if (param instanceof Double) { - double value = ((Double) param).doubleValue(); - doc.put(varName, value); - } else if (param instanceof Float) { - float value = ((Float) param).floatValue(); - doc.put(varName, value); - } else if (param instanceof Long) { - long value = ((Long) param).longValue(); - doc.put(varName, value); - } else if (param instanceof Boolean) { - boolean value = ((Boolean) param).booleanValue(); - doc.put(varName, value); - } - field.setAccessible(accessFlag); - } - return doc; - } + // public static Document obj2Doc(T obj) throws Exception { + // Document doc = new Document(); + // Field[] fields = obj.getClass().getDeclaredFields(); + // for (Field field : fields) { + // String varName = field.getName(); + // boolean accessFlag = field.isAccessible(); + // if (!accessFlag) { + // field.setAccessible(true); + // } + // Object param = field.get(obj); + // if (param == null) { + // continue; + // } else if (param instanceof Integer) { + // int value = ((Integer) param).intValue(); + // doc.put(varName, value); + // } else if (param instanceof String) { + // String value = (String) param; + // doc.put(varName, value); + // } else if (param instanceof Double) { + // double value = ((Double) param).doubleValue(); + // doc.put(varName, value); + // } else if (param instanceof Float) { + // float value = ((Float) param).floatValue(); + // doc.put(varName, value); + // } else if (param instanceof Long) { + // long value = ((Long) param).longValue(); + // doc.put(varName, value); + // } else if (param instanceof Boolean) { + // boolean value = ((Boolean) param).booleanValue(); + // doc.put(varName, value); + // } + // field.setAccessible(accessFlag); + // } + // return doc; + // } - public static T doc2Obj(Document doc, Class clazz) throws Exception { - T obj = clazz.newInstance(); - for (String key : doc.keySet()) { - Field field = clazz.getDeclaredField(key); - field.setAccessible(true); - field.set(obj, doc.get(key)); - } - return obj; + // public static T doc2Obj(Document doc, Class clazz) throws Exception { + // T obj = clazz.newInstance(); + // for (String key : doc.keySet()) { + // Field field = clazz.getDeclaredField(key); + // field.setAccessible(true); + // field.set(obj, doc.get(key)); + // } + // return obj; } } From 1ea40571d913a1b48449983d9e73c5c2dbd12173 Mon Sep 17 00:00:00 2001 From: huangsimin <474420502@qq.com> Date: Wed, 27 Jul 2022 16:25:10 +0800 Subject: [PATCH 31/37] =?UTF-8?q?=E5=8A=A0=E5=85=A5vscode=E8=B0=83?= =?UTF-8?q?=E8=AF=95=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/launch.json | 18 ++++ .vscode/settings.json | 3 + .vscode/tasks.json | 27 ++++++ restart.sh | 2 +- .../dataflow/controller/PacketsProcessor.java | 51 ++++++------ .../dataflow/statemachine/StateMachine.java | 82 ++++++++----------- .../statemachine/StateServerFactory.java | 9 +- .../statemachine/operate/Operate.java | 2 + .../statemachine/rpc/OperateProcessor.java | 2 +- .../com/yuandian/dataflow/utils/Utils.java | 8 ++ start.sh | 4 +- stop.sh | 1 + 12 files changed, 132 insertions(+), 77 deletions(-) create mode 100644 .vscode/launch.json create mode 100644 .vscode/settings.json create mode 100644 .vscode/tasks.json create mode 100644 src/main/java/com/yuandian/dataflow/utils/Utils.java diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..db80756 --- /dev/null +++ b/.vscode/launch.json @@ -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", + } + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..e0f15db --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "java.configuration.updateBuildConfiguration": "automatic" +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..7566731 --- /dev/null +++ b/.vscode/tasks.json @@ -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 + } + } + ] +} \ No newline at end of file diff --git a/restart.sh b/restart.sh index 3bb4f6e..a51605a 100755 --- a/restart.sh +++ b/restart.sh @@ -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 diff --git a/src/main/java/com/yuandian/dataflow/controller/PacketsProcessor.java b/src/main/java/com/yuandian/dataflow/controller/PacketsProcessor.java index 14edd27..2c40164 100644 --- a/src/main/java/com/yuandian/dataflow/controller/PacketsProcessor.java +++ b/src/main/java/com/yuandian/dataflow/controller/PacketsProcessor.java @@ -52,40 +52,45 @@ public class PacketsProcessor implements RpcProcessor(); + 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() { @Override public void run(Status status) { - - var state = this.getValue(); - var ws = state.getWorkers().get(StateServerFactory.getServerId()); - ws.setTaskQueueSize( ws.getTaskQueueSize() - request.packets.size()); - ws.setUpdateAt(Instant.now()); - - log.debug("workerState taskQueueSize: {} psize: {} state {}", ws.getTaskQueueSize(), request.packets.size(), state.getWorkers().size()); - - Operate.CallOperate(new Operate(OperateType.PUT,ws), new GenericClosure() { - @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); + 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()); + + log.debug("workerState taskQueueSize: {} psize: {} state {}", ws.getTaskQueueSize(), request.packets.size(), state.getWorkers().size()); + + Operate.CallOperate(new Operate(OperateType.PUT,ws), new GenericClosure() { + @Override + public void run(Status status) { + if(status.isOk()) { + log.info("{}", resp); + } } - rpcCtx.sendResponse(resp); - } - }); + }); + } + } } ); - + } @Override diff --git a/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java b/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java index cf3b6c1..28fef8e 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java @@ -20,7 +20,7 @@ import com.yuandian.dataflow.statemachine.closure.GenericClosure; import com.yuandian.dataflow.statemachine.operate.Operate; import com.yuandian.dataflow.statemachine.operate.Operate.OperateType; import com.yuandian.dataflow.statemachine.rpc.RaftResponse; - + import com.yuandian.dataflow.statemachine.rpc.OperateProcessor.OperateRequest; import com.yuandian.dataflow.statemachine.state.State; import com.yuandian.dataflow.statemachine.state.WorkerState; @@ -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 全局使用的唯一状态 @@ -70,46 +71,46 @@ public class StateMachine extends StateMachineAdapter { if (iter.done() != null) { // This task is applied by this node, get value from closure to avoid additional // parsing. - closure = (GenericClosure)iter.done(); // 只支持单一个State. 全状态机只支持一种提交 + closure = (GenericClosure) iter.done(); // 只支持单一个State. 全状态机只支持一种提交 op = closure.getValue(); - + } else { - // Have to parse FetchAddRequest from this user log. + // Have to parse FetchAddRequest from this user log. 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()); + log.info("{}", e.toString()); } - + } - if(op != null) { - switch(op.getType()) { + if (op != null) { + switch (op.getType()) { case PUT: - WorkerState ws = op.getValue(); + WorkerState ws = op.getValue(); state.getWorkers().put(ws.peerId, ws); - if(closure != null) { + if (closure != null) { closure.success(op); closure.run(Status.OK()); } break; case REMOVE: - if(closure != null) { + if (closure != null) { closure.success(op); closure.run(Status.OK()); } break; default: break; - + } } else { } - - iter.next(); } @@ -136,21 +137,21 @@ public class StateMachine extends StateMachineAdapter { this.leaderTerm.set(term); // 判断是否Master线程还在跑, 如果存在则中断 - if(MasterFactory.getMasterExecute().isAlive()) { + if (MasterFactory.getMasterExecute().isAlive()) { MasterFactory.getMasterExecute().interrupt(); } - - var ss = StateServerFactory.getStateServer(); - ss.readIndexState( new GenericClosure() { + + var ss = StateServerFactory.getStateServer(); + ss.readIndexState(new GenericClosure() { @Override public void run(Status status) { - - var ws = state.getWorkers().get( StateServerFactory.getServerId() ); - if(ws == null) { + + var ws = state.getWorkers().get(StateServerFactory.getServerId()); + if (ws == null) { ws = new WorkerState(StateServerFactory.getServerId()); } - + Operate op = new Operate(OperateType.PUT, ws); ss.applyOperate(op, new GenericClosure() { @Override @@ -159,7 +160,7 @@ public class StateMachine extends StateMachineAdapter { } }); } - + }); // 当成为master时候 必须启动 @@ -175,21 +176,17 @@ public class StateMachine extends StateMachineAdapter { super.onLeaderStop(status); // 判断是否Master线程还在跑, 如果存在则中断 - if(MasterFactory.getMasterExecute().isAlive()) { + if (MasterFactory.getMasterExecute().isAlive()) { MasterFactory.getMasterExecute().interrupt(); } - } - - @Override public void onShutdown() { log.debug("onShutdown"); super.onShutdown(); } - @Override public void onStartFollowing(LeaderChangeContext ctx) { @@ -197,12 +194,12 @@ public class StateMachine extends StateMachineAdapter { try { // 判断是否Master线程还在跑, 如果存在则中断 - if(MasterFactory.getMasterExecute().isAlive()) { + if (MasterFactory.getMasterExecute().isAlive()) { MasterFactory.getMasterExecute().interrupt(); } - + var ws = new WorkerState(StateServerFactory.getServerId()); - log.debug("my: {} leader id {}",StateServerFactory.getServerId(), StateServerFactory.getLeaderId()); + log.debug("my: {} leader id {}", StateServerFactory.getServerId(), StateServerFactory.getLeaderId()); var op = new Operate(OperateType.PUT, ws); @@ -212,10 +209,10 @@ public class StateMachine extends StateMachineAdapter { log.info("{} {}", status, this.getResponse()); } }); - + return; } catch (Exception e) { - log.info("{}", e.toString()); + log.info("{}", e.toString()); } super.onStartFollowing(ctx); @@ -228,12 +225,12 @@ public class StateMachine extends StateMachineAdapter { @Override public void onStopFollowing(LeaderChangeContext ctx) { - log.debug("{} {}",ctx, StateServerFactory.getCluster().getServerId()); + log.debug("{} {}", ctx, StateServerFactory.getCluster().getServerId()); var ss = StateServerFactory.getStateServer(); var ws = new WorkerState(StateServerFactory.getServerId()); - - log.debug("my: {} leader id {}",StateServerFactory.getServerId(), StateServerFactory.getLeaderId()); + + log.debug("my: {} leader id {}", StateServerFactory.getServerId(), StateServerFactory.getLeaderId()); var op = new Operate(OperateType.PUT, ws); Operate.CallOperate(op, new GenericClosure() { @@ -243,14 +240,7 @@ public class StateMachine extends StateMachineAdapter { } }); - super.onStopFollowing(ctx); } - - - - - - } diff --git a/src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java b/src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java index c5d724a..7521b7e 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java @@ -188,17 +188,18 @@ public class StateServerFactory { getNode().readIndex(BytesUtil.EMPTY_BYTES, new ReadIndexClosure() { @Override public void run(Status status, long index, byte[] reqCtx) { - if( status.isOk()) { + 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 closure) { // 所有的提交都必须再leader进行 if (!ss.isLeader()) { ss.handlerNotLeaderError(closure); diff --git a/src/main/java/com/yuandian/dataflow/statemachine/operate/Operate.java b/src/main/java/com/yuandian/dataflow/statemachine/operate/Operate.java index 0194b1a..df2cf67 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/operate/Operate.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/operate/Operate.java @@ -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) result; closure.setResponse(resp); closure.success(resp.getValue()); + closure.run(Status.OK()); } }, 5000); diff --git a/src/main/java/com/yuandian/dataflow/statemachine/rpc/OperateProcessor.java b/src/main/java/com/yuandian/dataflow/statemachine/rpc/OperateProcessor.java index 96a825a..4ad2efd 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/rpc/OperateProcessor.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/rpc/OperateProcessor.java @@ -64,7 +64,7 @@ public class OperateProcessor implements RpcProcessor closure = new GenericClosure() { @Override public void run(Status status) { rpcCtx.sendResponse(getResponse()); diff --git a/src/main/java/com/yuandian/dataflow/utils/Utils.java b/src/main/java/com/yuandian/dataflow/utils/Utils.java new file mode 100644 index 0000000..1ba5e8f --- /dev/null +++ b/src/main/java/com/yuandian/dataflow/utils/Utils.java @@ -0,0 +1,8 @@ +package com.yuandian.dataflow.utils; + +public class Utils { + + public static void main(String[] args) { + + } +} diff --git a/start.sh b/start.sh index 2b4c76e..3746270 100755 --- a/start.sh +++ b/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 \ No newline at end of file +# screen -S raft-2 -X logfile flush 0 \ No newline at end of file diff --git a/stop.sh b/stop.sh index 12f7ef1..9c0b857 100755 --- a/stop.sh +++ b/stop.sh @@ -2,3 +2,4 @@ screen -S raft-0 -X quit screen -S raft-1 -X quit screen -S raft-2 -X quit +exit 0 From 5298c168eff768177f02c0a3748fd7d6bfab8818 Mon Sep 17 00:00:00 2001 From: huangsimin <474420502@qq.com> Date: Wed, 27 Jul 2022 18:02:24 +0800 Subject: [PATCH 32/37] =?UTF-8?q?=E8=B0=83=E8=AF=95leader?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/launch.json | 3 +- .vscode/tasks.json | 3 +- restart.sh | 3 +- .../java/com/yuandian/dataflow/Server.java | 5 +++ .../dataflow/controller/PacketsProcessor.java | 1 - .../controller/TransferLeaderProcessor.java | 39 +++++++++++++++++++ .../dataflow/statemachine/StateMachine.java | 13 ++++--- .../statemachine/rpc/OperateProcessor.java | 15 ++++++- start.sh | 13 ++++--- 9 files changed, 78 insertions(+), 17 deletions(-) create mode 100644 src/main/java/com/yuandian/dataflow/controller/TransferLeaderProcessor.java diff --git a/.vscode/launch.json b/.vscode/launch.json index db80756..979edf3 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -10,9 +10,10 @@ "request": "launch", "mainClass": "com.yuandian.dataflow.Server", "projectName": "dataflow", - "args": "2", + "args": ["2"], "preLaunchTask": "restart", "postDebugTask": "stopall", + } ] } \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 7566731..384c8de 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -5,9 +5,10 @@ "label": "restart", "type": "shell", "command": "sh restart.sh", + "isBackground": true, "presentation": { "echo": true, - "reveal": "always", + "reveal": "silent", "focus": false, "panel": "shared", "showReuseMessage": true, diff --git a/restart.sh b/restart.sh index a51605a..39698a2 100755 --- a/restart.sh +++ b/restart.sh @@ -1,2 +1,3 @@ #! /bin/bash -sh stop.sh & rm raftdata/ -rf && mvn 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 diff --git a/src/main/java/com/yuandian/dataflow/Server.java b/src/main/java/com/yuandian/dataflow/Server.java index 86232a4..b3556a2 100644 --- a/src/main/java/com/yuandian/dataflow/Server.java +++ b/src/main/java/com/yuandian/dataflow/Server.java @@ -22,8 +22,11 @@ public class Server { public static String peeridstr; public static String sprPort; public static Configuration conf ; + public static void main(String[] args) throws Exception { + + String[] peers = new String[]{"localhost:4440","localhost:4441","localhost:4442"}; String[] sprPeers = new String[]{"3440","3441","3442"}; @@ -39,6 +42,8 @@ public class Server { conf = JRaftUtils.getConfiguration(String.join(",", peers)); StateServerFactory.startStateServer(peeridstr, conf); + + // System.setProperty("server.port", sprPort); // ConfigurableApplicationContext app = SpringApplication.run(Server.class, args); // StateServerFactory.setAppCxt(app); diff --git a/src/main/java/com/yuandian/dataflow/controller/PacketsProcessor.java b/src/main/java/com/yuandian/dataflow/controller/PacketsProcessor.java index 2c40164..6afee1d 100644 --- a/src/main/java/com/yuandian/dataflow/controller/PacketsProcessor.java +++ b/src/main/java/com/yuandian/dataflow/controller/PacketsProcessor.java @@ -70,7 +70,6 @@ public class PacketsProcessor implements RpcProcessor { + + @Setter + @Getter + public static class LeaderRequest implements Serializable { + PeerId peer; + } + + @Override + public void handleRequest(RpcContext rpcCtx, LeaderRequest request) { + Status status = StateServerFactory.getCluster().getRaftNode().transferLeadershipTo(request.peer); + rpcCtx.sendResponse(status); + log.debug("[TransferLeader] {} change leader to {}", status, request.peer); + } + + @Override + public String interest() { + return LeaderRequest.class.getName(); + } + +} diff --git a/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java b/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java index 28fef8e..b854fdc 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java @@ -14,8 +14,11 @@ import com.alipay.sofa.jraft.core.StateMachineAdapter; import com.alipay.sofa.jraft.entity.LeaderChangeContext; import com.alipay.sofa.jraft.error.RaftException; import com.alipay.sofa.jraft.error.RemotingException; +import com.alipay.sofa.jraft.rpc.InvokeCallback; import com.alipay.sofa.jraft.storage.snapshot.SnapshotReader; import com.alipay.sofa.jraft.storage.snapshot.SnapshotWriter; +import com.yuandian.dataflow.Server; +import com.yuandian.dataflow.controller.TransferLeaderProcessor; import com.yuandian.dataflow.statemachine.closure.GenericClosure; import com.yuandian.dataflow.statemachine.operate.Operate; import com.yuandian.dataflow.statemachine.operate.Operate.OperateType; @@ -173,13 +176,12 @@ public class StateMachine extends StateMachineAdapter { public void onLeaderStop(final Status status) { log.debug("onLeaderStop {}", StateServerFactory.getCluster().getServerId()); this.leaderTerm.set(-1); - super.onLeaderStop(status); - // 判断是否Master线程还在跑, 如果存在则中断 if (MasterFactory.getMasterExecute().isAlive()) { MasterFactory.getMasterExecute().interrupt(); } + super.onLeaderStop(status); } @Override @@ -198,18 +200,19 @@ public class StateMachine extends StateMachineAdapter { MasterFactory.getMasterExecute().interrupt(); } + var ws = new WorkerState(StateServerFactory.getServerId()); log.debug("my: {} leader id {}", StateServerFactory.getServerId(), StateServerFactory.getLeaderId()); var op = new Operate(OperateType.PUT, ws); - - Operate.CallOperate(op, new GenericClosure() { + Operate.CallOperate(op, new GenericClosure() { @Override public void run(Status status) { log.info("{} {}", status, this.getResponse()); } }); - + + return; } catch (Exception e) { log.info("{}", e.toString()); diff --git a/src/main/java/com/yuandian/dataflow/statemachine/rpc/OperateProcessor.java b/src/main/java/com/yuandian/dataflow/statemachine/rpc/OperateProcessor.java index 4ad2efd..4c67936 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/rpc/OperateProcessor.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/rpc/OperateProcessor.java @@ -67,8 +67,19 @@ public class OperateProcessor implements RpcProcessor closure = new GenericClosure() { @Override public void run(Status status) { - rpcCtx.sendResponse(getResponse()); - log.info("{}", status); + + if(status.isOk()) { + log.info("{}", status); + rpcCtx.sendResponse(getResponse()); + return; + } + + + if(status.getRaftError() == RaftError.EPERM) { + //TODO: Not leader 需要转发 + log.info("{}", status); + } + } }; diff --git a/start.sh b/start.sh index 3746270..51c666e 100755 --- a/start.sh +++ b/start.sh @@ -1,19 +1,20 @@ #! /bin/bash screen -S raft-0 -X quit screen -S raft-1 -X quit -screen -S raft-2 -X quit +# screen -S raft-2 -X quit + + +sleep 5s + VERSION=1.0.0-SNAPSHOT - -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 sleep 1 -screen -S raft-0 -X logfile flush 0 -screen -S raft-1 -X logfile flush 0 +screen -S raft-0 -X logfile flush 0 +screen -S raft-1 -X logfile flush 0 # screen -S raft-2 -X logfile flush 0 \ No newline at end of file From 7795362d5a1b42eb8bc73fa5a3e45cf61fc4ced2 Mon Sep 17 00:00:00 2001 From: huangsimin Date: Wed, 27 Jul 2022 23:37:40 +0800 Subject: [PATCH 33/37] =?UTF-8?q?TODO:=20=E8=A7=A3=E5=86=B3=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E4=B8=8D=E5=88=B0=E8=BE=BE=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/tasks.json | 16 +++-- pom.xml | 6 +- restart.sh | 3 +- .../dataflow/controller/PacketsProcessor.java | 64 +++++++++---------- .../java/com/yuandian/dataflow/projo/Doc.java | 5 +- .../dataflow/statemachine/MasterFactory.java | 16 +++-- .../dataflow/statemachine/StateMachine.java | 1 - .../statemachine/StateServerFactory.java | 31 ++++----- .../statemachine/operate/Operate.java | 2 +- .../statemachine/rpc/OperateProcessor.java | 3 +- .../statemachine/rpc/RaftResponse.java | 1 - .../java/com/yuandian/dataflow/AppTest.java | 1 + .../statemachine/StateMachineTest.java | 2 +- start.sh | 7 +- 14 files changed, 72 insertions(+), 86 deletions(-) diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 384c8de..029d8f2 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -5,24 +5,30 @@ "label": "restart", "type": "shell", "command": "sh restart.sh", - "isBackground": true, + "isBackground": false, "presentation": { "echo": true, - "reveal": "silent", + "reveal": "always", "focus": false, - "panel": "shared", + "panel": "new", "showReuseMessage": true, "clear": false, "close": true - } + + }, }, { "label": "stopall", "type": "shell", "command": "sh stop.sh", "presentation": { + "echo": true, + "reveal": "always", + "focus": false, + "panel": "shared", "close": true - } + }, + } ] } \ No newline at end of file diff --git a/pom.xml b/pom.xml index 480ac89..2d4aaf4 100644 --- a/pom.xml +++ b/pom.xml @@ -11,9 +11,9 @@ UTF-8 - 8 - 8 - 8 + 11 + 11 + 11 3.20.1 1.7.4 diff --git a/restart.sh b/restart.sh index 39698a2..8e0f02d 100755 --- a/restart.sh +++ b/restart.sh @@ -1,3 +1,4 @@ #! /bin/bash -sh stop.sh & rm raftdata/ -rf && mvn 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 diff --git a/src/main/java/com/yuandian/dataflow/controller/PacketsProcessor.java b/src/main/java/com/yuandian/dataflow/controller/PacketsProcessor.java index 6afee1d..6c1b3fb 100644 --- a/src/main/java/com/yuandian/dataflow/controller/PacketsProcessor.java +++ b/src/main/java/com/yuandian/dataflow/controller/PacketsProcessor.java @@ -23,7 +23,7 @@ import com.yuandian.dataflow.statemachine.operate.Operate; import com.yuandian.dataflow.statemachine.operate.Operate.OperateType; import com.yuandian.dataflow.statemachine.rpc.RaftResponse; import com.yuandian.dataflow.statemachine.rpc.OperateProcessor; - + import com.yuandian.dataflow.statemachine.rpc.annotations.ProcessorRaft; import com.yuandian.dataflow.statemachine.state.State; @@ -36,7 +36,7 @@ import lombok.extern.slf4j.Slf4j; * description * * @author eson - *2022年7月21日-13:48:01 + * 2022年7月21日-13:48:01 */ @Slf4j @@ -51,45 +51,39 @@ public class PacketsProcessor implements RpcProcessor(); + resp.setSuccess(true); + rpcCtx.sendResponse(resp); - var resp = new RaftResponse<>(); - resp.setSuccess(true); - rpcCtx.sendResponse(resp); - - var ss = StateServerFactory.getStateServer(); - log.debug("{} handler request.packets.size(): {}", StateServerFactory.getServerId(), request.packets.size()); + var ss = StateServerFactory.getStateServer(); + log.debug("{} handler request.packets.size(): {}", StateServerFactory.getServerId(), request.packets.size()); - - ss.readIndexState( new GenericClosure() { + ss.readIndexState(new GenericClosure() { - @Override - public void run(Status status) { - log.debug("status {}", status); - if(status.isOk()) { - var state = this.getValue(); - var ws = state.getWorkers().get(StateServerFactory.getServerId()); + @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()); - - log.debug("workerState taskQueueSize: {} psize: {} state {}", ws.getTaskQueueSize(), request.packets.size(), state.getWorkers().size()); - - Operate.CallOperate(new Operate(OperateType.PUT,ws), new GenericClosure() { - @Override - public void run(Status status) { - if(status.isOk()) { - log.info("{}", resp); - } + ws.setTaskQueueSize(ws.getTaskQueueSize() - request.packets.size()); + ws.setUpdateAt(Instant.now()); + + log.debug("workerState taskQueueSize: {} psize: {} state {}", ws.getTaskQueueSize(), + request.packets.size(), state.getWorkers().size()); + Operate.CallOperate(new Operate(OperateType.PUT, ws), new GenericClosure() { + @Override + public void run(Status status) { + if (status.isOk()) { + log.info("{}", resp); } - }); - } - + } + }); } - - } ); - - + } + }); } @Override diff --git a/src/main/java/com/yuandian/dataflow/projo/Doc.java b/src/main/java/com/yuandian/dataflow/projo/Doc.java index 3d073fd..6ee2faa 100644 --- a/src/main/java/com/yuandian/dataflow/projo/Doc.java +++ b/src/main/java/com/yuandian/dataflow/projo/Doc.java @@ -52,10 +52,7 @@ public final class Doc { @BsonProperty("responseIp") public int responseIp ; - - - - + public static void main(String[] args) { MongoClient mgo = MongoClients.create("mongodb://yuandian:yuandian123@192.168.1.113:27017"); CodecProvider pojoCodecProvider = PojoCodecProvider.builder().register("com.yuandian.dataflow.projo").build(); diff --git a/src/main/java/com/yuandian/dataflow/statemachine/MasterFactory.java b/src/main/java/com/yuandian/dataflow/statemachine/MasterFactory.java index 9263085..67725eb 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/MasterFactory.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/MasterFactory.java @@ -62,16 +62,16 @@ public class MasterFactory { WorkerState ws = state.getWorkers().get(peer); if (ws != null) { // - var canDealTasks = MAX_TASKS - ws.getTaskQueueSize(); - log.debug("cap :{} peer: {}", canDealTasks, peer); - if (canDealTasks <= 0) { + var canTasks = MAX_TASKS - ws.getTaskQueueSize(); + log.debug("cap :{} peer: {}", canTasks, peer); + if (canTasks <= 0) { return; } ws.setUpdateAt(Instant.now()); ws.setTaskQueueSize(MAX_TASKS); var request = new PacketsRequest(); - for (int i = 0; i < canDealTasks; i++) { + for (int i = 0; i < canTasks; i++) { var p = Any.pack(BacktrackingFlowOuterClass.BacktrackingFlow .newBuilder() .setTableId(10086) @@ -82,14 +82,16 @@ public class MasterFactory { Operate.CallOperate(new Operate(OperateType.PUT, ws), new GenericClosure() { @Override public void run(Status status) { - - log.info("{}", status); + log.info("PacketsRequest run {}", status); try { ss.getRpcClient().invokeAsync(peer.getEndpoint(), request, new InvokeCallback() { @Override public void complete(Object result, Throwable err) { - log.info("PacketsRequest: {}", result); + if(err != null) { + log.debug("{}", err); + } + log.debug("PacketsRequest: {}", result); } }, 5000); } catch (InterruptedException | RemotingException e) { diff --git a/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java b/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java index b854fdc..0270fba 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java @@ -211,7 +211,6 @@ public class StateMachine extends StateMachineAdapter { log.info("{} {}", status, this.getResponse()); } }); - return; } catch (Exception e) { diff --git a/src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java b/src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java index 7521b7e..caccbe2 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java @@ -7,6 +7,7 @@ package com.yuandian.dataflow.statemachine; import java.io.File; +import java.lang.reflect.InvocationTargetException; import java.nio.ByteBuffer; import java.util.Set; import java.util.concurrent.Executor; @@ -141,7 +142,7 @@ public class StateServerFactory { nodeOptions.setInitialConf(conf); File RaftDataFile = new File(String.format("./raftdata/%d", port) ); - log.info("{}",RaftDataFile.mkdirs()); + log.info("mkdirs: {}",RaftDataFile.mkdirs()); nodeOptions.setLogUri( String.format("./raftdata/%d/logs", port) ); nodeOptions.setRaftMetaUri(String.format("./raftdata/%d/rafts", port)); @@ -150,18 +151,14 @@ public class StateServerFactory { nodeOptions.setFsm(fsm); cluster = new RaftGroupService(groupId, serverId, nodeOptions); - - - + Set> scans = new Reflections("com.yuandian.dataflow").getTypesAnnotatedWith(ProcessorRaft.class); scans.forEach((pRaftClass)->{ try { - cluster.getRpcServer().registerProcessor((RpcProcessor) pRaftClass.newInstance()); - } catch (InstantiationException e) { + cluster.getRpcServer().registerProcessor((RpcProcessor) pRaftClass.getDeclaredConstructor().newInstance()); + } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) { log.info("{}", e.toString()); - } catch (IllegalAccessException e) { - log.info("{}", e.toString()); - } + } }); node = cluster.start(); @@ -219,11 +216,9 @@ public class StateServerFactory { closure.run(new Status(RaftError.EINTERNAL, errorMsg)); } } - - - - public RaftResponse redirect() { - final RaftResponse response = new RaftResponse(); + + public RaftResponse redirect() { + final RaftResponse response = new RaftResponse(); response.setSuccess(false); if (this.node != null) { final PeerId leader = this.node.getLeaderId(); @@ -234,16 +229,12 @@ public class StateServerFactory { return response; } - public void handlerNotLeaderError(final GenericClosure closure) { + public void handlerNotLeaderError(final GenericClosure closure) { closure.failure("Not leader.", redirect().getRedirect()); closure.run(new Status(RaftError.EPERM, "Not leader")); } - - + private Executor createReadIndexExecutor() { - // final StoreEngineOptions opts = new StoreEngineOptions(); - // return StoreEngineHelper.createReadIndexExecutor(opts.getReadIndexCoreThreads()); - return ThreadPoolUtil.newBuilder() // .poolName("ReadIndexPool") // .enableMetric(true) // diff --git a/src/main/java/com/yuandian/dataflow/statemachine/operate/Operate.java b/src/main/java/com/yuandian/dataflow/statemachine/operate/Operate.java index df2cf67..3b822af 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/operate/Operate.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/operate/Operate.java @@ -71,7 +71,7 @@ public class Operate implements Serializable { @Override public void complete(Object result, Throwable err) { - log.info("{}", result); + log.info("Object result {}", result); //TODO: 解决回调的次序问题 var resp = (RaftResponse) result; closure.setResponse(resp); diff --git a/src/main/java/com/yuandian/dataflow/statemachine/rpc/OperateProcessor.java b/src/main/java/com/yuandian/dataflow/statemachine/rpc/OperateProcessor.java index 4c67936..86aae22 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/rpc/OperateProcessor.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/rpc/OperateProcessor.java @@ -73,8 +73,7 @@ public class OperateProcessor implements RpcProcessor implements Serializable { private T value; - private boolean success; /** * redirect peer id diff --git a/src/test/java/com/yuandian/dataflow/AppTest.java b/src/test/java/com/yuandian/dataflow/AppTest.java index 88cdb2f..e5ba148 100644 --- a/src/test/java/com/yuandian/dataflow/AppTest.java +++ b/src/test/java/com/yuandian/dataflow/AppTest.java @@ -40,6 +40,7 @@ import lombok.extern.slf4j.Slf4j; */ @DisplayName("AppTest") @Slf4j +@var public class AppTest { diff --git a/src/test/java/com/yuandian/dataflow/statemachine/StateMachineTest.java b/src/test/java/com/yuandian/dataflow/statemachine/StateMachineTest.java index 5e117a0..4bb07f5 100644 --- a/src/test/java/com/yuandian/dataflow/statemachine/StateMachineTest.java +++ b/src/test/java/com/yuandian/dataflow/statemachine/StateMachineTest.java @@ -13,7 +13,7 @@ import com.yuandian.dataflow.statemachine.rpc.RaftResponse; import com.yuandian.dataflow.statemachine.rpc.OperateProcessor.OperateRequest; import com.yuandian.dataflow.statemachine.state.State; -import lombok.var; + import lombok.extern.slf4j.Slf4j; @Slf4j diff --git a/start.sh b/start.sh index 51c666e..0ffea46 100755 --- a/start.sh +++ b/start.sh @@ -3,17 +3,14 @@ screen -S raft-0 -X quit screen -S raft-1 -X quit # screen -S raft-2 -X quit - - - -sleep 5s +sleep 1s VERSION=1.0.0-SNAPSHOT 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 -sleep 1 +sleep 0.5s screen -S raft-0 -X logfile flush 0 screen -S raft-1 -X logfile flush 0 From 9a9b28799d5ff42134648a3a3bb8c123cd6cec4c Mon Sep 17 00:00:00 2001 From: huangsimin <474420502@qq.com> Date: Thu, 28 Jul 2022 14:49:56 +0800 Subject: [PATCH 34/37] =?UTF-8?q?=E5=88=9D=E7=89=88=E4=BE=8B=E5=AD=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/yuandian/dataflow/Server.java | 15 +- .../dataflow/controller/PacketsProcessor.java | 29 +- .../controller/TransferLeaderProcessor.java | 8 +- .../dataflow/grpc/CollectPackets.java | 2 +- .../dataflow/statemachine/MasterFactory.java | 116 ++++---- .../dataflow/statemachine/StateFactory.java | 272 ++++++++++++++++++ .../dataflow/statemachine/StateMachine.java | 93 +++--- .../statemachine/StateServerFactory.java | 259 ----------------- .../statemachine/closure/GenericClosure.java | 13 +- .../statemachine/closure/StateClosure.java | 5 - .../statemachine/operate/Operate.java | 22 +- .../statemachine/rpc/OperateProcessor.java | 8 +- .../statemachine/state/WorkerState.java | 12 +- src/main/resources/logback.xml | 2 +- .../java/com/yuandian/dataflow/AppTest.java | 4 +- 15 files changed, 457 insertions(+), 403 deletions(-) create mode 100644 src/main/java/com/yuandian/dataflow/statemachine/StateFactory.java delete mode 100644 src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java delete mode 100644 src/main/java/com/yuandian/dataflow/statemachine/closure/StateClosure.java diff --git a/src/main/java/com/yuandian/dataflow/Server.java b/src/main/java/com/yuandian/dataflow/Server.java index b3556a2..7b3723e 100644 --- a/src/main/java/com/yuandian/dataflow/Server.java +++ b/src/main/java/com/yuandian/dataflow/Server.java @@ -2,11 +2,13 @@ package com.yuandian.dataflow; +import org.slf4j.MarkerFactory; + import com.alipay.sofa.jraft.JRaftUtils; import com.alipay.sofa.jraft.conf.Configuration; -import com.yuandian.dataflow.statemachine.StateServerFactory; +import com.yuandian.dataflow.statemachine.StateFactory; -import lombok.var; + import lombok.extern.slf4j.Slf4j; @@ -25,22 +27,19 @@ public class Server { public static void main(String[] args) throws Exception { - - String[] peers = new String[]{"localhost:4440","localhost:4441","localhost:4442"}; - String[] sprPeers = new String[]{"3440","3441","3442"}; - + var peeridx = Integer.parseInt(args[0]); var peeridstr = peers[ peeridx ]; - var sprPort = sprPeers[ peeridx ]; + // var peeridstr = peers[2]; // var sprPort = sprPeers[2]; log.info("{} {}", peeridstr, sprPort); conf = JRaftUtils.getConfiguration(String.join(",", peers)); - StateServerFactory.startStateServer(peeridstr, conf); + StateFactory.startStateServer(peeridstr, conf); diff --git a/src/main/java/com/yuandian/dataflow/controller/PacketsProcessor.java b/src/main/java/com/yuandian/dataflow/controller/PacketsProcessor.java index 6c1b3fb..69c6117 100644 --- a/src/main/java/com/yuandian/dataflow/controller/PacketsProcessor.java +++ b/src/main/java/com/yuandian/dataflow/controller/PacketsProcessor.java @@ -10,6 +10,9 @@ import java.io.Serializable; import java.time.Instant; import java.util.ArrayList; +import org.slf4j.Marker; +import org.slf4j.MarkerFactory; + import com.alipay.sofa.jraft.Status; import com.alipay.sofa.jraft.entity.PeerId; import com.alipay.sofa.jraft.error.RemotingException; @@ -17,7 +20,7 @@ import com.alipay.sofa.jraft.rpc.InvokeCallback; import com.alipay.sofa.jraft.rpc.RpcContext; import com.alipay.sofa.jraft.rpc.RpcProcessor; import com.google.protobuf.Any; -import com.yuandian.dataflow.statemachine.StateServerFactory; +import com.yuandian.dataflow.statemachine.StateFactory; import com.yuandian.dataflow.statemachine.closure.GenericClosure; import com.yuandian.dataflow.statemachine.operate.Operate; import com.yuandian.dataflow.statemachine.operate.Operate.OperateType; @@ -29,7 +32,7 @@ import com.yuandian.dataflow.statemachine.state.State; import lombok.Getter; import lombok.Setter; -import lombok.var; + import lombok.extern.slf4j.Slf4j; /** @@ -56,28 +59,28 @@ public class PacketsProcessor implements RpcProcessor 里的 getValue为 State的状态 ss.readIndexState(new GenericClosure() { @Override public void run(Status status) { - log.debug("status {}", status); + if (status.isOk()) { - var state = this.getValue(); - var ws = state.getWorkers().get(StateServerFactory.getServerId()); - + var state = this.getValue(); // 获取返回的状态 + var ws = state.getWorkers().get(StateFactory.getServerId()); ws.setTaskQueueSize(ws.getTaskQueueSize() - request.packets.size()); - ws.setUpdateAt(Instant.now()); + ws.setUpdateAt(Instant.now()); // 设置更新时间 - log.debug("workerState taskQueueSize: {} psize: {} state {}", ws.getTaskQueueSize(), - request.packets.size(), state.getWorkers().size()); - Operate.CallOperate(new Operate(OperateType.PUT, ws), new GenericClosure() { + // log.debug("workerState taskQueueSize: {} psize: {} state {}", ws.getTaskQueueSize(), + // request.packets.size(), state.getWorkers().size()); + Operate.CallOperate(new Operate(OperateType.PUT_WORKERSTATE, ws), new GenericClosure() { @Override public void run(Status status) { if (status.isOk()) { - log.info("{}", resp); + log.info("[{}] {}", StateFactory.getServerId(), resp); } } }); diff --git a/src/main/java/com/yuandian/dataflow/controller/TransferLeaderProcessor.java b/src/main/java/com/yuandian/dataflow/controller/TransferLeaderProcessor.java index 8372ff6..103133b 100644 --- a/src/main/java/com/yuandian/dataflow/controller/TransferLeaderProcessor.java +++ b/src/main/java/com/yuandian/dataflow/controller/TransferLeaderProcessor.java @@ -7,13 +7,17 @@ import com.alipay.sofa.jraft.entity.PeerId; import com.alipay.sofa.jraft.rpc.RpcContext; import com.alipay.sofa.jraft.rpc.RpcProcessor; import com.yuandian.dataflow.controller.PacketsProcessor.PacketsRequest; -import com.yuandian.dataflow.statemachine.StateServerFactory; +import com.yuandian.dataflow.statemachine.StateFactory; import com.yuandian.dataflow.statemachine.rpc.annotations.ProcessorRaft; import lombok.Getter; import lombok.Setter; import lombok.extern.slf4j.Slf4j; + +/** + * 例子 强制转换leader + */ @Slf4j @ProcessorRaft public class TransferLeaderProcessor implements RpcProcessor { @@ -26,7 +30,7 @@ public class TransferLeaderProcessor implements RpcProcessor() { + + // 读一致性 + StateFactory.readIndexState(new GenericClosure() { @Override public void run(Status status) { var state = this.getValue(); - + // log.debug("masterExecute start {} {}", status, alivePeers); alivePeers.forEach((peer) -> { - WorkerState ws = state.getWorkers().get(peer); - if (ws != null) { - // - var canTasks = MAX_TASKS - ws.getTaskQueueSize(); - log.debug("cap :{} peer: {}", canTasks, peer); - if (canTasks <= 0) { - return; - } - ws.setUpdateAt(Instant.now()); - ws.setTaskQueueSize(MAX_TASKS); - - var request = new PacketsRequest(); - for (int i = 0; i < canTasks; i++) { - var p = Any.pack(BacktrackingFlowOuterClass.BacktrackingFlow - .newBuilder() - .setTableId(10086) - .build()); - request.getPackets().add(p); - } - - Operate.CallOperate(new Operate(OperateType.PUT, ws), new GenericClosure() { - @Override - public void run(Status status) { - log.info("PacketsRequest run {}", status); - try { - ss.getRpcClient().invokeAsync(peer.getEndpoint(), request, - new InvokeCallback() { - @Override - public void complete(Object result, Throwable err) { - if(err != null) { - log.debug("{}", err); - } - log.debug("PacketsRequest: {}", result); - } - }, 5000); - } catch (InterruptedException | RemotingException e) { - log.info("error send packets {}", e.toString()); - } - } - }); + + if (state == null) { + log.error("readIndexState获取的状态为 {}", state); + return; } + + WorkerState ws = state.getWorkers().get(peer); + if (ws == null) { + log.error("WorkerState获取的状态为 {}", ws); + return; + } + + var canTasks = MAX_TASKS - ws.getTaskQueueSize(); + log.info("剩余能处理的任务数量[{}] :{}", peer, canTasks); + if (canTasks <= 0) { + return; + } + ws.setUpdateAt(Instant.now()); + ws.setTaskQueueSize(MAX_TASKS); + + // 模拟发送包的数据到该节点上 + var request = new PacketsRequest(); + for (int i = 0; i < canTasks; i++) { + var p = Any.pack(BacktrackingFlowOuterClass.BacktrackingFlow + .newBuilder() + .setTableId(10086) + .build()); + request.getPackets().add(p); + } + + + // 先提交 节点的 剩余能处理的任务数量. 然后再处理 + Operate.CallOperate(new Operate(OperateType.PUT_WORKERSTATE, ws), + new GenericClosure() { + @Override + public void run(Status status) { + log.info("PacketsRequest run {}", status); + try { + StateFactory.rpcClientInvokeAsync(peer.getEndpoint(), request, + new InvokeCallback() { + @Override + public void complete(Object result, Throwable err) { + if (err != null) { + // TODO: 如果错误, 需要让节点恢复任务处理的状态 + log.debug("{}", err); + } + log.debug("PacketsRequest: {}", result); + } + }, 5000); + } catch (InterruptedException | RemotingException e) { + log.info("error send packets {}", e.toString()); + } + } + }); + }); } - - } ); + + }); } Thread.sleep(5000); diff --git a/src/main/java/com/yuandian/dataflow/statemachine/StateFactory.java b/src/main/java/com/yuandian/dataflow/statemachine/StateFactory.java new file mode 100644 index 0000000..9399243 --- /dev/null +++ b/src/main/java/com/yuandian/dataflow/statemachine/StateFactory.java @@ -0,0 +1,272 @@ +/** + * description + * + * @author eson + *2022年7月12日-13:36:24 + */ +package com.yuandian.dataflow.statemachine; + +import java.io.File; +import java.lang.reflect.InvocationTargetException; +import java.nio.ByteBuffer; +import java.util.Set; +import java.util.concurrent.Executor; +import java.util.concurrent.SynchronousQueue; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.function.Consumer; +import java.util.function.Function; + +import org.reflections.Reflections; + +import com.alipay.remoting.NamedThreadFactory; +import com.alipay.remoting.exception.CodecException; +import com.alipay.remoting.serialization.SerializerManager; +import com.alipay.sofa.jraft.JRaftUtils; +import com.alipay.sofa.jraft.Node; +import com.alipay.sofa.jraft.RaftGroupService; +import com.alipay.sofa.jraft.Status; +import com.alipay.sofa.jraft.closure.ReadIndexClosure; +import com.alipay.sofa.jraft.conf.Configuration; +import com.alipay.sofa.jraft.entity.PeerId; +import com.alipay.sofa.jraft.entity.Task; +import com.alipay.sofa.jraft.error.RaftError; +import com.alipay.sofa.jraft.error.RemotingException; +import com.alipay.sofa.jraft.option.CliOptions; +import com.alipay.sofa.jraft.option.NodeOptions; +import com.alipay.sofa.jraft.rpc.InvokeCallback; +import com.alipay.sofa.jraft.rpc.InvokeContext; +import com.alipay.sofa.jraft.rpc.RpcClient; +import com.alipay.sofa.jraft.rpc.RpcProcessor; +import com.alipay.sofa.jraft.rpc.impl.BoltRaftRpcFactory; +import com.alipay.sofa.jraft.util.BytesUtil; +import com.alipay.sofa.jraft.util.Endpoint; +import com.alipay.sofa.jraft.util.ThreadPoolUtil; +import com.yuandian.dataflow.statemachine.closure.GenericClosure; +import com.yuandian.dataflow.statemachine.operate.Operate; +import com.yuandian.dataflow.statemachine.rpc.RaftResponse; + +import com.yuandian.dataflow.statemachine.rpc.OperateProcessor.OperateRequest; +import com.yuandian.dataflow.statemachine.rpc.annotations.ProcessorRaft; +import com.yuandian.dataflow.statemachine.state.State; +import com.yuandian.dataflow.statemachine.state.WorkerState; + +import lombok.Getter; +import lombok.Setter; + +import lombok.extern.slf4j.Slf4j; + +/** + * description + * + * @author eson + * 2022年7月12日-13:36:24 + */ +@Slf4j +public class StateFactory { + + private static StateServer ss; + + public static void startStateServer(String peerstr, Configuration conf) throws Exception { + if (ss != null) { + throw new Exception("重复初始化 InitStateServer"); + } + ss = new StateFactory.StateServer(peerstr, conf); + } + + public static boolean isLeader() { + return ss.node.isLeader(); + } + + public static PeerId getLeaderId() { + return ss.node.getLeaderId(); + } + + public static PeerId getServerId() { + return ss.cluster.getServerId(); + } + + public static Node getNode() { + return ss.node; + } + + public static Node getRaftNode() { + return ss.cluster.getRaftNode(); + } + + public static RpcClient getRpcClient() { + return ss.getRpcClient(); + } + + public static RaftGroupService getCluster() { + return ss.getCluster(); + } + + // 获取状态服务的对象 + public static StateServer getStateServer() { + return ss; + } + + public static void readIndexState(GenericClosure closure) { + ss.readIndexState(closure); + } + + public static void applyOperate(Operate op, GenericClosure closure) { + ss.applyOperate(op, closure); + } + + public static void rpcClientInvokeAsync(final Endpoint endpoint,final Object request,final InvokeCallback callback,final long timeoutMs) + throws InterruptedException, RemotingException { + ss.getRpcClient().invokeAsync(endpoint, request, callback, timeoutMs); + } + + public static Object rpcClientInvokeSync(final Endpoint endpoint, final Object request, final long timeoutMs) + throws InterruptedException, RemotingException { + return ss.getRpcClient().invokeSync(endpoint, request, timeoutMs); + } + + public static Object rpcClientInvokeSync(final Endpoint endpoint, final Object request, final InvokeContext ctx, + final long timeoutMs) throws InterruptedException, RemotingException { + return ss.getRpcClient().invokeSync(endpoint, request, ctx, timeoutMs); + } + + @Getter + @Setter + public static class StateServer { + + RpcClient rpcClient; + + private Node node; + private RaftGroupService cluster; + private StateMachine fsm; + + private String groupId = "dataflow"; + private Executor readIndexExecutor = createReadIndexExecutor(); + + public StateServer(String addr, Configuration conf) { + // String[] peers = new + // String[]{"localhost:4440","localhost:4441","localhost:4442"}; + // String[] sprPeers = new String[]{"3440","3441","3442"}; + + // var peeridstr = peers[Integer.parseInt(serverId)]; + // var sprPort = sprPeers[Integer.parseInt(args[0])]; + + // String groupId = "jraft"; + + // conf = + // JRaftUtils.getConfiguration("localhost:4440,localhost:4441,localhost:4442"); + + PeerId serverId = JRaftUtils.getPeerId(addr); + int port = serverId.getPort(); + + NodeOptions nodeOptions = new NodeOptions(); + + nodeOptions.setElectionTimeoutMs(1000); + nodeOptions.setSnapshotLogIndexMargin(3600); + nodeOptions.setInitialConf(conf); + + File RaftDataFile = new File(String.format("./raftdata/%d", port)); + log.info("mkdirs: {}", RaftDataFile.mkdirs()); + + nodeOptions.setLogUri(String.format("./raftdata/%d/logs", port)); + nodeOptions.setRaftMetaUri(String.format("./raftdata/%d/rafts", port)); + nodeOptions.setSnapshotUri(String.format("./raftdata/%d/snaps", port)); + fsm = new StateMachine(); // 状态实例初始化 + nodeOptions.setFsm(fsm); + + cluster = new RaftGroupService(groupId, serverId, nodeOptions); + + Set> scans = new Reflections("com.yuandian.dataflow").getTypesAnnotatedWith(ProcessorRaft.class); + scans.forEach((pRaftClass) -> { + try { + cluster.getRpcServer() + .registerProcessor((RpcProcessor) pRaftClass.getDeclaredConstructor().newInstance()); + } catch (InstantiationException | IllegalAccessException | IllegalArgumentException + | InvocationTargetException | NoSuchMethodException | SecurityException e) { + log.info("{}", e.toString()); + } + }); + node = cluster.start(); + + rpcClient = new BoltRaftRpcFactory().createRpcClient(); + rpcClient.init(new CliOptions()); + } + + public boolean isLeader() { + return this.fsm.isLeader(); + } + + public void readIndexState(GenericClosure closure) { + getNode().readIndex(BytesUtil.EMPTY_BYTES, new ReadIndexClosure() { + @Override + public void run(Status status, long index, byte[] reqCtx) { + log.debug("readIndexState({}) {}", getServerId(), status); + if (status.isOk()) { + // 回调失败 + closure.success(ss.fsm.getState()); + closure.setValue(ss.fsm.getState()); + } + closure.run(status); + } + }); + } + + public void applyOperate(Operate op, GenericClosure closure) { + // 所有的提交都必须再leader进行 + if (!ss.isLeader()) { + ss.handlerNotLeaderError(closure); + return; + } + + try { + closure.setValue(op); + final Task task = new Task(); + task.setData( + ByteBuffer.wrap(SerializerManager.getSerializer(SerializerManager.Hessian2).serialize(op))); + task.setDone(closure); // 确认所有数据 一致, 不需要加锁 + StateFactory.getStateServer().getNode().apply(task); + } catch (CodecException e) { + String errorMsg = "Fail to encode TaskState"; + log.debug(errorMsg, e); + closure.failure(errorMsg, PeerId.emptyPeer()); + closure.run(new Status(RaftError.EINTERNAL, errorMsg)); + } + } + + public RaftResponse redirect() { + final RaftResponse response = new RaftResponse(); + response.setSuccess(false); + if (this.node != null) { + final PeerId leader = this.node.getLeaderId(); + if (leader != null) { + response.setRedirect(leader); + } + } + return response; + } + + public void handlerNotLeaderError(final GenericClosure closure) { + closure.failure("Not leader.", redirect().getRedirect()); + closure.run(new Status(RaftError.EPERM, "Not leader")); + } + + private Executor createReadIndexExecutor() { + return ThreadPoolUtil.newBuilder() // + .poolName("ReadIndexPool") // + .enableMetric(true) // + .coreThreads(4) // + .maximumThreads(4) // + .keepAliveSeconds(60L) // + .workQueue(new SynchronousQueue<>()) // + .threadFactory(new NamedThreadFactory("ReadIndexService", true)) // + .rejectedHandler(new ThreadPoolExecutor.AbortPolicy()) // + .build(); + } + } + + public static void main(String[] args) throws InterruptedException, RemotingException { + var rpcClient = new BoltRaftRpcFactory().createRpcClient(); + rpcClient.init(new CliOptions()); + var resp = rpcClient.invokeSync(new Endpoint("localhost", 4441), new OperateRequest(), 5000); + log.info("{}", resp); + } +} diff --git a/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java b/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java index 0270fba..2409578 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/StateMachine.java @@ -28,7 +28,7 @@ import com.yuandian.dataflow.statemachine.rpc.OperateProcessor.OperateRequest; import com.yuandian.dataflow.statemachine.state.State; import com.yuandian.dataflow.statemachine.state.WorkerState; -import lombok.var; + import lombok.extern.slf4j.Slf4j; /** @@ -72,13 +72,13 @@ public class StateMachine extends StateMachineAdapter { Operate op = null; GenericClosure closure = null; if (iter.done() != null) { - // This task is applied by this node, get value from closure to avoid additional - // parsing. - closure = (GenericClosure) iter.done(); // 只支持单一个State. 全状态机只支持一种提交 + + // leader可以直接从 回调closure里提取operate + closure = (GenericClosure)iter.done(); // 只支持单一个State. 全状态机只支持一种提交 op = closure.getValue(); } else { - // Have to parse FetchAddRequest from this user log. + // 非leader 需要从getData反序列化出来后处理 final ByteBuffer data = iter.getData(); try { @@ -91,29 +91,34 @@ public class StateMachine extends StateMachineAdapter { } - if (op != null) { - switch (op.getType()) { - case PUT: - WorkerState ws = op.getValue(); - state.getWorkers().put(ws.peerId, ws); - if (closure != null) { - closure.success(op); - closure.run(Status.OK()); - } - break; - case REMOVE: - if (closure != null) { - closure.success(op); - closure.run(Status.OK()); - } - break; - default: - break; + if (op == null) { + log.error("op 为 {}. 存在错误, 可能版本不一致", op); + continue; + } - } - } else { + switch (op.getType()) { + + case PUT_WORKERSTATE: + + WorkerState ws = op.getValue(); + log.debug("PUT {}", ws.peerId); + state.getWorkers().put(ws.peerId, ws); + if (closure != null) { + closure.success(op); + closure.run(Status.OK()); + } + break; + case REMOVE: + if (closure != null) { + closure.success(op); + closure.run(Status.OK()); + } + break; + default: + break; } + iter.next(); } @@ -136,7 +141,7 @@ public class StateMachine extends StateMachineAdapter { @Override public void onLeaderStart(final long term) { - log.debug("onLeaderStart {}", StateServerFactory.getServerId()); + log.debug("onLeaderStart {}", StateFactory.getServerId()); this.leaderTerm.set(term); // 判断是否Master线程还在跑, 如果存在则中断 @@ -144,26 +149,23 @@ public class StateMachine extends StateMachineAdapter { MasterFactory.getMasterExecute().interrupt(); } - var ss = StateServerFactory.getStateServer(); - ss.readIndexState(new GenericClosure() { - + + StateFactory.readIndexState(new GenericClosure() { @Override public void run(Status status) { - var ws = state.getWorkers().get(StateServerFactory.getServerId()); + var ws = state.getWorkers().get(StateFactory.getServerId()); if (ws == null) { - ws = new WorkerState(StateServerFactory.getServerId()); + ws = new WorkerState(StateFactory.getServerId()); } - Operate op = new Operate(OperateType.PUT, ws); - ss.applyOperate(op, new GenericClosure() { + StateFactory.applyOperate(new Operate(OperateType.PUT_WORKERSTATE, ws), new GenericClosure() { @Override public void run(Status status) { log.debug("master update workerstate: {}", status); } }); } - }); // 当成为master时候 必须启动 @@ -174,7 +176,7 @@ public class StateMachine extends StateMachineAdapter { @Override public void onLeaderStop(final Status status) { - log.debug("onLeaderStop {}", StateServerFactory.getCluster().getServerId()); + log.debug("onLeaderStop {}", StateFactory.getCluster().getServerId()); this.leaderTerm.set(-1); // 判断是否Master线程还在跑, 如果存在则中断 if (MasterFactory.getMasterExecute().isAlive()) { @@ -192,7 +194,7 @@ public class StateMachine extends StateMachineAdapter { @Override public void onStartFollowing(LeaderChangeContext ctx) { - log.debug("[onStartFollowing] {} {}", ctx, StateServerFactory.getCluster().getServerId()); + log.debug("[onStartFollowing] {} {}", ctx, StateFactory.getCluster().getServerId()); try { // 判断是否Master线程还在跑, 如果存在则中断 @@ -201,14 +203,13 @@ public class StateMachine extends StateMachineAdapter { } - var ws = new WorkerState(StateServerFactory.getServerId()); - log.debug("my: {} leader id {}", StateServerFactory.getServerId(), StateServerFactory.getLeaderId()); + var ws = new WorkerState(StateFactory.getServerId()); + log.debug("my: {} leader id {}", StateFactory.getServerId(), StateFactory.getLeaderId()); - var op = new Operate(OperateType.PUT, ws); - Operate.CallOperate(op, new GenericClosure() { + Operate.CallOperate(new Operate(OperateType.PUT_WORKERSTATE, ws), new GenericClosure() { @Override public void run(Status status) { - log.info("{} {}", status, this.getResponse()); + log.info("onStartFollowing CallOperate {} {}", status, this.getResponse()); } }); @@ -227,14 +228,14 @@ public class StateMachine extends StateMachineAdapter { @Override public void onStopFollowing(LeaderChangeContext ctx) { - log.debug("{} {}", ctx, StateServerFactory.getCluster().getServerId()); + log.debug("{} {}", ctx, StateFactory.getCluster().getServerId()); - var ss = StateServerFactory.getStateServer(); - var ws = new WorkerState(StateServerFactory.getServerId()); + var ss = StateFactory.getStateServer(); + var ws = new WorkerState(StateFactory.getServerId()); - log.debug("my: {} leader id {}", StateServerFactory.getServerId(), StateServerFactory.getLeaderId()); + log.debug("my: {} leader id {}", StateFactory.getServerId(), StateFactory.getLeaderId()); - var op = new Operate(OperateType.PUT, ws); + var op = new Operate(OperateType.PUT_WORKERSTATE, ws); Operate.CallOperate(op, new GenericClosure() { @Override public void run(Status status) { diff --git a/src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java b/src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java deleted file mode 100644 index caccbe2..0000000 --- a/src/main/java/com/yuandian/dataflow/statemachine/StateServerFactory.java +++ /dev/null @@ -1,259 +0,0 @@ -/** - * description - * - * @author eson - *2022年7月12日-13:36:24 - */ -package com.yuandian.dataflow.statemachine; - -import java.io.File; -import java.lang.reflect.InvocationTargetException; -import java.nio.ByteBuffer; -import java.util.Set; -import java.util.concurrent.Executor; -import java.util.concurrent.SynchronousQueue; -import java.util.concurrent.ThreadPoolExecutor; -import java.util.function.Consumer; -import java.util.function.Function; - -import org.reflections.Reflections; - -import com.alipay.remoting.NamedThreadFactory; -import com.alipay.remoting.exception.CodecException; -import com.alipay.remoting.serialization.SerializerManager; -import com.alipay.sofa.jraft.JRaftUtils; -import com.alipay.sofa.jraft.Node; -import com.alipay.sofa.jraft.RaftGroupService; -import com.alipay.sofa.jraft.Status; -import com.alipay.sofa.jraft.closure.ReadIndexClosure; -import com.alipay.sofa.jraft.conf.Configuration; -import com.alipay.sofa.jraft.entity.PeerId; -import com.alipay.sofa.jraft.entity.Task; -import com.alipay.sofa.jraft.error.RaftError; -import com.alipay.sofa.jraft.error.RemotingException; -import com.alipay.sofa.jraft.option.CliOptions; -import com.alipay.sofa.jraft.option.NodeOptions; -import com.alipay.sofa.jraft.rpc.InvokeCallback; -import com.alipay.sofa.jraft.rpc.RpcClient; -import com.alipay.sofa.jraft.rpc.RpcProcessor; -import com.alipay.sofa.jraft.rpc.impl.BoltRaftRpcFactory; -import com.alipay.sofa.jraft.util.BytesUtil; -import com.alipay.sofa.jraft.util.Endpoint; -import com.alipay.sofa.jraft.util.ThreadPoolUtil; -import com.yuandian.dataflow.statemachine.closure.GenericClosure; -import com.yuandian.dataflow.statemachine.operate.Operate; -import com.yuandian.dataflow.statemachine.rpc.RaftResponse; - -import com.yuandian.dataflow.statemachine.rpc.OperateProcessor.OperateRequest; -import com.yuandian.dataflow.statemachine.rpc.annotations.ProcessorRaft; -import com.yuandian.dataflow.statemachine.state.State; -import com.yuandian.dataflow.statemachine.state.WorkerState; - -import lombok.Getter; -import lombok.Setter; -import lombok.var; -import lombok.extern.slf4j.Slf4j; - -/** - * description - * - * @author eson - *2022年7月12日-13:36:24 - */ -@Slf4j -@var -public class StateServerFactory { - - private static StateServer ss; - - public static void startStateServer(String peerstr, Configuration conf) throws Exception { - if(ss != null) { - throw new Exception("重复初始化 InitStateServer"); - } - ss = new StateServerFactory.StateServer(peerstr, conf); - } - - - public static boolean isLeader() { - return ss.node.isLeader() ; - } - - - public static PeerId getLeaderId() { - return ss.node.getLeaderId() ; - } - - public static PeerId getServerId() { - return ss.cluster.getServerId(); - } - - public static Node getNode() { - return ss.node ; - } - - public static Node getRaftNode() { - return ss.cluster.getRaftNode() ; - } - - public static RpcClient getRpcClient() { - return ss.getRpcClient(); - } - - public static RaftGroupService getCluster() { - return ss.getCluster(); - } - - // 获取状态服务的对象 - public static StateServer getStateServer() { - return ss; - } - - @Getter - @Setter - public static class StateServer { - - RpcClient rpcClient; - - private Node node; - private RaftGroupService cluster; - private StateMachine fsm; - - private String groupId = "dataflow"; - private Executor readIndexExecutor = createReadIndexExecutor(); - - public StateServer(String addr, Configuration conf) { - // String[] peers = new String[]{"localhost:4440","localhost:4441","localhost:4442"}; - // String[] sprPeers = new String[]{"3440","3441","3442"}; - - // var peeridstr = peers[Integer.parseInt(serverId)]; - // var sprPort = sprPeers[Integer.parseInt(args[0])]; - - // String groupId = "jraft"; - - // conf = JRaftUtils.getConfiguration("localhost:4440,localhost:4441,localhost:4442"); - - PeerId serverId = JRaftUtils.getPeerId(addr); - int port = serverId.getPort(); - - NodeOptions nodeOptions = new NodeOptions(); - - nodeOptions.setElectionTimeoutMs(1000); - nodeOptions.setSnapshotLogIndexMargin(3600); - nodeOptions.setInitialConf(conf); - - File RaftDataFile = new File(String.format("./raftdata/%d", port) ); - log.info("mkdirs: {}",RaftDataFile.mkdirs()); - - nodeOptions.setLogUri( String.format("./raftdata/%d/logs", port) ); - nodeOptions.setRaftMetaUri(String.format("./raftdata/%d/rafts", port)); - nodeOptions.setSnapshotUri(String.format("./raftdata/%d/snaps", port)); - fsm = new StateMachine(); // 状态实例初始化 - nodeOptions.setFsm(fsm); - - cluster = new RaftGroupService(groupId, serverId, nodeOptions); - - Set> scans = new Reflections("com.yuandian.dataflow").getTypesAnnotatedWith(ProcessorRaft.class); - scans.forEach((pRaftClass)->{ - try { - cluster.getRpcServer().registerProcessor((RpcProcessor) pRaftClass.getDeclaredConstructor().newInstance()); - } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) { - log.info("{}", e.toString()); - } - }); - node = cluster.start(); - - rpcClient = new BoltRaftRpcFactory().createRpcClient(); - rpcClient.init(new CliOptions()); - } - - - - public boolean isLeader() { - return this.fsm.isLeader(); - } - - - - public void useFsmState(Consumer dofunc) { - var state = ss.fsm.getState(); - synchronized(state) { - dofunc.accept(state); - } - } - - public void readIndexState(GenericClosure closure) { - getNode().readIndex(BytesUtil.EMPTY_BYTES, new ReadIndexClosure() { - @Override - public void run(Status status, long index, byte[] reqCtx) { - if(status.isOk()) { - // 回调失败 - closure.success(ss.fsm.getState()); - } - closure.run(status); - } - } ); - } - - - - public void applyOperate(Operate op, GenericClosure closure) { - // 所有的提交都必须再leader进行 - if (!ss.isLeader()) { - ss.handlerNotLeaderError(closure); - return; - } - - try { - closure.setValue(op); - final Task task = new Task(); - task.setData(ByteBuffer.wrap(SerializerManager.getSerializer(SerializerManager.Hessian2).serialize(op))); - task.setDone(closure); // 确认所有数据 一致, 不需要加锁 - StateServerFactory.getStateServer().getNode().apply(task); - } catch (CodecException e) { - String errorMsg = "Fail to encode TaskState"; - log.debug(errorMsg, e); - closure.failure(errorMsg, PeerId.emptyPeer()); - closure.run(new Status(RaftError.EINTERNAL, errorMsg)); - } - } - - public RaftResponse redirect() { - final RaftResponse response = new RaftResponse(); - response.setSuccess(false); - if (this.node != null) { - final PeerId leader = this.node.getLeaderId(); - if (leader != null) { - response.setRedirect(leader); - } - } - return response; - } - - public void handlerNotLeaderError(final GenericClosure closure) { - closure.failure("Not leader.", redirect().getRedirect()); - closure.run(new Status(RaftError.EPERM, "Not leader")); - } - - private Executor createReadIndexExecutor() { - return ThreadPoolUtil.newBuilder() // - .poolName("ReadIndexPool") // - .enableMetric(true) // - .coreThreads(4) // - .maximumThreads(4) // - .keepAliveSeconds(60L) // - .workQueue(new SynchronousQueue<>()) // - .threadFactory(new NamedThreadFactory("ReadIndexService", true)) // - .rejectedHandler(new ThreadPoolExecutor.AbortPolicy()) // - .build(); - } -} - - - - public static void main(String[] args) throws InterruptedException, RemotingException { - var rpcClient = new BoltRaftRpcFactory().createRpcClient(); - rpcClient.init(new CliOptions()); - var resp = rpcClient.invokeSync(new Endpoint("localhost",4441), new OperateRequest(), 5000); - log.info("{}", resp); - } -} diff --git a/src/main/java/com/yuandian/dataflow/statemachine/closure/GenericClosure.java b/src/main/java/com/yuandian/dataflow/statemachine/closure/GenericClosure.java index 002bed1..db6787a 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/closure/GenericClosure.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/closure/GenericClosure.java @@ -3,6 +3,7 @@ package com.yuandian.dataflow.statemachine.closure; import com.alipay.sofa.jraft.Closure; import com.alipay.sofa.jraft.Status; import com.alipay.sofa.jraft.entity.PeerId; +import com.yuandian.dataflow.statemachine.StateFactory; import com.yuandian.dataflow.statemachine.operate.Operate; import com.yuandian.dataflow.statemachine.rpc.RaftResponse; import com.yuandian.dataflow.statemachine.state.State; @@ -21,15 +22,21 @@ import org.slf4j.LoggerFactory; @ToString public abstract class GenericClosure implements Closure { + // 状态机的统一响应 private RaftResponse response; // 代表任务状态 private T value; public GenericClosure() { - + } + /** + * 错误的时候返回错误信息. 自动装配response + * @param errorMsg + * @param redirect + */ public void failure(final String errorMsg, final PeerId redirect) { final RaftResponse response = new RaftResponse(); response.setSuccess(false); @@ -38,6 +45,10 @@ public abstract class GenericClosure implements Closure { setResponse(response); } + /** + * 成功时调用该方法. 自动装配response + * @param value + */ public void success(final T value) { final RaftResponse response = new RaftResponse(); response.setValue(value); diff --git a/src/main/java/com/yuandian/dataflow/statemachine/closure/StateClosure.java b/src/main/java/com/yuandian/dataflow/statemachine/closure/StateClosure.java deleted file mode 100644 index e49a805..0000000 --- a/src/main/java/com/yuandian/dataflow/statemachine/closure/StateClosure.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.yuandian.dataflow.statemachine.closure; - -public class StateClosure { - -} diff --git a/src/main/java/com/yuandian/dataflow/statemachine/operate/Operate.java b/src/main/java/com/yuandian/dataflow/statemachine/operate/Operate.java index 3b822af..d385dd2 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/operate/Operate.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/operate/Operate.java @@ -5,14 +5,14 @@ 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; +import com.yuandian.dataflow.statemachine.StateFactory; import com.yuandian.dataflow.statemachine.closure.GenericClosure; import com.yuandian.dataflow.statemachine.rpc.OperateProcessor; import com.yuandian.dataflow.statemachine.rpc.RaftResponse; import com.yuandian.dataflow.statemachine.state.WorkerState; import lombok.Data; -import lombok.var; + import lombok.extern.slf4j.Slf4j; /** @@ -22,11 +22,17 @@ import lombok.extern.slf4j.Slf4j; */ @Slf4j @Data -@var public class Operate implements Serializable { public static enum OperateType { - PUT, REMOVE; + /** + * 同步WorkerState状态. + */ + PUT_WORKERSTATE, + /** + * 暂无想法 + */ + REMOVE; } private OperateType type; @@ -52,10 +58,10 @@ public class Operate implements Serializable { * @param closure 回调函数. Operate为返回值 */ public static void CallOperate(Operate op, GenericClosure closure) { - - var ss = StateServerFactory.getStateServer(); + log.debug("CallOperate Value {}", op.getValue()); + var ss = StateFactory.getStateServer(); // 如果是leader 就直接提交 - if (StateServerFactory.isLeader()) { + if (StateFactory.isLeader()) { ss.applyOperate(op, closure); return; } @@ -64,7 +70,7 @@ public class Operate implements Serializable { var request = new OperateProcessor.OperateRequest(); request.setOperate(op); - var leaderId = StateServerFactory.getLeaderId(); + var leaderId = StateFactory.getLeaderId(); try { ss.getRpcClient().invokeAsync(leaderId.getEndpoint(), request, new InvokeCallback() { diff --git a/src/main/java/com/yuandian/dataflow/statemachine/rpc/OperateProcessor.java b/src/main/java/com/yuandian/dataflow/statemachine/rpc/OperateProcessor.java index 86aae22..642a111 100644 --- a/src/main/java/com/yuandian/dataflow/statemachine/rpc/OperateProcessor.java +++ b/src/main/java/com/yuandian/dataflow/statemachine/rpc/OperateProcessor.java @@ -16,8 +16,8 @@ import com.alipay.sofa.jraft.entity.Task; import com.alipay.sofa.jraft.error.RaftError; import com.alipay.sofa.jraft.rpc.RpcContext; import com.alipay.sofa.jraft.rpc.RpcProcessor; -import com.yuandian.dataflow.statemachine.StateServerFactory; -import com.yuandian.dataflow.statemachine.StateServerFactory.StateServer; +import com.yuandian.dataflow.statemachine.StateFactory; +import com.yuandian.dataflow.statemachine.StateFactory.StateServer; import com.yuandian.dataflow.statemachine.closure.GenericClosure; import com.yuandian.dataflow.statemachine.operate.Operate; import com.yuandian.dataflow.statemachine.rpc.annotations.ProcessorRaft; @@ -29,7 +29,7 @@ import org.apache.commons.lang.StringUtils; import lombok.Getter; import lombok.Setter; import lombok.ToString; -import lombok.var; + import lombok.extern.slf4j.Slf4j; /** @@ -82,7 +82,7 @@ public class OperateProcessor implements RpcProcessor - %d{yyyyMMdd HH:mm:ss.SSS} %level %thread\(%file:%line\): %msg%n + %d{yyyy-MM-dd HH:mm:ss.SSS} %red(%level) %cyan(%thread\(%file:%line\)): %msg%n