@@ -24,14 +24,14 @@ namespace dolphindb
24
24
/// <summary>
25
25
/// Sets up a connection to DolphinDB server through TCP/IP protocol
26
26
/// Executes DolphinDB scripts
27
- ///
27
+ ///
28
28
/// Example:
29
- ///
29
+ ///
30
30
/// import dolphindb;
31
31
/// DBConnection conn = new DBConnection();
32
32
/// boolean success = conn.connect("localhost", 8080);
33
33
/// conn.run("sum(1..100)");
34
- ///
34
+ ///
35
35
/// </summary>
36
36
37
37
public class DBConnection
@@ -254,9 +254,18 @@ bool connect()
254
254
@in = littleEndian_ ? new LittleEndianDataInputStream ( new BufferedStream ( new NetworkStream ( socket_ ) ) ) :
255
255
( ExtendedDataInput ) new BigEndianDataInputStream ( new BufferedStream ( new NetworkStream ( socket_ ) ) ) ;
256
256
}
257
-
258
257
isConnected_ = true ;
259
258
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
+ }
260
269
261
270
if ( userId_ != null && userId_ . Length > 0 && password_ . Length > 0 )
262
271
{
@@ -332,6 +341,9 @@ private IEntity runInternal(string script, string scriptType, ProgressListener l
332
341
if ( parallelism <= 0 || parallelism > 64 )
333
342
throw new InvalidOperationException ( "parallelism must be greater than 0 and less than 65" ) ;
334
343
344
+ if ( priority < 0 || priority > 8 )
345
+ throw new InvalidOperationException ( "priority must be greater than -1 and less than 9" ) ;
346
+
335
347
script = script . Replace ( Environment . NewLine , "\n " ) ;
336
348
337
349
string body = scriptType + "\n " + script ;
@@ -1211,30 +1223,32 @@ public Node(string hostName, int port, double load = -1.0)
1211
1223
1212
1224
ExceptionType parseException ( string msg , out string host , out int port )
1213
1225
{
1226
+ host = "" ;
1227
+ port = 0 ;
1214
1228
int index = msg . IndexOf ( "<NotLeader>" ) ;
1215
1229
if ( index != - 1 )
1216
1230
{
1231
+ System . Console . WriteLine ( "check exception message: " + msg ) ;
1217
1232
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 ) ;
1220
1235
Console . Out . WriteLine ( string . Format ( "New leader is {0}:{1}." , host , port ) ) ;
1221
1236
return ExceptionType . ET_NEWLEADER ;
1222
1237
}
1223
- else if ( ( index = msg . IndexOf ( "<DataNodeNotAvail>" ) ) != - 1 )
1238
+ else if ( ( index = msg . IndexOf ( "<DataNodeNotAvail>" ) ) != - 1 || ( index = msg . IndexOf ( "<DataNodeNotReady>" ) ) != - 1 )
1224
1239
{
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);
1233
1249
//if (lastHost == newIp && lastPort == newPort)
1234
1250
//{
1235
- host = "" ;
1236
- port = 0 ;
1237
- Console . Out . WriteLine ( msg ) ;
1251
+ //Console.Out.WriteLine(msg);
1238
1252
return ExceptionType . ET_NODENOTAVAIL ;
1239
1253
//}
1240
1254
//else
@@ -1247,31 +1261,31 @@ ExceptionType parseException(string msg, out string host, out int port)
1247
1261
}
1248
1262
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 )
1249
1263
{
1250
- host = "" ;
1251
- port = 0 ;
1264
+ System . Console . WriteLine ( "check exception message: " + msg ) ;
1252
1265
return ExceptionType . ET_NOINITIALIZED ;
1253
1266
}
1254
1267
else if ( ( index = msg . IndexOf ( "Data type" ) ) != - 1 && ( index = msg . IndexOf ( "is not supported" ) ) != - 1 )
1255
1268
{
1256
- host = "" ;
1257
- port = 0 ;
1269
+ System . Console . WriteLine ( "check exception message: " + msg ) ;
1258
1270
return ExceptionType . ET_NOTSUPPORT ;
1259
1271
}
1260
1272
else
1261
1273
{
1262
- host = "" ;
1263
- port = 0 ;
1274
+ System . Console . WriteLine ( "exception thrown in run: " + msg ) ;
1264
1275
return ExceptionType . ET_UNKNOW ;
1265
1276
}
1266
1277
}
1267
1278
1268
1279
void parseIpPort ( string ipPort , out string ip , out int port )
1269
1280
{
1281
+ ip = "" ;
1282
+ port = 0 ;
1270
1283
string [ ] v = ipPort . Split ( ':' ) ;
1271
1284
if ( v . Length < 2 )
1272
1285
{
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");
1275
1289
}
1276
1290
ip = v [ 0 ] ;
1277
1291
port = int . Parse ( v [ 1 ] ) ;
0 commit comments