ankitjain64 commented on a change in pull request #2284:
URL: https://github.com/apache/hbase/pull/2284#discussion_r478708730



##########
File path: 
hbase-client/src/main/java/org/apache/hadoop/hbase/client/replication/ReplicationPeerConfigUtil.java
##########
@@ -450,6 +452,49 @@ public static ReplicationPeerConfig 
appendTableCFsToReplicationPeerConfig(
     return builder.build();
   }
 
+  /**
+   * Helper method to add base peer configs from Configuration to 
ReplicationPeerConfig
+   * if not present in latter.
+   *
+   * This merges the user supplied peer configuration
+   * {@link org.apache.hadoop.hbase.replication.ReplicationPeerConfig} with 
peer configs
+   * provided as property hbase.replication.peer.base.configs in hbase 
configuration.
+   * Expected format for this hbase configuration is "k1=v1;k2=v2,v2_1"
+   *
+   * @param conf Configuration
+   * @return ReplicationPeerConfig if peer configurations are updated else 
null.
+   */
+  public static ReplicationPeerConfig 
addBasePeerConfigsIfNotPresent(Configuration conf,
+    ReplicationPeerConfig receivedPeerConfig){
+    boolean isPeerConfigChanged = false;
+    String defaultPeerConfigs = 
conf.get(HBASE_REPLICATION_PEER_BASE_CONFIG,null);
+
+    ReplicationPeerConfigBuilder copiedPeerConfigBuilder = 
ReplicationPeerConfig.
+      newBuilder(receivedPeerConfig);
+    Map<String,String> peerConfigurations = 
receivedPeerConfig.getConfiguration();
+
+    if (defaultPeerConfigs != null && defaultPeerConfigs.length() != 0) {
+      String[] defaultPeerConfigList = defaultPeerConfigs.split(";");
+
+      for (String defaultPeerConfig :  defaultPeerConfigList) {
+        String[] configSplit = defaultPeerConfig.split("=");
+
+        if (configSplit != null && configSplit.length == 2) {
+          String configName = configSplit[0];
+          String configValue = configSplit[1];
+
+          // Only override if base config does not exist in existing peer 
configs
+          if (!peerConfigurations.containsKey(configName)) {
+            copiedPeerConfigBuilder.putConfiguration(configName,configValue);
+            isPeerConfigChanged = true;
+          }
+        }
+      }
+    }
+
+    return isPeerConfigChanged ? copiedPeerConfigBuilder.build() : null;

Review comment:
       I thought it's not a good idea not make a zk call to update storage if 
there are no changes to peer configurations, that's why modified the return 
objects here.  What do you think. ?

##########
File path: 
hbase-client/src/main/java/org/apache/hadoop/hbase/client/replication/ReplicationPeerConfigUtil.java
##########
@@ -450,6 +452,49 @@ public static ReplicationPeerConfig 
appendTableCFsToReplicationPeerConfig(
     return builder.build();
   }
 
+  /**
+   * Helper method to add base peer configs from Configuration to 
ReplicationPeerConfig
+   * if not present in latter.
+   *
+   * This merges the user supplied peer configuration
+   * {@link org.apache.hadoop.hbase.replication.ReplicationPeerConfig} with 
peer configs
+   * provided as property hbase.replication.peer.base.configs in hbase 
configuration.
+   * Expected format for this hbase configuration is "k1=v1;k2=v2,v2_1"
+   *
+   * @param conf Configuration
+   * @return ReplicationPeerConfig if peer configurations are updated else 
null.
+   */
+  public static ReplicationPeerConfig 
addBasePeerConfigsIfNotPresent(Configuration conf,
+    ReplicationPeerConfig receivedPeerConfig){
+    boolean isPeerConfigChanged = false;
+    String defaultPeerConfigs = 
conf.get(HBASE_REPLICATION_PEER_BASE_CONFIG,null);
+
+    ReplicationPeerConfigBuilder copiedPeerConfigBuilder = 
ReplicationPeerConfig.
+      newBuilder(receivedPeerConfig);
+    Map<String,String> peerConfigurations = 
receivedPeerConfig.getConfiguration();
+
+    if (defaultPeerConfigs != null && defaultPeerConfigs.length() != 0) {
+      String[] defaultPeerConfigList = defaultPeerConfigs.split(";");
+
+      for (String defaultPeerConfig :  defaultPeerConfigList) {
+        String[] configSplit = defaultPeerConfig.split("=");
+
+        if (configSplit != null && configSplit.length == 2) {
+          String configName = configSplit[0];
+          String configValue = configSplit[1];
+
+          // Only override if base config does not exist in existing peer 
configs
+          if (!peerConfigurations.containsKey(configName)) {
+            copiedPeerConfigBuilder.putConfiguration(configName,configValue);
+            isPeerConfigChanged = true;
+          }
+        }
+      }
+    }
+
+    return isPeerConfigChanged ? copiedPeerConfigBuilder.build() : null;

Review comment:
       Done in latest commit.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to