diff options
author | Ilia Shakhov <pixcc@ydb.tech> | 2025-02-18 21:42:47 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-02-18 18:42:47 +0000 |
commit | a48e9482272a322871b01f751ec853fd5efaf60f (patch) | |
tree | ea1bcddb74ff0b8805d9ed2613aa2feef0350694 | |
parent | eb1eed1cc26be0126ffacee14074898a2ad2b4b2 (diff) | |
download | ydb-a48e9482272a322871b01f751ec853fd5efaf60f.tar.gz |
Fix enable checksums persistance (#14757)
5 files changed, 107 insertions, 13 deletions
diff --git a/ydb/core/tx/schemeshard/schemeshard__init.cpp b/ydb/core/tx/schemeshard/schemeshard__init.cpp index a6f26ad507..630f10505e 100644 --- a/ydb/core/tx/schemeshard/schemeshard__init.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__init.cpp @@ -803,7 +803,7 @@ struct TSchemeShard::TTxInit : public TTransactionBase<TSchemeShard> { return true; } - typedef std::tuple<TPathId, TString, TString, TString, TString, bool, TString, ui32> TBackupSettingsRec; + typedef std::tuple<TPathId, TString, TString, TString, TString, bool, TString, ui32, bool> TBackupSettingsRec; typedef TDeque<TBackupSettingsRec> TBackupSettingsRows; template <typename SchemaTable, typename TRowSet> @@ -815,7 +815,8 @@ struct TSchemeShard::TTxInit : public TTransactionBase<TSchemeShard> { rowSet.template GetValueOrDefault<typename SchemaTable::ScanSettings>(""), rowSet.template GetValueOrDefault<typename SchemaTable::NeedToBill>(true), rowSet.template GetValueOrDefault<typename SchemaTable::TableDescription>(""), - rowSet.template GetValueOrDefault<typename SchemaTable::NumberOfRetries>(0) + rowSet.template GetValueOrDefault<typename SchemaTable::NumberOfRetries>(0), + rowSet.template GetValueOrDefault<typename SchemaTable::EnableChecksums>(false) ); } @@ -3791,6 +3792,7 @@ struct TSchemeShard::TTxInit : public TTransactionBase<TSchemeShard> { bool needToBill = std::get<5>(rec); TString tableDesc = std::get<6>(rec); ui32 nRetries = std::get<7>(rec); + bool enableChecksums = std::get<8>(rec); Y_ABORT_UNLESS(tableName.size() > 0); @@ -3800,6 +3802,7 @@ struct TSchemeShard::TTxInit : public TTransactionBase<TSchemeShard> { tableInfo->BackupSettings.SetTableName(tableName); tableInfo->BackupSettings.SetNeedToBill(needToBill); tableInfo->BackupSettings.SetNumberOfRetries(nRetries); + tableInfo->BackupSettings.SetEnableChecksums(enableChecksums); if (ytSerializedSettings) { auto settings = tableInfo->BackupSettings.MutableYTSettings(); diff --git a/ydb/core/tx/schemeshard/schemeshard_impl.cpp b/ydb/core/tx/schemeshard/schemeshard_impl.cpp index 96e4f30f9e..16ef3c3819 100644 --- a/ydb/core/tx/schemeshard/schemeshard_impl.cpp +++ b/ydb/core/tx/schemeshard/schemeshard_impl.cpp @@ -3360,7 +3360,8 @@ void TSchemeShard::PersistBackupSettings( NIceDb::TUpdate<Schema::BackupSettings::ScanSettings>(settings.GetScanSettings().SerializeAsString()), \ NIceDb::TUpdate<Schema::BackupSettings::NeedToBill>(settings.GetNeedToBill()), \ NIceDb::TUpdate<Schema::BackupSettings::TableDescription>(settings.GetTable().SerializeAsString()), \ - NIceDb::TUpdate<Schema::BackupSettings::NumberOfRetries>(settings.GetNumberOfRetries())); \ + NIceDb::TUpdate<Schema::BackupSettings::NumberOfRetries>(settings.GetNumberOfRetries()), \ + NIceDb::TUpdate<Schema::BackupSettings::EnableChecksums>(settings.GetEnableChecksums())); \ } else { \ db.Table<Schema::MigratedBackupSettings>().Key(pathId.OwnerId, pathId.LocalPathId).Update( \ NIceDb::TUpdate<Schema::MigratedBackupSettings::TableName>(settings.GetTableName()), \ @@ -3368,7 +3369,8 @@ void TSchemeShard::PersistBackupSettings( NIceDb::TUpdate<Schema::MigratedBackupSettings::ScanSettings>(settings.GetScanSettings().SerializeAsString()), \ NIceDb::TUpdate<Schema::MigratedBackupSettings::NeedToBill>(settings.GetNeedToBill()), \ NIceDb::TUpdate<Schema::MigratedBackupSettings::TableDescription>(settings.GetTable().SerializeAsString()), \ - NIceDb::TUpdate<Schema::MigratedBackupSettings::NumberOfRetries>(settings.GetNumberOfRetries())); \ + NIceDb::TUpdate<Schema::MigratedBackupSettings::NumberOfRetries>(settings.GetNumberOfRetries()), \ + NIceDb::TUpdate<Schema::MigratedBackupSettings::EnableChecksums>(settings.GetEnableChecksums())); \ } \ } diff --git a/ydb/core/tx/schemeshard/schemeshard_schema.h b/ydb/core/tx/schemeshard/schemeshard_schema.h index ce4c4e26cb..03b0639ff6 100644 --- a/ydb/core/tx/schemeshard/schemeshard_schema.h +++ b/ydb/core/tx/schemeshard/schemeshard_schema.h @@ -583,6 +583,7 @@ struct Schema : NIceDb::Schema { struct NumberOfRetries : Column<8, NScheme::NTypeIds::Uint32> {}; struct ScanSettings : Column<9, NScheme::NTypeIds::String> {}; struct NeedToBill : Column<10, NScheme::NTypeIds::Bool> {}; + struct EnableChecksums : Column<11, NScheme::NTypeIds::Bool> {}; // deprecated struct CreateDestinationFlag : Column<4, NScheme::NTypeIds::Bool> {}; struct EraseOldDataFlag : Column<5, NScheme::NTypeIds::Bool> {}; @@ -598,7 +599,8 @@ struct Schema : NIceDb::Schema { TableDescription, NumberOfRetries, ScanSettings, - NeedToBill + NeedToBill, + EnableChecksums >; }; @@ -613,6 +615,7 @@ struct Schema : NIceDb::Schema { struct NumberOfRetries : Column<9, NScheme::NTypeIds::Uint32> {}; struct ScanSettings : Column<10, NScheme::NTypeIds::String> {}; struct NeedToBill : Column<11, NScheme::NTypeIds::Bool> {}; + struct EnableChecksums : Column<12, NScheme::NTypeIds::Bool> {}; // deprecated struct CreateDestinationFlag : Column<5, NScheme::NTypeIds::Bool> {}; struct EraseOldDataFlag : Column<6, NScheme::NTypeIds::Bool> {}; @@ -629,7 +632,8 @@ struct Schema : NIceDb::Schema { TableDescription, NumberOfRetries, ScanSettings, - NeedToBill + NeedToBill, + EnableChecksums >; }; diff --git a/ydb/core/tx/schemeshard/ut_export/ut_export.cpp b/ydb/core/tx/schemeshard/ut_export/ut_export.cpp index d6f6e14dec..81825cc8bd 100644 --- a/ydb/core/tx/schemeshard/ut_export/ut_export.cpp +++ b/ydb/core/tx/schemeshard/ut_export/ut_export.cpp @@ -1,12 +1,13 @@ +#include <ydb/core/metering/metering.h> #include <ydb/core/protos/schemeshard/operations.pb.h> #include <ydb/core/tablet_flat/shared_cache_events.h> -#include <ydb/core/tx/schemeshard/ut_helpers/helpers.h> -#include <ydb/core/tx/schemeshard/ut_helpers/auditlog_helpers.h> -#include <ydb/core/tx/schemeshard/schemeshard_billing_helpers.h> +#include <ydb/core/testlib/actors/block_events.h> #include <ydb/core/tx/datashard/datashard.h> -#include <ydb/core/wrappers/ut_helpers/s3_mock.h> +#include <ydb/core/tx/schemeshard/schemeshard_billing_helpers.h> +#include <ydb/core/tx/schemeshard/ut_helpers/auditlog_helpers.h> +#include <ydb/core/tx/schemeshard/ut_helpers/helpers.h> #include <ydb/core/wrappers/s3_wrapper.h> -#include <ydb/core/metering/metering.h> +#include <ydb/core/wrappers/ut_helpers/s3_mock.h> #include <ydb/public/api/protos/ydb_export.pb.h> #include <util/string/builder.h> @@ -2387,6 +2388,78 @@ partitioning_settings { env.TestWaitNotification(runtime, txId); UNIT_ASSERT_VALUES_EQUAL(s3Mock.GetData().size(), 8); + const auto* dataChecksum = s3Mock.GetData().FindPtr("/data_00.csv.sha256"); + UNIT_ASSERT(dataChecksum); + UNIT_ASSERT_VALUES_EQUAL(*dataChecksum, "19dcd641390a61063ee45f3e6e06b8f0d3acfc33f934b9bf1ba204668a98f21d data_00.csv"); + + const auto* metadataChecksum = s3Mock.GetData().FindPtr("/metadata.json.sha256"); + UNIT_ASSERT(metadataChecksum); + UNIT_ASSERT_VALUES_EQUAL(*metadataChecksum, "b72575244ae0cce8dffd45f3537d1e412bfe39de4268f4f85f529cb529870903 metadata.json"); + + const auto* schemeChecksum = s3Mock.GetData().FindPtr("/scheme.pb.sha256"); + UNIT_ASSERT(schemeChecksum); + UNIT_ASSERT_VALUES_EQUAL(*schemeChecksum, "cb1fb80965ae92e6369acda2b3b5921fd5518c97d6437f467ce00492907f9eb6 scheme.pb"); + + const auto* permissionsChecksum = s3Mock.GetData().FindPtr("/permissions.pb.sha256"); + UNIT_ASSERT(permissionsChecksum); + UNIT_ASSERT_VALUES_EQUAL(*permissionsChecksum, "b41fd8921ff3a7314d9c702dc0e71aace6af8443e0102add0432895c5e50a326 permissions.pb"); + } + + Y_UNIT_TEST(EnableChecksumsPersistance) { + TTestBasicRuntime runtime; + TTestEnv env(runtime); + ui64 txId = 100; + + // Create test table + TestCreateTable(runtime, ++txId, "/MyRoot", R"( + Name: "Table" + Columns { Name: "key" Type: "Utf8" } + Columns { Name: "value" Type: "Utf8" } + KeyColumnNames: ["key"] + )"); + env.TestWaitNotification(runtime, txId); + + // Add some test data + UploadRow(runtime, "/MyRoot/Table", 0, {1}, {2}, {TCell::Make(1u)}, {TCell::Make(1u)}); + + TPortManager portManager; + const ui16 port = portManager.GetPort(); + + TS3Mock s3Mock({}, TS3Mock::TSettings(port)); + UNIT_ASSERT(s3Mock.Start()); + + // Block sending backup task to datashards + TBlockEvents<TEvDataShard::TEvProposeTransaction> block(runtime, [](auto& ev) { + NKikimrTxDataShard::TFlatSchemeTransaction schemeTx; + UNIT_ASSERT(schemeTx.ParseFromString(ev.Get()->Get()->GetTxBody())); + return schemeTx.HasBackup(); + }); + + // Start export and expect it to be blocked + TestExport(runtime, ++txId, "/MyRoot", Sprintf(R"( + ExportToS3Settings { + endpoint: "localhost:%d" + scheme: HTTP + items { + source_path: "/MyRoot/Table" + destination_prefix: "" + } + } + )", port)); + + runtime.WaitFor("backup task is sent to datashards", [&]{ return block.size() >= 1; }); + + // Stop blocking new events + block.Stop(); + + // Reboot SchemeShard to resend backup task + RebootTablet(runtime, TTestTxConfig::SchemeShard, runtime.AllocateEdgeActor()); + + // Wait for export to complete + env.TestWaitNotification(runtime, txId); + + // Verify checksums are created + UNIT_ASSERT_VALUES_EQUAL(s3Mock.GetData().size(), 8); const auto* dataChecksum = s3Mock.GetData().FindPtr("/data_00.csv.sha256"); UNIT_ASSERT(dataChecksum); diff --git a/ydb/tests/functional/scheme_tests/canondata/tablet_scheme_tests.TestTabletSchemes.test_tablet_schemes_flat_schemeshard_/flat_schemeshard.schema b/ydb/tests/functional/scheme_tests/canondata/tablet_scheme_tests.TestTabletSchemes.test_tablet_schemes_flat_schemeshard_/flat_schemeshard.schema index 8759c64389..49deddffba 100644 --- a/ydb/tests/functional/scheme_tests/canondata/tablet_scheme_tests.TestTabletSchemes.test_tablet_schemes_flat_schemeshard_/flat_schemeshard.schema +++ b/ydb/tests/functional/scheme_tests/canondata/tablet_scheme_tests.TestTabletSchemes.test_tablet_schemes_flat_schemeshard_/flat_schemeshard.schema @@ -1169,6 +1169,11 @@ "ColumnId": 10, "ColumnName": "NeedToBill", "ColumnType": "Bool" + }, + { + "ColumnId": 11, + "ColumnName": "EnableChecksums", + "ColumnType": "Bool" } ], "ColumnsDropped": [], @@ -1184,7 +1189,8 @@ 7, 8, 9, - 10 + 10, + 11 ], "RoomID": 0, "Codec": 0, @@ -4549,6 +4555,11 @@ "ColumnId": 11, "ColumnName": "NeedToBill", "ColumnType": "Bool" + }, + { + "ColumnId": 12, + "ColumnName": "EnableChecksums", + "ColumnType": "Bool" } ], "ColumnsDropped": [], @@ -4565,7 +4576,8 @@ 8, 9, 10, - 11 + 11, + 12 ], "RoomID": 0, "Codec": 0, |