summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregory Wlodarek <gregory.wlodarek@mongodb.com>2021-06-09 15:37:06 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-06-10 19:25:00 +0000
commit7e352fc7ba520406477d23545eb4005523502d2e (patch)
tree3c750c50b77df41dfb0abe317f871bc93bc6bae6
parent44ec203a875bca343c2efea3b4cc205b9c630a32 (diff)
downloadmongo-7e352fc7ba520406477d23545eb4005523502d2e.tar.gz
SERVER-57426 Enable zstd compression for time-series collections by default
(cherry picked from commit 5476797a46b28156134fa7f13c15cd34f9e6ceb9)
-rw-r--r--jstests/noPassthrough/timeseries_block_compressor_options.js76
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_global_options.h2
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp10
3 files changed, 87 insertions, 1 deletions
diff --git a/jstests/noPassthrough/timeseries_block_compressor_options.js b/jstests/noPassthrough/timeseries_block_compressor_options.js
new file mode 100644
index 00000000000..34ebb245b75
--- /dev/null
+++ b/jstests/noPassthrough/timeseries_block_compressor_options.js
@@ -0,0 +1,76 @@
+/**
+ * Tests the collection block compressor during table creation for the following scenarios:
+ * 1. The default collection block compressor for regular collections is snappy and can be
+ * configured globally.
+ * 2. The default collection block compressor for time-series collections is zstd and ignores the
+ * configured global.
+ * 3. The collection block compressor passed into the 'create' command has the highest precedence
+ * for all types of collections.
+ *
+ * @tags: [requires_persistence, requires_wiredtiger]
+ */
+(function() {
+"use strict";
+
+jsTestLog("Scenario 1a: testing the default compressor for regular collections");
+let conn = MongoRunner.runMongod({});
+
+// The default for regular collections is snappy.
+assert.commandWorked(conn.getDB("db").createCollection("a"));
+let stats = conn.getDB("db").getCollection("a").stats();
+assert(stats["wiredTiger"]["creationString"].search("block_compressor=snappy") > -1);
+
+MongoRunner.stopMongod(conn);
+
+jsTestLog("Scenario 1b: testing the globally configured compressor for regular collections");
+conn = MongoRunner.runMongod({wiredTigerCollectionBlockCompressor: "none"});
+
+assert.commandWorked(conn.getDB("db").createCollection("a"));
+stats = conn.getDB("db").getCollection("a").stats();
+assert(stats["wiredTiger"]["creationString"].search("block_compressor=none") > -1);
+
+MongoRunner.stopMongod(conn);
+
+jsTestLog("Scenario 2a: testing the default compressor for time-series collections");
+conn = MongoRunner.runMongod({});
+
+// The default for time-series collections is zstd.
+const timeFieldName = 'time';
+assert.commandWorked(
+ conn.getDB("db").createCollection("a", {timeseries: {timeField: timeFieldName}}));
+stats = conn.getDB("db").getCollection("a").stats();
+assert(stats["wiredTiger"]["creationString"].search("block_compressor=zstd") > -1);
+
+MongoRunner.stopMongod(conn);
+
+jsTestLog("Scenario 2b: testing the globally configured compressor for time-series collections");
+conn = MongoRunner.runMongod({wiredTigerCollectionBlockCompressor: "none"});
+
+// Time-series collections ignore the globally configured compressor
+assert.commandWorked(
+ conn.getDB("db").createCollection("a", {timeseries: {timeField: timeFieldName}}));
+stats = conn.getDB("db").getCollection("a").stats();
+assert(stats["wiredTiger"]["creationString"].search("block_compressor=zstd") > -1);
+
+MongoRunner.stopMongod(conn);
+
+jsTestLog("Scenario 3: testing the compressor passed into the 'create' command");
+
+// The globally configured compressor will be ignored.
+conn = MongoRunner.runMongod({wiredTigerCollectionBlockCompressor: "none"});
+assert.commandWorked(conn.getDB("db").createCollection(
+ "a", {storageEngine: {wiredTiger: {configString: "block_compressor=zlib"}}}));
+assert.commandWorked(conn.getDB("db").createCollection("b", {
+ storageEngine: {wiredTiger: {configString: "block_compressor=zlib"}},
+ timeseries: {timeField: timeFieldName}
+}));
+
+stats = conn.getDB("db").getCollection("a").stats();
+jsTestLog(stats);
+assert(stats["wiredTiger"]["creationString"].search("block_compressor=zlib") > -1);
+
+stats = conn.getDB("db").getCollection("b").stats();
+assert(stats["wiredTiger"]["creationString"].search("block_compressor=zlib") > -1);
+
+MongoRunner.stopMongod(conn);
+}());
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_global_options.h b/src/mongo/db/storage/wiredtiger/wiredtiger_global_options.h
index ab361dd2d79..729c1fbcfad 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_global_options.h
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_global_options.h
@@ -38,6 +38,8 @@ namespace mongo {
class WiredTigerGlobalOptions {
public:
+ static constexpr auto kDefaultTimeseriesCollectionCompressor = "zstd"_sd;
+
WiredTigerGlobalOptions()
: cacheSizeGB(0),
statisticsLogDelaySecs(0),
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp
index 6393c3094c7..d9a63d860ec 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp
@@ -775,7 +775,15 @@ StatusWith<std::string> WiredTigerRecordStore::generateCreateString(
ss << "prefix_compression,";
}
- ss << "block_compressor=" << wiredTigerGlobalOptions.collectionBlockCompressor << ",";
+ ss << "block_compressor=";
+ if (options.timeseries) {
+ // Time-series collections use zstd compression by default.
+ ss << WiredTigerGlobalOptions::kDefaultTimeseriesCollectionCompressor;
+ } else {
+ // All other collections use the globally configured default.
+ ss << wiredTigerGlobalOptions.collectionBlockCompressor;
+ }
+ ss << ",";
ss << WiredTigerCustomizationHooks::get(getGlobalServiceContext())->getTableCreateConfig(ns);