Skip to content

Conversation

@ArafatKhan2198
Copy link
Contributor

@ArafatKhan2198 ArafatKhan2198 commented Jul 14, 2025

What changes were proposed in this pull request?

This pull request introduces a "materialized view" approach for Recon's Namespace Summary (NSSummary), significantly improving the speed of namespace usage calculations.

Approach and Implementation Details:

  1. Materialized Totals in NSSummary:
    • The numOfFiles and sizeOfFiles fields in org.apache.hadoop.ozone.recon.api.types.NSSummary now store the total number and size of files within a directory and all its subdirectories, not just direct files. This enables constant-time (O(1)) queries for aggregate usage.
  2. Real-time Propagation on Events:
    • The org.apache.hadoop.ozone.recon.tasks.NSSummaryTaskDbEventHandler is enhanced to immediately propagate changes:
      • File Events (PUT/DELETE): When a file is added or deleted, its size and count changes are propagated upwards through its entire parent chain to update ancestor NSSummary totals.
      • Directory Deletion Events: When a directory is deleted, its NSSummary is unlinked (its parentId set to 0L), and its total file count and size (at the moment of deletion) are decremented from its parent and all ancestors. The deleted directory's NSSummary itself retains its historical totals.
  3. Idempotent Deletion Handling:
    • The logic ensures that deletion events are handled idempotently. If a directory is deleted first (and its totals propagated), subsequent deletion events for files within that already unlinked directory will not cause redundant decrements in ancestor totals. Similarly, if a file is deleted first, the subsequent deletion of its parent directory will not re-decrement already adjusted totals.
  4. Simplified API Queries:
    • The org.apache.hadoop.ozone.recon.api.handlers.EntityHandler now directly uses the pre-calculated numOfFiles and sizeOfFiles from NSSummary for total counts and sizes, eliminating the need for recursive tree traversals at query time.

What is the link to the Apache JIRA

https://issues.apache.org/jira/browse/HDDS-13432

How was this patch tested?

Manually verified the changes, also added Unit Tests to verify the changes.

@ArafatKhan2198 ArafatKhan2198 changed the title Materialize Approach Accelerating Namespace Usage Calculation in Recon using - Materialised Approach Jul 14, 2025
@ArafatKhan2198 ArafatKhan2198 changed the title Accelerating Namespace Usage Calculation in Recon using - Materialised Approach HDDS-13432. Accelerating Namespace Usage Calculation in Recon using - Materialised Approach Jul 14, 2025
@devmadhuu devmadhuu self-requested a review July 15, 2025 05:23
@ArafatKhan2198 ArafatKhan2198 force-pushed the HDDS-13432-Materialized-Approach branch from cdd2d20 to d82c5c9 Compare August 1, 2025 12:40
Copy link
Contributor

@devmadhuu devmadhuu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ArafatKhan2198 Thanks for the patch. Pls check few comments.

@devmadhuu
Copy link
Contributor

especially for deletion events.

Is this true. I believe this is true even for diskUsage(Namespace usage) page as well.

@devmadhuu
Copy link
Contributor

Alos pls resolve conflicts.

@ArafatKhan2198
Copy link
Contributor Author

ArafatKhan2198 commented Aug 4, 2025

@devmadhuu @sumitagrawl

I found a bug in my implementation code that handles directory deletions. When a directory is deleted, the system correctly updates the parent directory's total file count and size, but it fails to accurately update the file size distribution histogram. This leads to incorrect information about the size categories of files in the parent directory.

Simple Example

Imagine a directory /home with two subdirectories:

  • /home/dir_A (contains one 100-byte file)
  • /home/dir_B (contains one 500-byte file)

The file size distribution for /home should show one file in the "100-byte" bin and one file in the "500-byte" bin.

When /home/dir_B is deleted, the bug causes the system to only decrement the total file count and size of /home. The file size distribution for /home would still incorrectly show a file in both the "100-byte" and "500-byte" bins, even though the 500-byte file is gone.

I have applied a fix to ensures that when a directory is deleted, the parent directory's file size distribution is correctly updated by subtracting the specific file size distribution of the deleted directory. After the fix, deleting /home/dir_B would result in /home's distribution correctly showing only one file in the "100-byte" bin.

I've thoroughly tested this fix with unit tests for both file and directory deletion scenarios to ensure everything works correctly.

@ArafatKhan2198
Copy link
Contributor Author

Hi @sumitagrawl and @devmadhuu,

I have reverted the changes. We are no longer focusing on the File Bucket Distribution for now. We can consider implementing and tracking it later through this HDDS-13539 after further discussions. For the time being, please review the current state so we can proceed with the implementation.

Materialized Size/Count Optimization - Event Handling Rules

Every change must update the immediate parent AND propagate to ALL ancestors up to the root. This ensures every directory knows its total size/count including all subdirectories.

File Addition

What happens: New file created

Action:

  1. Add file size and count to immediate parent directory
  2. Propagate these additions up to ALL ancestor directories
  3. Update file size distribution bucket for immediate parent only

File Deletion

What happens: File removed

Action:

  1. Subtract file size and count from immediate parent directory
  2. Propagate these subtractions up to ALL ancestor directories
  3. Update file size distribution bucket for immediate parent only

Directory Addition

What happens: Directory explicitly created (might already exist with content)

Action:

  1. Set directory name and parent relationship
  2. Add directory to parent's child list
  3. CRITICAL: If directory already had files (from earlier file operations), propagate those existing totals up to ALL ancestors

Directory Deletion

What happens: Directory and all contents removed

Action:

  1. Get the directory's total size and file count (represents everything inside it)
  2. Subtract these totals from immediate parent
  3. Propagate these subtractions up to ALL ancestor directories
  4. Remove directory from parent's child list and unlink it

@ArafatKhan2198 ArafatKhan2198 force-pushed the HDDS-13432-Materialized-Approach branch from 9d8c33b to 2c64f4e Compare August 5, 2025 14:11
@ArafatKhan2198 ArafatKhan2198 force-pushed the HDDS-13432-Materialized-Approach branch from f1279aa to 2c64f4e Compare August 5, 2025 15:15
Copy link
Contributor

@sumitagrawl sumitagrawl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ArafatKhan2198 Thanks for working over this, given few comments

Copy link
Contributor

@sumitagrawl sumitagrawl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ArafatKhan2198 Thanks for working over this, given few comments

Copy link
Contributor

@sumitagrawl sumitagrawl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@devmadhuu devmadhuu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ArafatKhan2198 for the improved changes. LGTM now +1

@ArafatKhan2198 ArafatKhan2198 marked this pull request as ready for review August 7, 2025 08:58
@ArafatKhan2198
Copy link
Contributor Author

@ArafatKhan2198 ArafatKhan2198 merged commit 3c7bd2e into apache:master Aug 11, 2025
81 of 82 checks passed
errose28 added a commit to errose28/ozone that referenced this pull request Aug 12, 2025
* master: (55 commits)
  HDDS-13525. Rename configuration property to ozone.om.compaction.service.enabled (apache#8928)
  HDDS-13519. Reconciliation should continue if a peer datanode is unreachable (apache#8908)
  HDDS-13566. Fix incorrect authorizer class in ACL documentation (apache#8931)
  HDDS-13084. Trigger on-demand container scan when a container moves from open to unhealthy. (apache#8904)
  HDDS-13432. Accelerating Namespace Usage Calculation in Recon using - Materialised Approach (apache#8797)
  HDDS-13557. Bump jline to 3.30.5 (apache#8920)
  HDDS-13556. Bump assertj-core to 3.27.4 (apache#8919)
  HDDS-13543. [Docs] Design doc for OM bootstrapping process with snapshots. (apache#8900)
  HDDS-13541. Bump sonar-maven-plugin to 5.1.0.4751 (apache#8911)
  HDDS-13101. Remove duplicate information in datanode list output (apache#8523)
  HDDS-13528. Handle null paths when the NSSummary is initializing (apache#8901)
  HDDS-12990. (addendum) Generate tree from metadata when it does not exist during getContainerChecksumInfo call (apache#8881)
  HDDS-13086. Block duplicate reconciliation requests for the same container and datanode within the datanode. (apache#8905)
  HDDS-12990. Generate tree from metadata when it doesn't exist during getContainerChecksumInfo call (apache#8881)
  HDDS-12824. Optimize container checksum read during datanode startup (apache#8604)
  HDDS-13522. Rename axisLabel for No. of delete request received (apache#8879)
  HDDS-12196. Document ozone repair cli (apache#8849)
  HDDS-13514. Intermittent failure in TestNSSummaryMemoryLeak (apache#8889)
  HDDS-13423. Log reason for triggering on-demand container scan (apache#8854)
  HDDS-13466. Disable flaky TestOmSnapshotFsoWithNativeLibWithLinkedBuckets
  ...
@ArafatKhan2198 ArafatKhan2198 changed the title HDDS-13432. Accelerating Namespace Usage Calculation in Recon using - Materialised Approach HDDS-13432. Accelerating Namespace Usage Calculation in Recon using - Aggregation Approach Aug 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants