Skip to content

Commit c152836

Browse files
committed
Initialize to prevent borrowing nullptr's
1 parent f2a67c6 commit c152836

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

.github/config/muted_ya.txt

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ ydb/core/client/ut TClientTest.PromoteFollower
44
ydb/core/client/ut TClientTest.ReadFromFollower
55
ydb/core/client/ut TFlatTest.AutoSplitMergeQueue
66
ydb/core/cms/ut_sentinel TSentinelTests.BSControllerCantChangeStatus
7-
ydb/core/debug_tools/ut OperationLog.ConcurrentWrites
87
ydb/core/quoter/ut QuoterWithKesusTest.PrefetchCoefficient
98
ydb/core/kafka_proxy/ut KafkaProtocol.CreatePartitionsScenario
109
ydb/core/kafka_proxy/ut KafkaProtocol.ProduceScenario

ydb/core/debug_tools/operation_log.h

+12-2
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,15 @@ class TOperationLog {
2727
private:
2828
constexpr static ui32 Capacity = S;
2929
std::array<std::atomic<TString*>, S> Records;
30-
// RecordIdx is shifted to prevent underflow on decrement
30+
// RecordPosition is shifted to prevent underflow on decrement
3131
std::atomic<ui64> NextRecordPosition = Capacity;
3232

3333
public:
34-
TOperationLog() = default;
34+
TOperationLog(bool initializeRecords = true, TString defaultValue = "Race occured, try again") {
35+
if (initializeRecords) {
36+
InitializeRecords(defaultValue);
37+
}
38+
};
3539

3640
TOperationLog(const TOperationLog& other) = delete;
3741
TOperationLog& operator=(const TOperationLog& other) = delete;
@@ -45,6 +49,12 @@ class TOperationLog {
4549
}
4650
}
4751

52+
bool InitializeRecords(TString value = "Race occured, try again") {
53+
for (auto& record : Records) {
54+
record.store(new TString(value))
55+
}
56+
}
57+
4858
BorrowedRecord BorrowByIdx(ui32 idx) {
4959
ui32 position = (NextRecordPosition.load() - 1 - idx) % Capacity;
5060
if (idx >= Size()) {

0 commit comments

Comments
 (0)