diff options
| author | e2xen <[email protected]> | 2023-06-14 15:15:36 +0000 |
|---|---|---|
| committer | ilnaz <[email protected]> | 2023-06-14 18:15:36 +0300 |
| commit | c35c89f6e630781a97a2384c5783d2cbbe10d588 (patch) | |
| tree | bc93145cbaf238e8af871a8d56756304e0a1ecd9 | |
| parent | 607f1bd3dab2c692f1b508929fde3bb5a89e3085 (diff) | |
add ordered option for ydb tools dump
add ordered option for ydb tools dump
Pull Request resolved: #245
| -rw-r--r-- | ydb/library/backup/backup.cpp | 25 | ||||
| -rw-r--r-- | ydb/library/backup/backup.h | 2 | ||||
| -rw-r--r-- | ydb/public/lib/ydb_cli/commands/ydb_tools.cpp | 4 | ||||
| -rw-r--r-- | ydb/public/lib/ydb_cli/commands/ydb_tools.h | 1 |
4 files changed, 19 insertions, 13 deletions
diff --git a/ydb/library/backup/backup.cpp b/ydb/library/backup/backup.cpp index be5f298313c..0919e2ec9a8 100644 --- a/ydb/library/backup/backup.cpp +++ b/ydb/library/backup/backup.cpp @@ -247,14 +247,17 @@ static void CloseAndRename(TFile& tmpFile, const TFsPath& fileName) { } TMaybe<TValue> TryReadTable(TDriver driver, const NTable::TTableDescription& desc, const TString& fullTablePath, - const TFsPath& folderPath, TMaybe<TValue> lastWrittenPK, ui32 *fileCounter) + const TFsPath& folderPath, TMaybe<TValue> lastWrittenPK, ui32 *fileCounter, bool ordered) { TMaybe<NTable::TTablePartIterator> iter; - auto readTableJob = [fullTablePath, &lastWrittenPK, &iter](NTable::TSession session) -> TStatus { + auto readTableJob = [fullTablePath, &lastWrittenPK, &iter, &ordered](NTable::TSession session) -> TStatus { NTable::TReadTableSettings settings; if (lastWrittenPK) { settings.From(NTable::TKeyBound::Exclusive(*lastWrittenPK)); } + if (ordered) { + settings.Ordered(); + } auto result = session.ReadTable(fullTablePath, settings).ExtractValueSync(); if (result.IsSuccess()) { iter = result; @@ -328,7 +331,7 @@ TMaybe<TValue> TryReadTable(TDriver driver, const NTable::TTableDescription& des } void ReadTable(TDriver driver, const NTable::TTableDescription& desc, const TString& fullTablePath, - const TFsPath& folderPath) { + const TFsPath& folderPath, bool ordered) { LOG_DEBUG("Going to ReadTable, fullPath: " << fullTablePath); auto timer = GetVerbosity() @@ -340,7 +343,7 @@ void ReadTable(TDriver driver, const NTable::TTableDescription& desc, const TStr i64 retries = READ_TABLE_RETRIES; ui32 fileCounter = 0; do { - lastWrittenPK = TryReadTable(driver, desc, fullTablePath, folderPath, lastWrittenPK, &fileCounter); + lastWrittenPK = TryReadTable(driver, desc, fullTablePath, folderPath, lastWrittenPK, &fileCounter, ordered); if (lastWrittenPK && retries) { LOG_DEBUG("ReadTable was not successfull, going to retry from lastWrittenPK# " << FormatValueYson(*lastWrittenPK).Quote()); @@ -466,7 +469,7 @@ void DropTable(TDriver driver, const TString& path) { } void BackupTable(TDriver driver, const TString& dbPrefix, const TString& backupPrefix, const TString& path, - const TFsPath& folderPath, bool schemaOnly, bool preservePoolKinds) { + const TFsPath& folderPath, bool schemaOnly, bool preservePoolKinds, bool ordered) { Y_ENSURE(!path.empty()); Y_ENSURE(path.back() != '/', path.Quote() << " path contains / in the end"); @@ -484,7 +487,7 @@ void BackupTable(TDriver driver, const TString& dbPrefix, const TString& backupP if (!schemaOnly) { const TString pathToTemporal = JoinDatabasePath(backupPrefix, path); - ReadTable(driver, desc, pathToTemporal, folderPath); + ReadTable(driver, desc, pathToTemporal, folderPath, ordered); } } @@ -522,7 +525,7 @@ static bool IsExcluded(const TString& path, const TVector<TRegExMatch>& exclusio void BackupFolderImpl(TDriver driver, const TString& dbPrefix, const TString& backupPrefix, TString path, const TFsPath folderPath, const TVector<TRegExMatch>& exclusionPatterns, - bool schemaOnly, bool useConsistentCopyTable, bool avoidCopy, bool preservePoolKinds) { + bool schemaOnly, bool useConsistentCopyTable, bool avoidCopy, bool preservePoolKinds, bool ordered) { LOG_DEBUG("Going to backup folder/table, dbPrefix: " << dbPrefix << " path: " << path); TFile(folderPath.Child(INCOMPLETE_FILE_NAME), CreateAlways); @@ -545,7 +548,7 @@ void BackupFolderImpl(TDriver driver, const TString& dbPrefix, const TString& ba if (schemaOnly) { if (dbIt.IsTable()) { BackupTable(driver, dbIt.GetTraverseRoot(), backupPrefix, dbIt.GetRelPath(), - childFolderPath, schemaOnly, preservePoolKinds); + childFolderPath, schemaOnly, preservePoolKinds, ordered); childFolderPath.Child(INCOMPLETE_FILE_NAME).DeleteIfExists(); } } else if (!avoidCopy) { @@ -619,7 +622,7 @@ void BackupFolderImpl(TDriver driver, const TString& dbPrefix, const TString& ba copiedTablesStatuses.erase(dbIt.GetFullPath()); } BackupTable(driver, dbIt.GetTraverseRoot(), avoidCopy ? dbIt.GetTraverseRoot() : backupPrefix, dbIt.GetRelPath(), - childFolderPath, schemaOnly, preservePoolKinds); + childFolderPath, schemaOnly, preservePoolKinds, ordered); if (!avoidCopy) { DropTable(driver, tmpTablePath); } @@ -663,7 +666,7 @@ void CheckedCreateBackupFolder(const TFsPath& folderPath) { // folderPath - relative path to folder in local filesystem where backup will be stored void BackupFolder(TDriver driver, const TString& database, const TString& relDbPath, TFsPath folderPath, const TVector<TRegExMatch>& exclusionPatterns, - bool schemaOnly, bool useConsistentCopyTable, bool avoidCopy, bool savePartialResult, bool preservePoolKinds) { + bool schemaOnly, bool useConsistentCopyTable, bool avoidCopy, bool savePartialResult, bool preservePoolKinds, bool ordered) { TString temporalBackupPostfix = CreateTemporalBackupName(); if (!folderPath) { folderPath = temporalBackupPostfix; @@ -682,7 +685,7 @@ void BackupFolder(TDriver driver, const TString& database, const TString& relDbP TString dbPrefix = JoinDatabasePath(database, relDbPath); TString path; BackupFolderImpl(driver, dbPrefix, tmpDbFolder, path, folderPath, exclusionPatterns, - schemaOnly, useConsistentCopyTable, avoidCopy, preservePoolKinds); + schemaOnly, useConsistentCopyTable, avoidCopy, preservePoolKinds, ordered); } catch (...) { if (!schemaOnly && !avoidCopy) { RemoveClusterDirectoryRecursive(driver, tmpDbFolder); diff --git a/ydb/library/backup/backup.h b/ydb/library/backup/backup.h index 269f96d9b9d..f990c3c7223 100644 --- a/ydb/library/backup/backup.h +++ b/ydb/library/backup/backup.h @@ -35,7 +35,7 @@ public: void BackupFolder(TDriver driver, const TString& database, const TString& relDbPath, TFsPath folderPath, const TVector<TRegExMatch>& exclusionPatterns, bool schemaOnly, bool useConsistentCopyTable, bool avoidCopy = false, bool savePartialResult = false, - bool preservePoolKinds = false); + bool preservePoolKinds = false, bool ordered = false); struct TRestoreFolderParams { bool OnlyCheck = false; diff --git a/ydb/public/lib/ydb_cli/commands/ydb_tools.cpp b/ydb/public/lib/ydb_cli/commands/ydb_tools.cpp index 9393e330706..a848747cec8 100644 --- a/ydb/public/lib/ydb_cli/commands/ydb_tools.cpp +++ b/ydb/public/lib/ydb_cli/commands/ydb_tools.cpp @@ -69,6 +69,8 @@ void TCommandDump::Config(TConfig& config) { " Takes more time and is more likely to impact workload;\n" "table - take consistent snapshot per each table independently.") .DefaultValue("database").StoreResult(&ConsistencyLevel); + config.Opts->AddLongOption("ordered", "Preserve order by primary key in backup files.") + .StoreTrue(&Ordered); } void TCommandDump::Parse(TConfig& config) { @@ -92,7 +94,7 @@ int TCommandDump::Run(TConfig& config) { try { TString relPath = NYdb::RelPathFromAbsolute(config.Database, Path); NYdb::NBackup::BackupFolder(CreateDriver(config), config.Database, relPath, FilePath, ExclusionPatterns, - IsSchemeOnly, useConsistentCopyTable, AvoidCopy, SavePartialResult, PreservePoolKinds); + IsSchemeOnly, useConsistentCopyTable, AvoidCopy, SavePartialResult, PreservePoolKinds, Ordered); } catch (const NYdb::NBackup::TYdbErrorException& e) { e.LogToStderr(); return EXIT_FAILURE; diff --git a/ydb/public/lib/ydb_cli/commands/ydb_tools.h b/ydb/public/lib/ydb_cli/commands/ydb_tools.h index 3a1218a9816..168426aa417 100644 --- a/ydb/public/lib/ydb_cli/commands/ydb_tools.h +++ b/ydb/public/lib/ydb_cli/commands/ydb_tools.h @@ -43,6 +43,7 @@ private: bool SavePartialResult = false; TString ConsistencyLevel; bool PreservePoolKinds = false; + bool Ordered = false; }; class TCommandRestore : public TToolsCommand, public TCommandWithPath { |
