You are viewing a plain text version of this content. The canonical link for it is here.
Posted to hdfs-dev@hadoop.apache.org by GitBox <gi...@apache.org> on 2019/10/22 02:28:17 UTC

[GitHub] [hadoop-ozone] arp7 commented on a change in pull request #7: HDDS-1228. Chunk Scanner Checkpoints

arp7 commented on a change in pull request #7: HDDS-1228. Chunk Scanner Checkpoints
URL: https://github.com/apache/hadoop-ozone/pull/7#discussion_r337312099
 
 

 ##########
 File path: hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/impl/ContainerDataScanOrder.java
 ##########
 @@ -0,0 +1,57 @@
+/*
+ * 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.container.common.impl;
+
+import org.apache.hadoop.ozone.container.common.interfaces.Container;
+
+import java.time.Instant;
+import java.util.Comparator;
+import java.util.Optional;
+
+/**
+ * Orders containers:
+ * 1. containers not yet scanned first,
+ * 2. then least recently scanned first,
+ * 3. ties are broken by containerID.
+ */
+public class ContainerDataScanOrder implements Comparator<Container<?>> {
+
+  public static final Comparator<Container<?>> INSTANCE =
+      new ContainerDataScanOrder();
+
+  @Override
+  public int compare(Container<?> o1, Container<?> o2) {
+    ContainerData d1 = o1.getContainerData();
+    ContainerData d2 = o2.getContainerData();
+
+    Optional<Instant> scan1 = d1.lastDataScanTime();
+    boolean scanned1 = scan1.isPresent();
+    Optional<Instant> scan2 = d2.lastDataScanTime();
+    boolean scanned2 = scan2.isPresent();
+
+    int result = Boolean.compare(scanned1, scanned2);
+    if (0 == result && scanned1 && scanned2) {
+      result = scan1.get().compareTo(scan2.get());
+    }
+    if (0 == result) {
+      result = Long.compare(d1.getContainerID(), d2.getContainerID());
 
 Review comment:
   I think this check is incomplete. If scanned1 is absent however scanned2 is present, then o1 should order before o2, irrespective of their container IDs.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: hdfs-dev-unsubscribe@hadoop.apache.org
For additional commands, e-mail: hdfs-dev-help@hadoop.apache.org