Skip to content

Initialize all records to prevent borrowing nullptr's #2723

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/config/muted_ya.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ ydb/core/client/ut TClientTest.PromoteFollower
ydb/core/client/ut TClientTest.ReadFromFollower
ydb/core/client/ut TFlatTest.AutoSplitMergeQueue
ydb/core/cms/ut_sentinel TSentinelTests.BSControllerCantChangeStatus
ydb/core/debug_tools/ut OperationLog.ConcurrentWrites
ydb/core/quoter/ut QuoterWithKesusTest.PrefetchCoefficient
ydb/core/kafka_proxy/ut KafkaProtocol.CreatePartitionsScenario
ydb/core/kafka_proxy/ut KafkaProtocol.ProduceScenario
Expand Down
17 changes: 12 additions & 5 deletions ydb/core/debug_tools/operation_log.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@ class TOperationLog {
private:
constexpr static ui32 Capacity = S;
std::array<std::atomic<TString*>, S> Records;
// RecordIdx is shifted to prevent underflow on decrement
// RecordPosition is shifted to prevent underflow on decrement
std::atomic<ui64> NextRecordPosition = Capacity;

public:
TOperationLog() = default;

TOperationLog(const TOperationLog& other) = delete;
TOperationLog& operator=(const TOperationLog& other) = delete;
TOperationLog(bool initializeRecords = true, TString defaultValue = "Race occured, try again") {
if (initializeRecords) {
InitializeRecords(defaultValue);
}
};

TOperationLog(TOperationLog&& other) = default;
TOperationLog& operator=(TOperationLog&& other) = default;
Expand All @@ -45,6 +46,12 @@ class TOperationLog {
}
}

void InitializeRecords(TString value = "Race occured, try again") {
for (auto& record : Records) {
record.store(new TString(value));
}
}

BorrowedRecord BorrowByIdx(ui32 idx) {
ui32 position = (NextRecordPosition.load() - 1 - idx) % Capacity;
if (idx >= Size()) {
Expand Down