[NO ISSUE][CLUS] Avoid eager refresh cluster state

- user model changes: no
- storage format changes: no
- interface changes: no

Details:

- When clearing rebalance required cluster state, let the rebalance
  operation update the cluster state to avoid changing the cluster
  state during the rebalance.
- Make file replication logs debug level.

Change-Id: Ia1f3d84fe8ad82f34d4ad039efd353f7b534d4d6
Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/15163
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Murtadha Hubail <mhubail@apache.org>
Reviewed-by: Ali Alsuliman <ali.al.solaiman@gmail.com>
diff --git a/asterixdb/asterix-replication/src/main/java/org/apache/asterix/replication/messaging/ReplicateFileTask.java b/asterixdb/asterix-replication/src/main/java/org/apache/asterix/replication/messaging/ReplicateFileTask.java
index bf1613c..5bec257 100644
--- a/asterixdb/asterix-replication/src/main/java/org/apache/asterix/replication/messaging/ReplicateFileTask.java
+++ b/asterixdb/asterix-replication/src/main/java/org/apache/asterix/replication/messaging/ReplicateFileTask.java
@@ -95,7 +95,7 @@
             }
             //delete mask
             Files.delete(maskPath);
-            LOGGER.info("received file {} from master", localPath);
+            LOGGER.debug("received file {} from master", localPath);
             ReplicationProtocol.sendAck(worker.getChannel(), worker.getReusableBuffer());
         } catch (IOException e) {
             throw new ReplicationException(e);
diff --git a/asterixdb/asterix-replication/src/main/java/org/apache/asterix/replication/sync/FileSynchronizer.java b/asterixdb/asterix-replication/src/main/java/org/apache/asterix/replication/sync/FileSynchronizer.java
index 813b293..968f883 100644
--- a/asterixdb/asterix-replication/src/main/java/org/apache/asterix/replication/sync/FileSynchronizer.java
+++ b/asterixdb/asterix-replication/src/main/java/org/apache/asterix/replication/sync/FileSynchronizer.java
@@ -58,7 +58,7 @@
             String masterNode = appCtx.getReplicaManager().isPartitionOwner(replica.getIdentifier().getPartition())
                     ? appCtx.getServiceContext().getNodeId() : null;
             ReplicateFileTask task = new ReplicateFileTask(file, filePath.getFile().length(), metadata, masterNode);
-            LOGGER.info("attempting to replicate {} to replica {}", task, replica);
+            LOGGER.debug("attempting to replicate {} to replica {}", task, replica);
             ReplicationProtocol.sendTo(replica, task);
             // send the file itself
             try (RandomAccessFile fromFile = new RandomAccessFile(filePath.getFile(), "r");
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/utils/ClusterStateManager.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/utils/ClusterStateManager.java
index 6de1dda..052f568 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/utils/ClusterStateManager.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/utils/ClusterStateManager.java
@@ -470,7 +470,12 @@
     @Override
     public synchronized void setRebalanceRequired(boolean rebalanceRequired) throws HyracksDataException {
         this.rebalanceRequired = rebalanceRequired;
-        refreshState();
+        // if the cluster requires a rebalance, we will refresh the cluster state to ensure the state is updated
+        // to REBALANCE_REQUIRED. Otherwise, we will let the rebalance operation update the cluster state to avoid
+        // changing the cluster state during the rebalance
+        if (rebalanceRequired) {
+            refreshState();
+        }
     }
 
     @Override