fapifta commented on a change in pull request #3155:
URL: https://github.com/apache/ozone/pull/3155#discussion_r818806052
##########
File path:
hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/DatanodeVersion.java
##########
@@ -20,16 +20,30 @@
/**
* Versioning for datanode.
*/
-public final class DatanodeVersions {
+public enum DatanodeVersion {
- public static final int DEFAULT_VERSION = 0;
+ DEFAULT_VERSION(0, "Initial version"),
- public static final int SEPARATE_RATIS_PORTS_AVAILABLE = 1;
+ SEPARATE_RATIS_PORTS_AVAILABLE(1, "Version with separated Ratis port.");
- // this should always point to the latest version
- public static final int CURRENT_VERSION = SEPARATE_RATIS_PORTS_AVAILABLE;
Review comment:
I would argue that Enum.values() creates a new array each time. values
is an implicit method, and according to the Enum<E extends Enum> class
documentation, it relies on Class<?>#getEnumConstants() method to return the
enum values array.
Internally this uses a volatile array, and the implicit values() method
returns just a reference to that array which is initialized lazily on first
access inside the Class object.
So all in all, in the latest() method we store that reference internally,
and then use it twice. I haven't searched for written evidence, but I would bet
JIT optimize this under the hood and does not create a new reference in the
stack just inlines the access and uses the reference in the class object.
--
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]