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