summaryrefslogtreecommitdiff
path: root/jstests/noPassthrough/timeseries_block_compressor_options.js
blob: 34ebb245b75a249f54751359fb38fbb25353be53 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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);
}());