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 snapshot control in case sys view requests #7824

Merged
merged 3 commits into from
Aug 15, 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
45 changes: 30 additions & 15 deletions ydb/core/tx/columnshard/inflight_request_tracker.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "inflight_request_tracker.h"
#include "columnshard_impl.h"
#include "columnshard_schema.h"
#include "inflight_request_tracker.h"

#include "data_sharing/common/transactions/tx_extension.h"
#include "engines/column_engine.h"
#include "engines/reader/plain_reader/constructor/read_metadata.h"
Expand All @@ -9,28 +10,27 @@
namespace NKikimr::NColumnShard {

void TInFlightReadsTracker::RemoveInFlightRequest(ui64 cookie, const NOlap::TVersionedIndex* /*index*/, const TInstant now) {
Y_ABORT_UNLESS(RequestsMeta.contains(cookie), "Unknown request cookie %" PRIu64, cookie);
const auto& readMetaList = RequestsMeta[cookie];
auto it = RequestsMeta.find(cookie);
AFL_VERIFY(it != RequestsMeta.end())("cookie", cookie);
const auto& readMetaList = it->second;

for (const auto& readMetaBase : readMetaList) {
NOlap::NReader::NPlain::TReadMetadata::TConstPtr readMeta = std::dynamic_pointer_cast<const NOlap::NReader::NPlain::TReadMetadata>(readMetaBase);

if (!readMeta) {
continue;
}
{
auto it = SnapshotsLive.find(readMeta->GetRequestSnapshot());
auto it = SnapshotsLive.find(readMetaBase->GetRequestSnapshot());
AFL_VERIFY(it != SnapshotsLive.end());
if (it->second.DelRequest(cookie, now)) {
SnapshotsLive.erase(it);
Counters->OnSnapshotsInfo(SnapshotsLive.size(), GetSnapshotToClean());
}
}

auto insertStorage = StoragesManager->GetInsertOperator();
auto tracker = insertStorage->GetBlobsTracker();
for (const auto& committedBlob : readMeta->CommittedBlobs) {
tracker->FreeBlob(committedBlob.GetBlobRange().GetBlobId());
if (NOlap::NReader::NPlain::TReadMetadata::TConstPtr readMeta =
std::dynamic_pointer_cast<const NOlap::NReader::NPlain::TReadMetadata>(readMetaBase)) {
auto insertStorage = StoragesManager->GetInsertOperator();
auto tracker = insertStorage->GetBlobsTracker();
for (const auto& committedBlob : readMeta->CommittedBlobs) {
tracker->FreeBlob(committedBlob.GetBlobRange().GetBlobId());
}
}
}

Expand Down Expand Up @@ -85,8 +85,7 @@ class TTransactionSavePersistentSnapshots: public NOlap::NDataSharing::TExtended
NColumnShard::TColumnShard* self, std::set<NOlap::TSnapshot>&& saveSnapshots, std::set<NOlap::TSnapshot>&& removeSnapshots)
: TBase(self)
, SaveSnapshots(std::move(saveSnapshots))
, RemoveSnapshots(std::move(removeSnapshots))
{
, RemoveSnapshots(std::move(removeSnapshots)) {
AFL_VERIFY(SaveSnapshots.size() || RemoveSnapshots.size());
}
};
Expand Down Expand Up @@ -138,4 +137,20 @@ bool TInFlightReadsTracker::LoadFromDatabase(NTable::TDatabase& tableDB) {
return true;
}

NKikimr::TConclusion<ui64> TInFlightReadsTracker::AddInFlightRequest(
NOlap::NReader::TReadMetadataBase::TConstPtr readMeta, const NOlap::TVersionedIndex* index) {
const ui64 cookie = NextCookie++;
auto it = SnapshotsLive.find(readMeta->GetRequestSnapshot());
if (it == SnapshotsLive.end()) {
it = SnapshotsLive.emplace(readMeta->GetRequestSnapshot(), TSnapshotLiveInfo::BuildFromRequest(readMeta->GetRequestSnapshot())).first;
Counters->OnSnapshotsInfo(SnapshotsLive.size(), GetSnapshotToClean());
}
it->second.AddRequest(cookie);
auto status = AddToInFlightRequest(cookie, readMeta, index);
if (!status) {
return status;
}
return cookie;
}

} // namespace NKikimr::NColumnShard
16 changes: 1 addition & 15 deletions ydb/core/tx/columnshard/inflight_request_tracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,21 +92,7 @@ class TInFlightReadsTracker {

// Returns a unique cookie associated with this request
[[nodiscard]] TConclusion<ui64> AddInFlightRequest(
NOlap::NReader::TReadMetadataBase::TConstPtr readMeta, const NOlap::TVersionedIndex* index) {
const ui64 cookie = NextCookie++;
auto it = SnapshotsLive.find(readMeta->GetRequestSnapshot());
if (it == SnapshotsLive.end()) {
it =
SnapshotsLive.emplace(readMeta->GetRequestSnapshot(), TSnapshotLiveInfo::BuildFromRequest(readMeta->GetRequestSnapshot())).first;
Counters->OnSnapshotsInfo(SnapshotsLive.size(), GetSnapshotToClean());
}
it->second.AddRequest(cookie);
auto status = AddToInFlightRequest(cookie, readMeta, index);
if (!status) {
return status;
}
return cookie;
}
NOlap::NReader::TReadMetadataBase::TConstPtr readMeta, const NOlap::TVersionedIndex* index);

void RemoveInFlightRequest(ui64 cookie, const NOlap::TVersionedIndex* index, const TInstant now);

Expand Down
Loading