diff options
author | Max Hirschhorn <max.hirschhorn@mongodb.com> | 2015-07-20 10:22:57 -0400 |
---|---|---|
committer | Max Hirschhorn <max.hirschhorn@mongodb.com> | 2015-07-20 10:22:57 -0400 |
commit | d0dd378bea15f8dd71312cf33f435ab7cbc06b5a (patch) | |
tree | 66ade9109a14d5ccdcb258cb7f187c77619b3504 | |
parent | 92c6ee5cedf09928720b79592981dc1c6aeb0482 (diff) | |
download | mongo-d0dd378bea15f8dd71312cf33f435ab7cbc06b5a.tar.gz |
SERVER-19083 Strip out WT internal metadata from creation string.
Ensures that the creation strings returned by the "collStats" command
can be used to construct an identically configured collection or index.
-rw-r--r-- | jstests/noPassthroughWithMongod/wt_roundtrip_creation_string.js | 48 | ||||
-rw-r--r-- | src/mongo/db/storage/wiredtiger/wiredtiger_util.cpp | 2 |
2 files changed, 49 insertions, 1 deletions
diff --git a/jstests/noPassthroughWithMongod/wt_roundtrip_creation_string.js b/jstests/noPassthroughWithMongod/wt_roundtrip_creation_string.js new file mode 100644 index 00000000000..d927cbb541a --- /dev/null +++ b/jstests/noPassthroughWithMongod/wt_roundtrip_creation_string.js @@ -0,0 +1,48 @@ +/** + * Tests that the creation string returned by the collStats command can be used to create a + * collection or index with the same WiredTiger options. + */ +(function() { + 'use strict'; + + // Skip this test if not running with the "wiredTiger" storage engine. + if (db.serverStatus().storageEngine.name !== 'wiredTiger') { + jsTest.log('Skipping test because storageEngine is not "wiredTiger"'); + return; + } + + var collNamePrefix = 'wt_roundtrip_creation_string'; + + // Drop the collections used by the test to ensure that the create commands don't fail because + // the collections already exist. + db[collNamePrefix].source.drop(); + db[collNamePrefix].dest.drop(); + + assert.commandWorked(db.createCollection(collNamePrefix + '.source')); + assert.commandWorked(db[collNamePrefix].source.createIndex({a: 1}, {name: 'a_1'})); + + var collStats = db.runCommand({collStats: collNamePrefix + '.source'}); + assert.commandWorked(collStats); + + assert.commandWorked(db.runCommand({ + create: collNamePrefix + '.dest', + storageEngine: { + wiredTiger: { + configString: collStats.wiredTiger.creationString + } + } + }), 'unable to create collection using the creation string of another collection'); + + assert.commandWorked(db.runCommand({ + createIndexes: collNamePrefix + '.dest', + indexes: [{ + key: {b: 1}, + name: 'b_1', + storageEngine: { + wiredTiger: { + configString: collStats.indexDetails.a_1.creationString + } + } + }] + }), 'unable to create index using the creation string of another index'); +})(); diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_util.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_util.cpp index c71672d5522..203c5722c73 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_util.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_util.cpp @@ -99,7 +99,7 @@ void WiredTigerUtil::fetchTypeAndSourceURI(OperationContext* opCtx, StatusWith<std::string> WiredTigerUtil::getMetadata(OperationContext* opCtx, StringData uri) { invariant(opCtx); - WiredTigerCursor curwrap("metadata:", WiredTigerSession::kMetadataTableId, false, opCtx); + WiredTigerCursor curwrap("metadata:create", WiredTigerSession::kMetadataTableId, false, opCtx); WT_CURSOR* cursor = curwrap.get(); invariant(cursor); std::string strUri = uri.toString(); |