forked from mooncake-track/Mooncake
fix(store): add mutex locks for thread-safe metrics retrieval (#804)
* fix(store): add mutex locks for thread-safe metrics retrieval and comparisons * refactor(get_metrics_internal): require caller to hold m_mutex instead of internal locking
This commit is contained in:
parent
0cc51a60ac
commit
03a26184ea
|
|
@ -173,7 +173,7 @@ class OffsetAllocator : public std::enable_shared_from_this<OffsetAllocator> {
|
|||
|
||||
// Internal method to get metrics without locking (caller must hold m_mutex)
|
||||
[[nodiscard]]
|
||||
OffsetAllocatorMetrics get_metrics_internal() const;
|
||||
OffsetAllocatorMetrics get_metrics_internal() const REQUIRES(m_mutex);
|
||||
|
||||
std::unique_ptr<__Allocator> m_allocator GUARDED_BY(m_mutex);
|
||||
uint64_t m_base;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
#include "offset_allocator/offset_allocator.hpp"
|
||||
#include "mutex.h"
|
||||
#include "serializer.h"
|
||||
#include "types.h"
|
||||
|
||||
|
|
@ -297,6 +298,8 @@ class OffsetAllocatorTest : public ::testing::Test {
|
|||
|
||||
void assertAllocatorEQ(const std::shared_ptr<OffsetAllocator>& a,
|
||||
const std::shared_ptr<OffsetAllocator>& b) {
|
||||
MutexLocker lock_a(&a->m_mutex);
|
||||
MutexLocker lock_b(&b->m_mutex);
|
||||
// Compare basic member variables
|
||||
ASSERT_EQ(a->m_base, b->m_base);
|
||||
ASSERT_EQ(a->m_multiplier_bits, b->m_multiplier_bits);
|
||||
|
|
@ -353,6 +356,8 @@ class OffsetAllocatorTest : public ::testing::Test {
|
|||
// Compare two allocators bytes by bytes to detect one bit difference.
|
||||
bool isAllocatorEqual(const std::shared_ptr<OffsetAllocator>& a,
|
||||
const std::shared_ptr<OffsetAllocator>& b) {
|
||||
MutexLocker lock_a(&a->m_mutex);
|
||||
MutexLocker lock_b(&b->m_mutex);
|
||||
// Compare basic member variables
|
||||
if (memcmp(&a->m_base, &b->m_base, sizeof(a->m_base)) != 0)
|
||||
return false;
|
||||
|
|
|
|||
Loading…
Reference in New Issue