-
Notifications
You must be signed in to change notification settings - Fork 615
HDDS-8627. Recon - API for Count of deletePending directories #5037
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 7 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
5140d09
Rebased the PR
ArafatKhan2198 3143a60
Fixed code review comments
ArafatKhan2198 9357281
Made changes to UPDATE method
ArafatKhan2198 1e82a34
Added new handlers
ArafatKhan2198 c758832
Addressed review comments
ArafatKhan2198 ab5870f
Added Reprocess to different handler
ArafatKhan2198 7084528
Fixed the failing UT's
ArafatKhan2198 05bd28a
Renamed Handler names and removed Handler for fileTable
ArafatKhan2198 2571218
Removed FileTable Handler, using keyInsights handler in its place
ArafatKhan2198 e6379a6
Merge branch 'master' into HDDS-8627
ArafatKhan2198 0cdaf6a
Removed conflict symbol
ArafatKhan2198 9bbc5ac
Review comments fixed
ArafatKhan2198 4eb8ab1
Removed the handleUpdateEvent logic as it is not needed for deletedTable
ArafatKhan2198 f5389ea
Renames Variables
ArafatKhan2198 48585c0
Fixed checkstyle issues
ArafatKhan2198 cc5f472
Fixed review comments
ArafatKhan2198 a4f609e
Made code review changes
ArafatKhan2198 e015a9f
Removed the size calculation part of Deleted Directory Handler
ArafatKhan2198 9eb4182
Made review changes
ArafatKhan2198 be86803
Fixed checkstyle issues
ArafatKhan2198 67b8818
Removed the getTablesToCalculateSize() and will be using the table ha…
ArafatKhan2198 9cf05fc
Removed the method getTablesToCalculateSize
ArafatKhan2198 e1e1535
Fixed bugs
ArafatKhan2198 832f290
Fixed checkstyle issues
ArafatKhan2198 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
165 changes: 165 additions & 0 deletions
165
...recon/src/main/java/org/apache/hadoop/ozone/recon/tasks/DeletedDirectoryTableHandler.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,165 @@ | ||
| 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.apache.hadoop.ozone.recon.api.types.NSSummary; | ||
| import org.apache.hadoop.ozone.recon.spi.impl.ReconNamespaceSummaryManagerImpl; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.Collection; | ||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
|
|
||
| /** | ||
| * Manages records in the Deleted Directory Table, updating counts and sizes of | ||
| * pending Directory Deletions in the backend. | ||
| */ | ||
| public class DeletedDirectoryTableHandler implements OmTableHandler { | ||
|
|
||
| private ReconNamespaceSummaryManagerImpl reconNamespaceSummaryManager; | ||
|
|
||
| private static final Logger LOG = | ||
| LoggerFactory.getLogger(DeletedTableHandler.class); | ||
|
|
||
| public DeletedDirectoryTableHandler( | ||
| ReconNamespaceSummaryManagerImpl reconNamespaceSummaryManager) { | ||
| this.reconNamespaceSummaryManager = reconNamespaceSummaryManager; | ||
| } | ||
|
|
||
| /** | ||
| * Invoked by the process method to add information on those directories that | ||
| * have been backlogged in the backend for deletion. | ||
| */ | ||
| @Override | ||
| public void handlePutEvent(OMDBUpdateEvent<String, Object> event, | ||
| String tableName, | ||
| Collection<String> sizeRelatedTables, | ||
| HashMap<String, Long> objectCountMap, | ||
| HashMap<String, Long> unreplicatedSizeCountMap, | ||
| HashMap<String, Long> replicatedSizeCountMap) | ||
| throws IOException { | ||
| String countKey = getTableCountKeyFromTable(tableName); | ||
| String unReplicatedSizeKey = getUnReplicatedSizeKeyFromTable(tableName); | ||
|
|
||
| if (event.getValue() != null) { | ||
| OmKeyInfo omKeyInfo = (OmKeyInfo) event.getValue(); | ||
| objectCountMap.computeIfPresent(countKey, (k, count) -> count + 1L); | ||
| Long newDeletedDirectorySize = | ||
| fetchSizeForDeletedDirectory(omKeyInfo.getObjectID()); | ||
| unreplicatedSizeCountMap.computeIfPresent(unReplicatedSizeKey, | ||
|
ArafatKhan2198 marked this conversation as resolved.
Outdated
|
||
| (k, size) -> size + newDeletedDirectorySize); | ||
| } else { | ||
| LOG.warn("Put event does not have the Key Info for {}.", | ||
| event.getKey()); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Invoked by the process method to remove information on those directories | ||
| * that have been successfully deleted from the backend. | ||
| */ | ||
| @Override | ||
| public void handleDeleteEvent(OMDBUpdateEvent<String, Object> event, | ||
| String tableName, | ||
| Collection<String> sizeRelatedTables, | ||
| HashMap<String, Long> objectCountMap, | ||
| HashMap<String, Long> unreplicatedSizeCountMap, | ||
| HashMap<String, Long> replicatedSizeCountMap) | ||
| throws IOException { | ||
| String countKey = getTableCountKeyFromTable(tableName); | ||
| String unReplicatedSizeKey = getUnReplicatedSizeKeyFromTable(tableName); | ||
|
|
||
| if (event.getValue() != null) { | ||
| OmKeyInfo omKeyInfo = (OmKeyInfo) event.getValue(); | ||
| objectCountMap.computeIfPresent(countKey, (k, count) -> count - 1L); | ||
| Long newDeletedDirectorySize = | ||
| fetchSizeForDeletedDirectory(omKeyInfo.getObjectID()); | ||
|
ArafatKhan2198 marked this conversation as resolved.
Outdated
|
||
| unreplicatedSizeCountMap.computeIfPresent(unReplicatedSizeKey, | ||
|
ArafatKhan2198 marked this conversation as resolved.
Outdated
|
||
| (k, size) -> size > newDeletedDirectorySize ? | ||
| size - newDeletedDirectorySize : 0L); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Invoked by the process method to update the statistics on the directories | ||
| * pending to be deleted. | ||
| */ | ||
| @Override | ||
| public void handleUpdateEvent(OMDBUpdateEvent<String, Object> event, | ||
| String tableName, | ||
| Collection<String> sizeRelatedTables, | ||
| HashMap<String, Long> objectCountMap, | ||
| HashMap<String, Long> unreplicatedSizeCountMap, | ||
| HashMap<String, Long> replicatedSizeCountMap) { | ||
| // The size of deleted directories cannot change hence no-op. | ||
| return; | ||
| } | ||
|
|
||
| /** | ||
| * Invoked by the reprocess method to calculate the records count of the | ||
| * deleted directories and their sizes. | ||
| */ | ||
| @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 += | ||
| fetchSizeForDeletedDirectory(omKeyInfo.getObjectID()); | ||
| count++; | ||
| } | ||
| } | ||
| } | ||
| return Triple.of(count, unReplicatedSize, replicatedSize); | ||
| } | ||
|
|
||
| /** | ||
| * Given an object ID, return total data size (no replication) | ||
| * under this object. Note:- This method is RECURSIVE. | ||
| * | ||
| * @param objectId the object's ID | ||
| * @return total used data size in bytes | ||
| * @throws IOException ioEx | ||
| */ | ||
| protected long fetchSizeForDeletedDirectory(long objectId) | ||
| throws IOException { | ||
| // Iterate the NSSummary table. | ||
| Table<Long, NSSummary> summaryTable = | ||
| reconNamespaceSummaryManager.getNSSummaryTable(); | ||
| Map<Long, NSSummary> summaryMap = new HashMap<>(); | ||
|
|
||
| NSSummary nsSummary = reconNamespaceSummaryManager.getNSSummary(objectId); | ||
| if (nsSummary == null) { | ||
| return 0L; | ||
| } | ||
| long totalSize = nsSummary.getSizeOfFiles(); | ||
| for (long childId : nsSummary.getChildDir()) { | ||
| totalSize += fetchSizeForDeletedDirectory(childId); | ||
| } | ||
| return totalSize; | ||
| } | ||
|
|
||
| public static String getTableCountKeyFromTable(String tableName) { | ||
| return tableName + "Count"; | ||
| } | ||
|
|
||
| public static String getReplicatedSizeKeyFromTable(String tableName) { | ||
| return tableName + "ReplicatedDataSize"; | ||
| } | ||
|
|
||
| public static String getUnReplicatedSizeKeyFromTable(String tableName) { | ||
| return tableName + "UnReplicatedDataSize"; | ||
| } | ||
| } | ||
176 changes: 176 additions & 0 deletions
176
...op-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/tasks/DeletedTableHandler.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,176 @@ | ||
| package org.apache.hadoop.ozone.recon.tasks; | ||
|
|
||
| import org.apache.commons.lang3.tuple.Pair; | ||
| 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.RepeatedOmKeyInfo; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.Collection; | ||
| import java.util.HashMap; | ||
|
|
||
| /** | ||
| * Manages records in the Deleted Table, updating counts and sizes of | ||
| * pending Key Deletions in the backend. | ||
| */ | ||
| public class DeletedTableHandler implements OmTableHandler { | ||
|
|
||
| private static final Logger LOG = | ||
| LoggerFactory.getLogger(DeletedTableHandler.class); | ||
|
|
||
| /** | ||
| * Invoked by the process method to add information on those keys that have | ||
| * been backlogged in the backend for deletion. | ||
| */ | ||
| @Override | ||
| public void handlePutEvent(OMDBUpdateEvent<String, Object> event, | ||
| String tableName, | ||
| Collection<String> sizeRelatedTables, | ||
| HashMap<String, Long> objectCountMap, | ||
| HashMap<String, Long> unreplicatedSizeCountMap, | ||
| HashMap<String, Long> replicatedSizeCountMap) | ||
| throws IOException { | ||
|
|
||
| String countKey = getTableCountKeyFromTable(tableName); | ||
| String unReplicatedSizeKey = getUnReplicatedSizeKeyFromTable(tableName); | ||
| String replicatedSizeKey = getReplicatedSizeKeyFromTable(tableName); | ||
|
|
||
| if (event.getValue() != null) { | ||
| 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()); | ||
| } else { | ||
| LOG.warn("Put event does not have the Key Info for {}.", | ||
| event.getKey()); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| /** | ||
| * Invoked by the process method to remove information on those keys that have | ||
| * been successfully deleted from the backend. | ||
| */ | ||
| @Override | ||
| public void handleDeleteEvent(OMDBUpdateEvent<String, Object> event, | ||
|
ArafatKhan2198 marked this conversation as resolved.
|
||
| String tableName, | ||
| Collection<String> sizeRelatedTables, | ||
| HashMap<String, Long> objectCountMap, | ||
| HashMap<String, Long> unreplicatedSizeCountMap, | ||
| HashMap<String, Long> replicatedSizeCountMap) | ||
| throws IOException { | ||
|
|
||
| String countKey = getTableCountKeyFromTable(tableName); | ||
| String unReplicatedSizeKey = getUnReplicatedSizeKeyFromTable(tableName); | ||
| String replicatedSizeKey = getReplicatedSizeKeyFromTable(tableName); | ||
|
|
||
| if (event.getValue() != null) { | ||
| 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); | ||
| } else { | ||
| LOG.warn("Delete event does not have the Key Info for {}.", | ||
| event.getKey()); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Invoked by the process method to update the statistics on the keys | ||
| * pending to be deleted. | ||
| */ | ||
| @Override | ||
| public void handleUpdateEvent(OMDBUpdateEvent<String, Object> event, | ||
|
ArafatKhan2198 marked this conversation as resolved.
|
||
| String tableName, | ||
| Collection<String> sizeRelatedTables, | ||
| 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() != null) { | ||
| if (event.getOldValue() == null) { | ||
| LOG.warn("Update event does not have the old Key Info for {}.", | ||
| event.getKey()); | ||
| return; | ||
| } | ||
| RepeatedOmKeyInfo oldRepeatedOmKeyInfo = | ||
| (RepeatedOmKeyInfo) event.getOldValue(); | ||
| RepeatedOmKeyInfo newRepeatedOmKeyInfo = | ||
| (RepeatedOmKeyInfo) event.getValue(); | ||
| objectCountMap.computeIfPresent(countKey, | ||
| (k, count) -> count > 0 ? | ||
| count - oldRepeatedOmKeyInfo.getOmKeyInfoList().size() + | ||
| newRepeatedOmKeyInfo.getOmKeyInfoList().size() : 0L); | ||
| Pair<Long, Long> oldSize = oldRepeatedOmKeyInfo.getTotalSize(); | ||
| Pair<Long, Long> newSize = newRepeatedOmKeyInfo.getTotalSize(); | ||
| unreplicatedSizeCountMap.computeIfPresent(unReplicatedSizeKey, | ||
| (k, size) -> size - oldSize.getLeft() + newSize.getLeft()); | ||
| replicatedSizeCountMap.computeIfPresent(replicatedSizeKey, | ||
| (k, size) -> size - oldSize.getRight() + newSize.getRight()); | ||
|
|
||
| } else { | ||
| LOG.warn("Update event does not have the Key Info for {}.", | ||
| event.getKey()); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Invoked by the reprocess method to calculate the records count of the | ||
| * deleted table and the sizes of replicated and unreplicated keys that are | ||
| * pending deletion in Ozone. | ||
| */ | ||
| @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) { | ||
| RepeatedOmKeyInfo repeatedOmKeyInfo = (RepeatedOmKeyInfo) kv | ||
| .getValue(); | ||
| Pair<Long, Long> result = repeatedOmKeyInfo.getTotalSize(); | ||
| unReplicatedSize += result.getRight(); | ||
| replicatedSize += result.getLeft(); | ||
| // Since we can have multiple deleted keys of same name | ||
| count += repeatedOmKeyInfo.getOmKeyInfoList().size(); | ||
| } | ||
| } | ||
| } | ||
| return Triple.of(count, unReplicatedSize, replicatedSize); | ||
| } | ||
|
|
||
| public static String getTableCountKeyFromTable(String tableName) { | ||
| return tableName + "Count"; | ||
| } | ||
|
|
||
| public static String getReplicatedSizeKeyFromTable(String tableName) { | ||
| return tableName + "ReplicatedDataSize"; | ||
| } | ||
|
|
||
| public static String getUnReplicatedSizeKeyFromTable(String tableName) { | ||
| return tableName + "UnReplicatedDataSize"; | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.