summaryrefslogtreecommitdiff
path: root/src/mongo/db/sorter/sorter.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/sorter/sorter.h')
-rw-r--r--src/mongo/db/sorter/sorter.h29
1 files changed, 27 insertions, 2 deletions
diff --git a/src/mongo/db/sorter/sorter.h b/src/mongo/db/sorter/sorter.h
index aed12ffdfe2..440da3b54c3 100644
--- a/src/mongo/db/sorter/sorter.h
+++ b/src/mongo/db/sorter/sorter.h
@@ -40,6 +40,7 @@
#include <vector>
#include "mongo/bson/util/builder.h"
+#include "mongo/platform/atomic_word.h"
#include "mongo/util/bufreader.h"
/**
@@ -91,6 +92,14 @@
namespace mongo {
/**
+ * For collecting file usage metrics.
+ */
+struct SorterFileStats {
+ AtomicWord<long long> opened;
+ AtomicWord<long long> closed;
+};
+
+/**
* Runtime options that control the Sorter's behavior
*/
struct SortOptions {
@@ -108,7 +117,14 @@ struct SortOptions {
// extSortAllowed is true.
std::string tempDir;
- SortOptions() : limit(0), maxMemoryUsageBytes(64 * 1024 * 1024), extSortAllowed(false) {}
+ // If set, allows us to observe Sorter file handle usage.
+ SorterFileStats* sorterFileStats;
+
+ SortOptions()
+ : limit(0),
+ maxMemoryUsageBytes(64 * 1024 * 1024),
+ extSortAllowed(false),
+ sorterFileStats(nullptr) {}
// Fluent API to support expressions like SortOptions().Limit(1000).ExtSortAllowed(true)
@@ -131,6 +147,11 @@ struct SortOptions {
tempDir = newTempDir;
return *this;
}
+
+ SortOptions& FileStats(SorterFileStats* newSorterFileStats) {
+ sorterFileStats = newSorterFileStats;
+ return *this;
+ }
};
/**
@@ -219,7 +240,8 @@ public:
*/
class File {
public:
- File(std::string path) : _path(std::move(path)) {
+ File(std::string path, SorterFileStats* stats = nullptr)
+ : _path(std::move(path)), _stats(stats) {
invariant(!_path.empty());
}
@@ -266,6 +288,9 @@ public:
// Whether to keep the on-disk file even after this in-memory object has been destructed.
bool _keep = false;
+
+ // If set, this points to an external metrics holder for tracking file open/close activity.
+ SorterFileStats* _stats;
};
explicit Sorter(const SortOptions& opts);