adoroszlai commented on a change in pull request #3155:
URL: https://github.com/apache/ozone/pull/3155#discussion_r823564029



##########
File path: 
hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/DatanodeVersion.java
##########
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hdds;
+
+/**
+ * Versioning for datanode.
+ */
+public enum DatanodeVersion implements ComponentVersion {
+
+  DEFAULT_VERSION(0, "Initial version"),
+
+  SEPARATE_RATIS_PORTS_AVAILABLE(1, "Version with separated Ratis port."),
+
+  FUTURE_VERSION(-1, "Used internally in the client when the server side is "
+      + " newer and an unknown server version has arrived to the client.");
+
+  public static final DatanodeVersion CURRENT = latest();
+  public static final int CURRENT_VERSION = CURRENT.version;
+
+  private final int version;
+  private final String description;
+
+  DatanodeVersion(int version, String description) {
+    this.version = version;
+    this.description = description;
+  }
+
+  @Override
+  public String description() {
+    return description;
+  }
+
+  @Override
+  public int toProtoValue() {
+    return version;
+  }
+
+  public static DatanodeVersion fromProtoValue(int value) {
+    DatanodeVersion[] versions = DatanodeVersion.values();
+    if (value >= versions.length || value < 0) {
+      return FUTURE_VERSION;
+    }
+    return versions[value];

Review comment:
       Minor suggestion for improvement, while we wait for @errose28 to take a 
look.
   
   ```java
     private static final Map<Integer, DatanodeVersion> BY_PROTO_VALUE =
         Arrays.stream(DatanodeVersion.values())
           .collect(toMap(DatanodeVersion::toProtoValue, identity()));
   
     public static DatanodeVersion fromProtoValue(int value) {
       return BY_PROTO_VALUE.getOrDefault(value, FUTURE_VERSION);
     }
   ```
   
   This allows gaps in `version` number, and avoids the `values()` call for 
each lookup.




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

To unsubscribe, e-mail: [email protected]

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