Skip to content

Commit

Permalink
SERVER-51918 create feature flag for lock free reads
Browse files Browse the repository at this point in the history
  • Loading branch information
benety authored and Evergreen Agent committed Dec 18, 2020
1 parent 5886419 commit 4e9450a
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 24 deletions.
2 changes: 1 addition & 1 deletion etc/evergreen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11053,7 +11053,7 @@ buildvariants:
- rhel62-small
expansions: &enterprise-rhel-62-64-bit-lock-free-reads-expansions
test_flags: >-
--mongodSetParameters="{disableLockFreeReads: false}" --excludeWithAnyTags=incompatible_with_lockfreereads
--mongodSetParameters="{featureFlagLockFreeReads: true}" --excludeWithAnyTags=incompatible_with_lockfreereads
compile_flags: >-
-j$(grep -c ^processor /proc/cpuinfo)
--ssl
Expand Down
38 changes: 21 additions & 17 deletions jstests/noPassthrough/disable_lock_free_reads_server_parameter.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/**
* Tests the 'disableLockFreeReads' startup setParameter.
* Tests the 'featureFlagLockFreeReads' startup setParameter.
*
* User set disableLockFreeReads will be overridden to true (disabled) if:
* User set featureFlagLockFreeReads will be overridden to false (disabled) if:
* - with enableMajorityReadConcern=false
* Otherwise, the default for disableLockFreeReads is true.
* Otherwise, the default for featureFlagLockFreeReads is false.
*
* This test is not compatible with the special Lock Free Reads build variant because
* disableLockFreeReads is overridden there.
Expand All @@ -22,48 +22,52 @@

const replSetName = 'disable_lock_free_reads_server_parameter';

jsTest.log("Starting server with disableLockFreeReads=false in standalone mode: this should turn " +
"on lock-free reads.");
jsTest.log(
"Starting server with featureFlagLockFreeReads=true in standalone mode: this should turn " +
"on lock-free reads.");

let conn = MongoRunner.runMongod({setParameter: "disableLockFreeReads=false"});
let conn = MongoRunner.runMongod({setParameter: "featureFlagLockFreeReads=true"});
assert(conn);
checkLog.containsJson(conn, 4788403); // Logging that lock-free reads is enabled.
MongoRunner.stopMongod(conn);

jsTest.log("Starting server with disableLockFreeReads=true in standalone mode: this is the " +
jsTest.log("Starting server with featureFlagLockFreeReads=false in standalone mode: this is the " +
"default and nothing should happen.");

conn = MongoRunner.runMongod({setParameter: "disableLockFreeReads=true"});
conn = MongoRunner.runMongod({setParameter: "featureFlagLockFreeReads=false"});
assert(conn);
assert(!checkLog.checkContainsOnce(conn, "disabling lock-free reads"));
checkLog.containsJson(conn, 4788402); // Logging that lock-free reads is disabled.
MongoRunner.stopMongod(conn);

jsTest.log("Starting server with disableLockFreeReads=false and enableMajorityReadConcern=false: " +
"this should override the setting to true.");
jsTest.log(
"Starting server with featureFlagLockFreeReads=true and enableMajorityReadConcern=false: " +
"this should override the setting to true.");

conn = MongoRunner.runMongod({
replSet: replSetName,
enableMajorityReadConcern: false,
setParameter: "disableLockFreeReads=false"
setParameter: "featureFlagLockFreeReads=true"
});
assert(conn);
checkLog.containsJson(conn, 4788401); // Logging eMRCf disables lock-free reads.
checkLog.containsJson(conn, 4788402); // Logging that lock-free reads is disabled.
MongoRunner.stopMongod(conn);

jsTest.log("Starting server as a replica set member with disableLockFreeReads=false: this should " +
"turn on lock-free reads.");
jsTest.log("Starting server as a replica set member with featureFlagLockFreeReads=true: this " +
"should turn on lock-free reads.");

conn = MongoRunner.runMongod({replSet: replSetName, setParameter: "disableLockFreeReads=false"});
conn = MongoRunner.runMongod({replSet: replSetName, setParameter: "featureFlagLockFreeReads=true"});
assert(conn);
checkLog.containsJson(conn, 4788403); // Logging that lock-free reads is enabled.
MongoRunner.stopMongod(conn);

jsTest.log("Starting server as a replica set member with disableLockFreeReads=true: this is the " +
"default and nothing should happen.");
jsTest.log(
"Starting server as a replica set member with featureFlagLockFreeReads=false: this is the " +
"default and nothing should happen.");

conn = MongoRunner.runMongod({replSet: replSetName, setParameter: "disableLockFreeReads=true"});
conn =
MongoRunner.runMongod({replSet: replSetName, setParameter: "featureFlagLockFreeReads=false"});
assert(conn);
assert(!checkLog.checkContainsOnce(conn, "disabling lock-free reads"));
checkLog.containsJson(conn, 4788402); // Logging that lock-free reads is disabled.
Expand Down
1 change: 1 addition & 0 deletions src/mongo/db/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ env.Library(
'$BUILD_DIR/mongo/db/repl/repl_settings',
'$BUILD_DIR/mongo/db/repl/replica_set_messages',
'$BUILD_DIR/mongo/db/storage/storage_options',
'$BUILD_DIR/mongo/idl/feature_flag',
'$BUILD_DIR/mongo/util/options_parser/options_parser',
'global_settings',
'server_options_base',
Expand Down
6 changes: 6 additions & 0 deletions src/mongo/db/mongod_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
#include "mongo/db/server_options_base.h"
#include "mongo/db/server_options_nongeneral_gen.h"
#include "mongo/db/server_options_server_helpers.h"
#include "mongo/db/storage/storage_parameters_gen.h"
#include "mongo/logv2/log.h"
#include "mongo/logv2/log_domain_global.h"
#include "mongo/logv2/log_manager.h"
Expand Down Expand Up @@ -481,6 +482,11 @@ Status storeMongodOptions(const moe::Environment& params) {
storageGlobalParams.noTableScan.store(params["notablescan"].as<bool>());
}

// Initialize lock-free reads support from feature flag. This may be adjusted later based on
// replica set config.
storageGlobalParams.disableLockFreeReads =
!feature_flags::gLockFreeReads.isEnabledAndIgnoreFCV();

repl::ReplSettings replSettings;
if (params.count("replication.replSet")) {
/* seed list of hosts for the repl set */
Expand Down
2 changes: 1 addition & 1 deletion src/mongo/db/storage/storage_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ struct StorageGlobalParams {
// Disables lock-free reads, adjustable via setParameter. Can be disabled by certain user
// settings with which lock-free reads are incompatible: standalone mode; and
// enableMajorityReadConcern=false.
bool disableLockFreeReads;
bool disableLockFreeReads = true;

// Delay in seconds between triggering the next checkpoint after the completion of the previous
// one. A value of 0 indicates that checkpointing will be skipped.
Expand Down
9 changes: 4 additions & 5 deletions src/mongo/db/storage/storage_parameters.idl
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,12 @@ server_parameters:
default: 2048
validator:
gte: 1
disableLockFreeReads:
description: "Disables the lock-free reads feature."
set_at: [ startup ]
cpp_varname: 'storageGlobalParams.disableLockFreeReads'
default: true

feature_flags:
featureFlagLockFreeReads:
description: "Support for lock-free reads."
cpp_varname: feature_flags::gLockFreeReads
default: false
featureFlagTimeseriesCollection:
description: "When enabled, support for time-series collections"
cpp_varname: feature_flags::gTimeseriesCollection
Expand Down

0 comments on commit 4e9450a

Please sign in to comment.