@@ -108,6 +108,7 @@ public String toString() {
108108 private final TableName tableName ;
109109 private final IntSupplier getNumOfReplicas ;
110110 private volatile boolean isStopped = false ;
111+ private final static int UNINITIALIZED_NUM_OF_REPLICAS = -1 ;
111112
112113 CatalogReplicaLoadBalanceSimpleSelector (TableName tableName , AsyncConnectionImpl conn ,
113114 IntSupplier getNumOfReplicas ) {
@@ -116,7 +117,7 @@ public String toString() {
116117 this .getNumOfReplicas = getNumOfReplicas ;
117118
118119 // This numOfReplicas is going to be lazy initialized.
119- this .numOfReplicas = CatalogReplicaLoadBalanceSelector . UNINITIALIZED_NUM_OF_REPLICAS ;
120+ this .numOfReplicas = UNINITIALIZED_NUM_OF_REPLICAS ;
120121 // Start chores
121122 this .conn .getChoreService ().scheduleChore (getCacheCleanupChore (this ));
122123 this .conn .getChoreService ().scheduleChore (getRefreshReplicaCountChore (this ));
@@ -145,7 +146,7 @@ public void onError(HRegionLocation loc) {
145146 */
146147 private int getRandomReplicaId () {
147148 int cachedNumOfReplicas = this .numOfReplicas ;
148- if (cachedNumOfReplicas == CatalogReplicaLoadBalanceSelector . UNINITIALIZED_NUM_OF_REPLICAS ) {
149+ if (cachedNumOfReplicas == UNINITIALIZED_NUM_OF_REPLICAS ) {
149150 cachedNumOfReplicas = refreshCatalogReplicaCount ();
150151 this .numOfReplicas = cachedNumOfReplicas ;
151152 }
@@ -261,16 +262,16 @@ private void cleanupReplicaReplicaStaleCache() {
261262 private int refreshCatalogReplicaCount () {
262263 int newNumOfReplicas = this .getNumOfReplicas .getAsInt ();
263264 LOG .debug ("Refreshed replica count {}" , newNumOfReplicas );
264- // If the returned number of replicas is -1, it is caused by failure to fetch the
265- // replica count. Do not update the numOfReplicas in this case.
266- if (newNumOfReplicas == CatalogReplicaLoadBalanceSelector .UNINITIALIZED_NUM_OF_REPLICAS ) {
267- LOG .error ("Failed to fetch Table {}'s region replica count" , tableName );
268- return this .numOfReplicas ;
265+ if (newNumOfReplicas == 1 ) {
266+ LOG .warn ("Table {}'s region replica count is 1, maybe a misconfiguration or failure to "
267+ + "fetch the replica count" , tableName );
269268 }
270-
271269 int cachedNumOfReplicas = this .numOfReplicas ;
270+
271+ // If the returned number of replicas is 1, it is mostly caused by failure to fetch the
272+ // replica count. Do not update the numOfReplicas in this case.
272273 if ((cachedNumOfReplicas == UNINITIALIZED_NUM_OF_REPLICAS ) ||
273- (cachedNumOfReplicas != newNumOfReplicas )) {
274+ (( cachedNumOfReplicas != newNumOfReplicas ) && ( newNumOfReplicas != 1 ) )) {
274275 this .numOfReplicas = newNumOfReplicas ;
275276 }
276277 return newNumOfReplicas ;
0 commit comments