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/18 08:34:43 UTC

[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

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