diff options
author | Benety Goh <benety@mongodb.com> | 2020-03-02 19:55:13 -0500 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-03-03 01:06:37 +0000 |
commit | 33ba055bad586903038902825c14948038ad495e (patch) | |
tree | 00220a0d3343f1a3fda3be43d2f82f278e257ec7 | |
parent | a1f6d2eb74268b140929c3f280c37299617d596a (diff) | |
download | mongo-33ba055bad586903038902825c14948038ad495e.tar.gz |
SERVER-46235 log IndexDescriptor as BSON
-rw-r--r-- | jstests/noPassthrough/index_stepdown_after_init.js | 18 | ||||
-rw-r--r-- | jstests/noPassthrough/index_stepdown_before_init.js | 7 | ||||
-rw-r--r-- | jstests/noPassthrough/index_stepdown_duplicate.js | 13 | ||||
-rw-r--r-- | jstests/noPassthrough/index_stepdown_unique.js | 9 | ||||
-rw-r--r-- | jstests/noPassthrough/indexbg_shutdown.js | 88 | ||||
-rw-r--r-- | src/mongo/db/catalog/index_catalog_impl.cpp | 8 | ||||
-rw-r--r-- | src/mongo/db/catalog/multi_index_block.cpp | 2 |
7 files changed, 114 insertions, 31 deletions
diff --git a/jstests/noPassthrough/index_stepdown_after_init.js b/jstests/noPassthrough/index_stepdown_after_init.js index 2d2c4b96e46..f6ab28c30fa 100644 --- a/jstests/noPassthrough/index_stepdown_after_init.js +++ b/jstests/noPassthrough/index_stepdown_after_init.js @@ -35,10 +35,13 @@ assert.commandWorked(primary.adminCommand( const createIdx = IndexBuildTest.startIndexBuild(primary, coll.getFullName(), {a: 1}); -if (isJsonLogNoConn()) { - checkLog.contains( - primary, - /\"index build: starting on {ns} properties: {descriptor} using method: {method}\".*\"descriptor\":\"{ v: 2, key: { a:/); +if (isJsonLog(primary)) { + checkLog.containsJson(primary, 20384, { + ns: coll.getFullName(), + descriptor: (desc) => { + return desc.name === 'a_1'; + }, + }); } else { checkLog.contains( primary, @@ -62,9 +65,10 @@ assert.neq(0, exitCode, 'expected shell to exit abnormally due to index build be if (!IndexBuildTest.supportsTwoPhaseIndexBuild(primary)) { // Wait for the IndexBuildCoordinator thread, not the command thread, to report the index build // as failed. - if (isJsonLogNoConn()) { - checkLog.contains( - primary, "\"ctx\":\"IndexBuildsCoordinatorMongod-0\",\"msg\":\"Index build failed"); + if (isJsonLog(primary)) { + checkLog.containsJson(primary, 20649, { + nss: coll.getFullName(), + }); } else { checkLog.contains(primary, '[IndexBuildsCoordinatorMongod-0] Index build failed: '); } diff --git a/jstests/noPassthrough/index_stepdown_before_init.js b/jstests/noPassthrough/index_stepdown_before_init.js index 3e573d7b4e7..1d17c205cdf 100644 --- a/jstests/noPassthrough/index_stepdown_before_init.js +++ b/jstests/noPassthrough/index_stepdown_before_init.js @@ -7,6 +7,7 @@ "use strict"; load("jstests/libs/fail_point_util.js"); +load("jstests/libs/logv2_helpers.js"); load('jstests/noPassthrough/libs/index_build.js'); const rst = new ReplSetTest({ @@ -59,7 +60,11 @@ assert.neq(0, exitCode, 'expected shell to exit abnormally due to index build be // With both single-phase and two-phase index builds, a stepdown at this point will abort the index // build because the builder thread cannot generate an optime. Wait for the command thread, not the // IndexBuildsCoordinator, to report the index build as failed. -checkLog.contains(primary, 'Index build failed: '); +if (isJsonLog(primary)) { + checkLog.containsJson(primary, 20449); +} else { + checkLog.contains(primary, 'Index build failed: '); +} // Check that no new index has been created. This verifies that the index build was aborted // rather than successfully completed. diff --git a/jstests/noPassthrough/index_stepdown_duplicate.js b/jstests/noPassthrough/index_stepdown_duplicate.js index ff3db94f3d7..fb874472304 100644 --- a/jstests/noPassthrough/index_stepdown_duplicate.js +++ b/jstests/noPassthrough/index_stepdown_duplicate.js @@ -8,6 +8,7 @@ (function() { "use strict"; +load('jstests/libs/logv2_helpers.js'); load('jstests/noPassthrough/libs/index_build.js'); const rst = new ReplSetTest({ @@ -37,7 +38,17 @@ assert.commandWorked(primary.adminCommand( // Use a custom index name because we are going to reuse it later with a different key pattern. const createIdx = IndexBuildTest.startIndexBuild(primary, coll.getFullName(), {a: 1}, {name: 'myidx'}); -checkLog.contains(primary, new RegExp('index build: starting.*' + coll.getFullName() + '.*myidx')); +if (isJsonLog(primary)) { + checkLog.containsJson(primary, 20384, { + ns: coll.getFullName(), + descriptor: (desc) => { + return desc.name === 'myidx'; + }, + }); +} else { + checkLog.contains(primary, + new RegExp('index build: starting.*' + coll.getFullName() + '.*myidx')); +} const newPrimary = rst.getSecondary(); diff --git a/jstests/noPassthrough/index_stepdown_unique.js b/jstests/noPassthrough/index_stepdown_unique.js index 5a56ab5fa71..c18c7e8d0b2 100644 --- a/jstests/noPassthrough/index_stepdown_unique.js +++ b/jstests/noPassthrough/index_stepdown_unique.js @@ -7,6 +7,7 @@ (function() { "use strict"; +load("jstests/libs/logv2_helpers.js"); load('jstests/noPassthrough/libs/index_build.js'); const rst = new ReplSetTest({ @@ -49,7 +50,13 @@ assert.neq(0, exitCode, 'expected shell to exit abnormally due to index build be // Wait for the IndexBuildCoordinator thread, not the command thread, to report the index build // as failed. -checkLog.contains(primary, /IndexBuildsCoordinatorMongod-0.*Index build failed: /); +if (isJsonLog(primary)) { + checkLog.containsJson(primary, 20649, { + nss: coll.getFullName(), + }); +} else { + checkLog.contains(primary, /IndexBuildsCoordinatorMongod-0.*Index build failed: /); +} IndexBuildTest.assertIndexes(coll, 1, ['_id_']); rst.stopSet(); diff --git a/jstests/noPassthrough/indexbg_shutdown.js b/jstests/noPassthrough/indexbg_shutdown.js index 0b7140eead3..30d4e543fff 100644 --- a/jstests/noPassthrough/indexbg_shutdown.js +++ b/jstests/noPassthrough/indexbg_shutdown.js @@ -12,6 +12,7 @@ (function() { "use strict"; +load("jstests/libs/logv2_helpers.js"); load('jstests/noPassthrough/libs/index_build.js'); var dbname = 'bgIndexSec'; @@ -81,32 +82,87 @@ jsTestLog('Index builds started on secondary. Op ID of one of the builds: ' + op assert.commandWorked(secondDB.killOp(opId)); // There should be a message for each index we tried to create. -checkLog.containsWithCount( - replTest.getSecondary(), - new RegExp(`(index build: starting on ${ - masterColl - .getFullName()} properties: \\{ v: 2, key: \\{ i:|index build: starting on .*"ns":"${ - masterColl.getFullName()}".*"descriptor":"\\{ v: 2, key: \\{ i)`), - indexSpecs.length); +if (isJsonLog(second)) { + checkLog.containsJson(second, 20384, { + ns: masterColl.getFullName(), + descriptor: (desc) => { + return desc.name === 'ij1'; + }, + }); + checkLog.containsJson(second, 20384, { + ns: masterColl.getFullName(), + descriptor: (desc) => { + return desc.name === 'ij2'; + }, + }); + checkLog.containsJson(second, 20384, { + ns: masterColl.getFullName(), + descriptor: (desc) => { + return desc.name === 'ij3'; + }, + }); + checkLog.containsJson(second, 20384, { + ns: masterColl.getFullName(), + descriptor: (desc) => { + return desc.name === 'ij4'; + }, + }); +} else { + checkLog.containsWithCount( + second, + new RegExp( + `(index build: starting on ${ + masterColl + .getFullName()} properties: \\{ v: 2, key: \\{ i:|index build: starting on .*"ns":"${ + masterColl.getFullName()}".*"descriptor":"\\{ v: 2, key: \\{ i)`), + indexSpecs.length); +} jsTest.log("Restarting secondary to retry replication"); // Secondary should restart cleanly. assert.commandWorked(second.adminCommand( {configureFailPoint: 'leaveIndexBuildUnfinishedForShutdown', mode: 'alwaysOn'})); IndexBuildTest.resumeIndexBuilds(second); -replTest.restart(secondaryId, {}, /*wait=*/true); +second = replTest.restart(secondaryId, {}, /*wait=*/true); // There should again be a message for each index we tried to create, because the server // restarts the interrupted index build upon process startup. Note, the RAMLog is reset on // restart, so there should just be one set of messages in the RAMLog after restart, even though // the message was logged twice in total. -checkLog.containsWithCount( - replTest.getSecondary(), - new RegExp(`(index build: starting on ${ - masterColl - .getFullName()} properties: \\{ v: 2, key: \\{ i:|index build: starting on .*"ns":"${ - masterColl.getFullName()}".*"descriptor":"\\{ v: 2, key: \\{ i)`), - indexSpecs.length); - +if (isJsonLog(second)) { + checkLog.containsJson(second, 20384, { + ns: masterColl.getFullName(), + descriptor: (desc) => { + return desc.name === 'ij1'; + }, + }); + checkLog.containsJson(second, 20384, { + ns: masterColl.getFullName(), + descriptor: (desc) => { + return desc.name === 'ij2'; + }, + }); + checkLog.containsJson(second, 20384, { + ns: masterColl.getFullName(), + descriptor: (desc) => { + return desc.name === 'ij3'; + }, + }); + checkLog.containsJson(second, 20384, { + ns: masterColl.getFullName(), + descriptor: (desc) => { + return desc.name === 'ij4'; + }, + }); +} else { + checkLog.containsWithCount( + replTest.getSecondary(), + new RegExp( + `(index build: starting on ${ + masterColl + .getFullName()} properties: \\{ v: 2, key: \\{ i:|index build: starting on .*"ns":"${ + masterColl.getFullName()}".*"descriptor":"\\{ v: 2, key: \\{ i)`), + indexSpecs.length); +} replTest.stopSet(); }()); diff --git a/src/mongo/db/catalog/index_catalog_impl.cpp b/src/mongo/db/catalog/index_catalog_impl.cpp index e8079ede4b9..f1010b7fccb 100644 --- a/src/mongo/db/catalog/index_catalog_impl.cpp +++ b/src/mongo/db/catalog/index_catalog_impl.cpp @@ -909,7 +909,7 @@ void IndexCatalogImpl::dropAllIndexes(OperationContext* opCtx, string indexName = indexNamesToDrop[i]; const IndexDescriptor* desc = findIndexByName(opCtx, indexName, true); invariant(desc); - LOGV2_DEBUG(20355, 1, "\t dropAllIndexes dropping: {desc}", "desc"_attr = desc->toString()); + LOGV2_DEBUG(20355, 1, "\t dropAllIndexes dropping: {desc}", "desc"_attr = *desc); IndexCatalogEntry* entry = _readyIndexes.find(desc); invariant(entry); @@ -1136,7 +1136,7 @@ int IndexCatalogImpl::numIndexesReady(OperationContext* opCtx) const { if (itIndexes.size() != completedIndexes.size()) { LOGV2(20357, "index catalog reports: "); for (const IndexDescriptor* i : itIndexes) { - LOGV2(20358, " index: {i}", "i"_attr = i->toString()); + LOGV2(20358, " index: {i}", "i"_attr = *i); } LOGV2(20359, "collection catalog reports: "); @@ -1660,12 +1660,12 @@ Status IndexCatalogImpl::compactIndexes(OperationContext* opCtx) { LOGV2_DEBUG(20363, 1, "compacting index: {entry_descriptor}", - "entry_descriptor"_attr = entry->descriptor()->toString()); + "entry_descriptor"_attr = *(entry->descriptor())); Status status = entry->accessMethod()->compact(opCtx); if (!status.isOK()) { LOGV2_ERROR(20377, "failed to compact index: {entry_descriptor}", - "entry_descriptor"_attr = entry->descriptor()->toString()); + "entry_descriptor"_attr = *(entry->descriptor())); return status; } } diff --git a/src/mongo/db/catalog/multi_index_block.cpp b/src/mongo/db/catalog/multi_index_block.cpp index db7f0ef6df9..b6c4d6a1bdb 100644 --- a/src/mongo/db/catalog/multi_index_block.cpp +++ b/src/mongo/db/catalog/multi_index_block.cpp @@ -338,7 +338,7 @@ StatusWith<std::vector<BSONObj>> MultiIndexBlock::init(OperationContext* opCtx, LOGV2(20384, "index build: starting on {ns} properties: {descriptor} using method: {method}", "ns"_attr = ns, - "descriptor"_attr = descriptor->toString(), + "descriptor"_attr = *descriptor, "method"_attr = _method); if (index.bulk) LOGV2(20385, |