Skip to content

Commit 9a92c62

Browse files
rvu1024blinkov
authored andcommitted
Revert code with races in metadata loading
commit_hash:b1c25fd6fb86530c9b46b7e8f57e14df530e160e
1 parent aaecd86 commit 9a92c62

File tree

1 file changed

+49
-50
lines changed

1 file changed

+49
-50
lines changed

yt/yql/providers/yt/gateway/native/yql_yt_native.cpp

Lines changed: 49 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
#include <util/system/execpath.h>
6868
#include <util/system/guard.h>
6969
#include <util/system/shellcommand.h>
70+
#include <util/system/mutex.h>
7071
#include <util/ysaveload.h>
7172

7273
#include <algorithm>
@@ -2811,76 +2812,73 @@ class TYtNativeGateway : public IYtGateway {
28112812
TTableInfoResult& result)
28122813
{
28132814
TVector<NYT::TNode> attributes(tables.size());
2814-
TVector<TMaybe<NYT::TNode>> linkAttributes(tables.size());
2815+
NSorted::TSimpleMap<size_t, TString> requestSchemasIdxs;
28152816
{
2817+
TMutex lock;
28162818
auto batchGet = tx->CreateBatchRequest();
28172819
TVector<TFuture<void>> batchRes(Reserve(idxs.size()));
28182820
for (auto& idx: idxs) {
2819-
batchRes.push_back(batchGet->Get(tables[idx.first].Table() + "&/@").Apply(
2820-
[&attributes, &linkAttributes, idx] (const TFuture<NYT::TNode>& res) {
2821-
try {
2822-
NYT::TNode attrs = res.GetValue();
2823-
auto type = GetTypeFromAttributes(attrs, false);
2824-
if (type == "link") {
2825-
linkAttributes[idx.first] = attrs;
2826-
} else {
2827-
attributes[idx.first] = attrs;
2821+
batchRes.push_back(batchGet->Get(idx.second + "/@").Apply([&attributes, &requestSchemasIdxs, &lock, idx] (const TFuture<NYT::TNode>& res) {
2822+
attributes[idx.first] = res.GetValue();
2823+
if (attributes[idx.first].HasKey("schema") && attributes[idx.first]["schema"].IsEntity()) {
2824+
with_lock (lock) {
2825+
requestSchemasIdxs.push_back(idx);
28282826
}
2829-
} catch (const TErrorResponse& e) {
2830-
// Yt returns NoSuchTransaction as inner issue for ResolveError
2831-
if (!e.IsResolveError() || e.IsNoSuchTransaction()) {
2832-
throw;
2833-
}
2834-
// Just ignore. Original table path may be deleted at this time
28352827
}
28362828
}));
28372829
}
28382830
batchGet->ExecuteBatch();
28392831
WaitExceptionOrAll(batchRes).GetValue();
28402832
}
2841-
2833+
if (!requestSchemasIdxs.empty()) {
2834+
YQL_CLOG(INFO, ProviderYt) << "Additional request of @schema for " << requestSchemasIdxs.size() << " table(s)";
2835+
auto batchGet = tx->CreateBatchRequest();
2836+
TVector<TFuture<void>> batchRes(Reserve(requestSchemasIdxs.size()));
2837+
auto getOpts = TGetOptions()
2838+
.AttributeFilter(TAttributeFilter()
2839+
.AddAttribute("schema")
2840+
);
2841+
for (auto& idx: requestSchemasIdxs) {
2842+
batchRes.push_back(batchGet->Get(idx.second + "/@", getOpts).Apply([&attributes, idx] (const TFuture<NYT::TNode>& res) {
2843+
attributes[idx.first]["schema"] = res.GetValue().At("schema");
2844+
}));
2845+
}
2846+
batchGet->ExecuteBatch();
2847+
WaitExceptionOrAll(batchRes).GetValue();
2848+
}
28422849
{
2843-
auto schemaAttrFilter = TAttributeFilter().AddAttribute("schema");
2844-
TVector<NYT::TNode> schemas(tables.size());
2845-
28462850
auto batchGet = tx->CreateBatchRequest();
28472851
TVector<TFuture<void>> batchRes;
2848-
for (auto& idx : idxs) {
2849-
batchRes.push_back(batchGet->Get(tables[idx.first].Table() + "/@", TGetOptions().AttributeFilter(schemaAttrFilter))
2850-
.Apply([idx, &schemas] (const TFuture<NYT::TNode>& res) {
2851-
try {
2852-
schemas[idx.first] = res.GetValue();
2853-
} catch (const TErrorResponse& e) {
2854-
// Yt returns NoSuchTransaction as inner issue for ResolveError
2855-
if (!e.IsResolveError() || e.IsNoSuchTransaction()) {
2856-
throw;
2857-
}
2858-
// Just ignore. Original table path may be deleted at this time
2859-
}
2860-
}));
2861-
2862-
if (linkAttributes[idx.first]) {
2863-
const auto& linkAttr = *linkAttributes[idx.first];
2864-
batchRes.push_back(batchGet->Get(idx.second + "/@").Apply(
2865-
[idx, &linkAttr, &attributes](const TFuture<NYT::TNode>& f) {
2852+
auto getOpts = TGetOptions()
2853+
.AttributeFilter(TAttributeFilter()
2854+
.AddAttribute("type")
2855+
.AddAttribute(TString{QB2Premapper})
2856+
.AddAttribute(TString{YqlRowSpecAttribute})
2857+
);
2858+
for (auto& idx: idxs) {
2859+
batchRes.push_back(batchGet->Get(tables[idx.first].Table() + "&/@", getOpts).Apply([idx, &attributes](const TFuture<NYT::TNode>& f) {
2860+
try {
28662861
NYT::TNode attrs = f.GetValue();
2867-
attributes[idx.first] = attrs;
2868-
// override some attributes by the link ones
2869-
if (linkAttr.HasKey(QB2Premapper)) {
2870-
attributes[idx.first][QB2Premapper] = linkAttr[QB2Premapper];
2862+
if (GetTypeFromAttributes(attrs, false) == "link") {
2863+
// override some attributes by the link ones
2864+
if (attrs.HasKey(QB2Premapper)) {
2865+
attributes[idx.first][QB2Premapper] = attrs[QB2Premapper];
2866+
}
2867+
if (attrs.HasKey(YqlRowSpecAttribute)) {
2868+
attributes[idx.first][YqlRowSpecAttribute] = attrs[YqlRowSpecAttribute];
2869+
}
28712870
}
2872-
if (linkAttr.HasKey(YqlRowSpecAttribute)) {
2873-
attributes[idx.first][YqlRowSpecAttribute] = linkAttr[YqlRowSpecAttribute];
2871+
} catch (const TErrorResponse& e) {
2872+
// Yt returns NoSuchTransaction as inner issue for ResolveError
2873+
if (!e.IsResolveError() || e.IsNoSuchTransaction()) {
2874+
throw;
28742875
}
2875-
}));
2876-
}
2876+
// Just ignore. Original table path may be deleted at this time
2877+
}
2878+
}));
28772879
}
28782880
batchGet->ExecuteBatch();
28792881
WaitExceptionOrAll(batchRes).GetValue();
2880-
2881-
for (auto& idx: idxs) {
2882-
attributes[idx.first]["schema"] = schemas[idx.first]["schema"];
2883-
}
28842882
}
28852883

28862884
auto batchGet = tx->CreateBatchRequest();
@@ -2912,6 +2910,7 @@ class TYtNativeGateway : public IYtGateway {
29122910
}
29132911

29142912
statInfo->Id = attrs["id"].AsString();
2913+
YQL_ENSURE(statInfo->Id == TStringBuf(idx.second).Skip(1));
29152914
statInfo->TableRevision = attrs["revision"].IntCast<ui64>();
29162915
statInfo->Revision = GetContentRevision(attrs);
29172916

0 commit comments

Comments
 (0)