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

Fix leak of PartitionChooserActor #4131

Merged
merged 1 commit into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class TAbstractPartitionChooserActor: public TActorBootstrapped<TDerived> {
if (TableHelper.Initialize(ctx, SourceId)) {
return true;
}
StartIdle();
StartIdle();
TThis::ReplyError(ErrorCode::BAD_REQUEST, "Bad SourceId", ctx);
return false;
}
Expand All @@ -67,6 +67,8 @@ class TAbstractPartitionChooserActor: public TActorBootstrapped<TDerived> {
auto ctx = TActivationContext::ActorContextFor(SelfId());
TableHelper.CloseKqpSession(ctx);
PartitionHelper.Close(ctx);

TActorBootstrapped<TDerived>::PassAway();
}

bool NeedTable(const NActors::TActorContext& ctx) {
Expand All @@ -78,7 +80,7 @@ class TAbstractPartitionChooserActor: public TActorBootstrapped<TDerived> {
void InitTable(const NActors::TActorContext& ctx) {
TThis::Become(&TThis::StateInitTable);
const auto& pqConfig = AppData(ctx)->PQConfig;
TRACE("InitTable: SourceId="<< SourceId
TRACE("InitTable: SourceId="<< SourceId
<< " TopicsAreFirstClassCitizen=" << pqConfig.GetTopicsAreFirstClassCitizen()
<< " UseSrcIdMetaMappingInFirstClass=" <<pqConfig.GetUseSrcIdMetaMappingInFirstClass());
if (SourceId && pqConfig.GetTopicsAreFirstClassCitizen() && pqConfig.GetUseSrcIdMetaMappingInFirstClass()) {
Expand Down Expand Up @@ -259,14 +261,14 @@ class TAbstractPartitionChooserActor: public TActorBootstrapped<TDerived> {

protected:
void StartIdle() {
TThis::Become(&TThis::StateIdle);
TThis::Become(&TThis::StateIdle);
DEBUG("Start idle");
}

void HandleIdle(TEvPartitionChooser::TEvRefreshRequest::TPtr&, const TActorContext& ctx) {
if (PartitionPersisted) {
SendUpdateRequests(ctx);
}
}
}

STATEFN(StateIdle) {
Expand Down Expand Up @@ -303,7 +305,7 @@ class TAbstractPartitionChooserActor: public TActorBootstrapped<TDerived> {

TThis::Die(ctx);
}


protected:
const TActorId Parent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,10 @@ void TWriteSessionActor::Handle(TEvTicketParser::TEvAuthorizeTicketResult::TPtr&
void TWriteSessionActor::DiscoverPartition(const NActors::TActorContext& ctx) {
State = ES_WAIT_PARTITION;

if (PartitionChooser) {
ctx.Send(PartitionChooser, new TEvents::TEvPoison());
}

std::optional<ui32> preferedPartition = PreferedPartition == Max<ui32>() ? std::nullopt : std::optional(PreferedPartition);
PartitionChooser = ctx.RegisterWithSameMailbox(NPQ::CreatePartitionChooserActor(ctx.SelfID, Config, FullConverter, SourceId, preferedPartition));
}
Expand Down Expand Up @@ -894,7 +898,7 @@ void TWriteSessionActor::HandleWakeup(const TActorContext& ctx) {
ctx.Send(PartitionChooser, new NPQ::TEvPartitionChooser::TEvRefreshRequest());
LastSourceIdUpdate = now + SOURCEID_UPDATE_PERIOD;
}

if (now >= LogSessionDeadline) {
LogSession(ctx);
}
Expand Down
4 changes: 4 additions & 0 deletions ydb/services/persqueue_v1/actors/write_session_actor.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,10 @@ template<bool UseMigrationProtocol>
void TWriteSessionActor<UseMigrationProtocol>::DiscoverPartition(const NActors::TActorContext& ctx) {
State = ES_WAIT_PARTITION;

if (PartitionChooser) {
ctx.Send(PartitionChooser, new TEvents::TEvPoison());
}

std::optional<ui32> preferedPartition = PreferedPartition == Max<ui32>() ? std::nullopt : std::optional(PreferedPartition);
PartitionChooser = ctx.RegisterWithSameMailbox(NPQ::CreatePartitionChooserActor(ctx.SelfID, Config, FullConverter, SourceId, preferedPartition));
}
Expand Down
Loading