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

Offset tracker invariants #17381

Merged
merged 5 commits into from
Mar 26, 2024

Conversation

WillemKauf
Copy link
Contributor

@WillemKauf WillemKauf commented Mar 25, 2024

Changed storage::segment::offset_tracker from a struct to a class, made data fields private.

Added public "getter" and "setter" functions in order to vassert the necessary offset invariants.

Also packaged in some very minor changes (see commit 85d979bd79f7a9e41cb83237673f483c25e02ac1), including

  • removal of superfluous partition_probe forward declaration in cloud_storage/fwd.h
  • correct usage of static constexpr variable in cluster/cloud_storage_size_reducer.h
  • Unnecessary virtual specifier on a member function of a class marked final in cluster/id_allocator.h

Backports Required

  • none - not a bug fix
  • none - this is a backport
  • none - issue does not exist in previous branches
  • none - papercut/not impactful enough to backport
  • v23.3.x
  • v23.2.x

Release Notes

  • None

@vbotbuildovich
Copy link
Collaborator

vbotbuildovich commented Mar 26, 2024

Copy link
Member

@dotnwat dotnwat left a comment

Choose a reason for hiding this comment

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

looks good to me. i think a little commit history clean up is all that is needed.

src/v/cluster/cloud_storage_size_reducer.h Show resolved Hide resolved
src/v/archival/archival_policy.cc Show resolved Hide resolved
(set_offset_impl(std::forward<Ts>(ts)), ...);
vassert(
_committed_offset <= _stable_offset && _stable_offset <= _dirty_offset,
"Must maintain offset invariant: committed <= stable <= dirty");
Copy link
Member

Choose a reason for hiding this comment

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

print out the values in the assertion failure to aid in debugging

, _dirty_offset(model::prev_offset(base)) {}

template<typename... Ts>
void set_offsets(Ts&&... ts) {
Copy link
Member

Choose a reason for hiding this comment

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

nit: this looks fine, but I think you can remove all the forwarding references and pass around T values. the model::offset types are just a single integer / trivially copyable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fair! Forwarding references changed to pass by value.

@@ -285,7 +285,9 @@ static ss::future<std::optional<std::error_code>> get_file_range(
upl->final_file_offset = fsize;
upl->base_timestamp = segment->index().base_timestamp();
upl->max_timestamp = segment->index().max_timestamp();
if (!end_inclusive && segment->offsets().get_base_offset() == begin_inclusive) {
Copy link
Member

Choose a reason for hiding this comment

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

the two reformatting commits can be squashed together.

Comment on lines 89 to 93
static_assert(sizeof(T) && false, "Invalid offset type");
static_assert(always_false_v<T>, "Invalid offset type");
Copy link
Member

Choose a reason for hiding this comment

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

can be squashed back into the original commit

Comment on lines 527 to 529
//_tracker.committed_offset = _idx.max_offset();
//_tracker.stable_offset = _idx.max_offset();
//_tracker.dirty_offset = _idx.max_offset();
Copy link
Member

Choose a reason for hiding this comment

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

can be squashed back into the original commit

storage_resources resources;
};

TEST_F(segment_offset_tracker_fixture, get_and_set_offsets) {
Copy link
Member

Choose a reason for hiding this comment

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

nice

cluster: remove unnecessary virtual specifier
cloud_storage: removal of extra forward declaration
Comment on lines +77 to +81
model::term_id get_term() const { return _term; }
model::offset get_base_offset() const { return _base_offset; }
model::offset get_committed_offset() const { return _committed_offset; }
model::offset get_stable_offset() const { return _stable_offset; }
model::offset get_dirty_offset() const { return _dirty_offset; }
Copy link
Member

Choose a reason for hiding this comment

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

these accessors need to be in the previous commit so that the previous commit will compile.

@dotnwat dotnwat merged commit 908d9dc into redpanda-data:dev Mar 26, 2024
17 checks passed
set_offsets(t);
}

model::term_id get_term() const { return _term; }
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: get_ prefix is just noise to me. I suggest we name them just term(), base_offest() in the future. @dotnwat wdyt?

Copy link
Member

Choose a reason for hiding this comment

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

@nvartolomei yes, I think get_ is too verbose. If we want a prefix, I think using it for set_ is better as it is generally used far less.

Maybe bring it up in core storage and we can agree on a style and then change this depending on the outcome?

, _dirty_offset(model::prev_offset(base)) {}

template<typename... Ts>
void set_offsets(Ts... ts) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Neat & clever! 👍

Copy link
Contributor

Choose a reason for hiding this comment

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

Shall we also have a mean of enforcing that offsets don't move backwards? Unless it is a call to truncate?

@WillemKauf WillemKauf deleted the offset_tracker_invariants branch April 13, 2024 03:03
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