Skip to content

Commit c052295

Browse files
committed
SERVER-16186: newCollectionsUsePowerOf2Sizes should warn users it no longer works
1 parent ab70613 commit c052295

File tree

3 files changed

+46
-10
lines changed

3 files changed

+46
-10
lines changed

jstests/mmap_v1/use_power_of_2_a.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,4 @@ assert.eq(db.adminCommand({getParameter:1,
3030
newCollectionsUsePowerOf2Sizes: true}).newCollectionsUsePowerOf2Sizes, true);
3131

3232
test(1);
33-
assert.commandWorked(db.adminCommand({setParameter:1, newCollectionsUsePowerOf2Sizes: false}));
34-
test(0);
3533

36-
// reset the server to default value
37-
assert.commandWorked(db.adminCommand({setParameter:1, newCollectionsUsePowerOf2Sizes: true}));

jstests/tool/dumprestoreWithNoOptions.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ dbname2 = "NOT_"+dbname;
2323

2424
db.dropDatabase();
2525

26+
// MMapV1 always sets newcollectionsusepowerof2sizes, WT does not
27+
defaultFlags = { "flags" : 1 }
28+
var ss = db.serverStatus();
29+
30+
if (ss.storageEngine.name != "mmapv1") {
31+
defaultFlags = {};
32+
}
33+
2634
var options = { capped: true, size: 4096, autoIndexId: true };
2735
db.createCollection('capped', options);
2836
assert.eq( 1, db.capped.getIndexes().length, "auto index not created" );
@@ -45,7 +53,7 @@ t.runTool( "restore" , "--dir" , t.ext , "--noOptionsRestore");
4553

4654
assert.eq( 1, db.capped.count() , "wrong number of docs restored to capped" );
4755
assert(true !== db.capped.stats().capped, "restore options were not ignored");
48-
assert.eq( {}, db.capped.exists().options,
56+
assert.eq( defaultFlags, db.capped.exists().options,
4957
"restore options not ignored: " + tojson( db.capped.exists() ) );
5058

5159
// Dump/restore single DB
@@ -74,7 +82,7 @@ db = db.getSiblingDB(dbname2);
7482

7583
assert.eq( 1, db.capped.count() , "wrong number of docs restored to capped" );
7684
assert(true !== db.capped.stats().capped, "restore options were not ignored");
77-
assert.eq( {}, db.capped.exists().options,
85+
assert.eq( defaultFlags, db.capped.exists().options,
7886
"restore options not ignored: " + tojson( db.capped.exists() ) );
7987

8088
// Dump/restore single collection
@@ -106,7 +114,7 @@ db = db.getSiblingDB(dbname);
106114

107115
assert.eq( 1, db.capped.count() , "wrong number of docs restored to capped" );
108116
assert( true !== db.capped.stats().capped, "restore options were not ignored" );
109-
assert.eq( {}, db.capped.exists().options,
117+
assert.eq( defaultFlags, db.capped.exists().options,
110118
"restore options not ignored: " + tojson( db.capped.exists() ) );
111119

112120
t.stop();

src/mongo/db/storage/mmap_v1/mmap_v1_database_catalog_entry.cpp

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,37 @@
5858

5959
namespace mongo {
6060

61-
MONGO_EXPORT_SERVER_PARAMETER(newCollectionsUsePowerOf2Sizes, bool, true);
61+
namespace {
62+
bool newCollectionsUsePowerOf2SizesFlag = true; // Unused, needed for server parameter.
63+
64+
/**
65+
* Declaration for the "newCollectionsUsePowerOf2Sizes" server parameter,
66+
* which is now deprecated in 2.8.
67+
* Note that:
68+
* - setting to true performs a no-op.
69+
* - setting to false will fail.
70+
*/
71+
class NewCollectionsUsePowerOf2SizesParameter : public ExportedServerParameter<bool> {
72+
public:
73+
NewCollectionsUsePowerOf2SizesParameter() :
74+
ExportedServerParameter<bool>(ServerParameterSet::getGlobal(),
75+
"newCollectionsUsePowerOf2Sizes",
76+
&newCollectionsUsePowerOf2SizesFlag,
77+
true,
78+
true) {}
79+
80+
virtual Status validate(const bool& potentialNewValue) {
81+
if (!potentialNewValue) {
82+
return Status(ErrorCodes::BadValue,
83+
"newCollectionsUsePowerOf2Sizes cannot be set to false. "
84+
"Use noPadding instead during createCollection.");
85+
}
86+
87+
return Status::OK();
88+
}
89+
90+
} exportedNewCollectionsUsePowerOf2SizesParameter;
91+
}
6292

6393
/**
6494
* Registers the insertion of a new entry in the _collections cache with the RecoveryUnit,
@@ -618,8 +648,10 @@ namespace mongo {
618648
if ( options.flagsSet ) {
619649
md.setUserFlag( txn, options.flags );
620650
}
621-
else if ( newCollectionsUsePowerOf2Sizes ) {
622-
md.setUserFlag( txn, NamespaceDetails::Flag_UsePowerOf2Sizes );
651+
else {
652+
// For compatibility with previous versions if the user sets no flags,
653+
// we set Flag_UsePowerOf2Sizes in case the user downgrades
654+
md.setUserFlag(txn, NamespaceDetails::Flag_UsePowerOf2Sizes);
623655
}
624656
}
625657
else if ( options.cappedMaxDocs > 0 ) {

0 commit comments

Comments
 (0)