summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--share/www/script/test/stats.js19
-rw-r--r--src/couchdb/couch_db_updater.erl12
2 files changed, 25 insertions, 6 deletions
diff --git a/share/www/script/test/stats.js b/share/www/script/test/stats.js
index cf2581e9..6e37e741 100644
--- a/share/www/script/test/stats.js
+++ b/share/www/script/test/stats.js
@@ -80,9 +80,24 @@ couchTests.stats = function(debug) {
var testFun = function() {
var pre_dbs = getStat("couchdb", "open_databases").current || 0;
var pre_files = getStat("couchdb", "open_os_files").current || 0;
-
+
+ // We have to make sure that as we open the max'th database
+ // that we've waited for more than 1 second since opening
+ // the first database so that any delayed commits will be
+ // flushed.
+ var times = [];
for(var i = 0; i < max*2; i++) {
- newDb("test_suite_db_" + i, true);
+ if(i >= max) {
+ var msecs = (new Date()).getTime() - times[i-max];
+ if(msecs < 1000) {
+ CouchDB.request("GET", "/_sleep?time=" + (msecs+250));
+ }
+ }
+ db = newDb("test_suite_db_" + i, true);
+ times.push((new Date()).getTime());
+
+ // Trigger a delayed commit
+ db.save({_id: "" + i, "lang": "Awesome!"});
}
var open_dbs = getStat("couchdb", "open_databases").current;
diff --git a/src/couchdb/couch_db_updater.erl b/src/couchdb/couch_db_updater.erl
index 94414f2e..1da07326 100644
--- a/src/couchdb/couch_db_updater.erl
+++ b/src/couchdb/couch_db_updater.erl
@@ -656,8 +656,10 @@ commit_data(#db{fd=Fd,header=OldHeader,fsync_options=FsyncOptions}=Db, Delay) ->
if OldHeader == Header ->
Db;
Delay and (Db#db.waiting_delayed_commit == nil) ->
- Db#db{waiting_delayed_commit=
- erlang:send_after(1000, self(), delayed_commit)};
+ Db2 = Db#db{waiting_delayed_commit=
+ erlang:send_after(1000, self(), delayed_commit)},
+ ok = gen_server:call(Db2#db.main_pid, {db_updated, Db2}),
+ Db2;
Delay ->
Db;
true ->
@@ -680,9 +682,11 @@ commit_data(#db{fd=Fd,header=OldHeader,fsync_options=FsyncOptions}=Db, Delay) ->
_ -> ok
end,
- Db#db{waiting_delayed_commit=nil,
+ Db2 = Db#db{waiting_delayed_commit=nil,
header=Header,
- committed_update_seq=Db#db.update_seq}
+ committed_update_seq=Db#db.update_seq},
+ %ok = gen_server:call(Db2#db.main_pid, {db_updated, Db2}),
+ Db2
end.