You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by da...@apache.org on 2017/05/30 18:43:07 UTC

[couchdb] branch COUCHDB-3287-pluggable-storage-engines updated (7162a24 -> 85a163a)

This is an automated email from the ASF dual-hosted git repository.

davisp pushed a change to branch COUCHDB-3287-pluggable-storage-engines
in repository https://gitbox.apache.org/repos/asf/couchdb.git.

      from  7162a24   Mark pluggable storage engines as a feature
       new  89a985e   Add default storage engine config with comments
       new  b5e0d5a   Remove unnecessary pattern match
       new  33e1b4f   Fix typo
       new  9b4a4f9   Remove overly broad any() type
       new  fe02bcc   Rename handle_call and handle_info callbacks
       new  7cc7107   Remove outdated comment
       new  08f2fca   Fix type spec to allow disabling compression
       new  0549843   Update pattern match for clarity
       new  36df111   Remove stub for swapping engines
       new  6ef99bd   Remove unused function clause
       new  0d8a45f   Add a log message for misconfigured default engine
       new  68c3008   Add error and test for invalid engine
       new  85a163a   Reject unknown engines in chttpd

The 13 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "adds" were already present in the repository and have only
been added to this reference.


Summary of changes:
 rel/overlay/etc/default.ini           | 10 +++++
 src/chttpd/src/chttpd_db.erl          | 21 ++++++++--
 src/chttpd/test/chttpd_db_test.erl    | 16 +++++++-
 src/couch/src/couch_bt_engine.erl     | 12 +++---
 src/couch/src/couch_db.erl            |  6 ++-
 src/couch/src/couch_db_engine.erl     | 22 +++++------
 src/couch/src/couch_db_updater.erl    | 17 ++------
 src/couch/src/couch_server.erl        | 74 ++++++++++++++++++++---------------
 src/couch/test/couch_server_tests.erl | 16 ++++++++
 9 files changed, 123 insertions(+), 71 deletions(-)

-- 
To stop receiving notification emails like this one, please contact
['"commits@couchdb.apache.org" <co...@couchdb.apache.org>'].

[couchdb] 05/13: Rename handle_call and handle_info callbacks

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davisp pushed a commit to branch COUCHDB-3287-pluggable-storage-engines
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit fe02bcc8222e9559af5d70e38f0c11b87bd8d95d
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Tue May 30 11:27:08 2017 -0500

    Rename handle_call and handle_info callbacks
    
    This is to avoid clashing with the gen behavior callbacks in case
    someone ever decides to mix couch_db_engine and gen behaviors in a
    single module.
---
 src/couch/src/couch_bt_engine.erl  |  8 ++++----
 src/couch/src/couch_db_engine.erl  | 16 ++++++++--------
 src/couch/src/couch_db_updater.erl |  4 ++--
 3 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/src/couch/src/couch_bt_engine.erl b/src/couch/src/couch_bt_engine.erl
index 068d3c9..a5318cd 100644
--- a/src/couch/src/couch_bt_engine.erl
+++ b/src/couch/src/couch_bt_engine.erl
@@ -21,8 +21,8 @@
 
     init/2,
     terminate/2,
-    handle_call/2,
-    handle_info/2,
+    handle_db_updater_call/2,
+    handle_db_updater_info/2,
 
     incref/1,
     decref/1,
@@ -162,11 +162,11 @@ terminate(_Reason, St) ->
     ok.
 
 
-handle_call(Msg, St) ->
+handle_db_updater_call(Msg, St) ->
     {stop, {invalid_call, Msg}, {invalid_call, Msg}, St}.
 
 
-handle_info({'DOWN', Ref, _, _, _}, #st{fd_monitor=Ref} = St) ->
+handle_db_updater_info({'DOWN', Ref, _, _, _}, #st{fd_monitor=Ref} = St) ->
     {stop, normal, St#st{fd=undefined, fd_monitor=closed}}.
 
 
diff --git a/src/couch/src/couch_db_engine.erl b/src/couch/src/couch_db_engine.erl
index d788912..7271f3a 100644
--- a/src/couch/src/couch_db_engine.erl
+++ b/src/couch/src/couch_db_engine.erl
@@ -140,14 +140,14 @@
 % This is called in the context of couch_db_updater:handle_call/3
 % for any message that is unknown. It can be used to handle messages
 % from asynchronous processes like the engine's compactor if it has one.
--callback handle_call(Msg::any(), DbHandle::db_handle()) ->
+-callback handle_db_updater_call(Msg::any(), DbHandle::db_handle()) ->
         {reply, Resp::any(), NewDbHandle::db_handle()} |
         {stop, Reason::any(), Resp::any(), NewDbHandle::db_handle()}.
 
 
 % This is called in the context of couch_db_updater:handle_info/2
 % and has the same properties as handle_call/3.
--callback handle_info(Msg::any(), DbHandle::db_handle()) ->
+-callback handle_db_updater_info(Msg::any(), DbHandle::db_handle()) ->
     {noreply, NewDbHandle::db_handle()} |
     {noreply, NewDbHandle::db_handle(), Timeout::timeout()} |
     {stop, Reason::any(), NewDbHandle::db_handle()}.
@@ -573,8 +573,8 @@
 
     init/3,
     terminate/2,
-    handle_call/3,
-    handle_info/2,
+    handle_db_updater_call/3,
+    handle_db_updater_info/2,
 
     incref/1,
     decref/1,
@@ -647,11 +647,11 @@ terminate(Reason, #db{} = Db) ->
     Engine:terminate(Reason, EngineState).
 
 
-handle_call(Msg, _From, #db{} = Db) ->
+handle_db_updater_call(Msg, _From, #db{} = Db) ->
     #db{
         engine = {Engine, EngineState}
     } = Db,
-    case Engine:handle_call(Msg, EngineState) of
+    case Engine:handle_db_updater_call(Msg, EngineState) of
         {reply, Resp, NewState} ->
             {reply, Resp, Db#db{engine = {Engine, NewState}}};
         {stop, Reason, Resp, NewState} ->
@@ -659,12 +659,12 @@ handle_call(Msg, _From, #db{} = Db) ->
     end.
 
 
-handle_info(Msg, #db{} = Db) ->
+handle_db_updater_info(Msg, #db{} = Db) ->
     #db{
         name = Name,
         engine = {Engine, EngineState}
     } = Db,
-    case Engine:handle_info(Msg, EngineState) of
+    case Engine:handle_db_updater_info(Msg, EngineState) of
         {noreply, NewState} ->
             {noreply, Db#db{engine = {Engine, NewState}}};
         {noreply, NewState, Timeout} ->
diff --git a/src/couch/src/couch_db_updater.erl b/src/couch/src/couch_db_updater.erl
index dd5b4e7..ddf15a2 100644
--- a/src/couch/src/couch_db_updater.erl
+++ b/src/couch/src/couch_db_updater.erl
@@ -166,7 +166,7 @@ handle_call({purge_docs, IdRevs}, _From, Db) ->
     {reply, {ok, PurgeSeq, PurgedIdRevs}, Db2};
 
 handle_call(Msg, From, Db) ->
-    couch_db_engine:handle_call(Msg, From, Db).
+    couch_db_engine:handle_db_updater_call(Msg, From, Db).
 
 
 handle_cast({load_validation_funs, ValidationFuns}, Db) ->
@@ -267,7 +267,7 @@ handle_info({'EXIT', _Pid, normal}, Db) ->
 handle_info({'EXIT', _Pid, Reason}, Db) ->
     {stop, Reason, Db};
 handle_info(Msg, Db) ->
-    couch_db_engine:handle_info(Msg, Db).
+    couch_db_engine:handle_db_updater_info(Msg, Db).
 
 code_change(_OldVsn, State, _Extra) ->
     {ok, State}.

-- 
To stop receiving notification emails like this one, please contact
"commits@couchdb.apache.org" <co...@couchdb.apache.org>.

[couchdb] 06/13: Remove outdated comment

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davisp pushed a commit to branch COUCHDB-3287-pluggable-storage-engines
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 7cc7107c6c822da5b8685c41488fefcaaa741922
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Tue May 30 11:28:17 2017 -0500

    Remove outdated comment
---
 src/couch/src/couch_db.erl | 1 -
 1 file changed, 1 deletion(-)

diff --git a/src/couch/src/couch_db.erl b/src/couch/src/couch_db.erl
index 5018d25..0b24978 100644
--- a/src/couch/src/couch_db.erl
+++ b/src/couch/src/couch_db.erl
@@ -370,7 +370,6 @@ get_doc_info(Db, Id) ->
         Else
     end.
 
-%   returns {ok, DocInfo} or not_found
 get_full_doc_info(Db, Id) ->
     [Result] = get_full_doc_infos(Db, [Id]),
     Result.

-- 
To stop receiving notification emails like this one, please contact
"commits@couchdb.apache.org" <co...@couchdb.apache.org>.

[couchdb] 04/13: Remove overly broad any() type

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davisp pushed a commit to branch COUCHDB-3287-pluggable-storage-engines
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 9b4a4f9698e4b21f6738b9539dd57d56850f22f2
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Tue May 30 11:24:14 2017 -0500

    Remove overly broad any() type
---
 src/couch/src/couch_db_engine.erl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/couch/src/couch_db_engine.erl b/src/couch/src/couch_db_engine.erl
index 17a798c..d788912 100644
--- a/src/couch/src/couch_db_engine.erl
+++ b/src/couch/src/couch_db_engine.erl
@@ -96,7 +96,7 @@
             RootDir::filepath(),
             DbPath::filepath(),
             DelOpts::delete_options()) ->
-        ok | {error, Reason::atom()} | any().
+        ok | {error, Reason::atom()}.
 
 
 % This function can be called from multiple contexts. It

-- 
To stop receiving notification emails like this one, please contact
"commits@couchdb.apache.org" <co...@couchdb.apache.org>.

[couchdb] 09/13: Remove stub for swapping engines

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davisp pushed a commit to branch COUCHDB-3287-pluggable-storage-engines
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 36df11148bfdab88eb8cc3654cf849c43a9a795d
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Tue May 30 11:33:57 2017 -0500

    Remove stub for swapping engines
    
    This is vestigal code from an idea for swapping engines at compaction
    time. It was never fully implemented and got kicked out to a future v2
    of the API. For now I'll just remove the call out to an unimplemented
    function.
---
 src/couch/src/couch_db_updater.erl | 13 ++-----------
 1 file changed, 2 insertions(+), 11 deletions(-)

diff --git a/src/couch/src/couch_db_updater.erl b/src/couch/src/couch_db_updater.erl
index ddf15a2..4b591b3 100644
--- a/src/couch/src/couch_db_updater.erl
+++ b/src/couch/src/couch_db_updater.erl
@@ -190,13 +190,8 @@ handle_cast(start_compact, Db) ->
             % compact currently running, this is a no-op
             {noreply, Db}
     end;
-handle_cast({compact_done, CompactEngine, CompactInfo}, #db{} = OldDb) ->
-    {ok, NewDb} = case couch_db_engine:get_engine(OldDb) of
-        CompactEngine ->
-            couch_db_engine:finish_compaction(OldDb, CompactInfo);
-        _ ->
-            finish_engine_swap(OldDb, CompactEngine, CompactInfo)
-    end,
+handle_cast({compact_done, _Engine, CompactInfo}, #db{} = OldDb) ->
+    {ok, NewDb} = couch_db_engine:finish_compaction(OldDb, CompactInfo),
     {noreply, NewDb};
 
 handle_cast(Msg, #db{name = Name} = Db) ->
@@ -687,10 +682,6 @@ commit_data(Db, _) ->
     }.
 
 
-finish_engine_swap(_OldDb, _NewEngine, _CompactFilePath) ->
-    erlang:error(explode).
-
-
 pair_write_info(Old, New) ->
     lists:map(fun(FDI) ->
         case lists:keyfind(FDI#full_doc_info.id, #full_doc_info.id, Old) of

-- 
To stop receiving notification emails like this one, please contact
"commits@couchdb.apache.org" <co...@couchdb.apache.org>.

[couchdb] 01/13: Add default storage engine config with comments

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davisp pushed a commit to branch COUCHDB-3287-pluggable-storage-engines
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 89a985effff727ff95cc826878077eee48e72cf0
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Tue May 30 11:19:11 2017 -0500

    Add default storage engine config with comments
---
 rel/overlay/etc/default.ini | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/rel/overlay/etc/default.ini b/rel/overlay/etc/default.ini
index 5dc4628..07b4e70 100644
--- a/rel/overlay/etc/default.ini
+++ b/rel/overlay/etc/default.ini
@@ -35,6 +35,16 @@ default_security = admin_local
 ; stem_interactive_updates = true
 ; update_lru_on_read = true
 ; uri_file =
+; The default storage engine to use when creating databases
+; is set as a key into the [couchdb_engines] section.
+default_engine = couch
+
+[couchdb_engines]
+; The keys in this section are the filename extension that
+; the specified engine module will use. This is important so
+; that couch_server is able to find an existing database without
+; having to ask every configured engine.
+couch = couch_bt_engine
 
 [cluster]
 q=8

-- 
To stop receiving notification emails like this one, please contact
"commits@couchdb.apache.org" <co...@couchdb.apache.org>.

[couchdb] 11/13: Add a log message for misconfigured default engine

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davisp pushed a commit to branch COUCHDB-3287-pluggable-storage-engines
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 0d8a45f19a8002e5760b171270bc4ce5d7910a06
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Tue May 30 11:40:35 2017 -0500

    Add a log message for misconfigured default engine
    
    If a user sets the default engine to something that's not a key in the
    couchdb_engines section of the config we'll now log a helpful error
    message alerting them to that fact.
---
 src/couch/src/couch_server.erl | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/src/couch/src/couch_server.erl b/src/couch/src/couch_server.erl
index 42f3442..986cc34 100644
--- a/src/couch/src/couch_server.erl
+++ b/src/couch/src/couch_server.erl
@@ -669,6 +669,11 @@ get_default_engine(Server, DbName) ->
                 {Extension, Module} ->
                     {Module, make_filepath(RootDir, DbName, Extension)};
                 false ->
+                    Fmt = "Invalid storage engine extension ~s,"
+                            " configured engine extensions are: ~s",
+                    Exts = [E || {E, _} <- Engines],
+                    Args = [Extension, string:join(Exts, ", ")],
+                    couch_log:error(Fmt, Args),
                     Default
             end;
         _ ->

-- 
To stop receiving notification emails like this one, please contact
"commits@couchdb.apache.org" <co...@couchdb.apache.org>.

[couchdb] 03/13: Fix typo

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davisp pushed a commit to branch COUCHDB-3287-pluggable-storage-engines
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 33e1b4fd51dd5e419e8e24092d6e888ba75ec9cb
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Tue May 30 11:23:31 2017 -0500

    Fix typo
---
 src/couch/src/couch_db_engine.erl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/couch/src/couch_db_engine.erl b/src/couch/src/couch_db_engine.erl
index 97fa6fc..17a798c 100644
--- a/src/couch/src/couch_db_engine.erl
+++ b/src/couch/src/couch_db_engine.erl
@@ -510,7 +510,7 @@
 % This function may be called by many processes concurrently.
 %
 % This function is called to count the number of documents changed
-% since they given UpdateSeq (ie, not including the possible change
+% since the given UpdateSeq (ie, not including the possible change
 % at exactly UpdateSeq). It is currently only used internally to
 % provide a status update in a replication's _active_tasks entry
 % to indicate how many documents are left to be processed.

-- 
To stop receiving notification emails like this one, please contact
"commits@couchdb.apache.org" <co...@couchdb.apache.org>.

[couchdb] 08/13: Update pattern match for clarity

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davisp pushed a commit to branch COUCHDB-3287-pluggable-storage-engines
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 0549843becc36f05ddaab1f87892003ea3f59650
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Tue May 30 11:32:00 2017 -0500

    Update pattern match for clarity
---
 src/couch/src/couch_db.erl | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/couch/src/couch_db.erl b/src/couch/src/couch_db.erl
index 0b24978..c3bc4e4 100644
--- a/src/couch/src/couch_db.erl
+++ b/src/couch/src/couch_db.erl
@@ -1206,7 +1206,10 @@ set_new_att_revpos(#doc{revs={RevPos,_Revs},atts=Atts0}=Doc) ->
     Atts = lists:map(
         fun(Att) ->
             case couch_att:fetch(data, Att) of
-                {_Fd, _Sp} -> Att; % already commited to disk, don't set new rev
+                % already commited to disk, don't set new rev
+                {stream, _} -> Att;
+                {Fd, _} when is_pid(Fd) -> Att;
+                % write required so update RevPos
                 _ -> couch_att:store(revpos, RevPos+1, Att)
             end
         end, Atts0),

-- 
To stop receiving notification emails like this one, please contact
"commits@couchdb.apache.org" <co...@couchdb.apache.org>.

[couchdb] 13/13: Reject unknown engines in chttpd

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davisp pushed a commit to branch COUCHDB-3287-pluggable-storage-engines
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 85a163a114adba1249dbe5ea5c2048cfd5157390
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Tue May 30 13:42:47 2017 -0500

    Reject unknown engines in chttpd
---
 src/chttpd/src/chttpd_db.erl       | 21 +++++++++++++++++----
 src/chttpd/test/chttpd_db_test.erl | 16 ++++++++++++++--
 src/couch/src/couch_server.erl     |  1 +
 3 files changed, 32 insertions(+), 6 deletions(-)

diff --git a/src/chttpd/src/chttpd_db.erl b/src/chttpd/src/chttpd_db.erl
index efb2f6f..af05f35 100644
--- a/src/chttpd/src/chttpd_db.erl
+++ b/src/chttpd/src/chttpd_db.erl
@@ -284,13 +284,12 @@ create_db_req(#httpd{}=Req, DbName) ->
     N = chttpd:qs_value(Req, "n", config:get("cluster", "n", "3")),
     Q = chttpd:qs_value(Req, "q", config:get("cluster", "q", "8")),
     P = chttpd:qs_value(Req, "placement", config:get("cluster", "placement")),
-    E = iolist_to_binary(chttpd:qs_value(Req, "engine", "couch")),
+    EngineOpt = parse_engine_opt(Req),
     Options = [
         {n, N},
         {q, Q},
-        {placement, P},
-        {engine, E}
-    ],
+        {placement, P}
+    ] ++ EngineOpt,
     DocUrl = absolute_uri(Req, "/" ++ couch_util:url_encode(DbName)),
     case fabric:create_db(DbName, Options) of
     ok ->
@@ -1359,6 +1358,20 @@ get_md5_header(Req) ->
 parse_doc_query(Req) ->
     lists:foldl(fun parse_doc_query/2, #doc_query_args{}, chttpd:qs(Req)).
 
+parse_engine_opt(Req) ->
+    case chttpd:qs_value(Req, "engine") of
+        undefined ->
+            [];
+        Extension ->
+            Available = couch_server:get_engine_extensions(),
+            case lists:member(Extension, Available) of
+                true ->
+                    [{engine, iolist_to_binary(Extension)}];
+                false ->
+                    throw({bad_request, invalid_engine_extension})
+            end
+    end.
+
 parse_doc_query({Key, Value}, Args) ->
     case {Key, Value} of
         {"attachments", "true"} ->
diff --git a/src/chttpd/test/chttpd_db_test.erl b/src/chttpd/test/chttpd_db_test.erl
index b7ea7f0..f153b10 100644
--- a/src/chttpd/test/chttpd_db_test.erl
+++ b/src/chttpd/test/chttpd_db_test.erl
@@ -60,7 +60,8 @@ all_test_() ->
                     fun should_accept_live_as_an_alias_for_continuous/1,
                     fun should_return_404_for_delete_att_on_notadoc/1,
                     fun should_return_409_for_del_att_without_rev/1,
-                    fun should_return_200_for_del_att_with_rev/1
+                    fun should_return_200_for_del_att_with_rev/1,
+                    fun should_return_400_for_bad_engine/1
                 ]
             }
         }
@@ -92,7 +93,7 @@ should_accept_live_as_an_alias_for_continuous(Url) ->
         LastSeqNum = list_to_integer(binary_to_list(LastSeqNum0)),
 
         {ok, _, _, _} = create_doc(Url, "testdoc2"),
-        {ok, _, _, ResultBody2} = 
+        {ok, _, _, ResultBody2} =
             test_request:get(Url ++ "/_changes?feed=live&timeout=1", [?AUTH]),
         [_, CleanedResult] = binary:split(ResultBody2, <<"\n">>),
         {[{_, Seq}, _]} = ?JSON_DECODE(CleanedResult),
@@ -179,3 +180,14 @@ should_return_200_for_del_att_with_rev(Url) ->
       ),
       ?assertEqual(200, RC1)
     end).
+
+should_return_400_for_bad_engine(_) ->
+    ?_test(begin
+        TmpDb = ?tempdb(),
+        Addr = config:get("chttpd", "bind_address", "127.0.0.1"),
+        Port = mochiweb_socket_server:get(chttpd, port),
+        BaseUrl = lists:concat(["http://", Addr, ":", Port, "/", ?b2l(TmpDb)]),
+        Url = BaseUrl ++ "?engine=cowabunga",
+        {ok, Status, _, _} = test_request:put(Url, [?CONTENT_JSON, ?AUTH], "{}"),
+        ?assertEqual(400, Status)
+    end).
diff --git a/src/couch/src/couch_server.erl b/src/couch/src/couch_server.erl
index 1ad0334..9c15216 100644
--- a/src/couch/src/couch_server.erl
+++ b/src/couch/src/couch_server.erl
@@ -23,6 +23,7 @@
 -export([close_lru/0]).
 -export([delete_compaction_files/1]).
 -export([exists/1]).
+-export([get_engine_extensions/0]).
 
 % config_listener api
 -export([handle_config_change/5, handle_config_terminate/3]).

-- 
To stop receiving notification emails like this one, please contact
"commits@couchdb.apache.org" <co...@couchdb.apache.org>.

[couchdb] 02/13: Remove unnecessary pattern match

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davisp pushed a commit to branch COUCHDB-3287-pluggable-storage-engines
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit b5e0d5abad7b99807af0d4cd52fb333a9040047f
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Tue May 30 11:21:26 2017 -0500

    Remove unnecessary pattern match
---
 src/couch/src/couch_bt_engine.erl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/couch/src/couch_bt_engine.erl b/src/couch/src/couch_bt_engine.erl
index 0680ffd..068d3c9 100644
--- a/src/couch/src/couch_bt_engine.erl
+++ b/src/couch/src/couch_bt_engine.erl
@@ -300,7 +300,7 @@ open_docs(#st{} = St, DocIds) ->
 open_local_docs(#st{} = St, DocIds) ->
     Results = couch_btree:lookup(St#st.local_tree, DocIds),
     lists:map(fun
-        ({ok, #doc{} = Doc}) -> Doc;
+        ({ok, Doc}) -> Doc;
         (not_found) -> not_found
     end, Results).
 

-- 
To stop receiving notification emails like this one, please contact
"commits@couchdb.apache.org" <co...@couchdb.apache.org>.

[couchdb] 07/13: Fix type spec to allow disabling compression

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davisp pushed a commit to branch COUCHDB-3287-pluggable-storage-engines
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 08f2fca0dbd1565b58286d94d42b77b4be2dd0dd
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Tue May 30 11:28:44 2017 -0500

    Fix type spec to allow disabling compression
---
 src/couch/src/couch_db_engine.erl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/couch/src/couch_db_engine.erl b/src/couch/src/couch_db_engine.erl
index 7271f3a..a0400d5 100644
--- a/src/couch/src/couch_db_engine.erl
+++ b/src/couch/src/couch_db_engine.erl
@@ -46,7 +46,7 @@
 -type write_stream_options() :: [
         {buffer_size, Size::pos_integer()} |
         {encoding, atom()} |
-        {compression_level, pos_integer()}
+        {compression_level, non_neg_integer()}
     ].
 
 -type doc_fold_options() :: [

-- 
To stop receiving notification emails like this one, please contact
"commits@couchdb.apache.org" <co...@couchdb.apache.org>.

[couchdb] 10/13: Remove unused function clause

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davisp pushed a commit to branch COUCHDB-3287-pluggable-storage-engines
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 6ef99bd9f58220cde4cd526a008c760b458dac19
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Tue May 30 11:35:31 2017 -0500

    Remove unused function clause
---
 src/couch/src/couch_bt_engine.erl | 2 --
 1 file changed, 2 deletions(-)

diff --git a/src/couch/src/couch_bt_engine.erl b/src/couch/src/couch_bt_engine.erl
index a5318cd..ca98d01 100644
--- a/src/couch/src/couch_bt_engine.erl
+++ b/src/couch/src/couch_bt_engine.erl
@@ -827,8 +827,6 @@ reduce_sizes(S1, S2) ->
     reduce_sizes(US1, US2).
 
 
-active_size(#st{} = St, Size) when is_integer(Size) ->
-    active_size(St, #size_info{active=Size});
 active_size(#st{} = St, #size_info{} = SI) ->
     Trees = [
         St#st.id_tree,

-- 
To stop receiving notification emails like this one, please contact
"commits@couchdb.apache.org" <co...@couchdb.apache.org>.

[couchdb] 12/13: Add error and test for invalid engine

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davisp pushed a commit to branch COUCHDB-3287-pluggable-storage-engines
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 68c3008b8909c53d610ee839593b60c0912b636f
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Tue May 30 13:30:20 2017 -0500

    Add error and test for invalid engine
---
 src/couch/src/couch_server.erl        | 68 ++++++++++++++++++-----------------
 src/couch/test/couch_server_tests.erl | 16 +++++++++
 2 files changed, 52 insertions(+), 32 deletions(-)

diff --git a/src/couch/src/couch_server.erl b/src/couch/src/couch_server.erl
index 986cc34..1ad0334 100644
--- a/src/couch/src/couch_server.erl
+++ b/src/couch/src/couch_server.erl
@@ -437,7 +437,7 @@ handle_call({open, DbName, Options}, From, Server) ->
         ok ->
             case make_room(Server, Options) of
             {ok, Server2} ->
-                Engine = get_engine(Server2, DbNameList),
+                {ok, Engine} = get_engine(Server2, DbNameList),
                 {noreply, open_async(Server2, From, DbName, Engine, Options)};
             CloseError ->
                 {reply, CloseError, Server}
@@ -457,28 +457,32 @@ handle_call({open, DbName, Options}, From, Server) ->
     end;
 handle_call({create, DbName, Options}, From, Server) ->
     DbNameList = binary_to_list(DbName),
-    Engine = get_engine(Server, DbNameList, Options),
-    case check_dbname(Server, DbNameList) of
-    ok ->
-        case ets:lookup(couch_dbs, DbName) of
-        [] ->
-            case make_room(Server, Options) of
-            {ok, Server2} ->
-                {noreply, open_async(Server2, From, DbName, Engine,
-                        [create | Options])};
-            CloseError ->
-                {reply, CloseError, Server}
+    case get_engine(Server, DbNameList, Options) of
+    {ok, Engine} ->
+        case check_dbname(Server, DbNameList) of
+        ok ->
+            case ets:lookup(couch_dbs, DbName) of
+            [] ->
+                case make_room(Server, Options) of
+                {ok, Server2} ->
+                    {noreply, open_async(Server2, From, DbName, Engine,
+                            [create | Options])};
+                CloseError ->
+                    {reply, CloseError, Server}
+                end;
+            [#entry{req_type = open} = Entry] ->
+                % We're trying to create a database while someone is in
+                % the middle of trying to open it. We allow one creator
+                % to wait while we figure out if it'll succeed.
+                CrOptions = [create | Options],
+                Req = {create, DbName, Engine, CrOptions, From},
+                true = ets:insert(couch_dbs, Entry#entry{req_type = Req}),
+                {noreply, Server};
+            [_AlreadyRunningDb] ->
+                {reply, file_exists, Server}
             end;
-        [#entry{req_type = open} = Entry] ->
-            % We're trying to create a database while someone is in
-            % the middle of trying to open it. We allow one creator
-            % to wait while we figure out if it'll succeed.
-            CrOptions = [create | Options],
-            Req = {create, DbName, Engine, CrOptions, From},
-            true = ets:insert(couch_dbs, Entry#entry{req_type = Req}),
-            {noreply, Server};
-        [_AlreadyRunningDb] ->
-            {reply, file_exists, Server}
+        Error ->
+            {reply, Error, Server}
         end;
     Error ->
         {reply, Error, Server}
@@ -510,7 +514,7 @@ handle_call({delete, DbName, Options}, _From, Server) ->
         % Make sure and remove all compaction data
         delete_compaction_files(DbNameList, DelOpt),
 
-        {Engine, FilePath} = get_engine(Server, DbNameList),
+        {ok, {Engine, FilePath}} = get_engine(Server, DbNameList),
         RootDir = Server#server.root_dir,
         case couch_db_engine:delete(Engine, RootDir, FilePath, DelOpt) of
         ok ->
@@ -617,12 +621,12 @@ get_engine(Server, DbName, Options) ->
     case couch_util:get_value(engine, Options) of
         Ext when is_binary(Ext) ->
             ExtStr = binary_to_list(Ext),
-            case couch_util:get_value(ExtStr, Engines) of
-                Engine when is_atom(Engine) ->
+            case lists:keyfind(ExtStr, 1, Engines) of
+                {ExtStr, Engine} ->
                     Path = make_filepath(RootDir, DbName, ExtStr),
-                    {Engine, Path};
-                _ ->
-                    get_engine(Server, DbName)
+                    {ok, {Engine, Path}};
+                false ->
+                    {error, {invalid_engine_extension, Ext}}
             end;
         _ ->
             get_engine(Server, DbName)
@@ -639,7 +643,7 @@ get_engine(Server, DbName) ->
         [] ->
             get_default_engine(Server, DbName);
         [Engine] ->
-            Engine;
+            {ok, Engine};
         _ ->
             erlang:error(engine_conflict)
     end.
@@ -667,17 +671,17 @@ get_default_engine(Server, DbName) ->
         Extension when is_list(Extension) ->
             case lists:keyfind(Extension, 1, Engines) of
                 {Extension, Module} ->
-                    {Module, make_filepath(RootDir, DbName, Extension)};
+                    {ok, {Module, make_filepath(RootDir, DbName, Extension)}};
                 false ->
                     Fmt = "Invalid storage engine extension ~s,"
                             " configured engine extensions are: ~s",
                     Exts = [E || {E, _} <- Engines],
                     Args = [Extension, string:join(Exts, ", ")],
                     couch_log:error(Fmt, Args),
-                    Default
+                    {ok, Default}
             end;
         _ ->
-            Default
+            {ok, Default}
     end.
 
 
diff --git a/src/couch/test/couch_server_tests.erl b/src/couch/test/couch_server_tests.erl
index c52b3f6..a79f20f 100644
--- a/src/couch/test/couch_server_tests.erl
+++ b/src/couch/test/couch_server_tests.erl
@@ -89,3 +89,19 @@ should_delete(_, Db) ->
 
 deleted_files(ViewFile) ->
     filelib:wildcard(filename:rootname(ViewFile) ++ "*.deleted.*").
+
+
+bad_engine_option_test_() ->
+    {
+        setup,
+        fun start/0,
+        fun test_util:stop/1,
+        [
+            fun t_bad_engine_option/0
+        ]
+    }.
+
+
+t_bad_engine_option() ->
+    Resp = couch_server:create(?tempdb(), [{engine, <<"cowabunga!">>}]),
+    ?assertEqual(Resp, {error, {invalid_engine_extension, <<"cowabunga!">>}}).

-- 
To stop receiving notification emails like this one, please contact
"commits@couchdb.apache.org" <co...@couchdb.apache.org>.