ArafatKhan2198 commented on code in PR #5037:
URL: https://github.com/apache/ozone/pull/5037#discussion_r1471461731
##########
hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/api/TestEndpoints.java:
##########
@@ -263,6 +265,8 @@ private void initializeInjector() throws Exception {
reconScm = (ReconStorageContainerManagerFacade)
reconTestInjector.getInstance(OzoneStorageContainerManager.class);
+ reconNamespaceSummaryManager = reconTestInjector.getInstance(
Review Comment:
Done!
##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/tasks/OpenKeysInsightHandler.java:
##########
@@ -0,0 +1,175 @@
+/*
+ * 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.tasks;
+
+import org.apache.commons.lang3.tuple.Triple;
+import org.apache.hadoop.hdds.utils.db.Table;
+import org.apache.hadoop.hdds.utils.db.TableIterator;
+import org.apache.hadoop.ozone.om.helpers.OmKeyInfo;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.util.HashMap;
+
+/**
+ * Manages records in the OpenKey Table, updating counts and sizes of
+ * open keys in the backend.
+ */
+public class OpenKeysInsightHandler implements OmTableHandler {
+
+ private static final Logger LOG =
+ LoggerFactory.getLogger(OpenKeysInsightHandler.class);
+
+ /**
+ * Invoked by the process method to add information on those keys that have
+ * been open in the backend.
+ */
+ @Override
+ public void handlePutEvent(OMDBUpdateEvent<String, Object> event,
+ String tableName,
+ HashMap<String, Long> objectCountMap,
+ HashMap<String, Long> unReplicatedSizeMap,
+ HashMap<String, Long> replicatedSizeMap) {
+
+ String countKey = getTableCountKeyFromTable(tableName);
+ String unReplicatedSizeKey = getUnReplicatedSizeKeyFromTable(tableName);
+ String replicatedSizeKey = getReplicatedSizeKeyFromTable(tableName);
+
+ if (event.getValue() != null) {
+ OmKeyInfo omKeyInfo = (OmKeyInfo) event.getValue();
+ objectCountMap.computeIfPresent(countKey, (k, count) -> count + 1L);
+ unReplicatedSizeMap.computeIfPresent(unReplicatedSizeKey,
+ (k, size) -> size + omKeyInfo.getDataSize());
+ replicatedSizeMap.computeIfPresent(replicatedSizeKey,
+ (k, size) -> size + omKeyInfo.getReplicatedSize());
+ } else {
+ LOG.warn("Put event does not have the Key Info for {}.",
+ event.getKey());
+ }
+ }
+
+ /**
+ * Invoked by the process method to delete information on those keys that are
+ * no longer closed in the backend.
+ */
+ @Override
+ public void handleDeleteEvent(OMDBUpdateEvent<String, Object> event,
+ String tableName,
+ HashMap<String, Long> objectCountMap,
+ HashMap<String, Long> unReplicatedSizeMap,
+ HashMap<String, Long> replicatedSizeMap) {
+
+ String countKey = getTableCountKeyFromTable(tableName);
+ String unReplicatedSizeKey = getUnReplicatedSizeKeyFromTable(tableName);
+ String replicatedSizeKey = getReplicatedSizeKeyFromTable(tableName);
+
+ if (event.getValue() != null) {
+ OmKeyInfo omKeyInfo = (OmKeyInfo) event.getValue();
+ objectCountMap.computeIfPresent(countKey,
+ (k, count) -> count > 0 ? count - 1L : 0L);
+ unReplicatedSizeMap.computeIfPresent(unReplicatedSizeKey,
+ (k, size) -> size > omKeyInfo.getDataSize() ?
+ size - omKeyInfo.getDataSize() : 0L);
+ replicatedSizeMap.computeIfPresent(replicatedSizeKey,
+ (k, size) -> size > omKeyInfo.getReplicatedSize() ?
+ size - omKeyInfo.getReplicatedSize() : 0L);
+ } else {
+ LOG.warn("Delete event does not have the Key Info for {}.",
+ event.getKey());
+ }
+ }
+
+ /**
+ * Invoked by the process method to update information on those open keys
that
+ * have been updated in the backend.
+ */
+ @Override
+ public void handleUpdateEvent(OMDBUpdateEvent<String, Object> event,
+ String tableName,
+ HashMap<String, Long> objectCountMap,
+ HashMap<String, Long> unReplicatedSizeMap,
+ HashMap<String, Long> replicatedSizeMap) {
+
+ if (event.getValue() != null) {
+ if (event.getOldValue() == null) {
+ LOG.warn("Update event does not have the old Key Info for {}.",
+ event.getKey());
+ return;
+ }
+ String unReplicatedSizeKey = getUnReplicatedSizeKeyFromTable(tableName);
+ String replicatedSizeKey = getReplicatedSizeKeyFromTable(tableName);
+
+ // In Update event the count for the open table will not change. So we
+ // don't need to update the count.
+ OmKeyInfo oldKeyInfo = (OmKeyInfo) event.getOldValue();
+ OmKeyInfo newKeyInfo = (OmKeyInfo) event.getValue();
+ unReplicatedSizeMap.computeIfPresent(unReplicatedSizeKey,
+ (k, size) -> size - oldKeyInfo.getDataSize() +
+ newKeyInfo.getDataSize());
+ replicatedSizeMap.computeIfPresent(replicatedSizeKey,
+ (k, size) -> size - oldKeyInfo.getReplicatedSize() +
+ newKeyInfo.getReplicatedSize());
+ } else {
+ LOG.warn("Update event does not have the Key Info for {}.",
+ event.getKey());
+ }
+ }
+
+ /**
+ * This method is called by the reprocess method. It calculates the record
+ * counts for both the open key table and the open file table. Additionally,
+ * it computes the sizes of both replicated and unreplicated keys
+ * that are currently open in the backend.
+ */
+ @Override
+ public Triple<Long, Long, Long> getTableSizeAndCount(
+ TableIterator<String, ? extends Table.KeyValue<String, ?>> iterator)
+ throws IOException {
+ long count = 0;
+ long unReplicatedSize = 0;
+ long replicatedSize = 0;
+
+ if (iterator != null) {
+ while (iterator.hasNext()) {
+ Table.KeyValue<String, ?> kv = iterator.next();
+ if (kv != null && kv.getValue() != null) {
+ OmKeyInfo omKeyInfo = (OmKeyInfo) kv.getValue();
+ unReplicatedSize += omKeyInfo.getDataSize();
+ replicatedSize += omKeyInfo.getReplicatedSize();
+ count++;
+ }
+ }
+ }
+ return Triple.of(count, unReplicatedSize, replicatedSize);
+ }
+
+ public static String getTableCountKeyFromTable(String tableName) {
Review Comment:
Done!
##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/tasks/OmTableInsightTask.java:
##########
@@ -335,109 +271,33 @@ private void handleDeleteEvent(OMDBUpdateEvent<String,
Object> event,
}
}
- private void handleSizeRelatedTableDeleteEvent(
- OMDBUpdateEvent<String, Object> event,
- String tableName,
- HashMap<String, Long> objectCountMap,
- HashMap<String, Long> unreplicatedSizeCountMap,
- HashMap<String, Long> replicatedSizeCountMap) {
-
- String countKey = getTableCountKeyFromTable(tableName);
- String unReplicatedSizeKey = getUnReplicatedSizeKeyFromTable(tableName);
- String replicatedSizeKey = getReplicatedSizeKeyFromTable(tableName);
-
- if (event.getValue() instanceof OmKeyInfo) {
- // Handle DELETE for OpenKeyTable & OpenFileTable
- OmKeyInfo omKeyInfo = (OmKeyInfo) event.getValue();
- objectCountMap.computeIfPresent(countKey,
- (k, count) -> count > 0 ? count - 1L : 0L);
- unreplicatedSizeCountMap.computeIfPresent(unReplicatedSizeKey,
- (k, size) -> size > omKeyInfo.getDataSize() ?
- size - omKeyInfo.getDataSize() : 0L);
- replicatedSizeCountMap.computeIfPresent(replicatedSizeKey,
- (k, size) -> size > omKeyInfo.getReplicatedSize() ?
- size - omKeyInfo.getReplicatedSize() : 0L);
- } else if (event.getValue() instanceof RepeatedOmKeyInfo) {
- // Handle DELETE for DeletedTable
- RepeatedOmKeyInfo repeatedOmKeyInfo =
- (RepeatedOmKeyInfo) event.getValue();
- objectCountMap.computeIfPresent(countKey, (k, count) -> count > 0 ?
- count - repeatedOmKeyInfo.getOmKeyInfoList().size() : 0L);
- Pair<Long, Long> result = repeatedOmKeyInfo.getTotalSize();
- unreplicatedSizeCountMap.computeIfPresent(unReplicatedSizeKey,
- (k, size) -> size > result.getLeft() ? size - result.getLeft() : 0L);
- replicatedSizeCountMap.computeIfPresent(replicatedSizeKey,
- (k, size) -> size > result.getRight() ? size - result.getRight() :
- 0L);
- }
- }
+ /**
+ * Handle update events for size related tables.
+ */
private void handleUpdateEvent(OMDBUpdateEvent<String, Object> event,
String tableName,
Collection<String> sizeRelatedTables,
HashMap<String, Long> objectCountMap,
- HashMap<String, Long>
unreplicatedSizeCountMap,
- HashMap<String, Long> replicatedSizeCountMap)
{
+ HashMap<String, Long> unReplicatedSizeMap,
+ HashMap<String, Long> replicatedSizeMap) {
+
+ OmTableHandler tableHandler = tableHandlers.get(tableName);
if (event.getValue() != null) {
if (sizeRelatedTables.contains(tableName)) {
Review Comment:
Done!
##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/tasks/OmTableInsightTask.java:
##########
@@ -270,63 +236,33 @@ private void handlePutEvent(OMDBUpdateEvent<String,
Object> event,
String tableName,
Collection<String> sizeRelatedTables,
HashMap<String, Long> objectCountMap,
- HashMap<String, Long> unreplicatedSizeCountMap,
- HashMap<String, Long> replicatedSizeCountMap) {
+ HashMap<String, Long> unReplicatedSizeMap,
+ HashMap<String, Long> replicatedSizeMap)
+ throws IOException {
+ OmTableHandler tableHandler = tableHandlers.get(tableName);
- if (sizeRelatedTables.contains(tableName)) {
- handleSizeRelatedTablePutEvent(event, tableName, objectCountMap,
- unreplicatedSizeCountMap, replicatedSizeCountMap);
+ if (sizeRelatedTables.contains(tableName) && tableHandler != null) {
+ tableHandler.handlePutEvent(event, tableName, objectCountMap,
+ unReplicatedSizeMap, replicatedSizeMap);
} else {
String countKey = getTableCountKeyFromTable(tableName);
objectCountMap.computeIfPresent(countKey, (k, count) -> count + 1L);
}
}
- private void handleSizeRelatedTablePutEvent(
- OMDBUpdateEvent<String, Object> event,
- String tableName,
- HashMap<String, Long> objectCountMap,
- HashMap<String, Long> unreplicatedSizeCountMap,
- HashMap<String, Long> replicatedSizeCountMap) {
-
- String countKey = getTableCountKeyFromTable(tableName);
- String unReplicatedSizeKey = getUnReplicatedSizeKeyFromTable(tableName);
- String replicatedSizeKey = getReplicatedSizeKeyFromTable(tableName);
-
- if (event.getValue() instanceof OmKeyInfo) {
- // Handle PUT for OpenKeyTable & OpenFileTable
- OmKeyInfo omKeyInfo = (OmKeyInfo) event.getValue();
- objectCountMap.computeIfPresent(countKey, (k, count) -> count + 1L);
- unreplicatedSizeCountMap.computeIfPresent(unReplicatedSizeKey,
- (k, size) -> size + omKeyInfo.getDataSize());
- replicatedSizeCountMap.computeIfPresent(replicatedSizeKey,
- (k, size) -> size + omKeyInfo.getReplicatedSize());
- } else if (event.getValue() instanceof RepeatedOmKeyInfo) {
- // Handle PUT for DeletedTable
- RepeatedOmKeyInfo repeatedOmKeyInfo =
- (RepeatedOmKeyInfo) event.getValue();
- objectCountMap.computeIfPresent(countKey,
- (k, count) -> count + repeatedOmKeyInfo.getOmKeyInfoList().size());
- Pair<Long, Long> result = repeatedOmKeyInfo.getTotalSize();
- unreplicatedSizeCountMap.computeIfPresent(unReplicatedSizeKey,
- (k, size) -> size + result.getLeft());
- replicatedSizeCountMap.computeIfPresent(replicatedSizeKey,
- (k, size) -> size + result.getRight());
- }
- }
-
-
private void handleDeleteEvent(OMDBUpdateEvent<String, Object> event,
String tableName,
Collection<String> sizeRelatedTables,
HashMap<String, Long> objectCountMap,
- HashMap<String, Long>
unreplicatedSizeCountMap,
- HashMap<String, Long> replicatedSizeCountMap)
{
+ HashMap<String, Long> unReplicatedSizeMap,
+ HashMap<String, Long> replicatedSizeMap)
+ throws IOException {
+ OmTableHandler tableHandler = tableHandlers.get(tableName);
if (event.getValue() != null) {
if (sizeRelatedTables.contains(tableName)) {
Review Comment:
Done!
--
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]