sumitagrawl commented on code in PR #3783: URL: https://github.com/apache/ozone/pull/3783#discussion_r985412043
########## hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/ContainerReportQueue.java: ########## @@ -0,0 +1,364 @@ +/* + * 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.hdds.scm.server; + +import org.apache.hadoop.hdds.protocol.DatanodeDetails; +import org.apache.hadoop.hdds.scm.server.SCMDatanodeHeartbeatDispatcher.ContainerReportBase; +import org.apache.hadoop.hdds.scm.server.SCMDatanodeHeartbeatDispatcher.ContainerReportFromDatanode; +import org.apache.hadoop.hdds.scm.server.SCMDatanodeHeartbeatDispatcher.IncrementalContainerReportFromDatanode; +import org.apache.hadoop.hdds.server.events.FixedThreadPoolWithAffinityExecutor.IQueueMetrics; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicInteger; + +/** + * Customized queue to handle FCR and ICR from datanode optimally, + * avoiding duplicate FCR reports. + */ +public class ContainerReportQueue<VALUE extends ContainerReportBase> + implements BlockingQueue<VALUE>, IQueueMetrics { + + private static final Logger LOG = + LoggerFactory.getLogger(ContainerReportQueue.class); + + private static final Integer MAX_CAPACITY = 100000; + + private LinkedBlockingQueue<String> orderingQueue + = new LinkedBlockingQueue<>(); + private Map<String, List<VALUE>> dataMap = new HashMap<>(); + + private int capacity = 0; + + private AtomicInteger droppedCount = new AtomicInteger(); + + private boolean addContainerReport(VALUE val) { + ContainerReportFromDatanode report + = (ContainerReportFromDatanode) val; + synchronized (this) { + // 1. check if no previous report available, else add the report + DatanodeDetails dn = report.getDatanodeDetails(); + if (!dataMap.containsKey(dn.getUuidString())) { + ArrayList<VALUE> dataList = new ArrayList<>(); + dataList.add(val); + ++capacity; + dataMap.put(dn.getUuidString(), dataList); + orderingQueue.add(dn.getUuidString()); + return true; + } + + // 2. FCR report available + List<VALUE> dataList = dataMap.get(dn.getUuidString()); + boolean isReportRemoved = false; + if (!dataList.isEmpty()) { + // remove FCR and ICR (filter out deleted Container Report) Review Comment: updated comment -- 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]
