Skip to content

Conversation

hx235
Copy link
Contributor

@hx235 hx235 commented Sep 9, 2025

Context
Resuming compaction is designed to periodically record the progress of an ongoing compaction and can resume from that saved progress after interruptions such as cancellation, database shutdown, or crashes.

This PR introduces the data structures needed to store subcompaction progress in memory, along with serialization and deserialization support to persist and parse this progress to/from "a manifest-like compaction progress file" (the actual creation of such file is in upcoming PRs).

Flow of resuming: DB::OpenAndCompact() -> Compaction progress file -> SubcompactionProgress -> CompactionJob
Flow of persistence: CompactionJob -> SubcompactionProgress -> Compaction progress file -> DB that is called with OpenAndCompact()

Summary
Progress represented by SubcompactionProgress will be tracked at the scope of a subcompaction, which is the smallest independent unit of compaction work.

The frequency of recording this progress is once every N compaction output files (to be detailed in future PRs).

When recording, all fields, except for the output files metadata in SubcompactionProgress, will directly overwrite the corresponding fields from the last saved progress (See SubcompactionProgress and SubcompactionProgressBuilder for more).

As a bonus, this PR refactors the file metadata encoding and decoding utilities into two static helper functions, EncodeToNewFile4() and DecodeNewFile4From(), to support subcompaction progress usage.

Test plan:

  • Added various SubcompactionProgressTest unit tests in version_edit_test.cc to verify basic serialization/deserialization and forward compatibility handling
  • Existing UTs and stress/crash test

Follow up:

  • Move output entry number and file verification to after each file creation so we can remove kNumProcessedOutputRecords persistence support and make resuming compaction work with paranoid_file_checks=true (by default false). Output verification will be done before persistence of progress. As long as this follow-up is done before the landing of the integration PR to create the progress file, we can change the manifest-like compaction progress file format freely.

@meta-cla meta-cla bot added the CLA Signed label Sep 9, 2025
@facebook-github-bot
Copy link
Contributor

@hx235 has imported this pull request. If you are a Meta employee, you can view this in D81986583.

@hx235
Copy link
Contributor Author

hx235 commented Sep 9, 2025

Irrelevant gcc_no_test_run/clang-analyze failure since they show up in other simple change like https://github.com/facebook/rocksdb/actions/runs/17566358798/job/49894009961?pr=13924 and https://github.com/facebook/rocksdb/actions/runs/17566358798/job/49894009939?pr=13924

@hx235 hx235 force-pushed the resumable_compaction_progress_infra branch 2 times, most recently from 86fa190 to a0cbebd Compare September 9, 2025 03:28
@hx235 hx235 marked this pull request as draft September 9, 2025 06:57
@hx235 hx235 force-pushed the resumable_compaction_progress_infra branch from a0cbebd to a5b0550 Compare September 9, 2025 07:54
@hx235 hx235 changed the title Add data structures and (de)serialization support for resumable subcompaction progress Add in-memory data structures and (de)serialization support for resumable subcompaction progress Sep 9, 2025
@hx235 hx235 marked this pull request as ready for review September 9, 2025 12:10
@hx235 hx235 requested a review from jaykorean September 9, 2025 12:10
@facebook-github-bot
Copy link
Contributor

@hx235 has imported this pull request. If you are a Meta employee, you can view this in D81986583.

Copy link
Contributor

@jaykorean jaykorean left a comment

Choose a reason for hiding this comment

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

Change makes sense to me overall. Mostly nitpick comments.


// Structure to hold subcompaction progress information for resumable
// compaction
struct ResumableSubcompactionProgress {
Copy link
Contributor

Choose a reason for hiding this comment

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

Unless we have subcompaction progress that is not resumable, I think we can remove "Resumable" part out of all codebase. I would just call this SubcompactionProgress

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

: last_persisted_output_files_count_;
}

size_t& LastPersistedOutputFilesCount(bool is_proximal_level) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Instead of exposing both const & and &, I'd have Get/Set and disallow Get to be editable. This is also consistent with what VersionEdit does.

Same for NumProcessedOutputRecords.

For CompactionOutputFiles, AddToCompactionOutputFiles() instead of SetCompactionOutputFiles(). (We already have Clear())

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

<< CompactionOutputFiles(false).size();
oss << ", number proximal_level_compaction_output_files="
<< CompactionOutputFiles(true).size();
oss << ", last_persisted_output_file_count="
Copy link
Contributor

Choose a reason for hiding this comment

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

supernit: last_persisted_output_files_count=

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

.empty()) {
continue;
}
// Reserve space in vector to avoid repeated reallocations
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd consider using autovector

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

return oss.str();
}

private:
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Instead of having two of each (one for output level and one for proximal level) for output records, output files, count, etc. I'm wondering if we can group this per level output info, maybe call it SubcompactionPerLevelProgress,

And then in SubcompactionProgress can have two fields,

  • SubcompactionPerLevelProgress output_level_progress and
  • SubcompactionPerLevelProgress proximal_level_progress

I think this may simplify quite a bit of duplicate functions with is_proximal_level

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea - fixed

}

// Initialize accumulated progress if this is the first VersionEdit
if (!has_resumable_subcompaction_progress_) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: this check is not needed. Also wondering how HasAccumulatedResumableSubcompactionProgress() is going to be used (except for the tests)

Copy link
Contributor Author

@hx235 hx235 Sep 9, 2025

Choose a reason for hiding this comment

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

For context, it's for building back all the output files from the delta record before resuming.

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 resumable_compaction_progress_infra branch from a5b0550 to 4c237b3 Compare September 20, 2025 06:33
@facebook-github-bot
Copy link
Contributor

@hx235 has imported this pull request. If you are a Meta employee, you can view this in D81986583.

@hx235 hx235 changed the title Add in-memory data structures and (de)serialization support for resumable subcompaction progress Add in-memory data structures and (de)serialization support for subcompaction progress Sep 20, 2025
@hx235 hx235 requested a review from jaykorean September 20, 2025 09:36
Copy link
Contributor

@jaykorean jaykorean left a comment

Choose a reason for hiding this comment

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

LGTM!

@hx235 hx235 force-pushed the resumable_compaction_progress_infra branch from 4c237b3 to e236f84 Compare September 22, 2025 20:05
@facebook-github-bot
Copy link
Contributor

@hx235 has imported this pull request. If you are a Meta employee, you can view this in D81986583.

@facebook-github-bot
Copy link
Contributor

@hx235 merged this pull request in ab10ea0.

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.

3 participants