From bff8b7d9751fad8319124fbfa238446170885b21 Mon Sep 17 00:00:00 2001 From: Adam Kocoloski Date: Sat, 15 Aug 2009 01:55:32 +0000 Subject: delayed commits are now a config option, off by default. Closes COUCHDB-449 git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@804427 13f79535-47bb-0310-9956-ffa450edef68 --- share/www/script/test/delayed_commits.js | 106 +++++++++++++++++-------------- 1 file changed, 58 insertions(+), 48 deletions(-) (limited to 'share') diff --git a/share/www/script/test/delayed_commits.js b/share/www/script/test/delayed_commits.js index 27ef24c8..80d345b1 100644 --- a/share/www/script/test/delayed_commits.js +++ b/share/www/script/test/delayed_commits.js @@ -16,79 +16,86 @@ couchTests.delayed_commits = function(debug) { db.createDb(); if (debug) debugger; - // By default, couchdb doesn't fully commit documents to disk right away, - // it waits about a second to batch the full commit flush along with any - // other updates. If it crashes or is restarted you may lose the most - // recent commits. + run_on_modified_server( + [{section: "couchdb", + key: "delayed_commits", + value: "true"}], - T(db.save({_id:"1",a:2,b:4}).ok); - T(db.open("1") != null); + function () { + // By default, couchdb doesn't fully commit documents to disk right away, + // it waits about a second to batch the full commit flush along with any + // other updates. If it crashes or is restarted you may lose the most + // recent commits. - restartServer(); + T(db.save({_id:"1",a:2,b:4}).ok); + T(db.open("1") != null); - T(db.open("1") == null); // lost the update. - // note if we waited > 1 sec before the restart, the doc would likely - // commit. + restartServer(); + T(db.open("1") == null); // lost the update. + // note if we waited > 1 sec before the restart, the doc would likely + // commit. - // Retry the same thing but with full commits on. - var db2 = new CouchDB("test_suite_db", {"X-Couch-Full-Commit":"true"}); + // Retry the same thing but with full commits on. - T(db2.save({_id:"1",a:2,b:4}).ok); - T(db2.open("1") != null); + var db2 = new CouchDB("test_suite_db", {"X-Couch-Full-Commit":"true"}); - restartServer(); + T(db2.save({_id:"1",a:2,b:4}).ok); + T(db2.open("1") != null); - T(db2.open("1") != null); + restartServer(); - // You can update but without committing immediately, and then ensure - // everything is commited in the last step. + T(db2.open("1") != null); - T(db.save({_id:"2",a:2,b:4}).ok); - T(db.open("2") != null); - T(db.ensureFullCommit().ok); - restartServer(); + // You can update but without committing immediately, and then ensure + // everything is commited in the last step. - T(db.open("2") != null); + T(db.save({_id:"2",a:2,b:4}).ok); + T(db.open("2") != null); + T(db.ensureFullCommit().ok); + restartServer(); - // However, it's possible even when flushed, that the server crashed between - // the update and the commit, and you don't want to check to make sure - // every doc you updated actually made it to disk. So record the instance - // start time of the database before the updates and then check it again - // after the flush (the instance start time is returned by the flush - // operation). if they are the same, we know everything was updated - // safely. + T(db.open("2") != null); - // First try it with a crash. + // However, it's possible even when flushed, that the server crashed between + // the update and the commit, and you don't want to check to make sure + // every doc you updated actually made it to disk. So record the instance + // start time of the database before the updates and then check it again + // after the flush (the instance start time is returned by the flush + // operation). if they are the same, we know everything was updated + // safely. - var instanceStartTime = db.info().instance_start_time; + // First try it with a crash. - T(db.save({_id:"3",a:2,b:4}).ok); - T(db.open("3") != null); + var instanceStartTime = db.info().instance_start_time; - restartServer(); + T(db.save({_id:"3",a:2,b:4}).ok); + T(db.open("3") != null); - var commitResult = db.ensureFullCommit(); - T(commitResult.ok && commitResult.instance_start_time != instanceStartTime); - // start times don't match, meaning the server lost our change + restartServer(); - T(db.open("3") == null); // yup lost it + var commitResult = db.ensureFullCommit(); + T(commitResult.ok && commitResult.instance_start_time != instanceStartTime); + // start times don't match, meaning the server lost our change - // retry with no server restart + T(db.open("3") == null); // yup lost it - var instanceStartTime = db.info().instance_start_time; + // retry with no server restart - T(db.save({_id:"4",a:2,b:4}).ok); - T(db.open("4") != null); + var instanceStartTime = db.info().instance_start_time; - var commitResult = db.ensureFullCommit(); - T(commitResult.ok && commitResult.instance_start_time == instanceStartTime); - // Successful commit, start times match! + T(db.save({_id:"4",a:2,b:4}).ok); + T(db.open("4") != null); - restartServer(); + var commitResult = db.ensureFullCommit(); + T(commitResult.ok && commitResult.instance_start_time == instanceStartTime); + // Successful commit, start times match! - T(db.open("4") != null); + restartServer(); + + T(db.open("4") != null); + }); // Now test that when we exceed the max_dbs_open, pending commits are safely // written. @@ -96,6 +103,9 @@ couchTests.delayed_commits = function(debug) { var max = 2; run_on_modified_server( [{section: "couchdb", + key: "delayed_commits", + value: "true"}, + {section: "couchdb", key: "max_dbs_open", value: max.toString()}], -- cgit v1.2.3