Skip to content

Commit e1b310a

Browse files
authored
Make permissions required in import if they were exported (#19331)
1 parent 89775a3 commit e1b310a

File tree

6 files changed

+52
-6
lines changed

6 files changed

+52
-6
lines changed

ydb/core/backup/common/metadata.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,26 @@ const std::optional<std::vector<TChangefeedMetadata>>& TMetadata::GetChangefeeds
3434
return Changefeeds;
3535
}
3636

37+
void TMetadata::SetEnablePermissions(bool enablePermissions) {
38+
EnablePermissions = enablePermissions;
39+
}
40+
41+
bool TMetadata::HasEnablePermissions() const {
42+
return EnablePermissions.has_value();
43+
}
44+
45+
bool TMetadata::GetEnablePermissions() const {
46+
return *EnablePermissions;
47+
}
48+
3749
TString TMetadata::Serialize() const {
3850
NJson::TJsonMap m;
3951
if (Version.Defined()) {
4052
m["version"] = *Version;
4153
}
54+
if (EnablePermissions) {
55+
m["permissions"] = static_cast<int>(*EnablePermissions);
56+
}
4257

4358
NJson::TJsonArray fullBackups;
4459
for (const auto& [tp, b] : FullBackups) {
@@ -76,6 +91,11 @@ TMetadata TMetadata::Deserialize(const TString& metadata) {
7691
result.Version = value.GetUIntegerSafe();
7792
}
7893

94+
if (json.Has("permissions")) {
95+
const int val = json["permissions"].GetInteger();
96+
result.EnablePermissions = val != 0;
97+
}
98+
7999
if (json.Has("changefeeds")) {
80100
// Changefeeds can be absent in older versions of metadata
81101
result.Changefeeds.emplace(); // explicitly say that the listing of changefeeds is throgh metadata

ydb/core/backup/common/metadata.h

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,30 @@ class TMetadata {
5555
void AddChangefeed(const TChangefeedMetadata& changefeed);
5656
const std::optional<std::vector<TChangefeedMetadata>>& GetChangefeeds() const;
5757

58+
void SetEnablePermissions(bool enablePermissions = true);
59+
bool HasEnablePermissions() const;
60+
bool GetEnablePermissions() const;
61+
5862
TString Serialize() const;
5963
static TMetadata Deserialize(const TString& metadata);
64+
6065
private:
6166
TString ConsistencyKey;
6267
TMap<TVirtualTimestamp, TFullBackupMetadata::TPtr> FullBackups;
6368
TMap<TVirtualTimestamp, TLogMetadata::TPtr> Logs;
64-
std::optional<std::vector<TChangefeedMetadata>> Changefeeds;
6569
TMaybeFail<ui64> Version;
70+
71+
// Changefeeds:
72+
// Undefined (previous versions): we don't know if we see the export with changefeeds or without them, so list suitable S3 files to find out all changefeeds
73+
// []: The export has no changefeeds
74+
// [...]: The export must have all changefeeds listed here
75+
std::optional<std::vector<TChangefeedMetadata>> Changefeeds;
76+
77+
// EnablePermissions:
78+
// Undefined (previous versions): we don't know if we see the export with permissions or without them, so check S3 for the permissions file existence
79+
// 0: The export has no permissions
80+
// 1: The export must have permissions file
81+
std::optional<bool> EnablePermissions;
6682
};
6783

6884
TString NormalizeItemPath(const TString& path);

ydb/core/tx/datashard/export_s3_uploader.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -946,6 +946,7 @@ IActor* TS3Export::CreateUploader(const TActorId& dataShard, ui64 txId) const {
946946

947947
TMetadata metadata;
948948
metadata.SetVersion(Task.GetEnableChecksums() ? 1 : 0);
949+
metadata.SetEnablePermissions(Task.GetEnablePermissions());
949950

950951
TVector<TChangefeedExportDescriptions> changefeeds;
951952
if (AppData()->FeatureFlags.GetEnableChangefeedsExport()) {

ydb/core/tx/schemeshard/schemeshard_export__create.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,7 @@ struct TSchemeShard::TExport::TTxProgress: public TSchemeShard::TXxport::TTxBase
387387
// to do: enable view checksum validation
388388
constexpr bool EnableChecksums = false;
389389
metadata.SetVersion(EnableChecksums ? 1 : 0);
390+
metadata.SetEnablePermissions(exportInfo.EnablePermissions);
390391

391392
TMaybe<NBackup::TEncryptionIV> iv;
392393
if (exportSettings.has_encryption_settings()) {

ydb/core/tx/schemeshard/schemeshard_import_getters.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,13 @@ class TSchemeGetter: public TGetterFromS3<TSchemeGetter> {
373373
<< ", result# " << result);
374374

375375
if (NoObjectFound(result.GetError().GetErrorType())) {
376-
StartDownloadingChangefeeds(); // permissions are optional
376+
Y_ABORT_UNLESS(ItemIdx < ImportInfo->Items.size());
377+
auto& item = ImportInfo->Items.at(ItemIdx);
378+
if (!item.Metadata.HasEnablePermissions()) {
379+
StartDownloadingChangefeeds(); // permissions are optional if we don't know if they were created during export
380+
} else {
381+
return Reply(Ydb::StatusIds::BAD_REQUEST, "No permissions file found");
382+
}
377383
return;
378384
} else if (!CheckResult(result, "HeadObject")) {
379385
return;
@@ -441,6 +447,9 @@ class TSchemeGetter: public TGetterFromS3<TSchemeGetter> {
441447
if (item.Metadata.HasVersion() && item.Metadata.GetVersion() == 0) {
442448
NeedValidateChecksums = false;
443449
}
450+
if (item.Metadata.HasEnablePermissions() && !item.Metadata.GetEnablePermissions()) {
451+
NeedDownloadPermissions = false;
452+
}
444453

445454
auto nextStep = [this]() {
446455
StartDownloadingScheme();
@@ -829,8 +838,7 @@ class TSchemeGetter: public TGetterFromS3<TSchemeGetter> {
829838
TVector<TString> ChangefeedsPrefixes;
830839
ui64 IndexDownloadedChangefeed = 0;
831840

832-
const bool NeedDownloadPermissions = true;
833-
841+
bool NeedDownloadPermissions = true;
834842
bool NeedValidateChecksums = true;
835843
}; // TSchemeGetter
836844

ydb/core/tx/schemeshard/ut_export/ut_export.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2440,7 +2440,7 @@ partitioning_settings {
24402440

24412441
const auto* metadataChecksum = S3Mock().GetData().FindPtr("/metadata.json.sha256");
24422442
UNIT_ASSERT(metadataChecksum);
2443-
UNIT_ASSERT_VALUES_EQUAL(*metadataChecksum, "843d475f20c5e337fdd3ef4e83b63081c182e26791cd891f7739be8b53167b1b metadata.json");
2443+
UNIT_ASSERT_VALUES_EQUAL(*metadataChecksum, "29c79eb8109b4142731fc894869185d6c0e99c4b2f605ea3fc726b0328b8e316 metadata.json");
24442444

24452445
const auto* schemeChecksum = S3Mock().GetData().FindPtr("/scheme.pb.sha256");
24462446
UNIT_ASSERT(schemeChecksum);
@@ -2507,7 +2507,7 @@ partitioning_settings {
25072507

25082508
const auto* metadataChecksum = S3Mock().GetData().FindPtr("/metadata.json.sha256");
25092509
UNIT_ASSERT(metadataChecksum);
2510-
UNIT_ASSERT_VALUES_EQUAL(*metadataChecksum, "843d475f20c5e337fdd3ef4e83b63081c182e26791cd891f7739be8b53167b1b metadata.json");
2510+
UNIT_ASSERT_VALUES_EQUAL(*metadataChecksum, "fbb85825fb12c5f38661864db884ba3fd1512fc4b0a2a41960d7d62d19318ab6 metadata.json");
25112511

25122512
const auto* schemeChecksum = S3Mock().GetData().FindPtr("/scheme.pb.sha256");
25132513
UNIT_ASSERT(schemeChecksum);

0 commit comments

Comments
 (0)