SERVER-113843 Ignore an expected data race. (#43932)

GitOrigin-RevId: d3627e49777057871059ddf311194f3c289070d1
This commit is contained in:
Brad Cater 2025-11-14 09:09:07 -05:00 committed by MongoDB Bot
parent fa4493168d
commit fed12cac99
4 changed files with 54 additions and 9 deletions

View File

@ -40,6 +40,7 @@
#include "mongo/stdx/unordered_map.h"
#include "mongo/stdx/unordered_set.h"
#include "mongo/util/background.h"
#include "mongo/util/concurrency/tsan_ignore.h"
#include "mongo/util/fail_point.h"
#include "mongo/util/testing_proctor.h"
@ -48,15 +49,6 @@
namespace mongo {
namespace {
// Ignore data races in certain functions when running with TSAN. For performance reasons,
// diagnostic commands are expected to race with concurrent lock acquisitions while gathering
// statistics.
#if __has_feature(thread_sanitizer)
#define MONGO_TSAN_IGNORE __attribute__((no_sanitize("thread")))
#else
#define MONGO_TSAN_IGNORE
#endif
MONGO_FAIL_POINT_DEFINE(enableTestOnlyFlagforRSTL);
MONGO_FAIL_POINT_DEFINE(failNonIntentLocksIfWaitNeeded);
@ -303,6 +295,8 @@ void Locker::getFlowControlTicket(OperationContext* opCtx, LockMode lockMode) {
}
}
// For performance reasons, diagnostic commands are expected to race with concurrent lock
// acquisitions while gathering statistics.
MONGO_TSAN_IGNORE
FlowControlTicketholder::CurOp Locker::getFlowControlStats() const {
return _flowControlStats;
@ -528,6 +522,8 @@ ResourceId Locker::getWaitingResource() const {
return _waitingResource;
}
// For performance reasons, diagnostic commands are expected to race with concurrent lock
// acquisitions while gathering statistics.
MONGO_TSAN_IGNORE
void Locker::getLockerInfo(
LockerInfo* lockerInfo,
@ -862,6 +858,8 @@ void Locker::dump() const {
LOGV2(20523, "Locker status", "id"_attr = _id, "requests"_attr = entries);
}
// For performance reasons, diagnostic commands are expected to race with concurrent lock
// acquisitions while gathering statistics.
MONGO_TSAN_IGNORE
LockResult Locker::_lockBegin(OperationContext* opCtx, ResourceId resId, LockMode mode) {
dassert(!getWaitingResource().isValid());

View File

@ -31,6 +31,7 @@
#include "mongo/platform/compiler.h"
#include "mongo/stdx/new.h"
#include "mongo/util/concurrency/tsan_ignore.h"
#include "mongo/util/concurrency/with_lock.h"
namespace mongo {
@ -54,8 +55,13 @@ class DataWithLockFreeReads {
public:
using datum_type = DatumT;
// Ignore data races in certain functions when running with TSAN. In
// particular, ignore concurrent access to _buffers[x] because it is
// protected by WithLock on write and by the generation counter on read.
// store() requires the caller to hold the lock that protects the
// uncached value to avoid races.
MONGO_TSAN_IGNORE
void store(WithLock lk, const datum_type& datum) {
auto curGen = _generation.load();
auto nextGen = curGen + 1;
@ -63,6 +69,7 @@ public:
invariant(_generation.compareAndSwap(&curGen, nextGen));
}
MONGO_TSAN_IGNORE
datum_type load() const {
while (true) {
// Get the counter, use it to index buffers and perform a read, and

View File

@ -15,6 +15,7 @@ filegroup(
"lock_free_read_list.h",
"spin_lock.h",
"ticketholder.h",
"tsan_ignore.h",
],
)

View File

@ -0,0 +1,39 @@
/**
* Copyright (C) 2025-present MongoDB, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the Server Side Public License, version 1,
* as published by MongoDB, Inc.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* Server Side Public License for more details.
*
* You should have received a copy of the Server Side Public License
* along with this program. If not, see
* <http://www.mongodb.com/licensing/server-side-public-license>.
*
* As a special exception, the copyright holders give permission to link the
* code of portions of this program with the OpenSSL library under certain
* conditions as described in each individual source file and distribute
* linked combinations including the program with the OpenSSL library. You
* must comply with the Server Side Public License in all respects for
* all of the code used other than as permitted herein. If you modify file(s)
* with this exception, you may extend this exception to your version of the
* file(s), but you are not obligated to do so. If you do not wish to do so,
* delete this exception statement from your version. If you delete this
* exception statement from all source files in the program, then also delete
* it in the license file.
*/
#pragma once
#include "mongo/platform/compiler.h"
// Ignore data races in certain functions when running with TSAN.
#if __has_feature(thread_sanitizer)
#define MONGO_TSAN_IGNORE __attribute__((no_sanitize("thread")))
#else
#define MONGO_TSAN_IGNORE
#endif