From ab57198abe3d550534725f7aeb45111749a0ae0a Mon Sep 17 00:00:00 2001 From: Adam Kocoloski Date: Tue, 25 Aug 2009 02:44:50 +0000 Subject: _ensure_full_commit?seq=N to ensure everything up to N is committed git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@807459 13f79535-47bb-0310-9956-ffa450edef68 --- src/couchdb/couch_httpd_db.erl | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/couchdb/couch_httpd_db.erl b/src/couchdb/couch_httpd_db.erl index 32fa2935..ae58be2b 100644 --- a/src/couchdb/couch_httpd_db.erl +++ b/src/couchdb/couch_httpd_db.erl @@ -327,13 +327,29 @@ db_req(#httpd{path_parts=[_DbName]}=Req, _Db) -> send_method_not_allowed(Req, "DELETE,GET,HEAD,POST"); db_req(#httpd{method='POST',path_parts=[_,<<"_ensure_full_commit">>]}=Req, Db) -> - % make the batch save - committed = couch_batch_save:commit_now(Db#db.name, Db#db.user_ctx), - {ok, DbStartTime} = couch_db:ensure_full_commit(Db), + UpdateSeq = couch_db:get_update_seq(Db), + CommittedSeq = couch_db:get_committed_update_seq(Db), + {ok, StartTime} = + case couch_httpd:qs_value(Req, "seq") of + undefined -> + committed = couch_batch_save:commit_now(Db#db.name, Db#db.user_ctx), + couch_db:ensure_full_commit(Db); + RequiredStr -> + RequiredSeq = list_to_integer(RequiredStr), + if RequiredSeq > UpdateSeq -> + throw({bad_request, + "can't do a full commit ahead of current update_seq"}); + RequiredSeq > CommittedSeq -> + % user asked for an explicit sequence, don't commit any batches + couch_db:ensure_full_commit(Db); + true -> + {ok, Db#db.instance_start_time} + end + end, send_json(Req, 201, {[ - {ok, true}, - {instance_start_time, DbStartTime} - ]}); + {ok, true}, + {instance_start_time, StartTime} + ]}); db_req(#httpd{path_parts=[_,<<"_ensure_full_commit">>]}=Req, _Db) -> send_method_not_allowed(Req, "POST"); -- cgit v1.2.3