@@ -788,51 +788,64 @@ public boolean connect(String hostName, int port, String userId, String password
788
788
if ( bt !=null && bt .getDataForm () != Entity .DATA_FORM .DF_TABLE )
789
789
throw new IOException ("Run getClusterPerf() failed." );
790
790
791
- if (bt !=null && loadBalance_ ) {
792
- //ignore very high load nodes, rand one in low load nodes
793
- List <Node > lowLoadNodes =new ArrayList <>();
794
- BasicStringVector colHost = (BasicStringVector ) bt .getColumn ("host" );
795
- BasicIntVector colPort = (BasicIntVector ) bt .getColumn ("port" );
796
- BasicDoubleVector memLoad = (BasicDoubleVector ) bt .getColumn ("memLoad" );
797
- BasicDoubleVector connLoad = (BasicDoubleVector ) bt .getColumn ("connLoad" );
798
- BasicDoubleVector avgLoad = (BasicDoubleVector ) bt .getColumn ("avgLoad" );
799
- for (int i = 0 ; i < colHost .rows (); i ++) {
800
- Node nodex = new Node (colHost .getString (i ), colPort .getInt (i ));
801
- Node pexistNode = null ;
802
- if (highAvailabilitySites != null ) {
803
- for (Node node : nodes_ ) {
804
- if ((node .hostName .equals (nodex .hostName ) || nodex .hostName .equals ("localhost" )) && node .port == nodex .port ){
805
- pexistNode = node ;
806
- break ;
791
+ if (bt !=null ) {
792
+ if (!loadBalance_ ) {
793
+ if (highAvailabilitySites == null ) {
794
+ BasicStringVector colHost = (BasicStringVector ) bt .getColumn ("host" );
795
+ BasicIntVector colPort = (BasicIntVector ) bt .getColumn ("port" );
796
+ for (int i = 0 ; i < colHost .rows (); i ++) {
797
+ Node curNode = new Node (colHost .getString (i ), colPort .getInt (i ));
798
+ if (!(curNode .hostName .equals (hostName ) && curNode .port == port ))
799
+ nodes_ .add (curNode );
800
+ }
801
+ }
802
+ } else {
803
+ // enable loadBalance
804
+ //ignore very high load nodes, rand one in low load nodes
805
+ List <Node > lowLoadNodes =new ArrayList <>();
806
+ BasicStringVector colHost = (BasicStringVector ) bt .getColumn ("host" );
807
+ BasicIntVector colPort = (BasicIntVector ) bt .getColumn ("port" );
808
+ BasicDoubleVector memLoad = (BasicDoubleVector ) bt .getColumn ("memLoad" );
809
+ BasicDoubleVector connLoad = (BasicDoubleVector ) bt .getColumn ("connLoad" );
810
+ BasicDoubleVector avgLoad = (BasicDoubleVector ) bt .getColumn ("avgLoad" );
811
+ for (int i = 0 ; i < colHost .rows (); i ++) {
812
+ Node nodex = new Node (colHost .getString (i ), colPort .getInt (i ));
813
+ Node pexistNode = null ;
814
+ if (highAvailabilitySites != null ) {
815
+ for (Node node : nodes_ ) {
816
+ if ((node .hostName .equals (nodex .hostName ) || nodex .hostName .equals ("localhost" )) && node .port == nodex .port ){
817
+ pexistNode = node ;
818
+ break ;
819
+ }
807
820
}
821
+ //node is out of highAvailabilitySites
822
+ if (pexistNode == null )
823
+ continue ;
808
824
}
809
- //node is out of highAvailabilitySites
810
- if (pexistNode == null )
811
- continue ;
825
+ double load =(memLoad .getDouble (i )+connLoad .getDouble (i )+avgLoad .getDouble (i ))/3.0 ;
826
+ if (pexistNode != null ) {
827
+ pexistNode .load = load ;
828
+ } else {
829
+ pexistNode =new Node (colHost .getString (i ), colPort .getInt (i ), load );
830
+ nodes_ .add (pexistNode );
831
+ }
832
+ // low load
833
+ if (memLoad .getDouble (i )<0.8 && connLoad .getDouble (i )<0.9 && avgLoad .getDouble (i )<0.8 )
834
+ lowLoadNodes .add (pexistNode );
812
835
}
813
- double load =(memLoad .getDouble (i )+connLoad .getDouble (i )+avgLoad .getDouble (i ))/3.0 ;
814
- if (pexistNode != null ) {
815
- pexistNode .load = load ;
836
+
837
+ Node pMinNode ;
838
+ if (!lowLoadNodes .isEmpty ()) {
839
+ pMinNode =lowLoadNodes .get (nodeRandom_ .nextInt (lowLoadNodes .size ()));
816
840
} else {
817
- pexistNode =new Node (colHost .getString (i ), colPort .getInt (i ), load );
818
- nodes_ .add (pexistNode );
841
+ pMinNode =nodes_ .get (nodeRandom_ .nextInt (nodes_ .size ()));
819
842
}
820
- // low load
821
- if (memLoad .getDouble (i )<0.8 && connLoad .getDouble (i )<0.9 && avgLoad .getDouble (i )<0.8 )
822
- lowLoadNodes .add (pexistNode );
823
- }
824
843
825
- Node pMinNode ;
826
- if (!lowLoadNodes .isEmpty ()) {
827
- pMinNode =lowLoadNodes .get (nodeRandom_ .nextInt (lowLoadNodes .size ()));
828
- } else {
829
- pMinNode =nodes_ .get (nodeRandom_ .nextInt (nodes_ .size ()));
830
- }
831
-
832
- if (pMinNode != null && !pMinNode .equals (connectedNode )){
833
- log .info ("Switch to node: " + pMinNode .hostName + ":" + pMinNode .port );
834
- conn_ .close ();
835
- switchDataNode (pMinNode );
844
+ if (pMinNode != null && !pMinNode .equals (connectedNode )){
845
+ log .info ("Switch to node: " + pMinNode .hostName + ":" + pMinNode .port );
846
+ conn_ .close ();
847
+ switchDataNode (pMinNode );
848
+ }
836
849
}
837
850
}
838
851
} else {
0 commit comments