Skip to content

Commit 815e66d

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

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
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

+15-3
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,16 @@ 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;
32+
std::atomic<ui64> CommittedRecordPosition = Capacity;
3233

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

3641
TOperationLog(const TOperationLog& other) = delete;
3742
TOperationLog& operator=(const TOperationLog& other) = delete;
@@ -45,6 +50,12 @@ class TOperationLog {
4550
}
4651
}
4752

53+
bool InitializeRecords(TString value = "Race occured, try again") {
54+
for (auto& record : Records) {
55+
record.store(new TString(value))
56+
}
57+
}
58+
4859
BorrowedRecord BorrowByIdx(ui32 idx) {
4960
ui32 position = (NextRecordPosition.load() - 1 - idx) % Capacity;
5061
if (idx >= Size()) {
@@ -68,11 +79,12 @@ class TOperationLog {
6879
}
6980

7081
ui32 Size() const {
71-
return Min(NextRecordPosition.load() - Capacity, static_cast<ui64>(Capacity));
82+
return Min(CommittedRecordPosition.load() - Capacity, static_cast<ui64>(Capacity));
7283
}
7384

7485
void AddRecord(std::unique_ptr<TString>& value) {
7586
TString* prev = Records[NextRecordPosition.fetch_add(1) % Capacity].exchange(value.release());
87+
CommittedRecordPosition.fetch_add(1);
7688
if (prev) {
7789
delete prev;
7890
}

0 commit comments

Comments
 (0)