Skip to content

Commit

Permalink
Merge pull request #7832 from abhijat/prevent-trimming-segment-on-rem…
Browse files Browse the repository at this point in the history
…ote-partition-stop

cloud_storage: filter stopped segments on trim
  • Loading branch information
abhijat authored Dec 20, 2022
2 parents b211fb0 + 0b4f769 commit faab40f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/v/cloud_storage/materialized_segments.cc
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,10 @@ void materialized_segments::trim_segments(std::optional<size_t> target_free) {
*/
void materialized_segments::maybe_trim_segment(
materialized_segment_state& st, offload_list_t& to_offload) {
if (st.segment->is_stopped()) {
return;
}

if (st.segment->download_in_progress()) {
return;
}
Expand All @@ -309,8 +313,19 @@ void materialized_segments::maybe_trim_segment(
// this will delete and unlink the object from
// _materialized collection
if (st.parent) {
to_offload.push_back(
std::make_pair(st.parent.get(), st.base_rp_offset()));
if (
st.parent->state()
== remote_partition::partition_state::running) {
to_offload.push_back(
std::make_pair(st.parent.get(), st.base_rp_offset()));
} else {
vlog(
cst_log.info,
"Materialized segment {} offset {} not offloaded, partition "
"is stopping",
st.ntp(),
st.base_rp_offset());
}
} else {
// This cannot happen, because materialized_segment_state
// is only instantiated by remote_partition and will
Expand Down
2 changes: 2 additions & 0 deletions src/v/cloud_storage/remote_partition.cc
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,7 @@ remote_partition::aborted_transactions(offset_range offsets) {
}

ss::future<> remote_partition::stop() {
_state = partition_state::stopping;
vlog(_ctxlog.debug, "remote partition stop {} segments", _segments.size());

co_await _gate.close();
Expand All @@ -597,6 +598,7 @@ ss::future<> remote_partition::stop() {
// stopping readers is fast, the queue is not usually long, and destroying
// partitions is relatively infrequent.
co_await materialized().flush_evicted();
_state = partition_state::stopped;
}

/// Return reader back to segment_state
Expand Down
5 changes: 5 additions & 0 deletions src/v/cloud_storage/remote_partition.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ class remote_partition
/// Hook for materialized_segment to notify us when a segment is evicted
void offload_segment(model::offset);

enum class partition_state { running, stopping, stopped };
partition_state state() const { return _state; }

private:
friend struct materialized_segment_state;

Expand Down Expand Up @@ -185,6 +188,8 @@ class remote_partition

segment_map_t _segments;
partition_probe _probe;

partition_state _state{partition_state::running};
};

} // namespace cloud_storage

0 comments on commit faab40f

Please sign in to comment.