@@ -24,14 +24,14 @@ namespace dolphindb
2424 /// <summary>
2525 /// Sets up a connection to DolphinDB server through TCP/IP protocol
2626 /// Executes DolphinDB scripts
27- ///
27+ ///
2828 /// Example:
29- ///
29+ ///
3030 /// import dolphindb;
3131 /// DBConnection conn = new DBConnection();
3232 /// boolean success = conn.connect("localhost", 8080);
3333 /// conn.run("sum(1..100)");
34- ///
34+ ///
3535 /// </summary>
3636
3737 public class DBConnection
@@ -254,9 +254,18 @@ bool connect()
254254 @in = littleEndian_ ? new LittleEndianDataInputStream ( new BufferedStream ( new NetworkStream ( socket_ ) ) ) :
255255 ( ExtendedDataInput ) new BigEndianDataInputStream ( new BufferedStream ( new NetworkStream ( socket_ ) ) ) ;
256256 }
257-
258257 isConnected_ = true ;
259258
259+ if ( ! asynTask_ )
260+ {
261+ if ( ! ( ( BasicBoolean ) run ( "iif(getNodeType() == 0 or getNodeType() == 3 or getNodeType() == 4, isDataNodeInitialized(), bool(1))" ) ) . getValue ( ) )
262+ {
263+ System . Console . WriteLine ( "data node is not initialized. " ) ;
264+ socket_ . Close ( ) ;
265+ isConnected_ = false ;
266+ return false ;
267+ }
268+ }
260269
261270 if ( userId_ != null && userId_ . Length > 0 && password_ . Length > 0 )
262271 {
@@ -332,6 +341,9 @@ private IEntity runInternal(string script, string scriptType, ProgressListener l
332341 if ( parallelism <= 0 || parallelism > 64 )
333342 throw new InvalidOperationException ( "parallelism must be greater than 0 and less than 65" ) ;
334343
344+ if ( priority < 0 || priority > 8 )
345+ throw new InvalidOperationException ( "priority must be greater than -1 and less than 9" ) ;
346+
335347 script = script . Replace ( Environment . NewLine , "\n " ) ;
336348
337349 string body = scriptType + "\n " + script ;
@@ -1211,30 +1223,32 @@ public Node(string hostName, int port, double load = -1.0)
12111223
12121224 ExceptionType parseException ( string msg , out string host , out int port )
12131225 {
1226+ host = "" ;
1227+ port = 0 ;
12141228 int index = msg . IndexOf ( "<NotLeader>" ) ;
12151229 if ( index != - 1 )
12161230 {
1231+ System . Console . WriteLine ( "check exception message: " + msg ) ;
12171232 index = msg . IndexOf ( ">" ) ;
1218- string ipport = msg . Substring ( index + 1 ) ;
1219- parseIpPort ( ipport , out host , out port ) ;
1233+ string ipPort = msg . Substring ( index + 1 ) ;
1234+ parseIpPort ( ipPort , out host , out port ) ;
12201235 Console . Out . WriteLine ( string . Format ( "New leader is {0}:{1}." , host , port ) ) ;
12211236 return ExceptionType . ET_NEWLEADER ;
12221237 }
1223- else if ( ( index = msg . IndexOf ( "<DataNodeNotAvail>" ) ) != - 1 )
1238+ else if ( ( index = msg . IndexOf ( "<DataNodeNotAvail>" ) ) != - 1 || ( index = msg . IndexOf ( "<DataNodeNotReady>" ) ) != - 1 )
12241239 {
1225- index = msg . IndexOf ( ">" ) ;
1226- string ipPort = msg . Substring ( index + 1 ) ;
1227- string newIp ;
1228- int newPort ;
1229- parseIpPort ( ipPort , out newIp , out newPort ) ;
1230- string lastHost ;
1231- int lastPort ;
1232- conn_ . getHostPort ( out lastHost , out lastPort ) ;
1240+ System . Console . WriteLine ( "check exception message: " + msg ) ;
1241+ // index = msg.IndexOf(">");
1242+ // string ipPort = msg.Substring(index + 1);
1243+ // string newIp;
1244+ // int newPort;
1245+ // parseIpPort(ipPort, out newIp, out newPort);
1246+ // string lastHost;
1247+ // int lastPort;
1248+ // conn_.getHostPort(out lastHost, out lastPort);
12331249 //if (lastHost == newIp && lastPort == newPort)
12341250 //{
1235- host = "" ;
1236- port = 0 ;
1237- Console . Out . WriteLine ( msg ) ;
1251+ //Console.Out.WriteLine(msg);
12381252 return ExceptionType . ET_NODENOTAVAIL ;
12391253 //}
12401254 //else
@@ -1247,31 +1261,31 @@ ExceptionType parseException(string msg, out string host, out int port)
12471261 }
12481262 else if ( ( index = msg . IndexOf ( "The datanode isn't initialized yet. Please try again later" ) ) != - 1 || ( index = msg . IndexOf ( "DFS is not enabled or the script was not executed on a data node." ) ) != - 1 )
12491263 {
1250- host = "" ;
1251- port = 0 ;
1264+ System . Console . WriteLine ( "check exception message: " + msg ) ;
12521265 return ExceptionType . ET_NOINITIALIZED ;
12531266 }
12541267 else if ( ( index = msg . IndexOf ( "Data type" ) ) != - 1 && ( index = msg . IndexOf ( "is not supported" ) ) != - 1 )
12551268 {
1256- host = "" ;
1257- port = 0 ;
1269+ System . Console . WriteLine ( "check exception message: " + msg ) ;
12581270 return ExceptionType . ET_NOTSUPPORT ;
12591271 }
12601272 else
12611273 {
1262- host = "" ;
1263- port = 0 ;
1274+ System . Console . WriteLine ( "exception thrown in run: " + msg ) ;
12641275 return ExceptionType . ET_UNKNOW ;
12651276 }
12661277 }
12671278
12681279 void parseIpPort ( string ipPort , out string ip , out int port )
12691280 {
1281+ ip = "" ;
1282+ port = 0 ;
12701283 string [ ] v = ipPort . Split ( ':' ) ;
12711284 if ( v . Length < 2 )
12721285 {
1273- throw new InvalidOperationException ( "The format of highAvailabilitySite " + ipPort +
1274- " is incorrect, should be host:port, e.g. 192.168.1.1:8848" ) ;
1286+ return ;
1287+ // throw new InvalidOperationException("The format of highAvailabilitySite " + ipPort +
1288+ // " is incorrect, should be host:port, e.g. 192.168.1.1:8848");
12751289 }
12761290 ip = v [ 0 ] ;
12771291 port = int . Parse ( v [ 1 ] ) ;
0 commit comments