Skip to content

Commit b99f854

Browse files
fix segfault and memory leaks in CS (#7288)
Co-authored-by: ivanmorozov333 <[email protected]>
1 parent 725b0df commit b99f854

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
lines changed

ydb/core/formats/arrow/common/container.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@ TGeneralContainer::TGeneralContainer(const std::shared_ptr<arrow::RecordBatch>&
117117
Initialize();
118118
}
119119

120+
TGeneralContainer::TGeneralContainer(const ui32 recordsCount)
121+
: RecordsCount(recordsCount)
122+
, Schema(std::make_shared<NModifier::TSchema>()) {
123+
}
124+
120125
std::shared_ptr<NKikimr::NArrow::NAccessor::IChunkedArray> TGeneralContainer::GetAccessorByNameVerified(const std::string& fieldId) const {
121126
auto result = GetAccessorByNameOptional(fieldId);
122127
AFL_VERIFY(result)("event", "cannot_find_accessor_in_general_container")("field_id", fieldId)("schema", Schema->ToString());

ydb/core/formats/arrow/common/container.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ class TGeneralContainer {
2929
std::vector<std::shared_ptr<NAccessor::IChunkedArray>> Columns;
3030
void Initialize();
3131
public:
32+
TGeneralContainer(const ui32 recordsCount);
33+
34+
ui32 GetRecordsCountVerified() const {
35+
AFL_VERIFY(RecordsCount);
36+
return *RecordsCount;
37+
}
38+
3239
TString DebugString() const;
3340

3441
[[nodiscard]] TConclusionStatus SyncSchemaTo(const std::shared_ptr<arrow::Schema>& schema,
@@ -67,7 +74,6 @@ class TGeneralContainer {
6774

6875
[[nodiscard]] TConclusionStatus AddField(const std::shared_ptr<arrow::Field>& f, const std::shared_ptr<arrow::ChunkedArray>& data);
6976

70-
TGeneralContainer() = default;
7177
TGeneralContainer(const std::shared_ptr<arrow::Table>& table);
7278
TGeneralContainer(const std::shared_ptr<arrow::RecordBatch>& table);
7379
TGeneralContainer(const std::shared_ptr<arrow::Schema>& schema, std::vector<std::shared_ptr<NAccessor::IChunkedArray>>&& columns);

ydb/core/tx/columnshard/engines/scheme/versions/abstract_scheme.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ TConclusion<std::shared_ptr<NArrow::TGeneralContainer>> ISnapshotSchema::Normali
3535
AFL_VERIFY(dataSchema.GetSnapshot() < GetSnapshot());
3636
const std::shared_ptr<arrow::Schema>& resultArrowSchema = GetSchema();
3737

38-
std::shared_ptr<NArrow::TGeneralContainer> result = std::make_shared<NArrow::TGeneralContainer>();
38+
std::shared_ptr<NArrow::TGeneralContainer> result = std::make_shared<NArrow::TGeneralContainer>(batch->GetRecordsCountVerified());
3939
for (size_t i = 0; i < resultArrowSchema->fields().size(); ++i) {
4040
auto& resultField = resultArrowSchema->fields()[i];
4141
auto columnId = GetIndexInfo().GetColumnId(resultField->name());

ydb/core/tx/columnshard/transactions/operators/sharing.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ bool TSharingTransactionOperator::DoParse(TColumnShard& owner, const TString& da
2828
AFL_WARN(NKikimrServices::TX_COLUMNSHARD)("event", "session_exists")("session_id", SharingTask->GetSessionId())("info", SharingTask->DebugString());
2929
} else {
3030
SharingTask->Confirm();
31+
TxPropose = SharingSessionsManager->ProposeDestSession(&owner, SharingTask);
3132
}
3233

33-
TxPropose = SharingSessionsManager->ProposeDestSession(&owner, SharingTask);
3434

3535
return true;
3636
}
@@ -47,8 +47,8 @@ void TSharingTransactionOperator::DoStartProposeOnComplete(TColumnShard& /*owner
4747
if (!SessionExistsFlag) {
4848
AFL_VERIFY(!!TxPropose);
4949
TxPropose->Complete(ctx);
50+
TxPropose.reset();
5051
}
51-
TxPropose.release();
5252
}
5353

5454
bool TSharingTransactionOperator::ProgressOnExecute(

0 commit comments

Comments
 (0)