Skip to content
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

Fix crash in CompactFiles() of conflict range under preclude_last_level_data_seconds > 0 #12628

Closed

Conversation

hx235
Copy link
Contributor

@hx235 hx235 commented May 8, 2024

Context/Summary:

Previously CompactFiles() used RangeOverlapWithCompaction() to check for conflict when sanitizing input files while later used FilesRangeOverlapWithCompaction() to assert for no conflict. The latter function checks for more conflict scenarios than the former does, particularly the ones arising from preclude_last_level_data_seconds > 0 (i.e, compaction can output to second-to-the-last level). So we ran into assertion violation in CompactFiles() like below

 Assertion `output_level == 0 || !FilesRangeOverlapWithCompaction( input_files, output_level, Compaction::EvaluatePenultimateLevel(vstorage, ioptions_, start_level, output_level))' failed.

This PR make CompactFiles() used FilesRangeOverlapWithCompaction() and return Aborted status upon range conflict instead of crashing (during debug build) or proceed incorrectly (during non-debug build). To do so cleanly, I included a refactoring to make FilesRangeOverlapWithCompaction() part of SanitizeAndConvertCompactionInputFiles(), replacing RangeOverlapWithCompaction().

Test:
New UT crashed before the fix and return correct status after the fix.

@facebook-github-bot
Copy link
Contributor

@hx235 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@hx235 hx235 force-pushed the compact_file_key_placement_conflict branch from 83192e4 to 8a7a288 Compare May 8, 2024 21:01
@facebook-github-bot
Copy link
Contributor

@hx235 has updated the pull request. You must reimport the pull request before landing.

@facebook-github-bot
Copy link
Contributor

@hx235 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@hx235 hx235 changed the title Fix crash of CompactFiles() with conflict range under preclude_last_level_data_seconds > 0 Fix crash in CompactFiles() of conflict range under preclude_last_level_data_seconds > 0 May 8, 2024
@hx235 hx235 force-pushed the compact_file_key_placement_conflict branch from 8a7a288 to c38b294 Compare May 8, 2024 21:18
@facebook-github-bot
Copy link
Contributor

@hx235 has updated the pull request. You must reimport the pull request before landing.

@hx235 hx235 force-pushed the compact_file_key_placement_conflict branch from c38b294 to 133e8a3 Compare May 8, 2024 21:18
@facebook-github-bot
Copy link
Contributor

@hx235 has updated the pull request. You must reimport the pull request before landing.

@facebook-github-bot
Copy link
Contributor

@hx235 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

Copy link
Contributor

@pdillinger pdillinger left a comment

Choose a reason for hiding this comment

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

I'm not a compaction expert so I don't want to review changes to compaction preconditions.

I did confirm this is an old bug, with your unit test failing in 8.8.fb, the earliest I tried.

db/compaction/compaction_picker.cc Outdated Show resolved Hide resolved
@hx235 hx235 force-pushed the compact_file_key_placement_conflict branch from 133e8a3 to e722b2b Compare May 8, 2024 21:40
@facebook-github-bot
Copy link
Contributor

@hx235 has updated the pull request. You must reimport the pull request before landing.

@facebook-github-bot
Copy link
Contributor

@hx235 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@hx235 hx235 requested a review from ajkr May 8, 2024 22:42
@hx235
Copy link
Contributor Author

hx235 commented May 9, 2024

Potential conflict with #12633 (comment)

@hx235 hx235 requested a review from cbi42 May 9, 2024 22:20
Copy link
Member

@cbi42 cbi42 left a comment

Choose a reason for hiding this comment

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

LGTM

// `converted_input_files`.
// When the input parameters do not describe a valid
// compaction, the function will try to fix the input_files by adding
// necessary files. If it's not possible to conver an invalid input_files
Copy link
Member

Choose a reason for hiding this comment

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

convert?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

// To force below two CompactFiles() in order to coerce range conflict on L1
// upon (2)
// (1): Compact [k2] at L0 and [k3] at L1 and output to L1 and L0
// (2): Compact [k4] at L1 and [k1, k5] at L2 and output to L1 and L2
Copy link
Member

Choose a reason for hiding this comment

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

In this case, it does not seem like an actual conflict: universal with preclude feature should only output to the penultimate level the keys that are within the key range of input files from penultimate level:

bool safe_to_penultimate_level =
compaction_->WithinPenultimateLevelOutputRange(ikey_for_range_check);
. So only k4 can be potentially output to L1.

However, I think this change is fine since this seems to be an existing behavior.


// To force below two CompactFiles() in order to coerce range conflict on L1
// upon (2)
// (1): Compact [k2] at L0 and [k3] at L1 and output to L1 and L0
Copy link
Member

Choose a reason for hiding this comment

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

Output to L1?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@hx235 hx235 force-pushed the compact_file_key_placement_conflict branch from e722b2b to a70079f Compare May 11, 2024 23:02
@facebook-github-bot
Copy link
Contributor

@hx235 has updated the pull request. You must reimport the pull request before landing.

@facebook-github-bot
Copy link
Contributor

@hx235 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@hx235 merged this pull request in 20213d0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants