Skip to content
Browse files

Minor changes for new indexing engine.

This commit makes some minor preparations in various files to prepare
for the new indexer support. This commit holds most of the differences
to existing files.



git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@1171145 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
1 parent 41c8430 commit c66ebaab7eaeccd591fbd2c684484503a26b598d @davisp davisp committed
View
2 Makefile.am
@@ -82,7 +82,7 @@ THANKS.gz: $(top_srcdir)/THANKS
-gzip -9 < $< > $@
check: dev
- $(top_builddir)/test/etap/run
+ $(top_builddir)/test/etap/run test/etap
cover: dev
rm -f cover/*.coverdata
View
9 src/Makefile.am
@@ -10,4 +10,11 @@
## License for the specific language governing permissions and limitations under
## the License.
-SUBDIRS = couchdb ejson erlang-oauth etap ibrowse mochiweb snappy
+SUBDIRS = \
+ couchdb \
+ ejson \
+ erlang-oauth \
+ etap \
+ ibrowse \
+ mochiweb \
+ snappy
View
13 src/couchdb/couch_ejson_compare.erl
@@ -12,7 +12,7 @@
-module(couch_ejson_compare).
--export([less/2]).
+-export([less/2, less_json_ids/2, less_json/2]).
-on_load(init/0).
@@ -41,6 +41,17 @@ less(A, B) ->
less_erl(A, B)
end.
+less_json_ids({JsonA, IdA}, {JsonB, IdB}) ->
+ case less(JsonA, JsonB) of
+ 0 ->
+ IdA < IdB;
+ Result ->
+ Result < 0
+ end.
+
+less_json(A,B) ->
+ less(A, B) < 0.
+
less_nif(A, B) ->
less_erl(A, B).
View
20 src/couchdb/couch_file.erl
@@ -29,7 +29,7 @@
-export([append_raw_chunk/2, assemble_file_chunk/1, assemble_file_chunk/2]).
-export([append_term/2, append_term/3, append_term_md5/2, append_term_md5/3]).
-export([write_header/2, read_header/1]).
--export([delete/2, delete/3, init_delete_dir/1]).
+-export([delete/2, delete/3, nuke_dir/2, init_delete_dir/1]).
% gen_server callbacks
-export([init/1, terminate/2, code_change/3]).
@@ -214,6 +214,24 @@ delete(RootDir, Filepath, Async) ->
end.
+nuke_dir(RootDelDir, Dir) ->
+ FoldFun = fun(File) ->
+ Path = Dir ++ "/" ++ File,
+ case delete(RootDelDir, Path, false) of
+ {error, eperm} -> ok = nuke_dir(RootDelDir, Path);
+ {error, enoent} -> ok;
+ ok -> ok
+ end
+ end,
+ case file:list_dir(Dir) of
+ {ok, Files} ->
+ lists:foreach(FoldFun, Files),
+ ok = file:del_dir(Dir);
+ {error, enoent} ->
+ ok
+ end.
+
+
init_delete_dir(RootDir) ->
Dir = filename:join(RootDir,".delete"),
% note: ensure_dir requires an actual filename companent, which is the
View
11 src/couchdb/couch_httpd.erl
@@ -21,7 +21,8 @@
-export([verify_is_server_admin/1,unquote/1,quote/1,recv/2,recv_chunked/4,error_info/1]).
-export([make_fun_spec_strs/1]).
-export([make_arity_1_fun/1, make_arity_2_fun/1, make_arity_3_fun/1]).
--export([parse_form/1,json_body/1,json_body_obj/1,body/1,doc_etag/1, make_etag/1, etag_respond/3]).
+-export([parse_form/1,json_body/1,json_body_obj/1,body/1]).
+-export([doc_etag/1, make_etag/1, etag_match/2, etag_respond/3, etag_maybe/2]).
-export([primary_header_value/2,partition/1,serve_file/3,serve_file/4, server_header/0]).
-export([start_chunked_response/3,send_chunk/2,log_request/2]).
-export([start_response_length/4, start_response/3, send/2]).
@@ -578,6 +579,14 @@ etag_respond(Req, CurrentEtag, RespFun) ->
RespFun()
end.
+etag_maybe(Req, RespFun) ->
+ try
+ RespFun()
+ catch
+ throw:{etag_match, ETag} ->
+ send_response(Req, 304, [{"ETag", ETag}], <<>>)
+ end.
+
verify_is_server_admin(#httpd{user_ctx=UserCtx}) ->
verify_is_server_admin(UserCtx);
verify_is_server_admin(#user_ctx{roles=Roles}) ->
View
38 src/couchdb/couch_util.erl
@@ -27,6 +27,8 @@
-export([reorder_results/2]).
-export([url_strip_password/1]).
-export([encode_doc_id/1]).
+-export([with_db/2]).
+-export([doc_member/3]).
-include("couch_db.hrl").
@@ -429,3 +431,39 @@ encode_doc_id(<<"_local/", Rest/binary>>) ->
"_local/" ++ url_encode(Rest);
encode_doc_id(Id) ->
url_encode(Id).
+
+
+with_db(Db, Fun) when is_record(Db, db) ->
+ Fun(Db);
+with_db(DbName, Fun) ->
+ case couch_db:open_int(DbName, []) of
+ {ok, Db} ->
+ try
+ Fun(Db)
+ after
+ catch couch_db:close(Db)
+ end;
+ Else ->
+ throw(Else)
+ end.
+
+
+% Rescued from couch_httpd_view.erl, this should really go
+% somewhere else but I can't decide where.
+doc_member(Db, #doc_info{id=Id, revs=[#rev_info{rev=Rev} | _]} = Info, Opts) ->
+ ?LOG_DEBUG("Include Doc: ~p ~p", [Id, Rev]),
+ case couch_db:open_doc(Db, Info, [deleted | Opts]) of
+ {ok, Doc} ->
+ [{doc, couch_doc:to_json_obj(Doc, [])}];
+ _ ->
+ [{doc, null}]
+ end;
+doc_member(Db, {DocId, Rev}, Opts) ->
+ ?LOG_DEBUG("Include Doc: ~p ~p", [DocId, Rev]),
+ case (catch couch_httpd_db:couch_doc_open(Db, DocId, Rev, Opts)) of
+ #doc{} = Doc ->
+ JsonDoc = couch_doc:to_json_obj(Doc, []),
+ [{doc, JsonDoc}];
+ _Else ->
+ [{doc, null}]
+ end.
View
21 test/etap/run.tpl
@@ -13,15 +13,20 @@
# the License.
SRCDIR="%abs_top_srcdir%"
-BUILDIR="%abs_top_builddir%"
+BUILDDIR="%abs_top_builddir%"
+export ERL_LIBS="$BUILDDIR/src/:$ERL_LIBS"
+export ERL_FLAGS="$ERL_FLAGS -pa $BUILDDIR/test/etap/"
-export ERL_FLAGS="$ERL_FLAGS -pa $BUILDIR/test/etap/"
+if test $# -eq 1; then
+ OPTS=""
+ TGT=$1
+else
+ OPTS=$1
+ TGT=$2
+fi
-if test $# -gt 0; then
- while [ $# -gt 0 ]; do
- $1
- shift
- done
+if test -f $TGT; then
+ prove $OPTS $TGT
else
- prove $SRCDIR/test/etap/*.t
+ prove $OPTS $TGT/*.t
fi
View
26 test/etap/test_util.erl.in
@@ -14,6 +14,7 @@
-export([init_code_path/0]).
-export([source_file/1, build_file/1, config_files/0]).
+-export([run/2]).
srcdir() ->
"@abs_top_srcdir@".
@@ -22,8 +23,15 @@ builddir() ->
"@abs_top_builddir@".
init_code_path() ->
- Paths = ["etap", "couchdb", "ejson", "erlang-oauth", "ibrowse", "mochiweb",
- "snappy"],
+ Paths = [
+ "etap",
+ "couchdb",
+ "ejson",
+ "erlang-oauth",
+ "ibrowse",
+ "mochiweb",
+ "snappy"
+ ],
lists:foreach(fun(Name) ->
code:add_patha(filename:join([builddir(), "src", Name]))
end, Paths).
@@ -40,3 +48,17 @@ config_files() ->
source_file("test/etap/random_port.ini"),
build_file("etc/couchdb/local_dev.ini")
].
+
+
+run(Plan, Fun) ->
+ test_util:init_code_path(),
+ etap:plan(Plan),
+ case (catch Fun()) of
+ ok ->
+ etap:end_tests();
+ Other ->
+ etap:diag(io_lib:format("Test died abnormally:~n~p", [Other])),
+ timer:sleep(500),
+ etap:bail(Other)
+ end,
+ ok.
View
2 utils/Makefile.am
@@ -23,7 +23,7 @@ run: ../bin/couchdb.tpl
-e "s|%bindir%|$(abs_top_builddir)/bin|g" \
-e "s|%defaultini%|default_dev.ini|g" \
-e "s|%localini%|local_dev.ini|g" \
- -e "s|%localerlanglibdir%|foo \
+ -e "s|%localerlanglibdir%|$(abs_top_builddir)\/src \
-pa $(abs_top_builddir)\/src\/couchdb \
-pa $(abs_top_builddir)\/src\/ejson \
-pa $(abs_top_builddir)\/src\/erlang-oauth \

0 comments on commit c66ebaa

Please sign in to comment.
Something went wrong with that request. Please try again.