Skip to content

LocalDB: low-priority cancellable transactions #15355

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

Merged
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
13 changes: 7 additions & 6 deletions ydb/core/tablet_flat/flat_exec_seat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ namespace NKikimr {
namespace NTabletFlatExecutor {

void TSeat::Complete(const TActorContext& ctx, bool isRW) noexcept {
if (Y_UNLIKELY(IsTerminated())) {
Y_ABORT_UNLESS(!isRW, "Terminating a read-write transaction");
Self->Terminate(TerminationReason, ctx);
Self->TxSpan.EndError("Terminated");
return;
}

NWilson::TSpan span(TWilsonTablet::TabletDetailed, Self->TxSpan.GetTraceId(), "Tablet.Transaction.Complete");
for (auto& callback : OnPersistent) {
callback();
Expand All @@ -15,11 +22,5 @@ namespace NTabletFlatExecutor {
Self->TxSpan.EndOk();
}

void TSeat::Terminate(ETerminationReason reason, const TActorContext& ctx) noexcept {
Self->Terminate(reason, ctx);

Self->TxSpan.EndError("Terminated");
}

} // namespace NTabletFlatExecutor
} // namespace NKikimr
25 changes: 21 additions & 4 deletions ydb/core/tablet_flat/flat_exec_seat.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "tablet_flat_executor.h"
#include "flat_sausagecache.h"

#include <util/generic/intrlist.h>
#include <util/generic/ptr.h>
#include <util/system/hp_timer.h>
#include <ydb/library/actors/wilson/wilson_span.h>
Expand All @@ -12,7 +13,17 @@
namespace NKikimr {
namespace NTabletFlatExecutor {

struct TSeat {
enum class ESeatState {
None,
Pending,
Active,
ActiveLow,
Postponed,
Waiting,
Done,
};

struct TSeat : public TIntrusiveListItem<TSeat> {
using TPinned = THashMap<TLogoBlobID, THashMap<ui32, TIntrusivePtr<TPrivatePageCachePinPad>>>;

TSeat(const TSeat&) = delete;
Expand All @@ -30,9 +41,11 @@ namespace NTabletFlatExecutor {
out << "}";
}

void Complete(const TActorContext& ctx, bool isRW) noexcept;
bool IsTerminated() const {
return TerminationReason != ETerminationReason::None;
}

void Terminate(ETerminationReason reason, const TActorContext& ctx) noexcept;
void Complete(const TActorContext& ctx, bool isRW) noexcept;

void StartEnqueuedSpan() noexcept {
WaitingSpan = NWilson::TSpan(TWilsonTablet::TabletDetailed, Self->TxSpan.GetTraceId(), "Tablet.Transaction.Enqueued");
Expand All @@ -54,7 +67,7 @@ namespace NTabletFlatExecutor {
return Self->TxSpan.GetTraceId();
}

const ui64 UniqID = Max<ui64>();
const ui64 UniqID;
const TAutoPtr<ITransaction> Self;
NWilson::TSpan WaitingSpan;
ui64 Retries = 0;
Expand All @@ -74,6 +87,10 @@ namespace NTabletFlatExecutor {
ui32 NotEnoughMemoryCount = 0;
ui64 TaskId = 0;

ESeatState State = ESeatState::Done;
bool LowPriority = false;
bool Cancelled = false;

TAutoPtr<TMemoryToken> AttachedMemory;
TIntrusivePtr<TMemoryGCToken> CapturedMemory;
TVector<std::function<void()>> OnPersistent;
Expand Down
Loading
Loading