Skip to content

Conversation

ray6080
Copy link
Contributor

@ray6080 ray6080 commented May 22, 2025

Description

Allocations for the following structures are now tracked + freed with the page manager:

  • hash index + overflow file + disk arrays
  • catalog
  • storage metadata

Also added a table function FILE_INFO for testing purposes. It returns the number of total pages in the data.kz file handle.

@royi-luo royi-luo force-pushed the index branch 2 times, most recently from 6a2cbe5 to 9c0837d Compare June 3, 2025 15:46
Copy link

codecov bot commented Jun 3, 2025

Codecov Report

Attention: Patch coverage is 92.63804% with 12 lines in your changes missing coverage. Please review.

Project coverage is 86.59%. Comparing base (f40b4e6) to head (6e59aed).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
src/storage/checkpointer.cpp 71.42% 4 Missing ⚠️
src/storage/index/hash_index.cpp 84.21% 3 Missing ⚠️
src/function/table/file_info.cpp 92.85% 2 Missing ⚠️
src/storage/overflow_file.cpp 90.47% 2 Missing ⚠️
src/storage/storage_manager.cpp 66.66% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #5443   +/-   ##
=======================================
  Coverage   86.58%   86.59%           
=======================================
  Files        1422     1423    +1     
  Lines       62492    62579   +87     
  Branches     7656     7678   +22     
=======================================
+ Hits        54110    54191   +81     
- Misses       8203     8209    +6     
  Partials      179      179           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@@ -274,7 +287,7 @@ DiskArrayInternal::getAPPageIdxAndAddAPToPIPIfNecessaryForWriteTrxNoLock(
KU_ASSERT(apIdx == getNumAPs(headerForWriteTrx));
// We need to add a new AP. This may further cause a new pip to be inserted, which is
// handled by the if/else-if/else branch below.
page_idx_t newAPPageIdx = fileHandle.addNewPage();
page_idx_t newAPPageIdx = fileHandle.getPageManager()->allocatePage();
Copy link
Contributor

Choose a reason for hiding this comment

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

I noticed the PIP does some manual eviction + truncation of allocated pages, can somebody else double-check if using this PIP as-is with the page manager is safe?

Copy link
Contributor

Choose a reason for hiding this comment

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

removePageIdxAndTruncateIfNecessary should be safe to remove, and I think it might be necessary to remove it since it truncates the file size (though at the moment just truncates the PageStates and other in memory structures, not the actual file on disk), and re-using pages from the middle of the file could break stuff.

I'm not sure about clearWALPageVersionAndRemovePageFromFrameIfNecessary, but I suspect it can also be removed. It appears that this is the only place we're using ShadowFile::clearShadowPage, is it not generally necessary to clear those when rolling back any more?

Copy link
Contributor

Choose a reason for hiding this comment

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

@ray6080 what are your thoughts on this?

Copy link
Contributor

Choose a reason for hiding this comment

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

Going to remove removePageIdxAndTruncateIfNecessary and keep clearWALPageVersionAndRemovePageFromFrameIfNecessary as-is for now, we can revisit this in the future if we need to.

@@ -88,5 +88,17 @@ size_t DiskArrayCollection::addDiskArray() {
return oldSize;
}

void DiskArrayCollection::reclaimStorage(PageManager& pageManager,
Copy link
Contributor

Choose a reason for hiding this comment

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

I copied the iteration logic for DiskArrayCollection::checkpoint() here, can you double-check to see if this is correct?

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems fine to me. Since the body is much shorter, you could even simplify it a little by starting with pageManager.freePage(firstHeaderPage) and then in the body freeing each nextHeaderPage (if its not invalid). But it doesn't make much difference.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good. In this case I think it's possible for the first header page to also be invalid so I'll keep it as-is just to keep it as one check.

@royi-luo royi-luo marked this pull request as ready for review June 3, 2025 21:34
@royi-luo royi-luo requested a review from benjaminwinger as a code owner June 3, 2025 21:34
@royi-luo royi-luo changed the title Reclaim space for hash index Reclaim space for all structures in data.kz file Jun 3, 2025
Copy link

github-actions bot commented Jun 3, 2025

Benchmark Result

Master commit hash: 0373992a8a0ce1a54a405aab2a84aab542d78645
Branch commit hash: 95c25cfdd1ba3e1f60278e4e1392649f506d7b2f

Query Group Query Name Mean Time - Commit (ms) Mean Time - Master (ms) Diff
aggregation q24 673.68 677.12 -3.44 (-0.51%)
aggregation q28 6551.50 6731.83 -180.34 (-2.68%)
filter q14 61.05 60.50 0.55 (0.92%)
filter q15 58.55 62.01 -3.46 (-5.58%)
filter q16 279.26 278.15 1.10 (0.40%)
filter q17 381.07 388.94 -7.88 (-2.02%)
filter q18 1876.38 1834.23 42.14 (2.30%)
filter zonemap-node 23.11 24.90 -1.79 (-7.20%)
filter zonemap-node-lhs-cast 22.99 25.22 -2.23 (-8.82%)
filter zonemap-node-null 22.68 24.85 -2.17 (-8.75%)
filter zonemap-rel 5638.93 5481.88 157.06 (2.86%)
fixed_size_expr_evaluator q07 619.22 628.11 -8.89 (-1.41%)
fixed_size_expr_evaluator q08 906.27 911.02 -4.75 (-0.52%)
fixed_size_expr_evaluator q09 905.33 917.84 -12.50 (-1.36%)
fixed_size_expr_evaluator q10 193.82 197.88 -4.06 (-2.05%)
fixed_size_expr_evaluator q11 194.49 198.05 -3.56 (-1.80%)
fixed_size_expr_evaluator q12 168.55 176.71 -8.17 (-4.62%)
fixed_size_expr_evaluator q13 1520.02 1503.44 16.58 (1.10%)
fixed_size_seq_scan q23 46.54 51.60 -5.06 (-9.80%)
join q29 679.46 700.73 -21.27 (-3.04%)
join q30 1627.63 1552.05 75.58 (4.87%)
join q31 8.06 5.25 2.81 (53.53%)
join SelectiveTwoHopJoin 50.56 44.25 6.32 (14.28%)
ldbc_snb_ic q35 7.57 8.60 -1.03 (-12.00%)
ldbc_snb_ic q36 77.36 91.54 -14.18 (-15.49%)
ldbc_snb_is q32 3.64 6.71 -3.07 (-45.74%)
ldbc_snb_is q33 12.48 12.02 0.46 (3.79%)
ldbc_snb_is q34 1.22 1.27 -0.05 (-3.96%)
limit push-down-limit-into-distinct 1973.24 1957.68 15.55 (0.79%)
multi-rel multi-rel-large-scan 2084.64 1771.09 313.54 (17.70%)
multi-rel multi-rel-lookup 3.22 7.59 -4.37 (-57.62%)
multi-rel multi-rel-small-scan 188.24 196.20 -7.96 (-4.06%)
order_by q25 63.45 66.82 -3.37 (-5.04%)
order_by q26 380.82 379.65 1.17 (0.31%)
order_by q27 1314.53 1310.18 4.35 (0.33%)
recursive_join recursive-join-bidirection 354.21 379.60 -25.39 (-6.69%)
recursive_join recursive-join-dense 7178.12 7003.91 174.20 (2.49%)
recursive_join recursive-join-path 23284.80 23248.24 36.56 (0.16%)
recursive_join recursive-join-sparse 9.39 10.41 -1.03 (-9.85%)
recursive_join recursive-join-trail 7094.66 6981.76 112.90 (1.62%)
scan_after_filter q01 106.69 104.20 2.49 (2.39%)
scan_after_filter q02 90.46 93.08 -2.62 (-2.82%)
shortest_path_ldbc100 q37 74.36 75.38 -1.03 (-1.37%)
shortest_path_ldbc100 q38 329.04 343.07 -14.03 (-4.09%)
shortest_path_ldbc100 q39 85.99 86.74 -0.75 (-0.87%)
shortest_path_ldbc100 q40 492.09 509.46 -17.37 (-3.41%)
var_size_expr_evaluator q03 2096.53 2028.59 67.94 (3.35%)
var_size_expr_evaluator q04 2134.75 2107.03 27.71 (1.32%)
var_size_expr_evaluator q05 2678.90 2614.11 64.79 (2.48%)
var_size_expr_evaluator q06 1303.31 1279.91 23.40 (1.83%)
var_size_seq_scan q19 1375.17 1345.72 29.46 (2.19%)
var_size_seq_scan q20 2604.18 2490.99 113.19 (4.54%)
var_size_seq_scan q21 2218.82 2184.39 34.43 (1.58%)
var_size_seq_scan q22 110.50 108.71 1.80 (1.65%)

@@ -274,7 +287,7 @@ DiskArrayInternal::getAPPageIdxAndAddAPToPIPIfNecessaryForWriteTrxNoLock(
KU_ASSERT(apIdx == getNumAPs(headerForWriteTrx));
// We need to add a new AP. This may further cause a new pip to be inserted, which is
// handled by the if/else-if/else branch below.
page_idx_t newAPPageIdx = fileHandle.addNewPage();
page_idx_t newAPPageIdx = fileHandle.getPageManager()->allocatePage();
Copy link
Contributor

Choose a reason for hiding this comment

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

removePageIdxAndTruncateIfNecessary should be safe to remove, and I think it might be necessary to remove it since it truncates the file size (though at the moment just truncates the PageStates and other in memory structures, not the actual file on disk), and re-using pages from the middle of the file could break stuff.

I'm not sure about clearWALPageVersionAndRemovePageFromFrameIfNecessary, but I suspect it can also be removed. It appears that this is the only place we're using ShadowFile::clearShadowPage, is it not generally necessary to clear those when rolling back any more?

@@ -88,5 +88,17 @@ size_t DiskArrayCollection::addDiskArray() {
return oldSize;
}

void DiskArrayCollection::reclaimStorage(PageManager& pageManager,
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems fine to me. Since the body is much shorter, you could even simplify it a little by starting with pageManager.freePage(firstHeaderPage) and then in the body freeing each nextHeaderPage (if its not invalid). But it doesn't make much difference.

@royi-luo royi-luo merged commit 2c39129 into master Jun 9, 2025
51 of 52 checks passed
@royi-luo royi-luo deleted the index branch June 9, 2025 14:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants