diff options
author | Adam Kocoloski <kocolosk@apache.org> | 2009-08-25 02:44:50 +0000 |
---|---|---|
committer | Adam Kocoloski <kocolosk@apache.org> | 2009-08-25 02:44:50 +0000 |
commit | ab57198abe3d550534725f7aeb45111749a0ae0a (patch) | |
tree | ccf65d6bdaa182aa28ee7eaf954aa19bd1e2ad4c | |
parent | 44fbfaa78d5931503f344055c7a122663ce1a704 (diff) |
_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
-rw-r--r-- | src/couchdb/couch_httpd_db.erl | 28 |
1 files changed, 22 insertions, 6 deletions
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"); |