summaryrefslogtreecommitdiff
path: root/jstests/views
diff options
context:
space:
mode:
authorKyle Suarez <kyle.suarez@mongodb.com>2016-08-17 14:09:05 -0400
committerKyle Suarez <kyle.suarez@mongodb.com>2016-08-17 14:14:55 -0400
commit4eaa5aafce9457ed0f90c5099eee45ab12e9c3a3 (patch)
tree09c735c914ebcf75494e4e5d65f16938c6d2337a /jstests/views
parent9ef2dd6eb418d61368a0025ba4efc6e81910b12b (diff)
downloadmongo-4eaa5aafce9457ed0f90c5099eee45ab12e9c3a3.tar.gz
SERVER-25492 mongod gracefully handles invalid views on startup
Allows mongod to be (re)started, even in the presence of invalid view definitions in system.views. View operations will fail until the offending views are removed.
Diffstat (limited to 'jstests/views')
-rw-r--r--jstests/views/durable_view_catalog.js34
1 files changed, 34 insertions, 0 deletions
diff --git a/jstests/views/durable_view_catalog.js b/jstests/views/durable_view_catalog.js
index 483c1fee5ff..2fd0a7f5c43 100644
--- a/jstests/views/durable_view_catalog.js
+++ b/jstests/views/durable_view_catalog.js
@@ -56,5 +56,39 @@
};
}));
assert.eq(listedViews, expectedViews, "persisted view definitions not correctly loaded");
+
+ // Insert an invalid view definition directly into system.views to bypass normal validation.
+ assert.writeOK(viewsDB.system.views.insert({_id: "badView", pipeline: "badType"}));
+
+ // Restarting the mongod should succeed despite the presence of invalid view definitions.
+ MongoRunner.stopMongod(conn);
+ conn = MongoRunner.runMongod(mongodArgs);
+ assert.neq(
+ null,
+ conn,
+ "after inserting bad views, failed to restart mongod with options: " + tojson(mongodArgs));
+
+ // Now that the database's view catalog has been marked as invalid, all view operations in that
+ // database should fail.
+ viewsDB = conn.getDB("test");
+ assert.commandFailedWithCode(viewsDB.runCommand({find: "view2"}),
+ ErrorCodes.InvalidViewDefinition);
+ assert.commandFailedWithCode(viewsDB.runCommand({create: "view4", viewOn: "collection"}),
+ ErrorCodes.InvalidViewDefinition);
+ assert.commandFailedWithCode(viewsDB.runCommand({collMod: "view2", viewOn: "view4"}),
+ ErrorCodes.InvalidViewDefinition);
+ assert.commandFailedWithCode(viewsDB.runCommand({drop: "view4"}),
+ ErrorCodes.InvalidViewDefinition);
+ // TODO(SERVER-25569): We expect this to fail in the presence of bad view definitions.
+ assert.commandWorked(viewsDB.runCommand({listCollections: 1}));
+
+ // Manually remove the invalid view definition from system.views, and then verify that view
+ // operations work successfully without requiring a server restart.
+ assert.writeOK(viewsDB.system.views.remove({_id: "badView"}));
+ assert.commandWorked(viewsDB.runCommand({find: "view2"}));
+ assert.commandWorked(viewsDB.runCommand({create: "view4", viewOn: "collection"}));
+ assert.commandWorked(viewsDB.runCommand({collMod: "view2", viewOn: "view4"}));
+ assert.commandWorked(viewsDB.runCommand({drop: "view4"}));
+ assert.commandWorked(viewsDB.runCommand({listCollections: 1}));
MongoRunner.stopMongod(conn);
})();