Repository navigation
Refactor, clean up, fixes, and more testing for SeqnoToTimeMapping - #11905
pdillinger wants to merge 4 commits into
Conversation
Summary:
This change is before a planned DBImpl change to ensure all sufficiently
recent sequence numbers since Open are covered by SeqnoToTimeMapping
(bug fix with existing test work-arounds). **Intended follow-up**
However, I found enough issues with SeqnoToTimeMapping to warrant this
PR first, including very small fixes in DB implementation related to API
contract of SeqnoToTimeMapping.
Functional fixes / changes:
* This fixes some mishandling of boundary cases. For example, if the
user decides to stop writing to DB, the last written sequence number
would perpetually have its write time updated to "now" and would always
be ineligible for migration to cold tier. Part of the problem is that
the SeqnoToTimeMapping would return a seqno known to have been written
before (immediately or otherwise) the requested time, but
compaction_job.cc would include that seqno in the preserve/exclude set.
That is fixed (in part) by adding one in compaction_job.cc (Other
changes outside of seqno_to_time_mapping.cc/h and tests are cosmetic.)
* That problem was worse because a whole range of seqnos could be updated
perpetually with new times in SeqnoToTimeMapping::Append (if no writes
to DB). That logic was apparently optimized for GetOldestApproximateTime
(now GetProximalTimeBeforeSeqno), which is not used in production, to
the detriment of GetOldestSequenceNum (now GetProximalSeqnoBeforeTime),
which is used in production. (Perhaps plans changed during development?)
This is fixed in Append to optimize for accuracy of
GetProximalSeqnoBeforeTime. (Unit tests added and updated.)
* Related: SeqnoToTimeMapping did not have a clear contract about the
relationships between seqnos and times, just the idea of a rough
correspondence. Now the class description makes it clear that the write
time of each recorded seqno comes before or at the associated time. And
this makes it easier to make clear the contract of each API function.
Some part of these changes has required an expanded test work-around for
the problem (see intended follow-up above) that the DB does not
immediately ensure recent seqnos are covered by its mapping. These
work-arounds will be removed with that planned work.
An apparent compaction bug is revealed in
PrecludeLastLevelTest::RangeDelsCauseFileEndpointsToOverlap, so that
test is disabled. (TODO: create a GitHub issue)
Cosmetic / code safety things (not exhaustive):
* Fix some confusing names.
* `seqno_time_mapping` was used inconsistently in places. Now just
`seqno_to_time_mapping` to correspond to class name.
* Rename confusing `GetOldestSequenceNum` -> `GetProximalSeqnoBeforeTime` and
`GetOldestApproximateTime` -> `GetProximalTimeBeforeSeqno`. Part of
the motivation is that our times and seqnos here have the same
underlying type, so we want to be clear about which is expected
where to avoid mixing.
* Rename `kUnknownSeqnoTime` to `kUnknownTimeBeforeAll` because the
value is a bad choice for unknown if we ever add ProximalAfterBlah
functions.
* Arithmetic on SeqnoTimePair doesn't make sense except for delta
encoding, so use better names / APIs with that in mind.
* (OMG) Don't allow direct comparison between SeqnoTimePair and
SequenceNumber. (There is no checking that it isn't compared against
time by accident.)
* A field name essentially matching the containing class name is a
confusing pattern (`seqno_time_mapping_`).
* Wrap calls to confusing (but useful) upper_bound and lower_bound
functions to have clearer names and more code reuse.
Test Plan:
GetOldestSequenceNum (now GetProximalSeqnoBeforeTime) and
TruncateOldEntries were lacking unit tests, despite both being used
in production (experimental feature). Added those and expanded others.
|
@pdillinger has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
| // comes at or after the sequence number and before the next sequence number, | ||
| // so this example: | ||
| // | ||
| // Seqno: 10, 11, ... 20, 21, ... 30, 31, ... |
There was a problem hiding this comment.
Just an idea, I found this example to be very helpful. Do you think it would make sense to copy this example over to the documentation of GetProximalTimeBeforeSeqno and GetProximalSeqnoBeforeTime each to show some examples of which direction these functions err towards.
| @@ -6380,7 +6380,7 @@ void DBImpl::RecordSeqnoToTimeMapping() { | |||
| bool appended = false; | |||
There was a problem hiding this comment.
Very minor. According to this:
// it is assumed that the recorded time in each pair
// comes at or after the sequence number and before the next sequence number,
And the above documentation, I think above two steps should be swapped in order to be consistent with the documentation?
There was a problem hiding this comment.
Thanks for catching that!
(If we standardized on sampling the time right before the seqno, we would technically need to make GetProximalSeqnoBeforeTime peer back one step further, making the results less accurate.)
jowlyzhang
left a comment
There was a problem hiding this comment.
Thank you for the improvement! I want to use this GetProximalTimeBeforeSeqno function for the iterator's write time implementation. Hope that will use this in production soon :)
cbi42
left a comment
There was a problem hiding this comment.
LGTM, thanks! Feel free to assign the issue about compaction bug to me.
|
@pdillinger has updated the pull request. You must reimport the pull request before landing. |
|
@pdillinger has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
|
@pdillinger merged this pull request in 02443dd. |
Summary: After meta#11905, I am preparing a DBImpl change to ensure all sufficiently recent sequence numbers since Open are covered by SeqnoToTimeMapping. **Intended follow-up** However, there are a number of test changes I want to make prior to that to make it clear I'm not entangling those test changes with possible regressions in production behavior. * Start mock time in the tests well beyond epoch (time 0) so that we aren't normally reaching into pre-history for current time minus preserve/preclude duration. * Majorly clean up BasicSeqnoToTimeMapping to avoid confusing hard-coded bounds on GetProximalTimeBeforeSeqno() results. * There is an unresolved/unexplained issue marked with FIXME that should be investigated when GetProximalTimeBeforeSeqno() is put into production. * MultiCFs test was strangely generating 5 L0 files, four of which would be compacted into an L1, and then letting TTL compaction compact 1@L0+1@L1. Changing the starting time of the tests seemed to mess up the TTL compaction. But I suspect the TTL compaction was unintentional, so I've cut it down to just 4 L0 files, which compacts predictably. * Unrelated: allow ROCKSDB_NO_STACK=1 to skip printing a stack trace on assertion failures. Test Plan: no changes to production code
Summary: After #11905, I am preparing a DBImpl change to ensure all sufficiently recent sequence numbers since Open are covered by SeqnoToTimeMapping. **Intended follow-up** However, there are a number of test changes I want to make prior to that to make it clear that I am not regressing the tests and production behavior at the same time. * Start mock time in the tests well beyond epoch (time 0) so that we aren't normally reaching into pre-history for current time minus the preserve/preclude duration. * Majorly clean up BasicSeqnoToTimeMapping to avoid confusing hard-coded bounds on GetProximalTimeBeforeSeqno() results. * There is an unresolved/unexplained issue marked with FIXME that should be investigated when GetProximalTimeBeforeSeqno() is put into production. * MultiCFs test was strangely generating 5 L0 files, four of which would be compacted into an L1, and then letting TTL compaction compact 1@L0+1@L1. Changing the starting time of the tests seemed to mess up the TTL compaction. But I suspect the TTL compaction was unintentional, so I've cut it down to just 4 L0 files, which compacts predictably. * Unrelated: allow ROCKSDB_NO_STACK=1 to skip printing a stack trace on assertion failures. Pull Request resolved: #11917 Test Plan: no changes to production code Reviewed By: jowlyzhang Differential Revision: D49841436 Pulled By: pdillinger fbshipit-source-id: 753348ace9c548e82bcb77fcc8b2ffb7a6beeb0a
…te level (#12063) Summary: The test failure in #11909 shows that we may compact keys outside of internal key range of penultimate level input files from last level to penultimate level, which can potentially cause overlapping files in the penultimate level. This PR updates the `Compaction::WithinPenultimateLevelOutputRange()` to check internal key range instead of user key. Other fixes: * skip range del sentinels when deciding output level for tiered compaction Pull Request resolved: #12063 Test Plan: - existing unit tests - apply the fix to #11905 and run `./tiered_compaction_test --gtest_filter="*RangeDelsCauseFileEndpointsToOverlap*"` Reviewed By: ajkr Differential Revision: D51288985 Pulled By: cbi42 fbshipit-source-id: 70085db5f5c3b15300bcbc39057d57b83fd9902a
…eta#11905) Summary: This change is before a planned DBImpl change to ensure all sufficiently recent sequence numbers since Open are covered by SeqnoToTimeMapping (bug fix with existing test work-arounds). **Intended follow-up** However, I found enough issues with SeqnoToTimeMapping to warrant this PR first, including very small fixes in DB implementation related to API contract of SeqnoToTimeMapping. Functional fixes / changes: * This fixes some mishandling of boundary cases. For example, if the user decides to stop writing to DB, the last written sequence number would perpetually have its write time updated to "now" and would always be ineligible for migration to cold tier. Part of the problem is that the SeqnoToTimeMapping would return a seqno known to have been written before (immediately or otherwise) the requested time, but compaction_job.cc would include that seqno in the preserve/exclude set. That is fixed (in part) by adding one in compaction_job.cc * That problem was worse because a whole range of seqnos could be updated perpetually with new times in SeqnoToTimeMapping::Append (if no writes to DB). That logic was apparently optimized for GetOldestApproximateTime (now GetProximalTimeBeforeSeqno), which is not used in production, to the detriment of GetOldestSequenceNum (now GetProximalSeqnoBeforeTime), which is used in production. (Perhaps plans changed during development?) This is fixed in Append to optimize for accuracy of GetProximalSeqnoBeforeTime. (Unit tests added and updated.) * Related: SeqnoToTimeMapping did not have a clear contract about the relationships between seqnos and times, just the idea of a rough correspondence. Now the class description makes it clear that the write time of each recorded seqno comes before or at the associated time, to support getting best results for GetProximalSeqnoBeforeTime. And this makes it easier to make clear the contract of each API function. * Update `DBImpl::RecordSeqnoToTimeMapping()` to follow this ordering in gathering samples. Some part of these changes has required an expanded test work-around for the problem (see intended follow-up above) that the DB does not immediately ensure recent seqnos are covered by its mapping. These work-arounds will be removed with that planned work. An apparent compaction bug is revealed in PrecludeLastLevelTest::RangeDelsCauseFileEndpointsToOverlap, so that test is disabled. Filed GitHub issue meta#11909 Cosmetic / code safety things (not exhaustive): * Fix some confusing names. * `seqno_time_mapping` was used inconsistently in places. Now just `seqno_to_time_mapping` to correspond to class name. * Rename confusing `GetOldestSequenceNum` -> `GetProximalSeqnoBeforeTime` and `GetOldestApproximateTime` -> `GetProximalTimeBeforeSeqno`. Part of the motivation is that our times and seqnos here have the same underlying type, so we want to be clear about which is expected where to avoid mixing. * Rename `kUnknownSeqnoTime` to `kUnknownTimeBeforeAll` because the value is a bad choice for unknown if we ever add ProximalAfterBlah functions. * Arithmetic on SeqnoTimePair doesn't make sense except for delta encoding, so use better names / APIs with that in mind. * (OMG) Don't allow direct comparison between SeqnoTimePair and SequenceNumber. (There is no checking that it isn't compared against time by accident.) * A field name essentially matching the containing class name is a confusing pattern (`seqno_time_mapping_`). * Wrap calls to confusing (but useful) upper_bound and lower_bound functions to have clearer names and more code reuse. Pull Request resolved: meta#11905 Test Plan: GetOldestSequenceNum (now GetProximalSeqnoBeforeTime) and TruncateOldEntries were lacking unit tests, despite both being used in production (experimental feature). Added those and expanded others. Reviewed By: jowlyzhang Differential Revision: D49755592 Pulled By: pdillinger fbshipit-source-id: f72a3baac74d24b963c77e538bba89a7fc8dce51
Summary: After meta#11905, I am preparing a DBImpl change to ensure all sufficiently recent sequence numbers since Open are covered by SeqnoToTimeMapping. **Intended follow-up** However, there are a number of test changes I want to make prior to that to make it clear that I am not regressing the tests and production behavior at the same time. * Start mock time in the tests well beyond epoch (time 0) so that we aren't normally reaching into pre-history for current time minus the preserve/preclude duration. * Majorly clean up BasicSeqnoToTimeMapping to avoid confusing hard-coded bounds on GetProximalTimeBeforeSeqno() results. * There is an unresolved/unexplained issue marked with FIXME that should be investigated when GetProximalTimeBeforeSeqno() is put into production. * MultiCFs test was strangely generating 5 L0 files, four of which would be compacted into an L1, and then letting TTL compaction compact 1@L0+1@L1. Changing the starting time of the tests seemed to mess up the TTL compaction. But I suspect the TTL compaction was unintentional, so I've cut it down to just 4 L0 files, which compacts predictably. * Unrelated: allow ROCKSDB_NO_STACK=1 to skip printing a stack trace on assertion failures. Pull Request resolved: meta#11917 Test Plan: no changes to production code Reviewed By: jowlyzhang Differential Revision: D49841436 Pulled By: pdillinger fbshipit-source-id: 753348ace9c548e82bcb77fcc8b2ffb7a6beeb0a
…te level (meta#12063) Summary: The test failure in meta#11909 shows that we may compact keys outside of internal key range of penultimate level input files from last level to penultimate level, which can potentially cause overlapping files in the penultimate level. This PR updates the `Compaction::WithinPenultimateLevelOutputRange()` to check internal key range instead of user key. Other fixes: * skip range del sentinels when deciding output level for tiered compaction Pull Request resolved: meta#12063 Test Plan: - existing unit tests - apply the fix to meta#11905 and run `./tiered_compaction_test --gtest_filter="*RangeDelsCauseFileEndpointsToOverlap*"` Reviewed By: ajkr Differential Revision: D51288985 Pulled By: cbi42 fbshipit-source-id: 70085db5f5c3b15300bcbc39057d57b83fd9902a
Summary:
This change is before a planned DBImpl change to ensure all sufficiently recent sequence numbers since Open are covered by SeqnoToTimeMapping (bug fix with existing test work-arounds). Intended follow-up
However, I found enough issues with SeqnoToTimeMapping to warrant this PR first, including very small fixes in DB implementation related to API contract of SeqnoToTimeMapping.
Functional fixes / changes:
DBImpl::RecordSeqnoToTimeMapping()to follow this ordering in gathering samples.Some part of these changes has required an expanded test work-around for the problem (see intended follow-up above) that the DB does not immediately ensure recent seqnos are covered by its mapping. These work-arounds will be removed with that planned work.
An apparent compaction bug is revealed in
PrecludeLastLevelTest::RangeDelsCauseFileEndpointsToOverlap, so that test is disabled. Filed GitHub issue #11909
Cosmetic / code safety things (not exhaustive):
seqno_time_mappingwas used inconsistently in places. Now justseqno_to_time_mappingto correspond to class name.GetOldestSequenceNum->GetProximalSeqnoBeforeTimeandGetOldestApproximateTime->GetProximalTimeBeforeSeqno. Part of the motivation is that our times and seqnos here have the same underlying type, so we want to be clear about which is expected where to avoid mixing.kUnknownSeqnoTimetokUnknownTimeBeforeAllbecause the value is a bad choice for unknown if we ever add ProximalAfterBlah functions.seqno_time_mapping_).Test Plan:
GetOldestSequenceNum (now GetProximalSeqnoBeforeTime) and TruncateOldEntries were lacking unit tests, despite both being used in production (experimental feature). Added those and expanded others.