xyuanlu commented on a change in pull request #1043:
URL: https://github.com/apache/helix/pull/1043#discussion_r438506585



##########
File path: 
helix-core/src/main/java/org/apache/helix/controller/rebalancer/topology/Topology.java
##########
@@ -81,62 +75,43 @@ public Topology(final List<String> allNodes, final 
List<String> liveNodes,
       throw new HelixException(String.format("Config for instances %s is not 
found!",
           _allInstances.removeAll(_instanceConfigMap.keySet())));
     }
-
     _clusterConfig = clusterConfig;
-    _types = new LinkedHashSet<>();
-    _topologyAwareEnabled = clusterConfig.isTopologyAwareEnabled();
 
-    if (_topologyAwareEnabled) {
+    if (clusterConfig.isTopologyAwareEnabled()) {
       String topologyDef = _clusterConfig.getTopology();
       if (topologyDef != null) {
         // Customized cluster topology definition is configured.
-        String[] types = topologyDef.trim().split("/");
-        for (int i = 0; i < types.length; i++) {
-          if (types[i].length() != 0) {
-            _types.add(types[i]);
+        String[] topologyStr = topologyDef.trim().split("/");
+        int lastValidTypeIdx = topologyStr.length - 1;
+        while(lastValidTypeIdx >= 0) {
+          if (topologyStr[lastValidTypeIdx].length() != 0) {
+            break;
           }
+          --lastValidTypeIdx;
         }
-        if (_types.size() == 0) {
-          logger.error("Invalid cluster topology definition " + topologyDef);
+        if (lastValidTypeIdx < 0) {
           throw new HelixException("Invalid cluster topology definition " + 
topologyDef);
-        } else {
-          String lastType = null;
-          for (String type : _types) {
-            _defaultDomainPathValues.put(type, "Helix_default_" + type);
-            lastType = type;
-          }
-          _endNodeType = lastType;
-          _faultZoneType = clusterConfig.getFaultZoneType();
-          if (_faultZoneType == null) {
-            _faultZoneType = _endNodeType;
-          }
-          if (!_types.contains(_faultZoneType)) {
-            throw new HelixException(String
-                .format("Invalid fault zone type %s, not present in topology 
definition %s.",
-                    _faultZoneType, topologyDef));
-          }
-          _useDefaultTopologyDef = false;
+        }
+        _endNodeType = topologyStr[lastValidTypeIdx];
+        _faultZoneType = clusterConfig.getFaultZoneType();
+        if (_faultZoneType == null) {
+          _faultZoneType = _endNodeType;
+        }
+        if (Arrays.stream(topologyStr).noneMatch(type -> 
type.equals(_faultZoneType))) {

Review comment:
       One more optimization. We could put this check in the else branch for 
line 97. If we already set the _faultZoneType to be the same as _endNodeType, 
then _faultZoneType must belongs to topologyStr. 




----------------------------------------------------------------
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]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to