diff options
author | Gregory Wlodarek <gregory.wlodarek@mongodb.com> | 2021-06-09 15:37:06 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-06-09 21:54:09 +0000 |
commit | 5476797a46b28156134fa7f13c15cd34f9e6ceb9 (patch) | |
tree | 7dd73f43d76da4d2b7b75e1fe22ad8d16082bcc9 | |
parent | 9f9b14e4c73d4ccb0d1f48c4faa73f4170f1c000 (diff) | |
download | mongo-5476797a46b28156134fa7f13c15cd34f9e6ceb9.tar.gz |
SERVER-57426 Enable zstd compression for time-series collections by default
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 880de670988..7856f10ceca 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); |