@@ -955,6 +955,153 @@ value {
955
955
UNIT_ASSERT_C (CheckDefaultFromSequence (table), " Invalid default value" );
956
956
}
957
957
958
+ Y_UNIT_TEST (ShouldRestoreSequence) {
959
+ TPortManager portManager;
960
+ const ui16 port = portManager.GetPort ();
961
+
962
+ TS3Mock s3Mock ({}, TS3Mock::TSettings (port));
963
+ UNIT_ASSERT (s3Mock.Start ());
964
+
965
+ TTestBasicRuntime runtime;
966
+ TTestEnv env (runtime);
967
+
968
+ ui64 txId = 100 ;
969
+
970
+ runtime.SetLogPriority (NKikimrServices::DATASHARD_BACKUP, NActors::NLog::PRI_TRACE);
971
+ runtime.SetLogPriority (NKikimrServices::DATASHARD_RESTORE, NActors::NLog::PRI_TRACE);
972
+ runtime.SetLogPriority (NKikimrServices::EXPORT, NActors::NLog::PRI_TRACE);
973
+ runtime.SetLogPriority (NKikimrServices::IMPORT, NActors::NLog::PRI_TRACE);
974
+ runtime.SetLogPriority (NKikimrServices::SEQUENCEPROXY, NActors::NLog::PRI_TRACE);
975
+
976
+ TestCreateIndexedTable (runtime, ++txId, " /MyRoot" , R"(
977
+ TableDescription {
978
+ Name: "Original"
979
+ Columns { Name: "key" Type: "Uint64" DefaultFromSequence: "myseq" }
980
+ Columns { Name: "value" Type: "Uint64" }
981
+ KeyColumnNames: ["key"]
982
+ }
983
+ SequenceDescription {
984
+ Name: "myseq"
985
+ }
986
+ )" );
987
+ env.TestWaitNotification (runtime, txId);
988
+
989
+ i64 value = DoNextVal (runtime, " /MyRoot/Original/myseq" );
990
+ UNIT_ASSERT_VALUES_EQUAL (value, 1 );
991
+
992
+ TestExport (runtime, ++txId, " /MyRoot" , Sprintf (R"(
993
+ ExportToS3Settings {
994
+ endpoint: "localhost:%d"
995
+ scheme: HTTP
996
+ items {
997
+ source_path: "/MyRoot/Original"
998
+ destination_prefix: ""
999
+ }
1000
+ }
1001
+ )" , port));
1002
+ env.TestWaitNotification (runtime, txId);
1003
+ TestGetExport (runtime, txId, " /MyRoot" );
1004
+
1005
+ TestImport (runtime, ++txId, " /MyRoot" , Sprintf (R"(
1006
+ ImportFromS3Settings {
1007
+ endpoint: "localhost:%d"
1008
+ scheme: HTTP
1009
+ items {
1010
+ source_prefix: ""
1011
+ destination_path: "/MyRoot/Restored"
1012
+ }
1013
+ }
1014
+ )" , port));
1015
+ env.TestWaitNotification (runtime, txId);
1016
+ TestGetImport (runtime, txId, " /MyRoot" );
1017
+
1018
+ const auto desc = DescribePath (runtime, " /MyRoot/Restored" , true , true );
1019
+ UNIT_ASSERT_VALUES_EQUAL (desc.GetStatus (), NKikimrScheme::StatusSuccess);
1020
+
1021
+ const auto & table = desc.GetPathDescription ().GetTable ();
1022
+
1023
+ value = DoNextVal (runtime, " /MyRoot/Restored/myseq" );
1024
+ UNIT_ASSERT_VALUES_EQUAL (value, 2 );
1025
+
1026
+ UNIT_ASSERT_C (CheckDefaultFromSequence (table), " Invalid default value" );
1027
+ }
1028
+
1029
+ Y_UNIT_TEST (ShouldRestoreSequenceWithOverflow) {
1030
+ TPortManager portManager;
1031
+ const ui16 port = portManager.GetPort ();
1032
+
1033
+ TS3Mock s3Mock ({}, TS3Mock::TSettings (port));
1034
+ UNIT_ASSERT (s3Mock.Start ());
1035
+
1036
+ TTestBasicRuntime runtime;
1037
+ TTestEnv env (runtime);
1038
+
1039
+ ui64 txId = 100 ;
1040
+
1041
+ runtime.SetLogPriority (NKikimrServices::DATASHARD_BACKUP, NActors::NLog::PRI_TRACE);
1042
+ runtime.SetLogPriority (NKikimrServices::DATASHARD_RESTORE, NActors::NLog::PRI_TRACE);
1043
+ runtime.SetLogPriority (NKikimrServices::EXPORT, NActors::NLog::PRI_TRACE);
1044
+ runtime.SetLogPriority (NKikimrServices::IMPORT, NActors::NLog::PRI_TRACE);
1045
+ runtime.SetLogPriority (NKikimrServices::SEQUENCEPROXY, NActors::NLog::PRI_TRACE);
1046
+
1047
+ TestCreateIndexedTable (runtime, ++txId, " /MyRoot" , R"(
1048
+ TableDescription {
1049
+ Name: "Original"
1050
+ Columns { Name: "key" Type: "Uint64" DefaultFromSequence: "myseq" }
1051
+ Columns { Name: "value" Type: "Uint64" }
1052
+ KeyColumnNames: ["key"]
1053
+ }
1054
+ SequenceDescription {
1055
+ Name: "myseq"
1056
+ MinValue: 1
1057
+ MaxValue: 2
1058
+ }
1059
+ )" );
1060
+ env.TestWaitNotification (runtime, txId);
1061
+
1062
+ i64 value = DoNextVal (runtime, " /MyRoot/Original/myseq" );
1063
+ UNIT_ASSERT_VALUES_EQUAL (value, 1 );
1064
+
1065
+ value = DoNextVal (runtime, " /MyRoot/Original/myseq" );
1066
+ UNIT_ASSERT_VALUES_EQUAL (value, 2 );
1067
+
1068
+ TestExport (runtime, ++txId, " /MyRoot" , Sprintf (R"(
1069
+ ExportToS3Settings {
1070
+ endpoint: "localhost:%d"
1071
+ scheme: HTTP
1072
+ items {
1073
+ source_path: "/MyRoot/Original"
1074
+ destination_prefix: ""
1075
+ }
1076
+ }
1077
+ )" , port));
1078
+ env.TestWaitNotification (runtime, txId);
1079
+ TestGetExport (runtime, txId, " /MyRoot" );
1080
+
1081
+ TestImport (runtime, ++txId, " /MyRoot" , Sprintf (R"(
1082
+ ImportFromS3Settings {
1083
+ endpoint: "localhost:%d"
1084
+ scheme: HTTP
1085
+ items {
1086
+ source_prefix: ""
1087
+ destination_path: "/MyRoot/Restored"
1088
+ }
1089
+ }
1090
+ )" , port));
1091
+ env.TestWaitNotification (runtime, txId);
1092
+ TestGetImport (runtime, txId, " /MyRoot" );
1093
+
1094
+ const auto desc = DescribePath (runtime, " /MyRoot/Restored" , true , true );
1095
+ UNIT_ASSERT_VALUES_EQUAL (desc.GetStatus (), NKikimrScheme::StatusSuccess);
1096
+
1097
+ const auto & table = desc.GetPathDescription ().GetTable ();
1098
+
1099
+ value = DoNextVal (runtime, " /MyRoot/Restored/myseq" , Ydb::StatusIds::SCHEME_ERROR);
1100
+ UNIT_ASSERT_VALUES_EQUAL (value, 2 );
1101
+
1102
+ UNIT_ASSERT_C (CheckDefaultFromSequence (table), " Invalid default value" );
1103
+ }
1104
+
958
1105
Y_UNIT_TEST (ExportImportPg) {
959
1106
TTestBasicRuntime runtime;
960
1107
TTestEnv env (runtime, TTestEnvOptions ().EnableTablePgTypes (true ));
0 commit comments