@@ -306,9 +306,10 @@ struct Schema : NIceDb::Schema {
306
306
307
307
struct BlobRangeOffset : Column<11 , NScheme::NTypeIds::Uint64> {};
308
308
struct BlobRangeSize : Column<12 , NScheme::NTypeIds::Uint64> {};
309
+ struct InsertWriteId : Column<13 , NScheme::NTypeIds::Uint64> {};
309
310
310
311
using TKey = TableKey<Committed, PlanStep, WriteTxId, PathId, DedupId>;
311
- using TColumns = TableColumns<Committed, PlanStep, WriteTxId, PathId, DedupId, BlobId, Meta, IndexPlanStep, IndexTxId, SchemaVersion, BlobRangeOffset, BlobRangeSize>;
312
+ using TColumns = TableColumns<Committed, PlanStep, WriteTxId, PathId, DedupId, BlobId, Meta, IndexPlanStep, IndexTxId, SchemaVersion, BlobRangeOffset, BlobRangeSize, InsertWriteId >;
312
313
};
313
314
314
315
struct IndexGranules : NIceDb::Schema::Table<GranulesTableId> {
@@ -808,6 +809,7 @@ struct Schema : NIceDb::Schema {
808
809
.Key ((ui8)recType, 0 , (ui64)data.GetInsertWriteId (), data.GetPathId (), " " )
809
810
.Update (NIceDb::TUpdate<InsertTable::BlobId>(data.GetBlobRange ().GetBlobId ().ToStringLegacy ()),
810
811
NIceDb::TUpdate<InsertTable::BlobRangeOffset>(data.GetBlobRange ().Offset ),
812
+ NIceDb::TUpdate<InsertTable::InsertWriteId>((ui64)data.GetInsertWriteId ()),
811
813
NIceDb::TUpdate<InsertTable::BlobRangeSize>(data.GetBlobRange ().Size ),
812
814
NIceDb::TUpdate<InsertTable::Meta>(data.GetMeta ().SerializeToProto ().SerializeAsString ()),
813
815
NIceDb::TUpdate<InsertTable::SchemaVersion>(data.GetSchemaVersion ()));
@@ -818,6 +820,7 @@ struct Schema : NIceDb::Schema {
818
820
.Key ((ui8)EInsertTableIds::Committed, data.GetSnapshot ().GetPlanStep (), data.GetSnapshot ().GetTxId (), data.GetPathId (),
819
821
data.GetDedupId ())
820
822
.Update (NIceDb::TUpdate<InsertTable::BlobId>(data.GetBlobRange ().GetBlobId ().ToStringLegacy ()),
823
+ NIceDb::TUpdate<InsertTable::InsertWriteId>((ui64)data.GetInsertWriteId ()),
821
824
NIceDb::TUpdate<InsertTable::BlobRangeOffset>(data.GetBlobRange ().Offset ),
822
825
NIceDb::TUpdate<InsertTable::BlobRangeSize>(data.GetBlobRange ().Size ),
823
826
NIceDb::TUpdate<InsertTable::Meta>(data.GetMeta ().SerializeToProto ().SerializeAsString ()),
@@ -982,15 +985,16 @@ class TInsertTableRecordLoadContext {
982
985
NColumnShard::Schema::EInsertTableIds RecType;
983
986
ui64 PlanStep;
984
987
ui64 WriteTxId;
988
+ TInsertWriteId InsertWriteId;
985
989
ui64 PathId;
986
990
YDB_ACCESSOR_DEF (TString, DedupId);
987
991
ui64 SchemaVersion;
988
992
TString BlobIdString;
989
993
std::optional<NOlap::TUnifiedBlobId> BlobId;
990
994
TString MetadataString;
991
995
std::optional<NKikimrTxColumnShard::TLogicalMetadata> Metadata;
992
- std::optional< ui64> RangeOffset;
993
- std::optional< ui64> RangeSize;
996
+ ui64 RangeOffset;
997
+ ui64 RangeSize;
994
998
995
999
void Prepare (const IBlobGroupSelector* dsGroupSelector) {
996
1000
AFL_VERIFY (!PreparedFlag);
@@ -1004,7 +1008,6 @@ class TInsertTableRecordLoadContext {
1004
1008
AFL_VERIFY (MetadataString);
1005
1009
Y_ABORT_UNLESS (meta.ParseFromString (MetadataString));
1006
1010
Metadata = std::move (meta);
1007
- AFL_VERIFY (!!RangeOffset == !!RangeSize);
1008
1011
}
1009
1012
1010
1013
bool PreparedFlag = false ;
@@ -1013,8 +1016,13 @@ class TInsertTableRecordLoadContext {
1013
1016
public:
1014
1017
TInsertWriteId GetInsertWriteId () const {
1015
1018
AFL_VERIFY (ParsedFlag);
1016
- AFL_VERIFY (RecType != NColumnShard::Schema::EInsertTableIds::Committed);
1017
- return (TInsertWriteId)WriteTxId;
1019
+ return InsertWriteId;
1020
+ }
1021
+
1022
+ ui64 GetTxId () const {
1023
+ AFL_VERIFY (ParsedFlag);
1024
+ AFL_VERIFY (RecType == NColumnShard::Schema::EInsertTableIds::Committed);
1025
+ return WriteTxId;
1018
1026
}
1019
1027
1020
1028
NColumnShard::Schema::EInsertTableIds GetRecType () const {
@@ -1024,6 +1032,7 @@ class TInsertTableRecordLoadContext {
1024
1032
1025
1033
ui64 GetPlanStep () const {
1026
1034
AFL_VERIFY (ParsedFlag);
1035
+ AFL_VERIFY (RecType == NColumnShard::Schema::EInsertTableIds::Committed);
1027
1036
return PlanStep;
1028
1037
}
1029
1038
@@ -1035,19 +1044,12 @@ class TInsertTableRecordLoadContext {
1035
1044
void Upsert (NIceDb::TNiceDb& db) const {
1036
1045
AFL_VERIFY (ParsedFlag);
1037
1046
using namespace NColumnShard ;
1038
- if (RangeOffset) {
1039
- db.Table <Schema::InsertTable>()
1040
- .Key ((ui8)RecType, PlanStep, WriteTxId, PathId, DedupId)
1041
- .Update (NIceDb::TUpdate<Schema::InsertTable::BlobId>(BlobIdString),
1042
- NIceDb::TUpdate<Schema::InsertTable::BlobRangeOffset>(*RangeOffset),
1043
- NIceDb::TUpdate<Schema::InsertTable::BlobRangeSize>(*RangeSize), NIceDb::TUpdate<Schema::InsertTable::Meta>(MetadataString),
1044
- NIceDb::TUpdate<Schema::InsertTable::SchemaVersion>(SchemaVersion));
1045
- } else {
1046
- db.Table <Schema::InsertTable>()
1047
- .Key ((ui8)RecType, PlanStep, WriteTxId, PathId, DedupId)
1048
- .Update (NIceDb::TUpdate<Schema::InsertTable::BlobId>(BlobIdString), NIceDb::TUpdate<Schema::InsertTable::Meta>(MetadataString),
1049
- NIceDb::TUpdate<Schema::InsertTable::SchemaVersion>(SchemaVersion));
1050
- }
1047
+ db.Table <Schema::InsertTable>()
1048
+ .Key ((ui8)RecType, PlanStep, WriteTxId, PathId, DedupId)
1049
+ .Update (NIceDb::TUpdate<Schema::InsertTable::BlobId>(BlobIdString),
1050
+ NIceDb::TUpdate<Schema::InsertTable::BlobRangeOffset>(RangeOffset),
1051
+ NIceDb::TUpdate<Schema::InsertTable::BlobRangeSize>(RangeSize), NIceDb::TUpdate<Schema::InsertTable::Meta>(MetadataString),
1052
+ NIceDb::TUpdate<Schema::InsertTable::SchemaVersion>(SchemaVersion));
1051
1053
}
1052
1054
1053
1055
template <class TRowset >
@@ -1059,41 +1061,40 @@ class TInsertTableRecordLoadContext {
1059
1061
PlanStep = rowset.template GetValue <Schema::InsertTable::PlanStep>();
1060
1062
WriteTxId = rowset.template GetValueOrDefault <Schema::InsertTable::WriteTxId>();
1061
1063
AFL_VERIFY (WriteTxId);
1064
+ InsertWriteId = (TInsertWriteId)rowset.template GetValueOrDefault <Schema::InsertTable::InsertWriteId>(WriteTxId);
1062
1065
1063
1066
PathId = rowset.template GetValue <Schema::InsertTable::PathId>();
1064
1067
DedupId = rowset.template GetValue <Schema::InsertTable::DedupId>();
1065
- SchemaVersion =
1066
- rowset.template HaveValue <Schema::InsertTable::SchemaVersion>() ? rowset.template GetValue <Schema::InsertTable::SchemaVersion>() : 0 ;
1068
+ SchemaVersion = rowset.template GetValueOrDefault <Schema::InsertTable::SchemaVersion>(0 );
1067
1069
BlobIdString = rowset.template GetValue <Schema::InsertTable::BlobId>();
1068
1070
MetadataString = rowset.template GetValue <Schema::InsertTable::Meta>();
1069
- if (rowset.template HaveValue <Schema::InsertTable::BlobRangeOffset>()) {
1070
- RangeOffset = rowset.template GetValue <Schema::InsertTable::BlobRangeOffset>();
1071
- }
1072
- if (rowset.template HaveValue <Schema::InsertTable::BlobRangeSize>()) {
1073
- RangeSize = rowset.template GetValue <Schema::InsertTable::BlobRangeSize>();
1074
- }
1071
+ AFL_VERIFY (rowset.template HaveValue <Schema::InsertTable::BlobRangeOffset>());
1072
+ AFL_VERIFY (rowset.template HaveValue <Schema::InsertTable::BlobRangeSize>());
1073
+ RangeOffset = rowset.template GetValue <Schema::InsertTable::BlobRangeOffset>();
1074
+ RangeSize = rowset.template GetValue <Schema::InsertTable::BlobRangeSize>();
1075
1075
}
1076
1076
1077
1077
NOlap::TCommittedData BuildCommitted (const IBlobGroupSelector* dsGroupSelector) {
1078
1078
Prepare (dsGroupSelector);
1079
1079
using namespace NColumnShard ;
1080
1080
AFL_VERIFY (RecType == Schema::EInsertTableIds::Committed);
1081
- auto userData = std::make_shared<NOlap::TUserData>(PathId,
1082
- NOlap::TBlobRange (*BlobId, RangeOffset. value_or ( 0 ) , RangeSize. value_or (BlobId-> BlobSize ()) ), *Metadata, SchemaVersion, std::nullopt);
1081
+ auto userData = std::make_shared<NOlap::TUserData>(
1082
+ PathId, NOlap::TBlobRange (*BlobId, RangeOffset, RangeSize), *Metadata, SchemaVersion, std::nullopt);
1083
1083
AFL_VERIFY (!!DedupId);
1084
1084
AFL_VERIFY (PlanStep);
1085
- return NOlap::TCommittedData (userData, PlanStep, WriteTxId, DedupId);
1085
+ return NOlap::TCommittedData (userData, PlanStep, WriteTxId, InsertWriteId, DedupId);
1086
1086
}
1087
1087
1088
1088
NOlap::TInsertedData BuildInsertedOrAborted (const IBlobGroupSelector* dsGroupSelector) {
1089
1089
Prepare (dsGroupSelector);
1090
1090
using namespace NColumnShard ;
1091
+ AFL_VERIFY (InsertWriteId == (TInsertWriteId)WriteTxId)(" insert" , InsertWriteId)(" write" , WriteTxId);
1091
1092
AFL_VERIFY (RecType != Schema::EInsertTableIds::Committed);
1092
- auto userData = std::make_shared<NOlap::TUserData>(PathId,
1093
- NOlap::TBlobRange (*BlobId, RangeOffset. value_or ( 0 ) , RangeSize. value_or (BlobId-> BlobSize ()) ), *Metadata, SchemaVersion, std::nullopt);
1093
+ auto userData = std::make_shared<NOlap::TUserData>(
1094
+ PathId, NOlap::TBlobRange (*BlobId, RangeOffset, RangeSize), *Metadata, SchemaVersion, std::nullopt);
1094
1095
AFL_VERIFY (!DedupId);
1095
1096
AFL_VERIFY (!PlanStep);
1096
- return NOlap::TInsertedData ((TInsertWriteId)WriteTxId , userData);
1097
+ return NOlap::TInsertedData (InsertWriteId , userData);
1097
1098
}
1098
1099
};
1099
1100
0 commit comments