Skip to content

Commit

Permalink
cluster: best-effort quiesce of archiver on leadership transfer
Browse files Browse the repository at this point in the history
This substantially reduces the probability of leaving orphaned
objects in the object store when partitions change leadership
under load, e.g. during upgrades or leader balancing.

This fixes a test failure that indirectly detects orphan
objects by checking that topic deletion clears all objects.

Fixes redpanda-data#8496
  • Loading branch information
jcsp committed Feb 1, 2023
1 parent 97e8a01 commit 8f19de2
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/v/cluster/partition.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include "prometheus/prometheus_sanitize.h"
#include "raft/types.h"

#include <seastar/util/defer.hh>

namespace cluster {

static bool is_id_allocator_topic(model::ntp ntp) {
Expand Down Expand Up @@ -601,7 +603,8 @@ ss::future<std::error_code>
partition::transfer_leadership(std::optional<model::node_id> target) {
vlog(
clusterlog.debug,
"Transferring leadership to {}",
"Transferring {} leadership to {}",
ntp(),
target.value_or(model::node_id{-1}));

// Some state machines need a preparatory phase to efficiently transfer
Expand All @@ -613,6 +616,23 @@ partition::transfer_leadership(std::optional<model::node_id> target) {
} else if (_tm_stm) {
stm_prepare_lock = co_await _tm_stm->prepare_transfer_leadership();
}

std::optional<ss::deferred_action<std::function<void()>>> complete_archiver;
if (_archiver) {
complete_archiver.emplace(
[a = &(*_archiver)]() { a->complete_transfer_leadership(); });
bool archiver_clean = co_await _archiver->prepare_transfer_leadership(
5s);
if (!archiver_clean) {
vlog(
clusterlog.error,
"Timed out waiting for {} uploads to complete before "
"transferring "
"leadership: proceeding anyway",
ntp());
}
}

co_return co_await _raft->do_transfer_leadership(target);
}

Expand Down

0 comments on commit 8f19de2

Please sign in to comment.