Skip to content

Conversation

benjaminwinger
Copy link
Contributor

Previously only happened during a checkpoint.
But if a rollback occurs after data has been written, there would be a bunch of small page ranges in the free page cache from data appended to the end of the file, which can be merged and truncated.

This works around an issue I was running into on my segmentation branch (CopyNodeAfterPKErrorRollbackFlushedGroups; maybe related to the issue with NODE_GROUP_SIZE_LOG2=12 in the FIXME, but I couldn't reproduce that), so I suspect that might be related to free space management (which probably hits this edge case by segmentation increasing the number of data chunks we're dealing with). I don't think it fixes that issue though.

Copy link

Benchmark Result

Master commit hash: b9d06703018de25b9c00530d0ddc207422c4768f
Branch commit hash: 14bf23d5d7aa61921dff1ea918551b07a32ecdaf

Query Group Query Name Mean Time - Commit (ms) Mean Time - Master (ms) Diff
recursive_join recursive-join-sparse 6.59 9.92 -3.33 (-33.57%)
Other queries
Query Group Query Name Mean Time - Commit (ms) Mean Time - Master (ms) Diff
aggregation q24 702.70 697.96 4.74 (0.68%)
aggregation q28 7693.09 7688.27 4.81 (0.06%)
filter q14 59.02 60.21 -1.20 (-1.99%)
filter q15 63.72 58.26 5.46 (9.38%)
filter q16 274.11 276.03 -1.92 (-0.70%)
filter q17 380.26 380.97 -0.71 (-0.19%)
filter q18 1797.93 1862.44 -64.51 (-3.46%)
filter zonemap-node 23.55 23.62 -0.07 (-0.31%)
filter zonemap-node-lhs-cast 23.92 23.79 0.14 (0.57%)
filter zonemap-node-null 23.43 23.53 -0.11 (-0.46%)
filter zonemap-rel 5582.80 5540.48 42.32 (0.76%)
fixed_size_expr_evaluator q07 625.84 626.66 -0.82 (-0.13%)
fixed_size_expr_evaluator q08 910.55 912.64 -2.09 (-0.23%)
fixed_size_expr_evaluator q09 911.31 912.34 -1.03 (-0.11%)
fixed_size_expr_evaluator q10 197.44 198.57 -1.13 (-0.57%)
fixed_size_expr_evaluator q11 197.59 197.08 0.51 (0.26%)
fixed_size_expr_evaluator q12 175.49 175.05 0.44 (0.25%)
fixed_size_expr_evaluator q13 1537.57 1501.85 35.72 (2.38%)
fixed_size_seq_scan q23 56.56 53.00 3.56 (6.72%)
join q29 782.04 764.01 18.03 (2.36%)
join q30 1644.56 1658.89 -14.33 (-0.86%)
join q31 5.18 4.81 0.37 (7.75%)
join SelectiveTwoHopJoin 52.21 52.10 0.11 (0.21%)
ldbc_snb_ic q35 8.71 9.72 -1.01 (-10.43%)
ldbc_snb_ic q36 80.40 98.48 -18.08 (-18.36%)
ldbc_snb_is q32 4.48 4.18 0.30 (7.06%)
ldbc_snb_is q33 13.14 11.50 1.64 (14.26%)
ldbc_snb_is q34 1.26 1.31 -0.06 (-4.27%)
limit push-down-limit-into-distinct 1963.80 1979.87 -16.07 (-0.81%)
multi-rel multi-rel-large-scan 1457.51 1491.72 -34.20 (-2.29%)
multi-rel multi-rel-lookup 8.96 10.97 -2.01 (-18.36%)
multi-rel multi-rel-small-scan 202.85 200.51 2.33 (1.16%)
order_by q25 66.35 69.65 -3.30 (-4.73%)
order_by q26 392.64 384.24 8.40 (2.19%)
order_by q27 1304.57 1304.28 0.29 (0.02%)
recursive_join recursive-join-bidirection 308.31 364.95 -56.64 (-15.52%)
recursive_join recursive-join-dense 6912.92 7033.84 -120.93 (-1.72%)
recursive_join recursive-join-path 23168.44 23130.29 38.16 (0.16%)
recursive_join recursive-join-trail 6871.69 6991.50 -119.82 (-1.71%)
scan_after_filter q01 103.40 101.85 1.55 (1.52%)
scan_after_filter q02 90.23 89.55 0.69 (0.77%)
shortest_path_ldbc100 q37 79.74 79.02 0.72 (0.91%)
shortest_path_ldbc100 q38 362.85 319.78 43.07 (13.47%)
shortest_path_ldbc100 q39 85.40 83.87 1.54 (1.83%)
shortest_path_ldbc100 q40 488.81 510.95 -22.14 (-4.33%)
var_size_expr_evaluator q03 2142.61 2126.97 15.64 (0.74%)
var_size_expr_evaluator q04 2112.23 2161.79 -49.55 (-2.29%)
var_size_expr_evaluator q05 2596.81 2642.11 -45.30 (-1.71%)
var_size_expr_evaluator q06 1279.93 1282.14 -2.21 (-0.17%)
var_size_seq_scan q19 1345.35 1353.87 -8.52 (-0.63%)
var_size_seq_scan q20 2643.17 2632.74 10.43 (0.40%)
var_size_seq_scan q21 2175.43 2162.74 12.70 (0.59%)
var_size_seq_scan q22 107.38 109.35 -1.97 (-1.80%)

@royi-luo
Copy link
Contributor

Closing this as the root issue should be addressed by #5922

@royi-luo royi-luo closed this Aug 22, 2025
@benjaminwinger
Copy link
Contributor Author

This also fixes the fragmentation issue after rollbacks though. Do we not want to handle that case?

@royi-luo
Copy link
Contributor

This also fixes the fragmentation issue after rollbacks though. Do we not want to handle that case?

Hmm yes we probably should since otherwise there would be quite a bit of unnecessary fragmentation in this case. There's some minor stuff I'd like to change design wise but sure let's still do this change.

@royi-luo royi-luo reopened this Aug 22, 2025
@@ -22,6 +22,7 @@ void OptimisticAllocator::rollback() {
for (const auto& entry : optimisticallyAllocatedPages) {
pageManager.freeImmediatelyRewritablePageRange(pageManager.getDataFH(), entry);
}
pageManager.mergeFreePages(pageManager.getDataFH());
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's do this in LocalStorage::rollback() instead. There's still some overhead to merging the free pages (since we resort + reinsert all the entries in the FSM) so let's call this function fewer times if we can.

@benjaminwinger benjaminwinger force-pushed the merge-free-pages-after-rollback branch from 3222c43 to 1581cf9 Compare August 22, 2025 20:17
Previously only happened during a checkpoint
But if a rollback occurs after data has been written, there would be a bunch of small page ranges in the free page cache from data appended to the end of the file, which can be merged and truncated
@benjaminwinger benjaminwinger force-pushed the merge-free-pages-after-rollback branch from 1581cf9 to 95aac1c Compare August 22, 2025 20:18
@@ -201,6 +202,10 @@ void FreeSpaceManager::finalizeCheckpoint(FileHandle* fileHandle) {
uncheckpointedFreePageRanges.clear();
}

void FreeSpaceManager::mergeFreePages(FileHandle* fileHandle) {
mergePageRanges(std::move(uncheckpointedFreePageRanges), fileHandle);
Copy link
Contributor

@royi-luo royi-luo Aug 22, 2025

Choose a reason for hiding this comment

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

Let's rename mergeFreePages to something like finalizeRollback (this in the page manager too)? I'd like the use case of this function to be very specific since in general we shouldn't we worrying about the structure of the FSM in other modules.

I'd also like to change this to only merge the existing page ranges. I don't want this function to truncate the data file (or modify uncheckpointedFreePageRanges, although in practice it should always be empty in this case) since I'd like to maintain the assumption that we don't touch the data file or anything persistent outside of checkpoint. Maybe you can just refactor mergePageRanges() into two functions and just call the one that only does the merging.

Copy link
Contributor Author

@benjaminwinger benjaminwinger Aug 22, 2025

Choose a reason for hiding this comment

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

Let's rename mergeFreePages to something like finalizeRollback? I'd like the use case of this function to be very specific since in general we shouldn't we worrying about the structure of the FSM in other modules.

That sounds like a good idea to me

I don't want this function to truncate the data file ... since I'd like to maintain the assumption that we don't touch the data file or anything persistent outside of checkpoint.

What about for copies where we already touch the data file outside of checkpoints? E.g. in CopyNodeAfterPKErrorRollbackFlushedGroups the rollback occurs after we've written some of the data (even if none of the data is written successfully, we currently write to the node table before updating the index, where the primary key insertion fails in that test). I would think that particularly for duplicate PK errors (e.g. if you accidentally copy the same input twice) we wouldn't want to keep the newly added pages, since the user might not want to retry.
Though isn't this only being used when we've touched the data file? We usually delay allocating pages until we're ready to write them.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it’s fine to leave the data as garbage, it should be either overwritten or truncated after the next checkpoint. Since we rollback local storage even if there is no COPY (e.g. after just issuing a rollback statement) I’d still like to keep those cases from touching disk if possible.

Copy link
Contributor

Choose a reason for hiding this comment

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

maybe only calling finalizerollback if we detect changes in the fsm works (we already have the versioning in place). That might also be unnecessarily complicating things though, I’ll leave this decision to you.

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.

2 participants