forked from ydb-platform/ydb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add backup collection schema path item (ydb-platform#10252)
- Loading branch information
Showing
43 changed files
with
1,549 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
ydb/core/tx/schemeshard/schemeshard__backup_collection_common.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#include "schemeshard__backup_collection_common.h" | ||
|
||
namespace NKikimr::NSchemeShard { | ||
|
||
std::optional<TBackupCollectionPaths> ResolveBackupCollectionPaths( | ||
const TString& rootPathStr, | ||
const TString& name, | ||
bool validateFeatureFlag, | ||
TOperationContext& context, | ||
THolder<TProposeResponse>& result) | ||
{ | ||
bool backupServiceEnabled = AppData()->FeatureFlags.GetEnableBackupService(); | ||
if (!backupServiceEnabled && validateFeatureFlag) { | ||
result->SetError(NKikimrScheme::StatusPreconditionFailed, "Backup collections are disabled. Please contact your system administrator to enable it"); | ||
return std::nullopt; | ||
} | ||
|
||
const TPath& rootPath = TPath::Resolve(rootPathStr, context.SS); | ||
{ | ||
const auto checks = rootPath.Check(); | ||
checks | ||
.NotEmpty() | ||
.NotUnderDomainUpgrade() | ||
.IsAtLocalSchemeShard() | ||
.IsResolved() | ||
.NotDeleted() | ||
.NotUnderDeleting() | ||
.IsCommonSensePath() | ||
.IsLikeDirectory() | ||
.FailOnRestrictedCreateInTempZone(); | ||
|
||
if (!checks) { | ||
result->SetError(checks.GetStatus(), checks.GetError()); | ||
return std::nullopt; | ||
} | ||
} | ||
|
||
const TString& backupCollectionsDir = JoinPath({rootPath.GetDomainPathString(), ".backups/collections"}); | ||
|
||
TPathSplitUnix absPathSplit(name); | ||
|
||
if (absPathSplit.size() > 1 && !absPathSplit.IsAbsolute) { | ||
result->SetError(NKikimrScheme::EStatus::StatusSchemeError, TStringBuilder() << "Backup collections must be placed directly in " << backupCollectionsDir); | ||
return std::nullopt; | ||
} | ||
|
||
const TPath& backupCollectionsPath = TPath::Resolve(backupCollectionsDir, context.SS); | ||
{ | ||
const auto checks = backupCollectionsPath.Check(); | ||
checks.NotUnderDomainUpgrade() | ||
.IsAtLocalSchemeShard() | ||
.IsResolved() | ||
.NotDeleted() | ||
.NotUnderDeleting() | ||
.IsCommonSensePath() | ||
.IsLikeDirectory(); | ||
|
||
if (!checks) { | ||
result->SetError(checks.GetStatus(), checks.GetError()); | ||
return std::nullopt; | ||
} | ||
} | ||
|
||
std::optional<TPath> parentPath; | ||
if (absPathSplit.size() > 1) { | ||
TString realParent = "/" + JoinRange("/", absPathSplit.begin(), absPathSplit.end() - 1); | ||
parentPath = TPath::Resolve(realParent, context.SS); | ||
} | ||
|
||
TPath dstPath = absPathSplit.IsAbsolute && parentPath ? parentPath->Child(TString(absPathSplit.back())) : rootPath.Child(name); | ||
if (!dstPath.PathString().StartsWith(backupCollectionsDir + "/")) { | ||
result->SetError(NKikimrScheme::EStatus::StatusSchemeError, TStringBuilder() << "Backup collections must be placed in " << backupCollectionsDir); | ||
return std::nullopt; | ||
} | ||
|
||
return TBackupCollectionPaths{rootPath, dstPath}; | ||
} | ||
|
||
} // namespace NKikimr::NSchemeShard |
24 changes: 24 additions & 0 deletions
24
ydb/core/tx/schemeshard/schemeshard__backup_collection_common.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#pragma once | ||
|
||
#include "schemeshard__operation_common.h" | ||
#include "schemeshard_impl.h" | ||
|
||
#include <util/generic/string.h> | ||
|
||
#include <optional> | ||
|
||
namespace NKikimr::NSchemeShard { | ||
|
||
struct TBackupCollectionPaths { | ||
TPath RootPath; | ||
TPath DstPath; | ||
}; | ||
|
||
std::optional<TBackupCollectionPaths> ResolveBackupCollectionPaths( | ||
const TString& rootPathStr, | ||
const TString& name, | ||
bool preValidateDst, | ||
TOperationContext& context, | ||
THolder<TProposeResponse>& result); | ||
|
||
} // namespace NKikimr::NSchemeShard |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.