Skip to content

VIEW: minor refactoring in import #14664

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 1 commit into from
Feb 17, 2025
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
42 changes: 31 additions & 11 deletions ydb/core/tx/schemeshard/schemeshard_import__create.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,35 @@ using namespace NTabletFlatExecutor;

namespace {

bool IsWaiting(const TImportInfo::TItem& item) {
return item.State == TImportInfo::EState::Waiting;
using TItem = TImportInfo::TItem;
using EState = TImportInfo::EState;

bool IsWaiting(const TItem& item) {
return item.State == EState::Waiting;
}

THashSet<EState> CollectItemStates(const TVector<TItem>& items) {
THashSet<EState> itemStates;
for (const auto& item : items) {
itemStates.emplace(item.State);
}
return itemStates;
}

bool AllDone(const THashSet<EState>& itemStates) {
return AllOf(itemStates, [](EState state) { return state == EState::Done; });
}

bool IsDoneOrWaiting(const TImportInfo::TItem& item) {
return TImportInfo::TItem::IsDone(item) || IsWaiting(item);
bool AllWaiting(const THashSet<EState>& itemStates) {
return AllOf(itemStates, [](EState state) { return state == EState::Waiting; });
}

bool AllDoneOrWaiting(const THashSet<EState>& itemStates) {
return AllOf(itemStates, [](EState state) { return state == EState::Done || state == EState::Waiting; });
}

// the item is to be created by query, i.e. it is not a table
bool IsCreatedByQuery(const TImportInfo::TItem& item) {
bool IsCreatedByQuery(const TItem& item) {
return !item.CreationQuery.empty();
}

Expand Down Expand Up @@ -904,13 +923,13 @@ struct TSchemeShard::TImport::TTxProgress: public TSchemeShard::TXxport::TTxBase
// Scheme error happens when the view depends on a table (or a view) that is not yet imported.
// Instead of tracking view dependencies, we simply retry the creation of the view later.
item.State = EState::Waiting;
Self->PersistImportItemState(db, importInfo, message.ItemIdx);

if (AllOf(importInfo->Items, IsWaiting)) {
// All items are waiting? Cancel the import, or we will end up waiting indefinitely.
const auto itemStates = CollectItemStates(importInfo->Items);
if (AllWaiting(itemStates)) {
// Cancel the import, or we will end up waiting indefinitely.
return CancelAndPersist(db, importInfo, message.ItemIdx, error, "creation query failed");
}

Self->PersistImportItemState(db, importInfo, message.ItemIdx);
return;
}

Expand Down Expand Up @@ -1218,10 +1237,11 @@ struct TSchemeShard::TImport::TTxProgress: public TSchemeShard::TXxport::TTxBase
return SendNotificationsIfFinished(importInfo);
}

if (AllOf(importInfo->Items, &TImportInfo::TItem::IsDone)) {
const auto itemStates = CollectItemStates(importInfo->Items);
if (AllDone(itemStates)) {
importInfo->State = EState::Done;
importInfo->EndTime = TAppData::TimeProvider->Now();
} else if (AllOf(importInfo->Items, IsDoneOrWaiting)) {
} else if (AllDoneOrWaiting(itemStates)) {
RetryViewsCreation(importInfo, db, ctx);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class TSchemeQueryExecutor: public TActorBootstrapped<TSchemeQueryExecutor> {
void Finish(Ydb::StatusIds::StatusCode status, std::variant<TString, NKikimrSchemeOp::TModifyScheme> result) {
auto logMessage = TStringBuilder() << "TSchemeQueryExecutor Reply"
<< ", self: " << SelfId()
<< ", success: " << status;
<< ", status: " << status;
LOG_I(logMessage);

std::visit([&]<typename T>(T& value) {
Expand Down
Loading