summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--share/www/script/test/stats.js27
-rw-r--r--src/couchdb/couch_db_updater.erl20
2 files changed, 21 insertions, 26 deletions
diff --git a/share/www/script/test/stats.js b/share/www/script/test/stats.js
index 7c32fdff..793b390d 100644
--- a/share/www/script/test/stats.js
+++ b/share/www/script/test/stats.js
@@ -85,28 +85,21 @@ couchTests.stats = function(debug) {
// that we've waited for more than 1 second since opening
// the first database so that any delayed commits will be
// flushed.
- var times = [];
+ var triggered = false;
+ var db = null;
for(var i = 0; i < max*2; i++) {
- if(i >= max) {
- if(i == max) {
- try {
- newDb("test_suite_db_" + i, true);
- T(0 === 1, "Should have failed to create max+1 db's quickly.");
- } catch(e) {
- T(e.reason == "all_dbs_active", "All db's should be active.");
- }
- }
- var msecs = (new Date()).getTime() - times[i-max];
- if(msecs < 1000) {
- CouchDB.request("GET", "/_sleep?time=" + (msecs+250));
- }
+ try {
+ db = newDb("test_suite_db_" + i, true);
+ } catch(e) {
+ triggered = true;
+ CouchDB.request("GET", "/_sleep?time=1500");
+ db = newDb("test_suite_db_" + i, true);
}
- db = newDb("test_suite_db_" + i, true);
- times.push((new Date()).getTime());
-
+
// Trigger a delayed commit
db.save({_id: "" + i, "lang": "Awesome!"});
}
+ T(triggered, "We managed to force a all_dbs_active error.");
var open_dbs = getStat("couchdb", "open_databases").current;
TEquals(open_dbs > 0, true, "We actually opened some dbs.");
diff --git a/src/couchdb/couch_db_updater.erl b/src/couchdb/couch_db_updater.erl
index 51a81efd..db5c43bc 100644
--- a/src/couchdb/couch_db_updater.erl
+++ b/src/couchdb/couch_db_updater.erl
@@ -208,7 +208,13 @@ handle_info({update_docs, Client, GroupedDocs, NonRepDocs, MergeConflicts,
{noreply, Db}
end;
handle_info(delayed_commit, Db) ->
- {noreply, commit_data(Db)}.
+ case commit_data(Db) of
+ Db ->
+ {noreply, Db};
+ Db2 ->
+ ok = gen_server:call(Db2#db.main_pid, {db_updated, Db2}),
+ {noreply, Db2}
+ end.
code_change(_OldVsn, State, _Extra) ->
{ok, State}.
@@ -656,10 +662,8 @@ commit_data(#db{fd=Fd,header=OldHeader,fsync_options=FsyncOptions}=Db, Delay) ->
if OldHeader == Header ->
Db;
Delay and (Db#db.waiting_delayed_commit == nil) ->
- 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;
+ Db#db{waiting_delayed_commit=
+ erlang:send_after(1000, self(), delayed_commit)};
Delay ->
Db;
true ->
@@ -682,11 +686,9 @@ commit_data(#db{fd=Fd,header=OldHeader,fsync_options=FsyncOptions}=Db, Delay) ->
_ -> ok
end,
- Db2 = Db#db{waiting_delayed_commit=nil,
+ Db#db{waiting_delayed_commit=nil,
header=Header,
- committed_update_seq=Db#db.update_seq},
- ok = gen_server:call(Db2#db.main_pid, {db_updated, Db2}),
- Db2
+ committed_update_seq=Db#db.update_seq}
end.