@@ -532,11 +532,7 @@ protected BlockingQueue<List<IMessage>> subscribeInternal(String host, int port,
532
532
List <String > backupSites , int resubTimeout , boolean subOnce , boolean createSubInfo ) throws IOException , RuntimeException {
533
533
Entity re ;
534
534
String topic = "" ;
535
- DBConnection dbConn ;
536
- if (listeningPort > 0 )
537
- dbConn = new DBConnection ();
538
- else
539
- dbConn = DBConnection .internalCreateEnableReverseStreamingDBConnection (false , false , false , false , false , SqlStdEnum .DolphinDB );
535
+ DBConnection dbConn = null ;
540
536
541
537
List <Site > parsedBackupSites = new ArrayList <>();
542
538
if (Objects .nonNull (backupSites ) && !backupSites .isEmpty ()) {
@@ -563,6 +559,8 @@ protected BlockingQueue<List<IMessage>> subscribeInternal(String host, int port,
563
559
for (int i = 0 ; i < parsedBackupSites .size () && !isConnected ; i ++) {
564
560
Site site = parsedBackupSites .get (i );
565
561
try {
562
+ checkServerVersion (site .host , site .port );
563
+ dbConn = createSubscribeInternalDBConnection ();
566
564
subscribeInternalConnect (dbConn , site .host , site .port , site .userName , site .passWord );
567
565
if (deserializer !=null &&!deserializer .isInited ())
568
566
deserializer .init (dbConn );
@@ -610,20 +608,21 @@ protected BlockingQueue<List<IMessage>> subscribeInternal(String host, int port,
610
608
}
611
609
612
610
re = dbConn .run ("publishTable" , params );
611
+ connList .add (dbConn );
613
612
} catch (IOException e ) {
614
613
log .error ("Connect to site " + site .host + ":" + site .port + " failed: " + e .getMessage ());
615
614
}
616
615
}
617
616
618
- Site curConnectedSite = parsedBackupSites .get (currentSiteIndexMap .get (topic ));
619
- checkServerVersion (curConnectedSite .host , curConnectedSite .port );
617
+ // Site curConnectedSite = parsedBackupSites.get(currentSiteIndexMap.get(topic));
618
+ // checkServerVersion(curConnectedSite.host, curConnectedSite.port);
620
619
621
620
if (!isConnected )
622
621
throw new IOException ("All sites try connect failed." );
623
622
}
624
623
625
624
if (parsedBackupSites .size () != 0 ) {
626
- connList .add (dbConn );
625
+ // connList.add(dbConn);
627
626
628
627
// prepare parsedBackupSites
629
628
for (int i = 0 ; i < parsedBackupSites .size (); i ++) {
@@ -658,6 +657,16 @@ protected BlockingQueue<List<IMessage>> subscribeInternal(String host, int port,
658
657
List <String > usr = Arrays .asList (userName , passWord );
659
658
users .put (tp , usr );
660
659
660
+ dbConn = createSubscribeInternalDBConnection ();
661
+ subscribeInternalConnect (dbConn , host , port , userName , passWord );
662
+
663
+ if (deserializer !=null &&!deserializer .isInited ())
664
+ deserializer .init (dbConn );
665
+ if (deserializer != null ){
666
+ BasicDictionary schema = (BasicDictionary ) dbConn .run (tableName + ".schema()" );
667
+ deserializer .checkSchema (schema );
668
+ }
669
+
661
670
String localIP = this .listeningHost ;
662
671
if (localIP .equals ("" ))
663
672
localIP = dbConn .getLocalAddress ().getHostAddress ();
@@ -668,7 +677,7 @@ protected BlockingQueue<List<IMessage>> subscribeInternal(String host, int port,
668
677
List <Entity > params = new ArrayList <Entity >();
669
678
params .add (new BasicString (tableName ));
670
679
params .add (new BasicString (actionName ));
671
- subscribeInternalConnect (dbConn , host , port , userName , passWord );
680
+ // subscribeInternalConnect(dbConn, host, port, userName, passWord);
672
681
re = dbConn .run ("getSubscriptionTopic" , params );
673
682
topic = ((BasicAnyVector ) re ).getEntity (0 ).getString ();
674
683
// lastBackupSiteTopic = topic;
@@ -921,4 +930,14 @@ private static void subscribeInternalConnect(DBConnection dbConn, String host, i
921
930
else
922
931
dbConn .connect (host , port );
923
932
}
933
+
934
+ private DBConnection createSubscribeInternalDBConnection () {
935
+ DBConnection dbConn ;
936
+ if (listeningPort > 0 )
937
+ dbConn = new DBConnection ();
938
+ else
939
+ dbConn = DBConnection .internalCreateEnableReverseStreamingDBConnection (false , false , false , false , false , SqlStdEnum .DolphinDB );
940
+
941
+ return dbConn ;
942
+ }
924
943
}
0 commit comments