You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by GitBox <gi...@apache.org> on 2021/07/16 14:42:09 UTC

[GitHub] [ozone] sodonnel opened a new pull request #2425: HDDS-5456. Inject a Clock into Replication Manager to allow timeouts to be tested

sodonnel opened a new pull request #2425:
URL: https://github.com/apache/ozone/pull/2425


   Replication Manager currently uses Time.monotonicNow() in a few places to check if a pending command should be timed out. 
   
   This is difficult to test without adding sleeps in the tests. 
   
   We should inject a Clock object to use rather than making calls to SystemTime directly to allow tests more flexibility.
   
   ## What changes were proposed in this pull request?
   
   (Please fill in changes proposed in this fix)
   
   ## What is the link to the Apache JIRA
   
   https://issues.apache.org/jira/browse/HDDS-5456
   
   ## How was this patch tested?
   
   New Unit test
   


-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] sodonnel commented on pull request #2425: HDDS-5456. Inject a Clock into Replication Manager to allow timeouts to be tested

Posted by GitBox <gi...@apache.org>.
sodonnel commented on pull request #2425:
URL: https://github.com/apache/ozone/pull/2425#issuecomment-882119464


   Thanks for the review @adoroszlai. I have merged the change to master.


-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] adoroszlai commented on a change in pull request #2425: HDDS-5456. Inject a Clock into Replication Manager to allow timeouts to be tested

Posted by GitBox <gi...@apache.org>.
adoroszlai commented on a change in pull request #2425:
URL: https://github.com/apache/ozone/pull/2425#discussion_r671806158



##########
File path: hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/common/MonotonicClock.java
##########
@@ -0,0 +1,81 @@
+/*
+ * 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
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  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.ozone.common;
+
+import org.apache.hadoop.util.Time;
+
+import java.time.Clock;
+import java.time.Instant;
+import java.time.ZoneId;
+
+/**
+ * This is a class which implements the Clock interface. It is a copy of the
+ * Java Clock.SystemClock only it uses MonotonicNow (nanotime) rather than
+ * System.currentTimeMills.
+ */
+
+public class MonotonicClock extends Clock {
+
+  private final ZoneId zoneId;
+
+  public MonotonicClock(ZoneId zone) {
+    this.zoneId = zone;
+  }
+
+  @Override
+  public ZoneId getZone() {
+    return zoneId;
+  }
+
+  @Override
+  public Clock withZone(ZoneId zone) {
+    if (zone.equals(this.zoneId)) {  // intentional NPE
+      return this;
+    }
+    return new MonotonicClock(zone);
+  }
+
+  @Override
+  public long millis() {
+    return Time.monotonicNow();
+  }
+
+  @Override
+  public Instant instant() {
+    return Instant.ofEpochMilli(millis());
+  }
+
+  @Override
+  public boolean equals(Object obj) {
+    if (obj instanceof MonotonicClock) {
+      return zoneId.equals(((MonotonicClock) obj).zoneId);

Review comment:
       `MonotonicClock` should be `final` or `equals` should check class equality instead of `instanceof`.  Otherwise equality of instances of a subclass and `MonotonicClock` would not be symmetric.

##########
File path: hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/StorageContainerManager.java
##########
@@ -600,7 +602,8 @@ private void initializeSystemManagers(OzoneConfiguration conf,
           eventQueue,
           scmContext,
           serviceManager,
-          scmNodeManager);
+          scmNodeManager,
+          new MonotonicClock(ZoneId.of("UTC")));

Review comment:
       Is there any reason not to use `ZoneOffset.UTC`?




-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] sodonnel commented on a change in pull request #2425: HDDS-5456. Inject a Clock into Replication Manager to allow timeouts to be tested

Posted by GitBox <gi...@apache.org>.
sodonnel commented on a change in pull request #2425:
URL: https://github.com/apache/ozone/pull/2425#discussion_r671808294



##########
File path: hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/StorageContainerManager.java
##########
@@ -600,7 +602,8 @@ private void initializeSystemManagers(OzoneConfiguration conf,
           eventQueue,
           scmContext,
           serviceManager,
-          scmNodeManager);
+          scmNodeManager,
+          new MonotonicClock(ZoneId.of("UTC")));

Review comment:
       No reason, except I didn't know about it :-) I will change it.




-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] sodonnel commented on a change in pull request #2425: HDDS-5456. Inject a Clock into Replication Manager to allow timeouts to be tested

Posted by GitBox <gi...@apache.org>.
sodonnel commented on a change in pull request #2425:
URL: https://github.com/apache/ozone/pull/2425#discussion_r671808506



##########
File path: hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/common/MonotonicClock.java
##########
@@ -0,0 +1,81 @@
+/*
+ * 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
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  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.ozone.common;
+
+import org.apache.hadoop.util.Time;
+
+import java.time.Clock;
+import java.time.Instant;
+import java.time.ZoneId;
+
+/**
+ * This is a class which implements the Clock interface. It is a copy of the
+ * Java Clock.SystemClock only it uses MonotonicNow (nanotime) rather than
+ * System.currentTimeMills.
+ */
+
+public class MonotonicClock extends Clock {
+
+  private final ZoneId zoneId;
+
+  public MonotonicClock(ZoneId zone) {
+    this.zoneId = zone;
+  }
+
+  @Override
+  public ZoneId getZone() {
+    return zoneId;
+  }
+
+  @Override
+  public Clock withZone(ZoneId zone) {
+    if (zone.equals(this.zoneId)) {  // intentional NPE
+      return this;
+    }
+    return new MonotonicClock(zone);
+  }
+
+  @Override
+  public long millis() {
+    return Time.monotonicNow();
+  }
+
+  @Override
+  public Instant instant() {
+    return Instant.ofEpochMilli(millis());
+  }
+
+  @Override
+  public boolean equals(Object obj) {
+    if (obj instanceof MonotonicClock) {
+      return zoneId.equals(((MonotonicClock) obj).zoneId);

Review comment:
       Thanks for pointing this out. I will make it final to avoid this problem. I basically copied this code from the Java SystemClock class, and it was a final class, so that explains why this code is that way.




-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] sodonnel merged pull request #2425: HDDS-5456. Inject a Clock into Replication Manager to allow timeouts to be tested

Posted by GitBox <gi...@apache.org>.
sodonnel merged pull request #2425:
URL: https://github.com/apache/ozone/pull/2425


   


-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org