diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index e41ee099a..3478b3cda 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -25,9 +25,9 @@ jobs: git clone https://github.com/vesoft-inc/nebula-docker-compose.git pushd nebula-docker-compose/ cp ../../client/src/test/resources/docker-compose.yaml . - docker-compose up -d + docker compose up -d sleep 30 - docker-compose ps + docker compose ps popd popd @@ -38,9 +38,9 @@ jobs: pushd ca cp -r ../../client/src/test/resources/ssl . cp ../../client/src/test/resources/docker-compose-casigned.yaml . - docker-compose -f docker-compose-casigned.yaml up -d + docker compose -f docker-compose-casigned.yaml up -d sleep 30 - docker-compose -f docker-compose-casigned.yaml ps + docker compose -f docker-compose-casigned.yaml ps popd popd @@ -51,9 +51,9 @@ jobs: pushd self cp -r ../../client/src/test/resources/ssl . cp ../../client/src/test/resources/docker-compose-selfsigned.yaml . - docker-compose -f docker-compose-selfsigned.yaml up -d + docker compose -f docker-compose-selfsigned.yaml up -d sleep 30 - docker-compose -f docker-compose-selfsigned.yaml ps + docker compose -f docker-compose-selfsigned.yaml ps popd popd diff --git a/.github/workflows/snapshot.yaml b/.github/workflows/snapshot.yaml index f20eca198..126944d50 100644 --- a/.github/workflows/snapshot.yaml +++ b/.github/workflows/snapshot.yaml @@ -26,9 +26,9 @@ jobs: git clone https://github.com/vesoft-inc/nebula-docker-compose.git pushd nebula-docker-compose/ cp ../../client/src/test/resources/docker-compose.yaml . - docker-compose up -d + docker compose up -d sleep 30 - docker-compose ps + docker compose ps popd popd @@ -39,9 +39,9 @@ jobs: pushd ca cp -r ../../client/src/test/resources/ssl . cp ../../client/src/test/resources/docker-compose-casigned.yaml . - docker-compose -f docker-compose-casigned.yaml up -d + docker compose -f docker-compose-casigned.yaml up -d sleep 30 - docker-compose -f docker-compose-casigned.yaml ps + docker compose -f docker-compose-casigned.yaml ps popd popd @@ -52,9 +52,9 @@ jobs: pushd self cp -r ../../client/src/test/resources/ssl . cp ../../client/src/test/resources/docker-compose-selfsigned.yaml . - docker-compose -f docker-compose-selfsigned.yaml up -d + docker compose -f docker-compose-selfsigned.yaml up -d sleep 30 - docker-compose -f docker-compose-selfsigned.yaml ps + docker compose -f docker-compose-selfsigned.yaml ps popd popd diff --git a/client/src/main/generated/com/vesoft/nebula/ErrorCode.java b/client/src/main/generated/com/vesoft/nebula/ErrorCode.java index 7b03581d4..054ec0451 100644 --- a/client/src/main/generated/com/vesoft/nebula/ErrorCode.java +++ b/client/src/main/generated/com/vesoft/nebula/ErrorCode.java @@ -50,6 +50,7 @@ public enum ErrorCode implements com.facebook.thrift.TEnum { E_PART_DISABLED(-34), E_PART_ALREADY_STARTED(-35), E_PART_ALREADY_STOPPED(-36), + E_QUERY_TIMEDOUT(-37), E_BAD_USERNAME_PASSWORD(-1001), E_SESSION_INVALID(-1002), E_SESSION_TIMEOUT(-1003), diff --git a/client/src/main/generated/com/vesoft/nebula/graph/GraphService.java b/client/src/main/generated/com/vesoft/nebula/graph/GraphService.java index 8e9f07426..bc28872d8 100644 --- a/client/src/main/generated/com/vesoft/nebula/graph/GraphService.java +++ b/client/src/main/generated/com/vesoft/nebula/graph/GraphService.java @@ -39,6 +39,8 @@ public interface Iface { public ExecutionResponse executeWithParameter(long sessionId, byte[] stmt, Map parameterMap) throws TException; + public ExecutionResponse executeWithTimeout(long sessionId, byte[] stmt, Map parameterMap, long timeout) throws TException; + public byte[] executeJson(long sessionId, byte[] stmt) throws TException; public byte[] executeJsonWithParameter(long sessionId, byte[] stmt, Map parameterMap) throws TException; @@ -59,6 +61,8 @@ public interface AsyncIface { public void executeWithParameter(long sessionId, byte[] stmt, Map parameterMap, AsyncMethodCallback resultHandler) throws TException; + public void executeWithTimeout(long sessionId, byte[] stmt, Map parameterMap, long timeout, AsyncMethodCallback resultHandler) throws TException; + public void executeJson(long sessionId, byte[] stmt, AsyncMethodCallback resultHandler) throws TException; public void executeJsonWithParameter(long sessionId, byte[] stmt, Map parameterMap, AsyncMethodCallback resultHandler) throws TException; @@ -258,6 +262,54 @@ public ExecutionResponse recv_executeWithParameter() throws TException throw new TApplicationException(TApplicationException.MISSING_RESULT, "executeWithParameter failed: unknown result"); } + public ExecutionResponse executeWithTimeout(long sessionId, byte[] stmt, Map parameterMap, long timeout) throws TException + { + ContextStack ctx = getContextStack("GraphService.executeWithTimeout", null); + this.setContextStack(ctx); + send_executeWithTimeout(sessionId, stmt, parameterMap, timeout); + return recv_executeWithTimeout(); + } + + public void send_executeWithTimeout(long sessionId, byte[] stmt, Map parameterMap, long timeout) throws TException + { + ContextStack ctx = this.getContextStack(); + super.preWrite(ctx, "GraphService.executeWithTimeout", null); + oprot_.writeMessageBegin(new TMessage("executeWithTimeout", TMessageType.CALL, seqid_)); + executeWithTimeout_args args = new executeWithTimeout_args(); + args.sessionId = sessionId; + args.stmt = stmt; + args.parameterMap = parameterMap; + args.timeout = timeout; + args.write(oprot_); + oprot_.writeMessageEnd(); + oprot_.getTransport().flush(); + super.postWrite(ctx, "GraphService.executeWithTimeout", args); + return; + } + + public ExecutionResponse recv_executeWithTimeout() throws TException + { + ContextStack ctx = super.getContextStack(); + long bytes; + TMessageType mtype; + super.preRead(ctx, "GraphService.executeWithTimeout"); + TMessage msg = iprot_.readMessageBegin(); + if (msg.type == TMessageType.EXCEPTION) { + TApplicationException x = TApplicationException.read(iprot_); + iprot_.readMessageEnd(); + throw x; + } + executeWithTimeout_result result = new executeWithTimeout_result(); + result.read(iprot_); + iprot_.readMessageEnd(); + super.postRead(ctx, "GraphService.executeWithTimeout", result); + + if (result.isSetSuccess()) { + return result.success; + } + throw new TApplicationException(TApplicationException.MISSING_RESULT, "executeWithTimeout failed: unknown result"); + } + public byte[] executeJson(long sessionId, byte[] stmt) throws TException { ContextStack ctx = getContextStack("GraphService.executeJson", null); @@ -458,9 +510,9 @@ public AsyncClient(TProtocolFactory protocolFactory, TAsyncClientManager clientM super(protocolFactory, clientManager, transport); } - public void authenticate(byte[] username, byte[] password, AsyncMethodCallback resultHandler37) throws TException { + public void authenticate(byte[] username, byte[] password, AsyncMethodCallback resultHandler38) throws TException { checkReady(); - authenticate_call method_call = new authenticate_call(username, password, resultHandler37, this, ___protocolFactory, ___transport); + authenticate_call method_call = new authenticate_call(username, password, resultHandler38, this, ___protocolFactory, ___transport); this.___currentMethod = method_call; ___manager.call(method_call); } @@ -468,8 +520,8 @@ public void authenticate(byte[] username, byte[] password, AsyncMethodCallback r public static class authenticate_call extends TAsyncMethodCall { private byte[] username; private byte[] password; - public authenticate_call(byte[] username, byte[] password, AsyncMethodCallback resultHandler38, TAsyncClient client34, TProtocolFactory protocolFactory35, TNonblockingTransport transport36) throws TException { - super(client34, protocolFactory35, transport36, resultHandler38, false); + public authenticate_call(byte[] username, byte[] password, AsyncMethodCallback resultHandler39, TAsyncClient client35, TProtocolFactory protocolFactory36, TNonblockingTransport transport37) throws TException { + super(client35, protocolFactory36, transport37, resultHandler39, false); this.username = username; this.password = password; } @@ -493,17 +545,17 @@ public AuthResponse getResult() throws TException { } } - public void signout(long sessionId, AsyncMethodCallback resultHandler42) throws TException { + public void signout(long sessionId, AsyncMethodCallback resultHandler43) throws TException { checkReady(); - signout_call method_call = new signout_call(sessionId, resultHandler42, this, ___protocolFactory, ___transport); + signout_call method_call = new signout_call(sessionId, resultHandler43, this, ___protocolFactory, ___transport); this.___currentMethod = method_call; ___manager.call(method_call); } public static class signout_call extends TAsyncMethodCall { private long sessionId; - public signout_call(long sessionId, AsyncMethodCallback resultHandler43, TAsyncClient client39, TProtocolFactory protocolFactory40, TNonblockingTransport transport41) throws TException { - super(client39, protocolFactory40, transport41, resultHandler43, true); + public signout_call(long sessionId, AsyncMethodCallback resultHandler44, TAsyncClient client40, TProtocolFactory protocolFactory41, TNonblockingTransport transport42) throws TException { + super(client40, protocolFactory41, transport42, resultHandler44, true); this.sessionId = sessionId; } @@ -524,9 +576,9 @@ public void getResult() throws TException { } } - public void execute(long sessionId, byte[] stmt, AsyncMethodCallback resultHandler47) throws TException { + public void execute(long sessionId, byte[] stmt, AsyncMethodCallback resultHandler48) throws TException { checkReady(); - execute_call method_call = new execute_call(sessionId, stmt, resultHandler47, this, ___protocolFactory, ___transport); + execute_call method_call = new execute_call(sessionId, stmt, resultHandler48, this, ___protocolFactory, ___transport); this.___currentMethod = method_call; ___manager.call(method_call); } @@ -534,8 +586,8 @@ public void execute(long sessionId, byte[] stmt, AsyncMethodCallback resultHandl public static class execute_call extends TAsyncMethodCall { private long sessionId; private byte[] stmt; - public execute_call(long sessionId, byte[] stmt, AsyncMethodCallback resultHandler48, TAsyncClient client44, TProtocolFactory protocolFactory45, TNonblockingTransport transport46) throws TException { - super(client44, protocolFactory45, transport46, resultHandler48, false); + public execute_call(long sessionId, byte[] stmt, AsyncMethodCallback resultHandler49, TAsyncClient client45, TProtocolFactory protocolFactory46, TNonblockingTransport transport47) throws TException { + super(client45, protocolFactory46, transport47, resultHandler49, false); this.sessionId = sessionId; this.stmt = stmt; } @@ -559,9 +611,9 @@ public ExecutionResponse getResult() throws TException { } } - public void executeWithParameter(long sessionId, byte[] stmt, Map parameterMap, AsyncMethodCallback resultHandler52) throws TException { + public void executeWithParameter(long sessionId, byte[] stmt, Map parameterMap, AsyncMethodCallback resultHandler53) throws TException { checkReady(); - executeWithParameter_call method_call = new executeWithParameter_call(sessionId, stmt, parameterMap, resultHandler52, this, ___protocolFactory, ___transport); + executeWithParameter_call method_call = new executeWithParameter_call(sessionId, stmt, parameterMap, resultHandler53, this, ___protocolFactory, ___transport); this.___currentMethod = method_call; ___manager.call(method_call); } @@ -570,8 +622,8 @@ public static class executeWithParameter_call extends TAsyncMethodCall { private long sessionId; private byte[] stmt; private Map parameterMap; - public executeWithParameter_call(long sessionId, byte[] stmt, Map parameterMap, AsyncMethodCallback resultHandler53, TAsyncClient client49, TProtocolFactory protocolFactory50, TNonblockingTransport transport51) throws TException { - super(client49, protocolFactory50, transport51, resultHandler53, false); + public executeWithParameter_call(long sessionId, byte[] stmt, Map parameterMap, AsyncMethodCallback resultHandler54, TAsyncClient client50, TProtocolFactory protocolFactory51, TNonblockingTransport transport52) throws TException { + super(client50, protocolFactory51, transport52, resultHandler54, false); this.sessionId = sessionId; this.stmt = stmt; this.parameterMap = parameterMap; @@ -597,9 +649,50 @@ public ExecutionResponse getResult() throws TException { } } - public void executeJson(long sessionId, byte[] stmt, AsyncMethodCallback resultHandler57) throws TException { + public void executeWithTimeout(long sessionId, byte[] stmt, Map parameterMap, long timeout, AsyncMethodCallback resultHandler58) throws TException { + checkReady(); + executeWithTimeout_call method_call = new executeWithTimeout_call(sessionId, stmt, parameterMap, timeout, resultHandler58, this, ___protocolFactory, ___transport); + this.___currentMethod = method_call; + ___manager.call(method_call); + } + + public static class executeWithTimeout_call extends TAsyncMethodCall { + private long sessionId; + private byte[] stmt; + private Map parameterMap; + private long timeout; + public executeWithTimeout_call(long sessionId, byte[] stmt, Map parameterMap, long timeout, AsyncMethodCallback resultHandler59, TAsyncClient client55, TProtocolFactory protocolFactory56, TNonblockingTransport transport57) throws TException { + super(client55, protocolFactory56, transport57, resultHandler59, false); + this.sessionId = sessionId; + this.stmt = stmt; + this.parameterMap = parameterMap; + this.timeout = timeout; + } + + public void write_args(TProtocol prot) throws TException { + prot.writeMessageBegin(new TMessage("executeWithTimeout", TMessageType.CALL, 0)); + executeWithTimeout_args args = new executeWithTimeout_args(); + args.setSessionId(sessionId); + args.setStmt(stmt); + args.setParameterMap(parameterMap); + args.setTimeout(timeout); + args.write(prot); + prot.writeMessageEnd(); + } + + public ExecutionResponse getResult() throws TException { + if (getState() != State.RESPONSE_READ) { + throw new IllegalStateException("Method call not finished!"); + } + TMemoryInputTransport memoryTransport = new TMemoryInputTransport(getFrameBuffer().array()); + TProtocol prot = super.client.getProtocolFactory().getProtocol(memoryTransport); + return (new Client(prot)).recv_executeWithTimeout(); + } + } + + public void executeJson(long sessionId, byte[] stmt, AsyncMethodCallback resultHandler63) throws TException { checkReady(); - executeJson_call method_call = new executeJson_call(sessionId, stmt, resultHandler57, this, ___protocolFactory, ___transport); + executeJson_call method_call = new executeJson_call(sessionId, stmt, resultHandler63, this, ___protocolFactory, ___transport); this.___currentMethod = method_call; ___manager.call(method_call); } @@ -607,8 +700,8 @@ public void executeJson(long sessionId, byte[] stmt, AsyncMethodCallback resultH public static class executeJson_call extends TAsyncMethodCall { private long sessionId; private byte[] stmt; - public executeJson_call(long sessionId, byte[] stmt, AsyncMethodCallback resultHandler58, TAsyncClient client54, TProtocolFactory protocolFactory55, TNonblockingTransport transport56) throws TException { - super(client54, protocolFactory55, transport56, resultHandler58, false); + public executeJson_call(long sessionId, byte[] stmt, AsyncMethodCallback resultHandler64, TAsyncClient client60, TProtocolFactory protocolFactory61, TNonblockingTransport transport62) throws TException { + super(client60, protocolFactory61, transport62, resultHandler64, false); this.sessionId = sessionId; this.stmt = stmt; } @@ -632,9 +725,9 @@ public byte[] getResult() throws TException { } } - public void executeJsonWithParameter(long sessionId, byte[] stmt, Map parameterMap, AsyncMethodCallback resultHandler62) throws TException { + public void executeJsonWithParameter(long sessionId, byte[] stmt, Map parameterMap, AsyncMethodCallback resultHandler68) throws TException { checkReady(); - executeJsonWithParameter_call method_call = new executeJsonWithParameter_call(sessionId, stmt, parameterMap, resultHandler62, this, ___protocolFactory, ___transport); + executeJsonWithParameter_call method_call = new executeJsonWithParameter_call(sessionId, stmt, parameterMap, resultHandler68, this, ___protocolFactory, ___transport); this.___currentMethod = method_call; ___manager.call(method_call); } @@ -643,8 +736,8 @@ public static class executeJsonWithParameter_call extends TAsyncMethodCall { private long sessionId; private byte[] stmt; private Map parameterMap; - public executeJsonWithParameter_call(long sessionId, byte[] stmt, Map parameterMap, AsyncMethodCallback resultHandler63, TAsyncClient client59, TProtocolFactory protocolFactory60, TNonblockingTransport transport61) throws TException { - super(client59, protocolFactory60, transport61, resultHandler63, false); + public executeJsonWithParameter_call(long sessionId, byte[] stmt, Map parameterMap, AsyncMethodCallback resultHandler69, TAsyncClient client65, TProtocolFactory protocolFactory66, TNonblockingTransport transport67) throws TException { + super(client65, protocolFactory66, transport67, resultHandler69, false); this.sessionId = sessionId; this.stmt = stmt; this.parameterMap = parameterMap; @@ -670,17 +763,17 @@ public byte[] getResult() throws TException { } } - public void verifyClientVersion(VerifyClientVersionReq req, AsyncMethodCallback resultHandler67) throws TException { + public void verifyClientVersion(VerifyClientVersionReq req, AsyncMethodCallback resultHandler73) throws TException { checkReady(); - verifyClientVersion_call method_call = new verifyClientVersion_call(req, resultHandler67, this, ___protocolFactory, ___transport); + verifyClientVersion_call method_call = new verifyClientVersion_call(req, resultHandler73, this, ___protocolFactory, ___transport); this.___currentMethod = method_call; ___manager.call(method_call); } public static class verifyClientVersion_call extends TAsyncMethodCall { private VerifyClientVersionReq req; - public verifyClientVersion_call(VerifyClientVersionReq req, AsyncMethodCallback resultHandler68, TAsyncClient client64, TProtocolFactory protocolFactory65, TNonblockingTransport transport66) throws TException { - super(client64, protocolFactory65, transport66, resultHandler68, false); + public verifyClientVersion_call(VerifyClientVersionReq req, AsyncMethodCallback resultHandler74, TAsyncClient client70, TProtocolFactory protocolFactory71, TNonblockingTransport transport72) throws TException { + super(client70, protocolFactory71, transport72, resultHandler74, false); this.req = req; } @@ -702,16 +795,16 @@ public VerifyClientVersionResp getResult() throws TException { } } - public void health(AsyncMethodCallback resultHandler72) throws TException { + public void health(AsyncMethodCallback resultHandler78) throws TException { checkReady(); - health_call method_call = new health_call(resultHandler72, this, ___protocolFactory, ___transport); + health_call method_call = new health_call(resultHandler78, this, ___protocolFactory, ___transport); this.___currentMethod = method_call; ___manager.call(method_call); } public static class health_call extends TAsyncMethodCall { - public health_call(AsyncMethodCallback resultHandler73, TAsyncClient client69, TProtocolFactory protocolFactory70, TNonblockingTransport transport71) throws TException { - super(client69, protocolFactory70, transport71, resultHandler73, false); + public health_call(AsyncMethodCallback resultHandler79, TAsyncClient client75, TProtocolFactory protocolFactory76, TNonblockingTransport transport77) throws TException { + super(client75, protocolFactory76, transport77, resultHandler79, false); } public void write_args(TProtocol prot) throws TException { @@ -743,6 +836,7 @@ public Processor(Iface iface) processMap_.put("signout", new signout()); processMap_.put("execute", new execute()); processMap_.put("executeWithParameter", new executeWithParameter()); + processMap_.put("executeWithTimeout", new executeWithTimeout()); processMap_.put("executeJson", new executeJson()); processMap_.put("executeJsonWithParameter", new executeJsonWithParameter()); processMap_.put("verifyClientVersion", new verifyClientVersion()); @@ -856,6 +950,27 @@ public void process(int seqid, TProtocol iprot, TProtocol oprot, TConnectionCont } + private class executeWithTimeout implements ProcessFunction { + public void process(int seqid, TProtocol iprot, TProtocol oprot, TConnectionContext server_ctx) throws TException + { + Object handler_ctx = event_handler_.getContext("GraphService.executeWithTimeout", server_ctx); + executeWithTimeout_args args = new executeWithTimeout_args(); + event_handler_.preRead(handler_ctx, "GraphService.executeWithTimeout"); + args.read(iprot); + iprot.readMessageEnd(); + event_handler_.postRead(handler_ctx, "GraphService.executeWithTimeout", args); + executeWithTimeout_result result = new executeWithTimeout_result(); + result.success = iface_.executeWithTimeout(args.sessionId, args.stmt, args.parameterMap, args.timeout); + event_handler_.preWrite(handler_ctx, "GraphService.executeWithTimeout", result); + oprot.writeMessageBegin(new TMessage("executeWithTimeout", TMessageType.REPLY, seqid)); + result.write(oprot); + oprot.writeMessageEnd(); + oprot.getTransport().flush(); + event_handler_.postWrite(handler_ctx, "GraphService.executeWithTimeout", result); + } + + } + private class executeJson implements ProcessFunction { public void process(int seqid, TProtocol iprot, TProtocol oprot, TConnectionContext server_ctx) throws TException { @@ -2410,18 +2525,18 @@ public void read(TProtocol iprot) throws TException { case PARAMETERMAP: if (__field.type == TType.MAP) { { - TMap _map74 = iprot.readMapBegin(); - this.parameterMap = new HashMap(Math.max(0, 2*_map74.size)); - for (int _i75 = 0; - (_map74.size < 0) ? iprot.peekMap() : (_i75 < _map74.size); - ++_i75) + TMap _map80 = iprot.readMapBegin(); + this.parameterMap = new HashMap(Math.max(0, 2*_map80.size)); + for (int _i81 = 0; + (_map80.size < 0) ? iprot.peekMap() : (_i81 < _map80.size); + ++_i81) { - byte[] _key76; - com.vesoft.nebula.Value _val77; - _key76 = iprot.readBinary(); - _val77 = new com.vesoft.nebula.Value(); - _val77.read(iprot); - this.parameterMap.put(_key76, _val77); + byte[] _key82; + com.vesoft.nebula.Value _val83; + _key82 = iprot.readBinary(); + _val83 = new com.vesoft.nebula.Value(); + _val83.read(iprot); + this.parameterMap.put(_key82, _val83); } iprot.readMapEnd(); } @@ -2458,9 +2573,9 @@ public void write(TProtocol oprot) throws TException { oprot.writeFieldBegin(PARAMETER_MAP_FIELD_DESC); { oprot.writeMapBegin(new TMap(TType.STRING, TType.STRUCT, this.parameterMap.size())); - for (Map.Entry _iter78 : this.parameterMap.entrySet()) { - oprot.writeBinary(_iter78.getKey()); - _iter78.getValue().write(oprot); + for (Map.Entry _iter84 : this.parameterMap.entrySet()) { + oprot.writeBinary(_iter84.getKey()); + _iter84.getValue().write(oprot); } oprot.writeMapEnd(); } @@ -2724,6 +2839,625 @@ public void validate() throws TException { } + public static class executeWithTimeout_args implements TBase, java.io.Serializable, Cloneable { + private static final TStruct STRUCT_DESC = new TStruct("executeWithTimeout_args"); + private static final TField SESSION_ID_FIELD_DESC = new TField("sessionId", TType.I64, (short)1); + private static final TField STMT_FIELD_DESC = new TField("stmt", TType.STRING, (short)2); + private static final TField PARAMETER_MAP_FIELD_DESC = new TField("parameterMap", TType.MAP, (short)3); + private static final TField TIMEOUT_FIELD_DESC = new TField("timeout", TType.I64, (short)4); + + public long sessionId; + public byte[] stmt; + public Map parameterMap; + public long timeout; + public static final int SESSIONID = 1; + public static final int STMT = 2; + public static final int PARAMETERMAP = 3; + public static final int TIMEOUT = 4; + + // isset id assignments + private static final int __SESSIONID_ISSET_ID = 0; + private static final int __TIMEOUT_ISSET_ID = 1; + private BitSet __isset_bit_vector = new BitSet(2); + + public static final Map metaDataMap; + + static { + Map tmpMetaDataMap = new HashMap(); + tmpMetaDataMap.put(SESSIONID, new FieldMetaData("sessionId", TFieldRequirementType.DEFAULT, + new FieldValueMetaData(TType.I64))); + tmpMetaDataMap.put(STMT, new FieldMetaData("stmt", TFieldRequirementType.DEFAULT, + new FieldValueMetaData(TType.STRING))); + tmpMetaDataMap.put(PARAMETERMAP, new FieldMetaData("parameterMap", TFieldRequirementType.DEFAULT, + new MapMetaData(TType.MAP, + new FieldValueMetaData(TType.STRING), + new StructMetaData(TType.STRUCT, com.vesoft.nebula.Value.class)))); + tmpMetaDataMap.put(TIMEOUT, new FieldMetaData("timeout", TFieldRequirementType.DEFAULT, + new FieldValueMetaData(TType.I64))); + metaDataMap = Collections.unmodifiableMap(tmpMetaDataMap); + } + + static { + FieldMetaData.addStructMetaDataMap(executeWithTimeout_args.class, metaDataMap); + } + + public executeWithTimeout_args() { + } + + public executeWithTimeout_args( + long sessionId, + byte[] stmt, + Map parameterMap, + long timeout) { + this(); + this.sessionId = sessionId; + setSessionIdIsSet(true); + this.stmt = stmt; + this.parameterMap = parameterMap; + this.timeout = timeout; + setTimeoutIsSet(true); + } + + /** + * Performs a deep copy on other. + */ + public executeWithTimeout_args(executeWithTimeout_args other) { + __isset_bit_vector.clear(); + __isset_bit_vector.or(other.__isset_bit_vector); + this.sessionId = TBaseHelper.deepCopy(other.sessionId); + if (other.isSetStmt()) { + this.stmt = TBaseHelper.deepCopy(other.stmt); + } + if (other.isSetParameterMap()) { + this.parameterMap = TBaseHelper.deepCopy(other.parameterMap); + } + this.timeout = TBaseHelper.deepCopy(other.timeout); + } + + public executeWithTimeout_args deepCopy() { + return new executeWithTimeout_args(this); + } + + public long getSessionId() { + return this.sessionId; + } + + public executeWithTimeout_args setSessionId(long sessionId) { + this.sessionId = sessionId; + setSessionIdIsSet(true); + return this; + } + + public void unsetSessionId() { + __isset_bit_vector.clear(__SESSIONID_ISSET_ID); + } + + // Returns true if field sessionId is set (has been assigned a value) and false otherwise + public boolean isSetSessionId() { + return __isset_bit_vector.get(__SESSIONID_ISSET_ID); + } + + public void setSessionIdIsSet(boolean __value) { + __isset_bit_vector.set(__SESSIONID_ISSET_ID, __value); + } + + public byte[] getStmt() { + return this.stmt; + } + + public executeWithTimeout_args setStmt(byte[] stmt) { + this.stmt = stmt; + return this; + } + + public void unsetStmt() { + this.stmt = null; + } + + // Returns true if field stmt is set (has been assigned a value) and false otherwise + public boolean isSetStmt() { + return this.stmt != null; + } + + public void setStmtIsSet(boolean __value) { + if (!__value) { + this.stmt = null; + } + } + + public Map getParameterMap() { + return this.parameterMap; + } + + public executeWithTimeout_args setParameterMap(Map parameterMap) { + this.parameterMap = parameterMap; + return this; + } + + public void unsetParameterMap() { + this.parameterMap = null; + } + + // Returns true if field parameterMap is set (has been assigned a value) and false otherwise + public boolean isSetParameterMap() { + return this.parameterMap != null; + } + + public void setParameterMapIsSet(boolean __value) { + if (!__value) { + this.parameterMap = null; + } + } + + public long getTimeout() { + return this.timeout; + } + + public executeWithTimeout_args setTimeout(long timeout) { + this.timeout = timeout; + setTimeoutIsSet(true); + return this; + } + + public void unsetTimeout() { + __isset_bit_vector.clear(__TIMEOUT_ISSET_ID); + } + + // Returns true if field timeout is set (has been assigned a value) and false otherwise + public boolean isSetTimeout() { + return __isset_bit_vector.get(__TIMEOUT_ISSET_ID); + } + + public void setTimeoutIsSet(boolean __value) { + __isset_bit_vector.set(__TIMEOUT_ISSET_ID, __value); + } + + @SuppressWarnings("unchecked") + public void setFieldValue(int fieldID, Object __value) { + switch (fieldID) { + case SESSIONID: + if (__value == null) { + unsetSessionId(); + } else { + setSessionId((Long)__value); + } + break; + + case STMT: + if (__value == null) { + unsetStmt(); + } else { + setStmt((byte[])__value); + } + break; + + case PARAMETERMAP: + if (__value == null) { + unsetParameterMap(); + } else { + setParameterMap((Map)__value); + } + break; + + case TIMEOUT: + if (__value == null) { + unsetTimeout(); + } else { + setTimeout((Long)__value); + } + break; + + default: + throw new IllegalArgumentException("Field " + fieldID + " doesn't exist!"); + } + } + + public Object getFieldValue(int fieldID) { + switch (fieldID) { + case SESSIONID: + return new Long(getSessionId()); + + case STMT: + return getStmt(); + + case PARAMETERMAP: + return getParameterMap(); + + case TIMEOUT: + return new Long(getTimeout()); + + default: + throw new IllegalArgumentException("Field " + fieldID + " doesn't exist!"); + } + } + + @Override + public boolean equals(Object _that) { + if (_that == null) + return false; + if (this == _that) + return true; + if (!(_that instanceof executeWithTimeout_args)) + return false; + executeWithTimeout_args that = (executeWithTimeout_args)_that; + + if (!TBaseHelper.equalsNobinary(this.sessionId, that.sessionId)) { return false; } + + if (!TBaseHelper.equalsSlow(this.isSetStmt(), that.isSetStmt(), this.stmt, that.stmt)) { return false; } + + if (!TBaseHelper.equalsSlow(this.isSetParameterMap(), that.isSetParameterMap(), this.parameterMap, that.parameterMap)) { return false; } + + if (!TBaseHelper.equalsNobinary(this.timeout, that.timeout)) { return false; } + + return true; + } + + @Override + public int hashCode() { + return Arrays.deepHashCode(new Object[] {sessionId, stmt, parameterMap, timeout}); + } + + public void read(TProtocol iprot) throws TException { + TField __field; + iprot.readStructBegin(metaDataMap); + while (true) + { + __field = iprot.readFieldBegin(); + if (__field.type == TType.STOP) { + break; + } + switch (__field.id) + { + case SESSIONID: + if (__field.type == TType.I64) { + this.sessionId = iprot.readI64(); + setSessionIdIsSet(true); + } else { + TProtocolUtil.skip(iprot, __field.type); + } + break; + case STMT: + if (__field.type == TType.STRING) { + this.stmt = iprot.readBinary(); + } else { + TProtocolUtil.skip(iprot, __field.type); + } + break; + case PARAMETERMAP: + if (__field.type == TType.MAP) { + { + TMap _map85 = iprot.readMapBegin(); + this.parameterMap = new HashMap(Math.max(0, 2*_map85.size)); + for (int _i86 = 0; + (_map85.size < 0) ? iprot.peekMap() : (_i86 < _map85.size); + ++_i86) + { + byte[] _key87; + com.vesoft.nebula.Value _val88; + _key87 = iprot.readBinary(); + _val88 = new com.vesoft.nebula.Value(); + _val88.read(iprot); + this.parameterMap.put(_key87, _val88); + } + iprot.readMapEnd(); + } + } else { + TProtocolUtil.skip(iprot, __field.type); + } + break; + case TIMEOUT: + if (__field.type == TType.I64) { + this.timeout = iprot.readI64(); + setTimeoutIsSet(true); + } else { + TProtocolUtil.skip(iprot, __field.type); + } + break; + default: + TProtocolUtil.skip(iprot, __field.type); + break; + } + iprot.readFieldEnd(); + } + iprot.readStructEnd(); + + + // check for required fields of primitive type, which can't be checked in the validate method + validate(); + } + + public void write(TProtocol oprot) throws TException { + validate(); + + oprot.writeStructBegin(STRUCT_DESC); + oprot.writeFieldBegin(SESSION_ID_FIELD_DESC); + oprot.writeI64(this.sessionId); + oprot.writeFieldEnd(); + if (this.stmt != null) { + oprot.writeFieldBegin(STMT_FIELD_DESC); + oprot.writeBinary(this.stmt); + oprot.writeFieldEnd(); + } + if (this.parameterMap != null) { + oprot.writeFieldBegin(PARAMETER_MAP_FIELD_DESC); + { + oprot.writeMapBegin(new TMap(TType.STRING, TType.STRUCT, this.parameterMap.size())); + for (Map.Entry _iter89 : this.parameterMap.entrySet()) { + oprot.writeBinary(_iter89.getKey()); + _iter89.getValue().write(oprot); + } + oprot.writeMapEnd(); + } + oprot.writeFieldEnd(); + } + oprot.writeFieldBegin(TIMEOUT_FIELD_DESC); + oprot.writeI64(this.timeout); + oprot.writeFieldEnd(); + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + @Override + public String toString() { + return toString(1, true); + } + + @Override + public String toString(int indent, boolean prettyPrint) { + String indentStr = prettyPrint ? TBaseHelper.getIndentedString(indent) : ""; + String newLine = prettyPrint ? "\n" : ""; + String space = prettyPrint ? " " : ""; + StringBuilder sb = new StringBuilder("executeWithTimeout_args"); + sb.append(space); + sb.append("("); + sb.append(newLine); + boolean first = true; + + sb.append(indentStr); + sb.append("sessionId"); + sb.append(space); + sb.append(":").append(space); + sb.append(TBaseHelper.toString(this.getSessionId(), indent + 1, prettyPrint)); + first = false; + if (!first) sb.append("," + newLine); + sb.append(indentStr); + sb.append("stmt"); + sb.append(space); + sb.append(":").append(space); + if (this.getStmt() == null) { + sb.append("null"); + } else { + int __stmt_size = Math.min(this.getStmt().length, 128); + for (int i = 0; i < __stmt_size; i++) { + if (i != 0) sb.append(" "); + sb.append(Integer.toHexString(this.getStmt()[i]).length() > 1 ? Integer.toHexString(this.getStmt()[i]).substring(Integer.toHexString(this.getStmt()[i]).length() - 2).toUpperCase() : "0" + Integer.toHexString(this.getStmt()[i]).toUpperCase()); + } + if (this.getStmt().length > 128) sb.append(" ..."); + } + first = false; + if (!first) sb.append("," + newLine); + sb.append(indentStr); + sb.append("parameterMap"); + sb.append(space); + sb.append(":").append(space); + if (this.getParameterMap() == null) { + sb.append("null"); + } else { + sb.append(TBaseHelper.toString(this.getParameterMap(), indent + 1, prettyPrint)); + } + first = false; + if (!first) sb.append("," + newLine); + sb.append(indentStr); + sb.append("timeout"); + sb.append(space); + sb.append(":").append(space); + sb.append(TBaseHelper.toString(this.getTimeout(), indent + 1, prettyPrint)); + first = false; + sb.append(newLine + TBaseHelper.reduceIndent(indentStr)); + sb.append(")"); + return sb.toString(); + } + + public void validate() throws TException { + // check for required fields + } + + } + + public static class executeWithTimeout_result implements TBase, java.io.Serializable, Cloneable { + private static final TStruct STRUCT_DESC = new TStruct("executeWithTimeout_result"); + private static final TField SUCCESS_FIELD_DESC = new TField("success", TType.STRUCT, (short)0); + + public ExecutionResponse success; + public static final int SUCCESS = 0; + + // isset id assignments + + public static final Map metaDataMap; + + static { + Map tmpMetaDataMap = new HashMap(); + tmpMetaDataMap.put(SUCCESS, new FieldMetaData("success", TFieldRequirementType.DEFAULT, + new StructMetaData(TType.STRUCT, ExecutionResponse.class))); + metaDataMap = Collections.unmodifiableMap(tmpMetaDataMap); + } + + static { + FieldMetaData.addStructMetaDataMap(executeWithTimeout_result.class, metaDataMap); + } + + public executeWithTimeout_result() { + } + + public executeWithTimeout_result( + ExecutionResponse success) { + this(); + this.success = success; + } + + /** + * Performs a deep copy on other. + */ + public executeWithTimeout_result(executeWithTimeout_result other) { + if (other.isSetSuccess()) { + this.success = TBaseHelper.deepCopy(other.success); + } + } + + public executeWithTimeout_result deepCopy() { + return new executeWithTimeout_result(this); + } + + public ExecutionResponse getSuccess() { + return this.success; + } + + public executeWithTimeout_result setSuccess(ExecutionResponse success) { + this.success = success; + return this; + } + + public void unsetSuccess() { + this.success = null; + } + + // Returns true if field success is set (has been assigned a value) and false otherwise + public boolean isSetSuccess() { + return this.success != null; + } + + public void setSuccessIsSet(boolean __value) { + if (!__value) { + this.success = null; + } + } + + public void setFieldValue(int fieldID, Object __value) { + switch (fieldID) { + case SUCCESS: + if (__value == null) { + unsetSuccess(); + } else { + setSuccess((ExecutionResponse)__value); + } + break; + + default: + throw new IllegalArgumentException("Field " + fieldID + " doesn't exist!"); + } + } + + public Object getFieldValue(int fieldID) { + switch (fieldID) { + case SUCCESS: + return getSuccess(); + + default: + throw new IllegalArgumentException("Field " + fieldID + " doesn't exist!"); + } + } + + @Override + public boolean equals(Object _that) { + if (_that == null) + return false; + if (this == _that) + return true; + if (!(_that instanceof executeWithTimeout_result)) + return false; + executeWithTimeout_result that = (executeWithTimeout_result)_that; + + if (!TBaseHelper.equalsNobinary(this.isSetSuccess(), that.isSetSuccess(), this.success, that.success)) { return false; } + + return true; + } + + @Override + public int hashCode() { + return Arrays.deepHashCode(new Object[] {success}); + } + + public void read(TProtocol iprot) throws TException { + TField __field; + iprot.readStructBegin(metaDataMap); + while (true) + { + __field = iprot.readFieldBegin(); + if (__field.type == TType.STOP) { + break; + } + switch (__field.id) + { + case SUCCESS: + if (__field.type == TType.STRUCT) { + this.success = new ExecutionResponse(); + this.success.read(iprot); + } else { + TProtocolUtil.skip(iprot, __field.type); + } + break; + default: + TProtocolUtil.skip(iprot, __field.type); + break; + } + iprot.readFieldEnd(); + } + iprot.readStructEnd(); + + + // check for required fields of primitive type, which can't be checked in the validate method + validate(); + } + + public void write(TProtocol oprot) throws TException { + oprot.writeStructBegin(STRUCT_DESC); + + if (this.isSetSuccess()) { + oprot.writeFieldBegin(SUCCESS_FIELD_DESC); + this.success.write(oprot); + oprot.writeFieldEnd(); + } + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + @Override + public String toString() { + return toString(1, true); + } + + @Override + public String toString(int indent, boolean prettyPrint) { + String indentStr = prettyPrint ? TBaseHelper.getIndentedString(indent) : ""; + String newLine = prettyPrint ? "\n" : ""; + String space = prettyPrint ? " " : ""; + StringBuilder sb = new StringBuilder("executeWithTimeout_result"); + sb.append(space); + sb.append("("); + sb.append(newLine); + boolean first = true; + + sb.append(indentStr); + sb.append("success"); + sb.append(space); + sb.append(":").append(space); + if (this.getSuccess() == null) { + sb.append("null"); + } else { + sb.append(TBaseHelper.toString(this.getSuccess(), indent + 1, prettyPrint)); + } + first = false; + sb.append(newLine + TBaseHelper.reduceIndent(indentStr)); + sb.append(")"); + return sb.toString(); + } + + public void validate() throws TException { + // check for required fields + } + + } + public static class executeJson_args implements TBase, java.io.Serializable, Cloneable, Comparable { private static final TStruct STRUCT_DESC = new TStruct("executeJson_args"); private static final TField SESSION_ID_FIELD_DESC = new TField("sessionId", TType.I64, (short)1); @@ -3483,18 +4217,18 @@ public void read(TProtocol iprot) throws TException { case PARAMETERMAP: if (__field.type == TType.MAP) { { - TMap _map79 = iprot.readMapBegin(); - this.parameterMap = new HashMap(Math.max(0, 2*_map79.size)); - for (int _i80 = 0; - (_map79.size < 0) ? iprot.peekMap() : (_i80 < _map79.size); - ++_i80) + TMap _map90 = iprot.readMapBegin(); + this.parameterMap = new HashMap(Math.max(0, 2*_map90.size)); + for (int _i91 = 0; + (_map90.size < 0) ? iprot.peekMap() : (_i91 < _map90.size); + ++_i91) { - byte[] _key81; - com.vesoft.nebula.Value _val82; - _key81 = iprot.readBinary(); - _val82 = new com.vesoft.nebula.Value(); - _val82.read(iprot); - this.parameterMap.put(_key81, _val82); + byte[] _key92; + com.vesoft.nebula.Value _val93; + _key92 = iprot.readBinary(); + _val93 = new com.vesoft.nebula.Value(); + _val93.read(iprot); + this.parameterMap.put(_key92, _val93); } iprot.readMapEnd(); } @@ -3531,9 +4265,9 @@ public void write(TProtocol oprot) throws TException { oprot.writeFieldBegin(PARAMETER_MAP_FIELD_DESC); { oprot.writeMapBegin(new TMap(TType.STRING, TType.STRUCT, this.parameterMap.size())); - for (Map.Entry _iter83 : this.parameterMap.entrySet()) { - oprot.writeBinary(_iter83.getKey()); - _iter83.getValue().write(oprot); + for (Map.Entry _iter94 : this.parameterMap.entrySet()) { + oprot.writeBinary(_iter94.getKey()); + _iter94.getValue().write(oprot); } oprot.writeMapEnd(); } diff --git a/client/src/main/generated/com/vesoft/nebula/storage/RequestCommon.java b/client/src/main/generated/com/vesoft/nebula/storage/RequestCommon.java index 94c7bcb37..bff4bb742 100644 --- a/client/src/main/generated/com/vesoft/nebula/storage/RequestCommon.java +++ b/client/src/main/generated/com/vesoft/nebula/storage/RequestCommon.java @@ -29,19 +29,23 @@ public class RequestCommon implements TBase, java.io.Serializable, Cloneable, Co private static final TField SESSION_ID_FIELD_DESC = new TField("session_id", TType.I64, (short)1); private static final TField PLAN_ID_FIELD_DESC = new TField("plan_id", TType.I64, (short)2); private static final TField PROFILE_DETAIL_FIELD_DESC = new TField("profile_detail", TType.BOOL, (short)3); + private static final TField TIMEOUT_FIELD_DESC = new TField("timeout", TType.I64, (short)4); public long session_id; public long plan_id; public boolean profile_detail; + public long timeout; public static final int SESSION_ID = 1; public static final int PLAN_ID = 2; public static final int PROFILE_DETAIL = 3; + public static final int TIMEOUT = 4; // isset id assignments private static final int __SESSION_ID_ISSET_ID = 0; private static final int __PLAN_ID_ISSET_ID = 1; private static final int __PROFILE_DETAIL_ISSET_ID = 2; - private BitSet __isset_bit_vector = new BitSet(3); + private static final int __TIMEOUT_ISSET_ID = 3; + private BitSet __isset_bit_vector = new BitSet(4); public static final Map metaDataMap; @@ -53,6 +57,8 @@ public class RequestCommon implements TBase, java.io.Serializable, Cloneable, Co new FieldValueMetaData(TType.I64))); tmpMetaDataMap.put(PROFILE_DETAIL, new FieldMetaData("profile_detail", TFieldRequirementType.OPTIONAL, new FieldValueMetaData(TType.BOOL))); + tmpMetaDataMap.put(TIMEOUT, new FieldMetaData("timeout", TFieldRequirementType.OPTIONAL, + new FieldValueMetaData(TType.I64))); metaDataMap = Collections.unmodifiableMap(tmpMetaDataMap); } @@ -66,7 +72,8 @@ public RequestCommon() { public RequestCommon( long session_id, long plan_id, - boolean profile_detail) { + boolean profile_detail, + long timeout) { this(); this.session_id = session_id; setSession_idIsSet(true); @@ -74,14 +81,17 @@ public RequestCommon( setPlan_idIsSet(true); this.profile_detail = profile_detail; setProfile_detailIsSet(true); + this.timeout = timeout; + setTimeoutIsSet(true); } public static class Builder { private long session_id; private long plan_id; private boolean profile_detail; + private long timeout; - BitSet __optional_isset = new BitSet(3); + BitSet __optional_isset = new BitSet(4); public Builder() { } @@ -104,6 +114,12 @@ public Builder setProfile_detail(final boolean profile_detail) { return this; } + public Builder setTimeout(final long timeout) { + this.timeout = timeout; + __optional_isset.set(__TIMEOUT_ISSET_ID, true); + return this; + } + public RequestCommon build() { RequestCommon result = new RequestCommon(); if (__optional_isset.get(__SESSION_ID_ISSET_ID)) { @@ -115,6 +131,9 @@ public RequestCommon build() { if (__optional_isset.get(__PROFILE_DETAIL_ISSET_ID)) { result.setProfile_detail(this.profile_detail); } + if (__optional_isset.get(__TIMEOUT_ISSET_ID)) { + result.setTimeout(this.timeout); + } return result; } } @@ -132,6 +151,7 @@ public RequestCommon(RequestCommon other) { this.session_id = TBaseHelper.deepCopy(other.session_id); this.plan_id = TBaseHelper.deepCopy(other.plan_id); this.profile_detail = TBaseHelper.deepCopy(other.profile_detail); + this.timeout = TBaseHelper.deepCopy(other.timeout); } public RequestCommon deepCopy() { @@ -207,6 +227,29 @@ public void setProfile_detailIsSet(boolean __value) { __isset_bit_vector.set(__PROFILE_DETAIL_ISSET_ID, __value); } + public long getTimeout() { + return this.timeout; + } + + public RequestCommon setTimeout(long timeout) { + this.timeout = timeout; + setTimeoutIsSet(true); + return this; + } + + public void unsetTimeout() { + __isset_bit_vector.clear(__TIMEOUT_ISSET_ID); + } + + // Returns true if field timeout is set (has been assigned a value) and false otherwise + public boolean isSetTimeout() { + return __isset_bit_vector.get(__TIMEOUT_ISSET_ID); + } + + public void setTimeoutIsSet(boolean __value) { + __isset_bit_vector.set(__TIMEOUT_ISSET_ID, __value); + } + public void setFieldValue(int fieldID, Object __value) { switch (fieldID) { case SESSION_ID: @@ -233,6 +276,14 @@ public void setFieldValue(int fieldID, Object __value) { } break; + case TIMEOUT: + if (__value == null) { + unsetTimeout(); + } else { + setTimeout((Long)__value); + } + break; + default: throw new IllegalArgumentException("Field " + fieldID + " doesn't exist!"); } @@ -249,6 +300,9 @@ public Object getFieldValue(int fieldID) { case PROFILE_DETAIL: return new Boolean(isProfile_detail()); + case TIMEOUT: + return new Long(getTimeout()); + default: throw new IllegalArgumentException("Field " + fieldID + " doesn't exist!"); } @@ -270,12 +324,14 @@ public boolean equals(Object _that) { if (!TBaseHelper.equalsNobinary(this.isSetProfile_detail(), that.isSetProfile_detail(), this.profile_detail, that.profile_detail)) { return false; } + if (!TBaseHelper.equalsNobinary(this.isSetTimeout(), that.isSetTimeout(), this.timeout, that.timeout)) { return false; } + return true; } @Override public int hashCode() { - return Arrays.deepHashCode(new Object[] {session_id, plan_id, profile_detail}); + return Arrays.deepHashCode(new Object[] {session_id, plan_id, profile_detail, timeout}); } @Override @@ -314,6 +370,14 @@ public int compareTo(RequestCommon other) { if (lastComparison != 0) { return lastComparison; } + lastComparison = Boolean.valueOf(isSetTimeout()).compareTo(other.isSetTimeout()); + if (lastComparison != 0) { + return lastComparison; + } + lastComparison = TBaseHelper.compareTo(timeout, other.timeout); + if (lastComparison != 0) { + return lastComparison; + } return 0; } @@ -352,6 +416,14 @@ public void read(TProtocol iprot) throws TException { TProtocolUtil.skip(iprot, __field.type); } break; + case TIMEOUT: + if (__field.type == TType.I64) { + this.timeout = iprot.readI64(); + setTimeoutIsSet(true); + } else { + TProtocolUtil.skip(iprot, __field.type); + } + break; default: TProtocolUtil.skip(iprot, __field.type); break; @@ -384,6 +456,11 @@ public void write(TProtocol oprot) throws TException { oprot.writeBool(this.profile_detail); oprot.writeFieldEnd(); } + if (isSetTimeout()) { + oprot.writeFieldBegin(TIMEOUT_FIELD_DESC); + oprot.writeI64(this.timeout); + oprot.writeFieldEnd(); + } oprot.writeFieldStop(); oprot.writeStructEnd(); } @@ -433,6 +510,16 @@ public String toString(int indent, boolean prettyPrint) { sb.append(TBaseHelper.toString(this.isProfile_detail(), indent + 1, prettyPrint)); first = false; } + if (isSetTimeout()) + { + if (!first) sb.append("," + newLine); + sb.append(indentStr); + sb.append("timeout"); + sb.append(space); + sb.append(":").append(space); + sb.append(TBaseHelper.toString(this.getTimeout(), indent + 1, prettyPrint)); + first = false; + } sb.append(newLine + TBaseHelper.reduceIndent(indentStr)); sb.append(")"); return sb.toString(); diff --git a/client/src/main/java/com/vesoft/nebula/client/graph/NebulaSession.java b/client/src/main/java/com/vesoft/nebula/client/graph/NebulaSession.java index f81a01211..ea22fae66 100644 --- a/client/src/main/java/com/vesoft/nebula/client/graph/NebulaSession.java +++ b/client/src/main/java/com/vesoft/nebula/client/graph/NebulaSession.java @@ -12,6 +12,7 @@ import com.vesoft.nebula.client.graph.net.SessionState; import com.vesoft.nebula.client.graph.net.SyncConnection; import java.io.Serializable; +import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.concurrent.atomic.AtomicBoolean; @@ -25,9 +26,9 @@ public class NebulaSession implements Serializable { private final Logger log = LoggerFactory.getLogger(this.getClass()); - private final long sessionID; - private final int timezoneOffset; - private SyncConnection connection; + private final long sessionID; + private final int timezoneOffset; + private SyncConnection connection; private final AtomicReference state = new AtomicReference<>(); private final AtomicBoolean isReleased = new AtomicBoolean(false); @@ -71,6 +72,25 @@ public ResultSet executeWithParameter(String stmt, Map parameter return new ResultSet(connection.executeWithParameter(sessionID, stmt, map), timezoneOffset); } + public ResultSet executeWithTimeout(String stmt, long timeoutMs) throws IOErrorException { + return executeWithParameterTimeout(stmt, + (Map) Collections.EMPTY_MAP, + timeoutMs); + } + + public ResultSet executeWithParameterTimeout(String stmt, + Map parameterMap, + long timeoutMs) throws IOErrorException { + Map map = new HashMap<>(); + parameterMap.forEach((key, value) -> map.put(key.getBytes(), Session.value2Nvalue(value))); + return new ResultSet(connection.executeWithParameterTimeout(sessionID, + stmt, + map, + timeoutMs), + timezoneOffset); + + } + public String executeJsonWithParameter(String stmt, Map parameterMap) throws IOErrorException { Map map = new HashMap<>(); diff --git a/client/src/main/java/com/vesoft/nebula/client/graph/SessionPool.java b/client/src/main/java/com/vesoft/nebula/client/graph/SessionPool.java index bdb7d0c3a..6aaad0886 100644 --- a/client/src/main/java/com/vesoft/nebula/client/graph/SessionPool.java +++ b/client/src/main/java/com/vesoft/nebula/client/graph/SessionPool.java @@ -7,6 +7,7 @@ import com.alibaba.fastjson.JSON; import com.vesoft.nebula.ErrorCode; +import com.vesoft.nebula.Value; import com.vesoft.nebula.client.graph.data.HostAddress; import com.vesoft.nebula.client.graph.data.ResultSet; import com.vesoft.nebula.client.graph.exception.AuthFailedException; @@ -14,10 +15,12 @@ import com.vesoft.nebula.client.graph.exception.ClientServerIncompatibleException; import com.vesoft.nebula.client.graph.exception.IOErrorException; import com.vesoft.nebula.client.graph.net.AuthResult; +import com.vesoft.nebula.client.graph.net.Session; import com.vesoft.nebula.client.graph.net.SessionState; import com.vesoft.nebula.client.graph.net.SyncConnection; import java.io.Serializable; import java.util.Collections; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.CopyOnWriteArrayList; @@ -206,7 +209,6 @@ public ResultSet execute(String stmt) throws IOErrorException, * @param parameterMap The nGql parameter map * @return The ResultSet */ - @Deprecated public ResultSet execute(String stmt, Map parameterMap) throws ClientServerIncompatibleException, AuthFailedException, IOErrorException, BindSpaceFailedException { @@ -232,6 +234,78 @@ public ResultSet execute(String stmt, Map parameterMap) return resultSet; } + public ResultSet executeWithTimeout(String stmt, + long timeoutMs) + throws IOErrorException, AuthFailedException, BindSpaceFailedException { + return executeWithParameterTimeout(stmt, + (Map) Collections.EMPTY_MAP, + timeoutMs); + } + + public ResultSet executeWithParameterTimeout(String stmt, + Map parameterMap, + long timeoutMs) + throws IOErrorException, AuthFailedException, BindSpaceFailedException { + if (timeoutMs <= 0) { + throw new IllegalArgumentException("timeout should be a positive number"); + } + stmtCheck(stmt); + checkSessionPool(); + NebulaSession nebulaSession = null; + ResultSet resultSet = null; + int tryTimes = 0; + while (tryTimes++ <= retryTimes) { + try { + nebulaSession = getSession(); + resultSet = nebulaSession.executeWithParameterTimeout(stmt, + parameterMap, + timeoutMs); + if (resultSet.isSucceeded() + || resultSet.getErrorCode() == ErrorCode.E_SEMANTIC_ERROR.getValue() + || resultSet.getErrorCode() == ErrorCode.E_SYNTAX_ERROR.getValue()) { + releaseSession(nebulaSession); + return resultSet; + } + log.warn(String.format("execute error, code: %d, message: %s, retry: %d", + resultSet.getErrorCode(), + resultSet.getErrorMessage(), + tryTimes)); + nebulaSession.release(); + sessionList.remove(nebulaSession); + try { + Thread.sleep(intervalTime); + } catch (InterruptedException interruptedException) { + // ignore + } + } catch (ClientServerIncompatibleException e) { + // will never get here. + } catch (AuthFailedException | BindSpaceFailedException e) { + throw e; + } catch (IOErrorException e) { + if (nebulaSession != null) { + nebulaSession.release(); + sessionList.remove(nebulaSession); + } + if (tryTimes < retryTimes) { + log.warn(String.format("execute failed for IOErrorException, message: %s, " + + "retry: %d", e.getMessage(), tryTimes)); + try { + Thread.sleep(intervalTime); + } catch (InterruptedException interruptedException) { + // ignore + } + } else { + throw e; + } + } + } + if (nebulaSession != null) { + nebulaSession.release(); + sessionList.remove(nebulaSession); + } + return resultSet; + } + public String executeJson(String stmt) throws ClientServerIncompatibleException, AuthFailedException, IOErrorException, BindSpaceFailedException { diff --git a/client/src/main/java/com/vesoft/nebula/client/graph/net/Session.java b/client/src/main/java/com/vesoft/nebula/client/graph/net/Session.java index aef1e53cf..2a17fa881 100644 --- a/client/src/main/java/com/vesoft/nebula/client/graph/net/Session.java +++ b/client/src/main/java/com/vesoft/nebula/client/graph/net/Session.java @@ -149,6 +149,68 @@ public synchronized ResultSet executeWithParameter( } } + + public ResultSet executeWithTimeout(String stmt, long timeoutMs) throws IOErrorException { + return executeWithParameterTimeout(stmt, + (Map) Collections.EMPTY_MAP, + timeoutMs); + } + + public ResultSet executeWithParameterTimeout(String stmt, + Map parameterMap, + long timeoutMs) throws IOErrorException { + if (connection == null) { + throw new IOErrorException(IOErrorException.E_CONNECT_BROKEN, + "The session was released, couldn't use again."); + } + if (timeoutMs <= 0) { + throw new IllegalArgumentException("timeout should be a positive number"); + } + Map map = new HashMap<>(); + parameterMap.forEach((key, value) -> map.put(key.getBytes(), value2Nvalue(value))); + + if (connectionIsBroken.get() && retryConnect) { + if (retryConnect()) { + ExecutionResponse resp = + connection.executeWithParameterTimeout(sessionID, stmt, map, timeoutMs); + return new ResultSet(resp, timezoneOffset); + } else { + throw new IOErrorException(IOErrorException.E_ALL_BROKEN, + "All servers are broken."); + } + } + + try { + ExecutionResponse resp = connection.executeWithParameterTimeout(sessionID, + stmt, + map, + timeoutMs); + return new ResultSet(resp, timezoneOffset); + } catch (IOErrorException ie) { + if (ie.getType() == IOErrorException.E_CONNECT_BROKEN) { + connectionIsBroken.set(true); + pool.updateServerStatus(); + + if (retryConnect) { + if (retryConnect()) { + connectionIsBroken.set(false); + ExecutionResponse resp = + connection.executeWithParameterTimeout(sessionID, + stmt, + map, + timeoutMs); + return new ResultSet(resp, timezoneOffset); + } else { + connectionIsBroken.set(true); + throw new IOErrorException(IOErrorException.E_ALL_BROKEN, + "All servers are broken."); + } + } + } + throw ie; + } + } + /** * Execute the nGql sentence. * Date and Datetime will be returned in UTC @@ -464,7 +526,7 @@ public synchronized void close() { /** * some value setter for java type (basic or nebula special type) that need convert to NValue */ - public static Map, Setter> LEAF_TYPE_AND_SETTER = + public static Map, Setter> LEAF_TYPE_AND_SETTER = new HashMap, Setter>() {{ put(Value.class, (Setter) (param) -> param); put(Boolean.class, (Setter) Value::bVal); @@ -495,7 +557,7 @@ public synchronized void close() { * some value setter for java type (complex java type include collections or date) that need * convert to NValue */ - public static Map, Setter> COMPLEX_TYPE_AND_SETTER = + public static Map, Setter> COMPLEX_TYPE_AND_SETTER = new LinkedHashMap, Setter>() {{ put(Collection.class, (Setter) (collection) -> { Value value = new Value(); diff --git a/client/src/main/java/com/vesoft/nebula/client/graph/net/SyncConnection.java b/client/src/main/java/com/vesoft/nebula/client/graph/net/SyncConnection.java index 4b79f48bc..c88d0faca 100644 --- a/client/src/main/java/com/vesoft/nebula/client/graph/net/SyncConnection.java +++ b/client/src/main/java/com/vesoft/nebula/client/graph/net/SyncConnection.java @@ -17,6 +17,7 @@ import com.facebook.thrift.utils.StandardCharsets; import com.google.common.base.Charsets; import com.vesoft.nebula.ErrorCode; +import com.vesoft.nebula.Value; import com.vesoft.nebula.client.graph.data.CASignedSSLParam; import com.vesoft.nebula.client.graph.data.HostAddress; import com.vesoft.nebula.client.graph.data.SSLParam; @@ -44,14 +45,14 @@ public class SyncConnection extends Connection { private static final Logger LOGGER = LoggerFactory.getLogger(SyncConnection.class); - protected TTransport transport = null; - protected TProtocol protocol = null; - private GraphService.Client client = null; - private int timeout = 0; - private SSLParam sslParam = null; - private boolean enabledSsl = false; - private SSLSocketFactory sslSocketFactory = null; - private boolean useHttp2 = false; + protected TTransport transport = null; + protected TProtocol protocol = null; + private GraphService.Client client = null; + private int timeout = 0; + private SSLParam sslParam = null; + private boolean enabledSsl = false; + private SSLSocketFactory sslSocketFactory = null; + private boolean useHttp2 = false; private Map headers = new HashMap<>(); @@ -96,7 +97,7 @@ public void open(HostAddress address, int timeout, SSLParam sslParam, boolean is if (resp.error_code != ErrorCode.SUCCEEDED) { client.getInputProtocol().getTransport().close(); throw new ClientServerIncompatibleException(new String(resp.getError_msg(), - Charsets.UTF_8)); + Charsets.UTF_8)); } } catch (TException | IOException e) { close(); @@ -131,7 +132,7 @@ public void open(HostAddress address, int timeout, if (resp.error_code != ErrorCode.SUCCEEDED) { client.getInputProtocol().getTransport().close(); throw new ClientServerIncompatibleException(new String(resp.getError_msg(), - Charsets.UTF_8)); + Charsets.UTF_8)); } } catch (TException e) { close(); @@ -143,7 +144,7 @@ public void open(HostAddress address, int timeout, * create protocol for http2 with tls */ private void getProtocolWithTlsHttp2() { - String url = "https://" + serverAddr.getHost() + ":" + serverAddr.getPort(); + String url = "https://" + serverAddr.getHost() + ":" + serverAddr.getPort(); TrustManager trustManager; if (SslUtil.getTrustManagers() == null || SslUtil.getTrustManagers().length == 0) { trustManager = null; @@ -165,7 +166,7 @@ private void getProtocolWithTlsHttp2() { private void getProtocolForTls() throws IOException { this.transport = new THeaderTransport(new TSocket( sslSocketFactory.createSocket(serverAddr.getHost(), - serverAddr.getPort()), this.timeout, this.timeout)); + serverAddr.getPort()), this.timeout, this.timeout)); this.protocol = new THeaderProtocol((THeaderTransport) transport); } @@ -217,7 +218,7 @@ public AuthResult authenticate(String user, String password) throws AuthFailedException, IOErrorException, ClientServerIncompatibleException { try { AuthResponse resp = client.authenticate(user.getBytes(Charsets.UTF_8), - password.getBytes(Charsets.UTF_8)); + password.getBytes(Charsets.UTF_8)); if (resp.error_code != ErrorCode.SUCCEEDED) { if (resp.error_msg != null) { throw new AuthFailedException(new String(resp.error_msg)); @@ -248,7 +249,8 @@ public AuthResult authenticate(String user, String password) public ExecutionResponse execute(long sessionID, String stmt) throws IOErrorException { return executeWithParameter(sessionID, - stmt, (Map) Collections.EMPTY_MAP); + stmt, + (Map) Collections.EMPTY_MAP); } public ExecutionResponse executeWithParameter(long sessionID, String stmt, @@ -280,14 +282,44 @@ public ExecutionResponse executeWithParameter(long sessionID, String stmt, } } + public ExecutionResponse executeWithParameterTimeout(long sessionID, + String stmt, + Map parameterMap, + long timeoutMs) throws IOErrorException { + try { + return client.executeWithTimeout(sessionID, + stmt.getBytes(Charsets.UTF_8), + parameterMap, + timeoutMs); + } catch (TException e) { + if (e instanceof TTransportException) { + TTransportException te = (TTransportException) e; + if (te.getType() == TTransportException.END_OF_FILE) { + throw new IOErrorException(IOErrorException.E_CONNECT_BROKEN, te.getMessage()); + } else if (te.getType() == TTransportException.NOT_OPEN) { + throw new IOErrorException(IOErrorException.E_NO_OPEN, te.getMessage()); + } else if (te.getType() == TTransportException.TIMED_OUT + || te.getMessage().contains("Read timed out")) { + try { + reopen(); + } catch (ClientServerIncompatibleException ex) { + LOGGER.error(ex.getMessage()); + } + throw new IOErrorException(IOErrorException.E_TIME_OUT, te.getMessage()); + } + } + throw new IOErrorException(IOErrorException.E_UNKNOWN, e.getMessage()); + } + } + public String executeJson(long sessionID, String stmt) throws IOErrorException { return executeJsonWithParameter(sessionID, stmt, - (Map) Collections.EMPTY_MAP); + (Map) Collections.EMPTY_MAP); } public String executeJsonWithParameter(long sessionID, String stmt, - Map parameterMap) + Map parameterMap) throws IOErrorException { try { byte[] result = diff --git a/client/src/test/java/com/vesoft/nebula/client/graph/net/TestSession.java b/client/src/test/java/com/vesoft/nebula/client/graph/net/TestSession.java index 2dcae27d3..d405dea8b 100644 --- a/client/src/test/java/com/vesoft/nebula/client/graph/net/TestSession.java +++ b/client/src/test/java/com/vesoft/nebula/client/graph/net/TestSession.java @@ -6,6 +6,7 @@ package com.vesoft.nebula.client.graph.net; import com.vesoft.nebula.Date; +import com.vesoft.nebula.ErrorCode; import com.vesoft.nebula.Row; import com.vesoft.nebula.Value; import com.vesoft.nebula.client.graph.NebulaPoolConfig; @@ -36,9 +37,9 @@ public void testMultiThreadUseTheSameSession() { nebulaPoolConfig.setMaxConnSize(1); List addresses = Arrays.asList(new HostAddress("127.0.0.1", 9670)); Assert.assertTrue(pool.init(addresses, nebulaPoolConfig)); - Session session = pool.getSession("root", "nebula", true); + Session session = pool.getSession("root", "nebula", true); ExecutorService executorService = Executors.newFixedThreadPool(10); - AtomicInteger failedCount = new AtomicInteger(0); + AtomicInteger failedCount = new AtomicInteger(0); for (int i = 0; i < 10; i++) { executorService.submit(() -> { try { @@ -96,12 +97,12 @@ public void testReconnectWithOneService() { @Test public void testReconnectWithMultiServices() { System.out.println("<==== testReconnectWithMultiServices ====>"); - Runtime runtime = Runtime.getRuntime(); - NebulaPool pool = new NebulaPool(); + Runtime runtime = Runtime.getRuntime(); + NebulaPool pool = new NebulaPool(); try { // make sure the graphd2_1 without any sessions - String cmd = "docker restart nebula-docker-compose_graphd2_1"; - Process p = runtime.exec(cmd); + String cmd = "docker restart nebula-docker-compose_graphd2_1"; + Process p = runtime.exec(cmd); p.waitFor(10, TimeUnit.SECONDS); ProcessUtil.printProcessStatus(cmd, p); @@ -183,12 +184,12 @@ public void testReconnectWithMultiServices() { @Test public void testExecuteWithParameter() { System.out.println("<==== testExecuteWithParameter ====>"); - Runtime runtime = Runtime.getRuntime(); - NebulaPool pool = new NebulaPool(); + Runtime runtime = Runtime.getRuntime(); + NebulaPool pool = new NebulaPool(); try { // make sure the graphd2_1 without any sessions - String cmd = "docker restart nebula-docker-compose_graphd2_1"; - Process p = runtime.exec(cmd); + String cmd = "docker restart nebula-docker-compose_graphd2_1"; + Process p = runtime.exec(cmd); p.waitFor(10, TimeUnit.SECONDS); ProcessUtil.printProcessStatus(cmd, p); @@ -212,7 +213,7 @@ public void testExecuteWithParameter() { paramMap.put("p2", true); paramMap.put("p3", 3.3); Value nvalue = new Value(); - Date date = new Date(); + Date date = new Date(); date.setYear((short) 2021); nvalue.setDVal(date); List list = new ArrayList<>(); @@ -255,4 +256,25 @@ public void testExecuteWithParameter() { pool.close(); } } + + // test for NebulaGraph Enterprise + public void testExecuteWithTimeout() { + System.out.println("<==== testExecuteWithTimeout ====>"); + NebulaPool pool = new NebulaPool(); + try { + NebulaPoolConfig nebulaPoolConfig = new NebulaPoolConfig(); + nebulaPoolConfig.setMaxConnSize(6); + List addresses = Arrays.asList( + new HostAddress("127.0.0.1", 3669)); + Assert.assertTrue(pool.init(addresses, nebulaPoolConfig)); + Session session = pool.getSession("root", "nebula", true); + ResultSet resultSet = session.executeWithTimeout( + "use test;match (v) return v limit 1000", + 1); + assert (resultSet.getErrorCode() == ErrorCode.E_QUERY_TIMEDOUT.getValue()); + } catch (Exception e) { + e.printStackTrace(); + assert false; + } + } } diff --git a/client/src/test/java/com/vesoft/nebula/client/graph/net/TestSessionPool.java b/client/src/test/java/com/vesoft/nebula/client/graph/net/TestSessionPool.java index 669a704d5..32231eb86 100644 --- a/client/src/test/java/com/vesoft/nebula/client/graph/net/TestSessionPool.java +++ b/client/src/test/java/com/vesoft/nebula/client/graph/net/TestSessionPool.java @@ -5,6 +5,7 @@ package com.vesoft.nebula.client.graph.net; +import com.vesoft.nebula.ErrorCode; import com.vesoft.nebula.client.graph.NebulaPoolConfig; import com.vesoft.nebula.client.graph.SessionPool; import com.vesoft.nebula.client.graph.SessionPoolConfig; @@ -535,4 +536,26 @@ public void testRetryForDownStoraged() { } } + + // test for NebulaGraph Enterprise + public void testExecuteWithTimeout() { + System.out.println("<==== testExecuteWithTimeout ====>"); + + try { + List addresses = Arrays.asList( + new HostAddress("127.0.0.1", 3669)); + SessionPoolConfig config = new SessionPoolConfig(addresses, + "test", + "root", + "nebula"); + SessionPool pool = new SessionPool(config); + ResultSet resultSet = pool.executeWithTimeout( + "use test;match (v) return v limit 1000", + 1); + assert (resultSet.getErrorCode() == ErrorCode.E_QUERY_TIMEDOUT.getValue()); + } catch (Exception e) { + e.printStackTrace(); + assert false; + } + } }