summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHaley Connelly <haley.connelly@mongodb.com>2023-01-23 10:01:30 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2023-01-23 11:00:14 +0000
commit053984fd853e1900c4558006d2ed577789648142 (patch)
tree2a8ac5fa649c07fcb3b644fe896071d2e829ecb9
parentd87dc510578b49b3ece44f16ac14e54d7166a634 (diff)
downloadmongo-053984fd853e1900c4558006d2ed577789648142.tar.gz
SERVER-70865 Make TicketHolder's queued() counter int64_t
-rw-r--r--src/mongo/util/concurrency/priority_ticketholder.h22
-rw-r--r--src/mongo/util/concurrency/semaphore_ticketholder.h4
-rw-r--r--src/mongo/util/concurrency/ticket_broker.h4
-rw-r--r--src/mongo/util/concurrency/ticketholder.cpp4
-rw-r--r--src/mongo/util/concurrency/ticketholder.h18
5 files changed, 28 insertions, 24 deletions
diff --git a/src/mongo/util/concurrency/priority_ticketholder.h b/src/mongo/util/concurrency/priority_ticketholder.h
index a9eb8a90933..18a2abf7d5e 100644
--- a/src/mongo/util/concurrency/priority_ticketholder.h
+++ b/src/mongo/util/concurrency/priority_ticketholder.h
@@ -63,8 +63,8 @@ public:
return _ticketsAvailable.load();
};
- int queued() const override final {
- int result = 0;
+ int64_t queued() const override final {
+ int64_t result = 0;
for (const auto& queue : _brokers) {
result += queue.waitingThreadsRelaxed();
}
@@ -75,15 +75,20 @@ public:
* Number of times low priority operations are expedited for ticket admission over normal
* priority operations.
*/
- std::int64_t expedited() const {
+ int64_t expedited() const {
return _expeditedLowPriorityAdmissions.loadRelaxed();
}
/**
* Returns the number of times the low priority queue is bypassed in favor of dequeuing from the
* normal priority queue when a ticket becomes available.
+ *
+ * Note: This method implicitly casts a uint64_t to an int64_t. In the case where the
+ * '_lowPriorityBypassCount' is > int64_t::Max(), it may return misleading numbers due to
+ * overflow. Since this method is strictly used for FTDC data reports, but not used for internal
+ * computations, this behavior is acceptable.
*/
- std::int64_t bypassed() const {
+ int64_t bypassed() const {
return _lowPriorityBypassCount.loadRelaxed();
};
@@ -139,7 +144,6 @@ private:
return _brokers[_enumToInt(queueType)];
}
-
static QueueType _getQueueType(const AdmissionContext* admCtx) {
auto priority = admCtx->getPriority();
switch (priority) {
@@ -168,19 +172,19 @@ private:
*
* Updates must be done under the _growthMutex.
*/
- int _lowPriorityBypassThreshold;
+ int64_t _lowPriorityBypassThreshold;
/**
* Counts the number of times normal operations are dequeued over operations queued in the low
* priority queue. We explicitly use an unsigned type here because rollover is desired.
*/
- AtomicWord<std::uint64_t> _lowPriorityBypassCount{0};
+ AtomicWord<uint64_t> _lowPriorityBypassCount{0};
/**
* Number of times ticket admission is expedited for low priority operations.
*/
- AtomicWord<std::int64_t> _expeditedLowPriorityAdmissions{0};
- AtomicWord<int> _ticketsAvailable;
+ AtomicWord<int64_t> _expeditedLowPriorityAdmissions{0};
+ AtomicWord<int64_t> _ticketsAvailable;
ServiceContext* _serviceContext;
};
} // namespace mongo
diff --git a/src/mongo/util/concurrency/semaphore_ticketholder.h b/src/mongo/util/concurrency/semaphore_ticketholder.h
index 7994956cf28..4f8dba0027a 100644
--- a/src/mongo/util/concurrency/semaphore_ticketholder.h
+++ b/src/mongo/util/concurrency/semaphore_ticketholder.h
@@ -53,10 +53,10 @@ public:
int available() const override final;
- int queued() const override final {
+ int64_t queued() const override final {
auto removed = _semaphoreStats.totalRemovedQueue.loadRelaxed();
auto added = _semaphoreStats.totalAddedQueue.loadRelaxed();
- return std::max(static_cast<int>(added - removed), 0);
+ return std::max(added - removed, (int64_t)0);
};
private:
diff --git a/src/mongo/util/concurrency/ticket_broker.h b/src/mongo/util/concurrency/ticket_broker.h
index 3cc00c0815f..3e6b3d63ce1 100644
--- a/src/mongo/util/concurrency/ticket_broker.h
+++ b/src/mongo/util/concurrency/ticket_broker.h
@@ -102,7 +102,7 @@ public:
*
* This value will be consistent if called while holding the growthLock.
*/
- int waitingThreadsRelaxed() const noexcept {
+ int64_t waitingThreadsRelaxed() const noexcept {
return _numQueued.loadRelaxed();
}
@@ -134,7 +134,7 @@ private:
/**
* Number of queued threads in the linked list.
*/
- AtomicWord<int> _numQueued;
+ AtomicWord<int64_t> _numQueued;
};
} // namespace mongo
diff --git a/src/mongo/util/concurrency/ticketholder.cpp b/src/mongo/util/concurrency/ticketholder.cpp
index 5cec045df5c..5421dbaa98e 100644
--- a/src/mongo/util/concurrency/ticketholder.cpp
+++ b/src/mongo/util/concurrency/ticketholder.cpp
@@ -154,12 +154,12 @@ void TicketHolderWithQueueingStats::_appendCommonQueueImplStats(BSONObjBuilder&
b.append("addedToQueue", added);
b.append("removedFromQueue", removed);
- b.append("queueLength", std::max(static_cast<int>(added - removed), 0));
+ b.append("queueLength", std::max(added - removed, (int64_t)0));
auto finished = stats.totalFinishedProcessing.loadRelaxed();
auto started = stats.totalStartedProcessing.loadRelaxed();
b.append("startedProcessing", started);
- b.append("processing", std::max(static_cast<int>(started - finished), 0));
+ b.append("processing", std::max(started - finished, (int64_t)0));
b.append("finishedProcessing", finished);
b.append("totalTimeProcessingMicros", stats.totalTimeProcessingMicros.loadRelaxed());
b.append("canceled", stats.totalCanceled.loadRelaxed());
diff --git a/src/mongo/util/concurrency/ticketholder.h b/src/mongo/util/concurrency/ticketholder.h
index ad774750664..9ac7ddf5c79 100644
--- a/src/mongo/util/concurrency/ticketholder.h
+++ b/src/mongo/util/concurrency/ticketholder.h
@@ -164,20 +164,20 @@ public:
* tickets.
*/
struct QueueStats {
- AtomicWord<std::int64_t> totalAddedQueue{0};
- AtomicWord<std::int64_t> totalRemovedQueue{0};
- AtomicWord<std::int64_t> totalFinishedProcessing{0};
- AtomicWord<std::int64_t> totalNewAdmissions{0};
- AtomicWord<std::int64_t> totalTimeProcessingMicros{0};
- AtomicWord<std::int64_t> totalStartedProcessing{0};
- AtomicWord<std::int64_t> totalCanceled{0};
- AtomicWord<std::int64_t> totalTimeQueuedMicros{0};
+ AtomicWord<int64_t> totalAddedQueue{0};
+ AtomicWord<int64_t> totalRemovedQueue{0};
+ AtomicWord<int64_t> totalFinishedProcessing{0};
+ AtomicWord<int64_t> totalNewAdmissions{0};
+ AtomicWord<int64_t> totalTimeProcessingMicros{0};
+ AtomicWord<int64_t> totalStartedProcessing{0};
+ AtomicWord<int64_t> totalCanceled{0};
+ AtomicWord<int64_t> totalTimeQueuedMicros{0};
};
/**
* Instantaneous number of operations waiting in queue for a ticket.
*/
- virtual int queued() const = 0;
+ virtual int64_t queued() const = 0;
/**
* Instantaneous number of tickets 'available' (not checked out by an operation) in the ticket