krishnaasawa1 commented on code in PR #4817:
URL: https://github.com/apache/ozone/pull/4817#discussion_r1226377009


##########
hadoop-hdds/common/src/main/resources/ozone-default.xml:
##########
@@ -3930,4 +3930,15 @@
       Max numbers of keys changed allowed for a snapshot diff job.
     </description>
   </property>
+
+  <property>
+    <name>ozone.om.upgrade.quota.recalculate.enable</name>

Review Comment:
   Cosmetic "enabled". All other properties in ozone uses enabled.



##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/service/QuotaRepairTask.java:
##########
@@ -0,0 +1,326 @@
+/*
+ * 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.om.service;
+
+import com.google.common.util.concurrent.UncheckedExecutionException;
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ArrayBlockingQueue;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicLong;
+import org.apache.hadoop.hdds.utils.db.BatchOperation;
+import org.apache.hadoop.hdds.utils.db.Table;
+import org.apache.hadoop.hdds.utils.db.TableIterator;
+import org.apache.hadoop.ozone.om.OMMetadataManager;
+import org.apache.hadoop.ozone.om.helpers.BucketLayout;
+import org.apache.hadoop.ozone.om.helpers.OmBucketInfo;
+import org.apache.hadoop.ozone.om.helpers.OmKeyInfo;
+import org.apache.hadoop.ozone.om.helpers.OmVolumeArgs;
+import org.apache.hadoop.ozone.om.lock.IOzoneManagerLock;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.apache.hadoop.ozone.OzoneConsts.OM_KEY_PREFIX;
+import static 
org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.BUCKET_LOCK;
+
+/**
+ * Quota repair task.
+ */
+public class QuotaRepairTask {
+  private static final Logger LOG = LoggerFactory.getLogger(
+      QuotaRepairTask.class);
+  private static final int BATCH_SIZE = 5000;
+  private static final int TASK_THREAD_CNT = 3;
+  private final OMMetadataManager metadataManager;
+  private final Map<String, OmBucketInfo> nameBucketInfoMap = new HashMap<>();
+  private final Map<String, OmBucketInfo> idBucketInfoMap = new HashMap<>();
+  private ExecutorService executor;
+  private final Map<String, CountPair> keyCountMap = new ConcurrentHashMap<>();
+  private final Map<String, CountPair> fileCountMap
+      = new ConcurrentHashMap<>();
+  private final Map<String, CountPair> directoryCountMap
+      = new ConcurrentHashMap<>();
+
+  public QuotaRepairTask(OMMetadataManager metadataManager) {
+    this.metadataManager = metadataManager;
+  }
+  
+  public void repair() throws Exception {
+    LOG.info("Starting quota repair task");
+    prepareAllVolumeBucketInfo();
+
+    IOzoneManagerLock lock = metadataManager.getLock();
+    // thread pool with 3 Table type * (1 task each + 3 thread each)
+    executor = Executors.newFixedThreadPool(12);

Review Comment:
   How the task threads decided as 3 per table type?



##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/service/QuotaRepairTask.java:
##########
@@ -0,0 +1,326 @@
+/*
+ * 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.om.service;
+
+import com.google.common.util.concurrent.UncheckedExecutionException;
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ArrayBlockingQueue;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicLong;
+import org.apache.hadoop.hdds.utils.db.BatchOperation;
+import org.apache.hadoop.hdds.utils.db.Table;
+import org.apache.hadoop.hdds.utils.db.TableIterator;
+import org.apache.hadoop.ozone.om.OMMetadataManager;
+import org.apache.hadoop.ozone.om.helpers.BucketLayout;
+import org.apache.hadoop.ozone.om.helpers.OmBucketInfo;
+import org.apache.hadoop.ozone.om.helpers.OmKeyInfo;
+import org.apache.hadoop.ozone.om.helpers.OmVolumeArgs;
+import org.apache.hadoop.ozone.om.lock.IOzoneManagerLock;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.apache.hadoop.ozone.OzoneConsts.OM_KEY_PREFIX;
+import static 
org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.BUCKET_LOCK;
+
+/**
+ * Quota repair task.
+ */
+public class QuotaRepairTask {
+  private static final Logger LOG = LoggerFactory.getLogger(
+      QuotaRepairTask.class);
+  private static final int BATCH_SIZE = 5000;
+  private static final int TASK_THREAD_CNT = 3;
+  private final OMMetadataManager metadataManager;
+  private final Map<String, OmBucketInfo> nameBucketInfoMap = new HashMap<>();
+  private final Map<String, OmBucketInfo> idBucketInfoMap = new HashMap<>();
+  private ExecutorService executor;
+  private final Map<String, CountPair> keyCountMap = new ConcurrentHashMap<>();
+  private final Map<String, CountPair> fileCountMap
+      = new ConcurrentHashMap<>();
+  private final Map<String, CountPair> directoryCountMap
+      = new ConcurrentHashMap<>();
+
+  public QuotaRepairTask(OMMetadataManager metadataManager) {
+    this.metadataManager = metadataManager;
+  }
+  
+  public void repair() throws Exception {
+    LOG.info("Starting quota repair task");
+    prepareAllVolumeBucketInfo();
+
+    IOzoneManagerLock lock = metadataManager.getLock();
+    // thread pool with 3 Table type * (1 task each + 3 thread each)
+    executor = Executors.newFixedThreadPool(12);
+    try {
+      nameBucketInfoMap.values().stream().forEach(e -> lock.acquireReadLock(
+          BUCKET_LOCK, e.getVolumeName(), e.getBucketName()));
+      repairCount();
+    } finally {
+      nameBucketInfoMap.values().stream().forEach(e -> lock.releaseReadLock(
+          BUCKET_LOCK, e.getVolumeName(), e.getBucketName()));
+      executor.shutdown();
+      LOG.info("Completed quota repair task");
+    }
+  }
+  
+  private void prepareAllVolumeBucketInfo() throws IOException {
+    try (TableIterator<String, ? extends Table.KeyValue<String, OmVolumeArgs>>
+        iterator = metadataManager.getVolumeTable().iterator()) {
+
+      OmVolumeArgs omVolumeArgs;
+      while (iterator.hasNext()) {
+        Table.KeyValue<String, OmVolumeArgs> entry =
+            iterator.next();
+        omVolumeArgs = entry.getValue();
+        getAllBuckets(omVolumeArgs.getVolume(), omVolumeArgs.getObjectID());
+      }
+    }
+  }
+  
+  private void getAllBuckets(String volumeName, long volumeId)
+      throws IOException {
+    List<OmBucketInfo> bucketList = metadataManager.listBuckets(
+        volumeName, null, null, Integer.MAX_VALUE, false);
+    for (OmBucketInfo bucketInfo : bucketList) {
+      bucketInfo.incrUsedNamespace(-bucketInfo.getUsedNamespace());
+      bucketInfo.incrUsedBytes(-bucketInfo.getUsedBytes());
+      nameBucketInfoMap.put(buildNamePath(volumeName,
+          bucketInfo.getBucketName()), bucketInfo);
+      idBucketInfoMap.put(buildIdPath(volumeId, bucketInfo.getObjectID()),
+          bucketInfo);
+    }
+  }
+  
+  private String buildNamePath(String volumeName, String bucketName) {
+    final StringBuilder builder = new StringBuilder();
+    builder.append(OM_KEY_PREFIX)
+        .append(volumeName)
+        .append(OM_KEY_PREFIX)
+        .append(bucketName)
+        .append(OM_KEY_PREFIX);
+    return builder.toString();
+  }
+
+  private String buildIdPath(long volumeId, long bucketId) {
+    final StringBuilder builder = new StringBuilder();
+    builder.append(OM_KEY_PREFIX)
+        .append(volumeId)
+        .append(OM_KEY_PREFIX)
+        .append(bucketId)
+        .append(OM_KEY_PREFIX);
+    return builder.toString();
+  }
+  
+  private void repairCount() throws Exception {
+    LOG.info("Starting quota repair for all keys, files and directories");
+    try {
+      nameBucketInfoMap.keySet().stream().forEach(e -> keyCountMap.put(e,

Review Comment:
   Even this can move to recalculateUsages thread context if layout and boolean 
is passed.



##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/service/QuotaRepairTask.java:
##########
@@ -0,0 +1,326 @@
+/*
+ * 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.om.service;
+
+import com.google.common.util.concurrent.UncheckedExecutionException;
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ArrayBlockingQueue;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicLong;
+import org.apache.hadoop.hdds.utils.db.BatchOperation;
+import org.apache.hadoop.hdds.utils.db.Table;
+import org.apache.hadoop.hdds.utils.db.TableIterator;
+import org.apache.hadoop.ozone.om.OMMetadataManager;
+import org.apache.hadoop.ozone.om.helpers.BucketLayout;
+import org.apache.hadoop.ozone.om.helpers.OmBucketInfo;
+import org.apache.hadoop.ozone.om.helpers.OmKeyInfo;
+import org.apache.hadoop.ozone.om.helpers.OmVolumeArgs;
+import org.apache.hadoop.ozone.om.lock.IOzoneManagerLock;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.apache.hadoop.ozone.OzoneConsts.OM_KEY_PREFIX;
+import static 
org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.BUCKET_LOCK;
+
+/**
+ * Quota repair task.
+ */
+public class QuotaRepairTask {
+  private static final Logger LOG = LoggerFactory.getLogger(
+      QuotaRepairTask.class);
+  private static final int BATCH_SIZE = 5000;
+  private static final int TASK_THREAD_CNT = 3;
+  private final OMMetadataManager metadataManager;
+  private final Map<String, OmBucketInfo> nameBucketInfoMap = new HashMap<>();
+  private final Map<String, OmBucketInfo> idBucketInfoMap = new HashMap<>();
+  private ExecutorService executor;
+  private final Map<String, CountPair> keyCountMap = new ConcurrentHashMap<>();
+  private final Map<String, CountPair> fileCountMap
+      = new ConcurrentHashMap<>();
+  private final Map<String, CountPair> directoryCountMap
+      = new ConcurrentHashMap<>();
+
+  public QuotaRepairTask(OMMetadataManager metadataManager) {
+    this.metadataManager = metadataManager;
+  }
+  
+  public void repair() throws Exception {
+    LOG.info("Starting quota repair task");
+    prepareAllVolumeBucketInfo();
+
+    IOzoneManagerLock lock = metadataManager.getLock();
+    // thread pool with 3 Table type * (1 task each + 3 thread each)
+    executor = Executors.newFixedThreadPool(12);
+    try {
+      nameBucketInfoMap.values().stream().forEach(e -> lock.acquireReadLock(
+          BUCKET_LOCK, e.getVolumeName(), e.getBucketName()));
+      repairCount();
+    } finally {
+      nameBucketInfoMap.values().stream().forEach(e -> lock.releaseReadLock(
+          BUCKET_LOCK, e.getVolumeName(), e.getBucketName()));
+      executor.shutdown();
+      LOG.info("Completed quota repair task");
+    }
+  }
+  
+  private void prepareAllVolumeBucketInfo() throws IOException {
+    try (TableIterator<String, ? extends Table.KeyValue<String, OmVolumeArgs>>
+        iterator = metadataManager.getVolumeTable().iterator()) {
+
+      OmVolumeArgs omVolumeArgs;
+      while (iterator.hasNext()) {
+        Table.KeyValue<String, OmVolumeArgs> entry =
+            iterator.next();
+        omVolumeArgs = entry.getValue();
+        getAllBuckets(omVolumeArgs.getVolume(), omVolumeArgs.getObjectID());
+      }
+    }
+  }
+  
+  private void getAllBuckets(String volumeName, long volumeId)
+      throws IOException {
+    List<OmBucketInfo> bucketList = metadataManager.listBuckets(
+        volumeName, null, null, Integer.MAX_VALUE, false);
+    for (OmBucketInfo bucketInfo : bucketList) {
+      bucketInfo.incrUsedNamespace(-bucketInfo.getUsedNamespace());
+      bucketInfo.incrUsedBytes(-bucketInfo.getUsedBytes());
+      nameBucketInfoMap.put(buildNamePath(volumeName,
+          bucketInfo.getBucketName()), bucketInfo);
+      idBucketInfoMap.put(buildIdPath(volumeId, bucketInfo.getObjectID()),
+          bucketInfo);
+    }
+  }
+  
+  private String buildNamePath(String volumeName, String bucketName) {
+    final StringBuilder builder = new StringBuilder();
+    builder.append(OM_KEY_PREFIX)
+        .append(volumeName)
+        .append(OM_KEY_PREFIX)
+        .append(bucketName)
+        .append(OM_KEY_PREFIX);
+    return builder.toString();
+  }
+
+  private String buildIdPath(long volumeId, long bucketId) {
+    final StringBuilder builder = new StringBuilder();
+    builder.append(OM_KEY_PREFIX)
+        .append(volumeId)
+        .append(OM_KEY_PREFIX)
+        .append(bucketId)
+        .append(OM_KEY_PREFIX);
+    return builder.toString();
+  }
+  
+  private void repairCount() throws Exception {
+    LOG.info("Starting quota repair for all keys, files and directories");
+    try {
+      nameBucketInfoMap.keySet().stream().forEach(e -> keyCountMap.put(e,
+          new CountPair()));
+      idBucketInfoMap.keySet().stream().forEach(e -> fileCountMap.put(e,
+          new CountPair()));
+      idBucketInfoMap.keySet().stream().forEach(e -> directoryCountMap.put(e,
+          new CountPair()));
+      
+      List<Future<?>> tasks = new ArrayList<>();
+      tasks.add(executor.submit(() -> recalculateUsages(

Review Comment:
   Instead of passing multiple params in recalculateUsages, can't we pass just 
pass Layout and avoid passing other params. For DirectoryTable yes we need to 
take care may be the boolean passing apart from layout will take care.
   
   



##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/service/QuotaRepairTask.java:
##########
@@ -0,0 +1,326 @@
+/*
+ * 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.om.service;
+
+import com.google.common.util.concurrent.UncheckedExecutionException;
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ArrayBlockingQueue;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicLong;
+import org.apache.hadoop.hdds.utils.db.BatchOperation;
+import org.apache.hadoop.hdds.utils.db.Table;
+import org.apache.hadoop.hdds.utils.db.TableIterator;
+import org.apache.hadoop.ozone.om.OMMetadataManager;
+import org.apache.hadoop.ozone.om.helpers.BucketLayout;
+import org.apache.hadoop.ozone.om.helpers.OmBucketInfo;
+import org.apache.hadoop.ozone.om.helpers.OmKeyInfo;
+import org.apache.hadoop.ozone.om.helpers.OmVolumeArgs;
+import org.apache.hadoop.ozone.om.lock.IOzoneManagerLock;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.apache.hadoop.ozone.OzoneConsts.OM_KEY_PREFIX;
+import static 
org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.BUCKET_LOCK;
+
+/**
+ * Quota repair task.
+ */
+public class QuotaRepairTask {
+  private static final Logger LOG = LoggerFactory.getLogger(
+      QuotaRepairTask.class);
+  private static final int BATCH_SIZE = 5000;

Review Comment:
   How we decided on batch count value as 5K?



##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/service/QuotaRepairTask.java:
##########
@@ -0,0 +1,326 @@
+/*
+ * 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.om.service;
+
+import com.google.common.util.concurrent.UncheckedExecutionException;
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ArrayBlockingQueue;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicLong;
+import org.apache.hadoop.hdds.utils.db.BatchOperation;
+import org.apache.hadoop.hdds.utils.db.Table;
+import org.apache.hadoop.hdds.utils.db.TableIterator;
+import org.apache.hadoop.ozone.om.OMMetadataManager;
+import org.apache.hadoop.ozone.om.helpers.BucketLayout;
+import org.apache.hadoop.ozone.om.helpers.OmBucketInfo;
+import org.apache.hadoop.ozone.om.helpers.OmKeyInfo;
+import org.apache.hadoop.ozone.om.helpers.OmVolumeArgs;
+import org.apache.hadoop.ozone.om.lock.IOzoneManagerLock;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.apache.hadoop.ozone.OzoneConsts.OM_KEY_PREFIX;
+import static 
org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.BUCKET_LOCK;
+
+/**
+ * Quota repair task.
+ */
+public class QuotaRepairTask {
+  private static final Logger LOG = LoggerFactory.getLogger(
+      QuotaRepairTask.class);
+  private static final int BATCH_SIZE = 5000;
+  private static final int TASK_THREAD_CNT = 3;
+  private final OMMetadataManager metadataManager;
+  private final Map<String, OmBucketInfo> nameBucketInfoMap = new HashMap<>();
+  private final Map<String, OmBucketInfo> idBucketInfoMap = new HashMap<>();
+  private ExecutorService executor;
+  private final Map<String, CountPair> keyCountMap = new ConcurrentHashMap<>();
+  private final Map<String, CountPair> fileCountMap
+      = new ConcurrentHashMap<>();
+  private final Map<String, CountPair> directoryCountMap
+      = new ConcurrentHashMap<>();
+
+  public QuotaRepairTask(OMMetadataManager metadataManager) {
+    this.metadataManager = metadataManager;
+  }
+  
+  public void repair() throws Exception {
+    LOG.info("Starting quota repair task");
+    prepareAllVolumeBucketInfo();
+
+    IOzoneManagerLock lock = metadataManager.getLock();
+    // thread pool with 3 Table type * (1 task each + 3 thread each)
+    executor = Executors.newFixedThreadPool(12);
+    try {
+      nameBucketInfoMap.values().stream().forEach(e -> lock.acquireReadLock(
+          BUCKET_LOCK, e.getVolumeName(), e.getBucketName()));
+      repairCount();
+    } finally {
+      nameBucketInfoMap.values().stream().forEach(e -> lock.releaseReadLock(
+          BUCKET_LOCK, e.getVolumeName(), e.getBucketName()));
+      executor.shutdown();
+      LOG.info("Completed quota repair task");
+    }
+  }
+  
+  private void prepareAllVolumeBucketInfo() throws IOException {
+    try (TableIterator<String, ? extends Table.KeyValue<String, OmVolumeArgs>>
+        iterator = metadataManager.getVolumeTable().iterator()) {
+
+      OmVolumeArgs omVolumeArgs;
+      while (iterator.hasNext()) {
+        Table.KeyValue<String, OmVolumeArgs> entry =
+            iterator.next();
+        omVolumeArgs = entry.getValue();
+        getAllBuckets(omVolumeArgs.getVolume(), omVolumeArgs.getObjectID());
+      }
+    }
+  }
+  
+  private void getAllBuckets(String volumeName, long volumeId)
+      throws IOException {
+    List<OmBucketInfo> bucketList = metadataManager.listBuckets(
+        volumeName, null, null, Integer.MAX_VALUE, false);
+    for (OmBucketInfo bucketInfo : bucketList) {
+      bucketInfo.incrUsedNamespace(-bucketInfo.getUsedNamespace());

Review Comment:
   I suppose this is to reset the values to 0 and later capturecount is 
repopulating correct new values?



-- 
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]

Reply via email to