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 2020/04/02 18:15:28 UTC

[GitHub] [hadoop-ozone] avijayanhwx commented on a change in pull request #753: HDDS-3237. Recon should provide the list of datanodes that a missing …

avijayanhwx commented on a change in pull request #753: HDDS-3237. Recon should provide the list of datanodes that a missing …
URL: https://github.com/apache/hadoop-ozone/pull/753#discussion_r402516043
 
 

 ##########
 File path: hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/persistence/ContainerSchemaManager.java
 ##########
 @@ -0,0 +1,105 @@
+/*
+ * 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.ozone.recon.persistence;
+
+import static org.hadoop.ozone.recon.schema.tables.ContainerHistoryTable.CONTAINER_HISTORY;
+
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+import org.hadoop.ozone.recon.schema.ContainerSchemaDefinition;
+import org.hadoop.ozone.recon.schema.tables.daos.ContainerHistoryDao;
+import org.hadoop.ozone.recon.schema.tables.daos.MissingContainersDao;
+import org.hadoop.ozone.recon.schema.tables.pojos.ContainerHistory;
+import org.hadoop.ozone.recon.schema.tables.pojos.MissingContainers;
+import org.jooq.DSLContext;
+import org.jooq.Record2;
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * Provide a high level API to access the Container Schema.
+ */
+@Singleton
+public class ContainerSchemaManager {
+  private ContainerHistoryDao containerHistoryDao;
+  private MissingContainersDao missingContainersDao;
+  private ContainerSchemaDefinition containerSchemaDefinition;
+
+  @Inject
+  public ContainerSchemaManager(ContainerHistoryDao containerHistoryDao,
+              ContainerSchemaDefinition containerSchemaDefinition,
+              MissingContainersDao missingContainersDao) {
+    this.containerHistoryDao = containerHistoryDao;
+    this.missingContainersDao = missingContainersDao;
+    this.containerSchemaDefinition = containerSchemaDefinition;
+  }
+
+  public void addMissingContainer(long containerID, long time) {
+    MissingContainers record = new MissingContainers(containerID, time);
+    missingContainersDao.insert(record);
+  }
+
+  public List<MissingContainers> getAllMissingContainers() {
+    return missingContainersDao.findAll();
+  }
+
+  public boolean isMissingContainer(long containerID) {
+    return missingContainersDao.existsById(containerID);
+  }
+
+  public void deleteMissingContainer(long containerID) {
+    missingContainersDao.deleteById(containerID);
+  }
+
+  public void upsertContainerHistory(long containerID, String datanode,
+                                     long time) {
+    DSLContext ctx = containerSchemaDefinition.getDSLContext();
+    Record2<Long, String> record =
+        ctx.newRecord(
+        CONTAINER_HISTORY.CONTAINER_ID,
+        CONTAINER_HISTORY.DATANODE_HOST).value1(containerID).value2(datanode);
+    ContainerHistory newRecord = new ContainerHistory();
+    newRecord.setContainerId(containerID);
+    newRecord.setDatanodeHost(datanode);
+    newRecord.setLastReportTimestamp(time);
+    if (containerHistoryDao.existsById(record)) {
+      newRecord.setFirstReportTimestamp(
+          containerHistoryDao.findById(record).getFirstReportTimestamp()
+      );
+      containerHistoryDao.update(newRecord);
+    } else {
+      newRecord.setFirstReportTimestamp(time);
+      containerHistoryDao.insert(newRecord);
+    }
+  }
+
+  public List<ContainerHistory> getAllContainerHistory(long containerID) {
+    return containerHistoryDao.fetchByContainerId(containerID);
+  }
+
+  public List<ContainerHistory> getLatestContainerHistory(long containerID,
+                                                          int limit) {
+    // Get container history sorted in descending order of timestamp
+    List<ContainerHistory> containerHistory =
 
 Review comment:
   Can we try and use ORDER BY and LIMIT on the DB side (using SELECT API maybe) instead of client side sorting and filtering?

----------------------------------------------------------------
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: ozone-issues-unsubscribe@hadoop.apache.org
For additional commands, e-mail: ozone-issues-help@hadoop.apache.org