summaryrefslogtreecommitdiff
path: root/src/mongo/crypto
diff options
context:
space:
mode:
authorErwin Pe <erwin.pe@mongodb.com>2023-05-04 16:30:11 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2023-05-04 17:38:37 +0000
commitfba9dd05de659730512c9f2af0752cc71793c2fd (patch)
treed6532c6921c3d114ece4c819ab80fc848545b3b5 /src/mongo/crypto
parent5a32ec32026d0d43c1d1748f8d4584a317b667c6 (diff)
downloadmongo-fba9dd05de659730512c9f2af0752cc71793c2fd.tar.gz
SERVER-76188 Integrate cleanup implementation with unsharded command invocation
Diffstat (limited to 'src/mongo/crypto')
-rw-r--r--src/mongo/crypto/fle_stats.cpp13
-rw-r--r--src/mongo/crypto/fle_stats.h15
-rw-r--r--src/mongo/crypto/fle_stats_test.cpp27
3 files changed, 51 insertions, 4 deletions
diff --git a/src/mongo/crypto/fle_stats.cpp b/src/mongo/crypto/fle_stats.cpp
index 1798682a12f..c652190b928 100644
--- a/src/mongo/crypto/fle_stats.cpp
+++ b/src/mongo/crypto/fle_stats.cpp
@@ -50,6 +50,8 @@ FLEStatusSection::FLEStatusSection(TickSource* tickSource)
_compactStats.setEsc(zeroStats);
_compactStats.setEcoc(zeroECOC);
+ _cleanupStats.setEsc(zeroStats);
+ _cleanupStats.setEcoc(zeroECOC);
}
FLEStatusSection& FLEStatusSection::get() {
@@ -62,12 +64,21 @@ BSONObj FLEStatusSection::generateSection(OperationContext* opCtx,
{
CompactStats temp;
{
- stdx::lock_guard<Mutex> lock(_mutex);
+ stdx::lock_guard<Mutex> lock(_compactMutex);
temp = _compactStats;
}
auto sub = BSONObjBuilder(builder.subobjStart("compactStats"));
temp.serialize(&sub);
}
+ {
+ CleanupStats temp;
+ {
+ stdx::lock_guard<Mutex> lock(_cleanupMutex);
+ temp = _cleanupStats;
+ }
+ auto sub = BSONObjBuilder(builder.subobjStart("cleanupStats"));
+ temp.serialize(&sub);
+ }
if (gTestingDiagnosticsEnabledAtStartup &&
gUnsupportedDangerousTestingFLEDiagnosticsEnabledAtStartup) {
diff --git a/src/mongo/crypto/fle_stats.h b/src/mongo/crypto/fle_stats.h
index 39eec428097..db596f48c3b 100644
--- a/src/mongo/crypto/fle_stats.h
+++ b/src/mongo/crypto/fle_stats.h
@@ -96,13 +96,19 @@ public:
EmuBinaryTracker makeEmuBinaryTracker();
void updateCompactionStats(const CompactStats& stats) {
- stdx::lock_guard<Mutex> lock(_mutex);
-
+ stdx::lock_guard<Mutex> lock(_compactMutex);
_hasStats.store(true);
accumulateStats(_compactStats.getEsc(), stats.getEsc());
accumulateStats(_compactStats.getEcoc(), stats.getEcoc());
}
+ void updateCleanupStats(const CleanupStats& stats) {
+ stdx::lock_guard<Mutex> lock(_cleanupMutex);
+ _hasStats.store(true);
+ accumulateStats(_cleanupStats.getEsc(), stats.getEsc());
+ accumulateStats(_cleanupStats.getEcoc(), stats.getEcoc());
+ }
+
private:
static void accumulateStats(ECStats& left, const ECStats& right) {
left.setRead(left.getRead() + right.getRead());
@@ -124,8 +130,11 @@ private:
AtomicWord<long long> emuBinarySuboperation;
AtomicWord<long long> emuBinaryTotalMillis;
- mutable Mutex _mutex = MONGO_MAKE_LATCH("FLECompactStats::_mutex");
+ mutable Mutex _compactMutex = MONGO_MAKE_LATCH("FLECompactStats::_mutex");
CompactStats _compactStats;
+
+ mutable Mutex _cleanupMutex = MONGO_MAKE_LATCH("FLECleanupStats::_mutex");
+ CleanupStats _cleanupStats;
};
} // namespace mongo
diff --git a/src/mongo/crypto/fle_stats_test.cpp b/src/mongo/crypto/fle_stats_test.cpp
index 1336c0ee4c6..a46f71386a3 100644
--- a/src/mongo/crypto/fle_stats_test.cpp
+++ b/src/mongo/crypto/fle_stats_test.cpp
@@ -64,6 +64,12 @@ protected:
IDLParserContext("compactStats"),
BSON("ecoc" << BSON("deleted" << 1 << "read" << 1) << "esc"
<< BSON("deleted" << 1 << "inserted" << 1 << "read" << 1 << "updated" << 1)));
+
+ CleanupStats cleanupStats = CleanupStats::parse(
+ IDLParserContext("cleanupStats"),
+ BSON("ecoc" << BSON("deleted" << 1 << "read" << 1) << "esc"
+ << BSON("deleted" << 1 << "inserted" << 1 << "read" << 1 << "updated" << 1)));
+
std::unique_ptr<TickSourceMock<Milliseconds>> tickSource;
std::unique_ptr<FLEStatusSection> instance;
OperationContextNoop opCtx;
@@ -76,6 +82,8 @@ TEST_F(FLEStatsTest, NoopStats) {
auto obj = instance->generateSection(&opCtx, BSONElement());
ASSERT_TRUE(obj.hasField("compactStats"));
ASSERT_BSONOBJ_EQ(zeroStats.toBSON(), obj["compactStats"].Obj());
+ ASSERT_TRUE(obj.hasField("cleanupStats"));
+ ASSERT_BSONOBJ_EQ(zeroStats.toBSON(), obj["cleanupStats"].Obj());
ASSERT_FALSE(obj.hasField("emuBinaryStats"));
}
@@ -88,6 +96,21 @@ TEST_F(FLEStatsTest, CompactStats) {
ASSERT_TRUE(obj.hasField("compactStats"));
ASSERT_BSONOBJ_NE(zeroStats.toBSON(), obj["compactStats"].Obj());
ASSERT_BSONOBJ_EQ(compactStats.toBSON(), obj["compactStats"].Obj());
+ ASSERT_TRUE(obj.hasField("cleanupStats"));
+ ASSERT_BSONOBJ_EQ(zeroStats.toBSON(), obj["cleanupStats"].Obj());
+ ASSERT_FALSE(obj.hasField("emuBinaryStats"));
+}
+
+TEST_F(FLEStatsTest, CleanupStats) {
+ instance->updateCleanupStats(cleanupStats);
+
+ ASSERT_TRUE(instance->includeByDefault());
+
+ auto obj = instance->generateSection(&opCtx, BSONElement());
+ ASSERT_TRUE(obj.hasField("compactStats"));
+ ASSERT_BSONOBJ_EQ(zeroStats.toBSON(), obj["compactStats"].Obj());
+ ASSERT_TRUE(obj.hasField("cleanupStats"));
+ ASSERT_BSONOBJ_EQ(cleanupStats.toBSON(), obj["cleanupStats"].Obj());
ASSERT_FALSE(obj.hasField("emuBinaryStats"));
}
@@ -102,6 +125,8 @@ TEST_F(FLEStatsTest, BinaryEmuStatsAreEmptyWithoutTesting) {
auto obj = instance->generateSection(&opCtx, BSONElement());
ASSERT_TRUE(obj.hasField("compactStats"));
ASSERT_BSONOBJ_EQ(zeroStats.toBSON(), obj["compactStats"].Obj());
+ ASSERT_TRUE(obj.hasField("cleanupStats"));
+ ASSERT_BSONOBJ_EQ(zeroStats.toBSON(), obj["cleanupStats"].Obj());
ASSERT_FALSE(obj.hasField("emuBinaryStats"));
}
@@ -121,6 +146,8 @@ TEST_F(FLEStatsTest, BinaryEmuStatsArePopulatedWithTesting) {
auto obj = instance->generateSection(&opCtx, BSONElement());
ASSERT_TRUE(obj.hasField("compactStats"));
ASSERT_BSONOBJ_EQ(zeroStats.toBSON(), obj["compactStats"].Obj());
+ ASSERT_TRUE(obj.hasField("cleanupStats"));
+ ASSERT_BSONOBJ_EQ(zeroStats.toBSON(), obj["cleanupStats"].Obj());
ASSERT_TRUE(obj.hasField("emuBinaryStats"));
ASSERT_EQ(1, obj["emuBinaryStats"]["calls"].Long());
ASSERT_EQ(1, obj["emuBinaryStats"]["suboperations"].Long());