Rename and clarify CompactionJobStats::has_num_input_records for clarity and set true by default #13929
Rename and clarify CompactionJobStats::has_num_input_records for clarity and set true by default #13929hx235 wants to merge 1 commit intofacebook:mainfrom
Conversation
|
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 |
jaykorean
left a comment
There was a problem hiding this comment.
Would you be able to add the context in the summary? Also a new test that would fail before the change and succeed after the change would be greatly helpful.
| sub_compact->compaction_job_stats.has_accurate_num_input_records &= | ||
| c_iter->HasNumInputEntryScanned(); | ||
| sub_compact->compaction_job_stats.num_input_records = | ||
| sub_compact->compaction_job_stats.num_input_records += |
There was a problem hiding this comment.
Does this mean the number of input records has been wrong for when max_subcompactions > 1? I'm little surprised that this wasn't caught by CompactionJobStatsTest::CompactionJobStatsTest
There was a problem hiding this comment.
It can be wrong even when max_subcompactions = 1 (edited). But it is not causing our trouble now because we always check CompactionJobStats::has_num_input_records before using this field. And we only use this field in input count verification.
There was a problem hiding this comment.
It can be wrong even when max_subcompactions = 0
Would you be able to elaborate little more? Also what does max_subcompactions = 0 mean? My understanding is that max_subcompactions = 1 means no sub compaction which is the default value.
If there's no sub_compaction (basically no chunking, compaction = one sub compaction), wouldn't we have the correct record count in the current code?
There was a problem hiding this comment.
I meant 1 sorry. By 1 subcompaction, that one subcompaction will still use c_iter and get the NumInputEntryScanned() from it. NumInputEntryScanned() can be inaccurate due to the reason cited in the PR summary https://github.com/facebook/rocksdb/pull/13929/files#diff-e6c876f655a21865c0f3dff94b9763f1bd40cf88a8a86f04868201b2e845a890R186-R199
There was a problem hiding this comment.
I thought must_count_input_entries is always true for compactions. I thought it was false for Flushes only, but I just learned that sub_compact->compaction->DoesInputReferenceBlobFiles() being false can set must_count_input_entries false. Now it makes sense to me that a single subcompaction's input record count could have been wrong in some cases like referencing blob files (not sure if there are other cases that we set must_count_input_entries false, though).
Hi - will add that when it's ready for review. Thanks! Added more context in the summary. It should not be a behavior change as we already do the right thing somehow by luck to prevent us getting into inaccuracy. |
5867ca1 to
dab1920
Compare
dab1920 to
57dcf58
Compare
| // True if `num_input_records` is accurate across all subcompactions. | ||
| // See CompactionIterator::must_count_input_entries for some implementation | ||
| // details why `num_input_records` may not be accurate. | ||
| bool has_accurate_num_input_records = true; |
There was a problem hiding this comment.
Will this ever be false now?
There was a problem hiding this comment.
Yes - through https://github.com/facebook/rocksdb/pull/13929/files#diff-f64bba74523047c4afe6b084718e61ea7696d687fbb07533d78e8f922b12a360R62 (existing behavior) since it's an AND operation
There was a problem hiding this comment.
Yes, I know that it's AND. My rephrased question would be "would stats.has_accurate_num_input_records ever be false"?
But, as I now realize that must_count_input_entries can be false in some cases, stats.has_accurate_num_input_records can be false. My original question was under wrong assumption that must_count_input_entries is always true for Compactions and false for Flushes only.
jaykorean
left a comment
There was a problem hiding this comment.
Thanks for the clarification!
| // True if `num_input_records` is accurate across all subcompactions. | ||
| // See CompactionIterator::must_count_input_entries for some implementation | ||
| // details why `num_input_records` may not be accurate. | ||
| bool has_accurate_num_input_records = true; |
There was a problem hiding this comment.
Yes, I know that it's AND. My rephrased question would be "would stats.has_accurate_num_input_records ever be false"?
But, as I now realize that must_count_input_entries can be false in some cases, stats.has_accurate_num_input_records can be false. My original question was under wrong assumption that must_count_input_entries is always true for Compactions and false for Flushes only.
| sub_compact->compaction_job_stats.has_accurate_num_input_records &= | ||
| c_iter->HasNumInputEntryScanned(); | ||
| sub_compact->compaction_job_stats.num_input_records = | ||
| sub_compact->compaction_job_stats.num_input_records += |
There was a problem hiding this comment.
I thought must_count_input_entries is always true for compactions. I thought it was false for Flushes only, but I just learned that sub_compact->compaction->DoesInputReferenceBlobFiles() being false can set must_count_input_entries false. Now it makes sense to me that a single subcompaction's input record count could have been wrong in some cases like referencing blob files (not sure if there are other cases that we set must_count_input_entries false, though).
Context/Summary:
Internally
CompactionJobStats ::num_input_recordsis only used for input record count verification and such verification always checks forCompactionJobStats::has_num_input_records(now renamed) before using this field. This is needed because theCompactionJobStats::num_input_recordsgets its number fromCompactionIterator::NumInputEntryScanned()in a subcompaction and this number can be inaccurate purposefully to increase performance, see CompactionIterator::must_count_input_entries for more.CompactionJobStats::has_num_input_recordsto more explicit naming and adds more comments. Not a behavior change.Also, aggregation of
CompactionJobStats::has_num_input_recordsamong all subcompactions is done by AND operation so it's false if any of the subcompaction has this field being false. The default value of this field should be "true" in order to not mistakenly "false" by default. We are currently fine becauseCompactionJobStats::Reset()that sets the value to be true is always called before such aggregation.CompactionJobStats::has_num_input_recordsto be false if the previous compaction carries inaccurate records. In order for this not be overwritten by the subsequent progress in here, this PR also changes this = to AND operation and +=. With the default valueCompactionJobStats::has_num_input_recordsnow to be true (or Reset() already called) andCompactionJobStats::num_input_records=0already, this will not a behavior change.Test: