Skip to content

Commit d838881

Browse files
authored
Merge pull request apache#17 from cloudant-labs/87336-add-disk_size-end-point
Add new end point to get disk size information for search index
2 parents 5fbbe3e + bc2f94b commit d838881

File tree

6 files changed

+48
-10
lines changed

6 files changed

+48
-10
lines changed

src/clouseau_rpc.erl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,14 @@
2121
-export([await/2, commit/2, get_update_seq/1, info/1, search/6, search/2]).
2222
-export([group1/7, group2/8, group2/2]).
2323
-export([delete/2, update/3, cleanup/1, cleanup/2]).
24-
-export([analyze/2, version/0]).
24+
-export([analyze/2, version/0, disk_size/1]).
2525

2626
open_index(Peer, Path, Analyzer) ->
2727
rpc({main, clouseau()}, {open, Peer, Path, Analyzer}).
2828

29+
disk_size(Path) ->
30+
rpc({main, clouseau()}, {disk_size, Path}).
31+
2932
await(Ref, MinSeq) ->
3033
rpc(Ref, {await, MinSeq}).
3134

src/dreyfus_fabric_info.erl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@
1919
-include_lib("mem3/include/mem3.hrl").
2020
-include_lib("couch/include/couch_db.hrl").
2121

22-
-export([go/3]).
22+
-export([go/4]).
2323

24-
go(DbName, DDocId, IndexName) when is_binary(DDocId) ->
24+
go(DbName, DDocId, IndexName, InfoLevel) when is_binary(DDocId) ->
2525
{ok, DDoc} = fabric:open_doc(DbName, <<"_design/", DDocId/binary>>, []),
26-
go(DbName, DDoc, IndexName);
26+
go(DbName, DDoc, IndexName, InfoLevel);
2727

28-
go(DbName, DDoc, IndexName) ->
28+
go(DbName, DDoc, IndexName, InfoLevel) ->
2929
Shards = mem3:shards(DbName),
30-
Workers = fabric_util:submit_jobs(Shards, dreyfus_rpc, info, [DDoc, IndexName]),
30+
Workers = fabric_util:submit_jobs(Shards, dreyfus_rpc, InfoLevel, [DDoc, IndexName]),
3131
RexiMon = fabric_util:create_monitors(Shards),
3232
Acc0 = {fabric_dict:init(Workers, nil), []},
3333
try

src/dreyfus_httpd.erl

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
-module(dreyfus_httpd).
1717

18-
-export([handle_search_req/3, handle_info_req/3,
18+
-export([handle_search_req/3, handle_info_req/3, handle_disk_size_req/3,
1919
handle_cleanup_req/2, handle_analyze_req/1]).
2020
-include("dreyfus.hrl").
2121
-include_lib("couch/include/couch_db.hrl").
@@ -108,7 +108,7 @@ handle_search_req(Req, _Db, _DDoc, _RetryCount, _RetryPause) ->
108108

109109
handle_info_req(#httpd{method='GET', path_parts=[_, _, _, _, IndexName]}=Req
110110
,#db{name=DbName}, #doc{id=Id}=DDoc) ->
111-
case dreyfus_fabric_info:go(DbName, DDoc, IndexName) of
111+
case dreyfus_fabric_info:go(DbName, DDoc, IndexName, info) of
112112
{ok, IndexInfoList} ->
113113
send_json(Req, 200, {[
114114
{name, <<Id/binary,"/",IndexName/binary>>},
@@ -122,6 +122,21 @@ handle_info_req(#httpd{path_parts=[_, _, _, _, _]}=Req, _Db, _DDoc) ->
122122
handle_info_req(Req, _Db, _DDoc) ->
123123
send_error(Req, {bad_request, "path not recognized"}).
124124

125+
handle_disk_size_req(#httpd{method='GET', path_parts=[_, _, _, _, IndexName]}=Req, #db{name=DbName}, #doc{id=Id}=DDoc) ->
126+
case dreyfus_fabric_info:go(DbName, DDoc, IndexName, disk_size) of
127+
{ok, IndexInfoList} ->
128+
send_json(Req, 200, {[
129+
{name, <<Id/binary,"/",IndexName/binary>>},
130+
{search_index, {IndexInfoList}}
131+
]});
132+
{error, Reason} ->
133+
send_error(Req, Reason)
134+
end;
135+
handle_disk_size_req(#httpd{path_parts=[_, _, _, _, _]}=Req, _Db, _DDoc) ->
136+
send_method_not_allowed(Req, "GET");
137+
handle_disk_size_req(Req, _Db, _DDoc) ->
138+
send_error(Req, {bad_request, "path not recognized"}).
139+
125140
handle_cleanup_req(#httpd{method='POST'}=Req, #db{name=DbName}) ->
126141
ok = dreyfus_fabric_cleanup:go(DbName),
127142
send_json(Req, 202, {[{ok, true}]});

src/dreyfus_httpd_handlers.erl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ db_handler(_) -> no_match.
2525

2626
design_handler(<<"_search">>) -> fun dreyfus_httpd:handle_search_req/3;
2727
design_handler(<<"_search_info">>) -> fun dreyfus_httpd:handle_info_req/3;
28+
design_handler(<<"_search_disk_size">>) -> fun dreyfus_httpd:handle_disk_size_req/3;
2829
design_handler(_) -> no_match.

src/dreyfus_index_manager.erl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
-define(BY_PID, dreyfus_by_pid).
2424

2525
% public api.
26-
-export([start_link/0, get_index/2]).
26+
-export([start_link/0, get_index/2, get_disk_size/2]).
2727

2828
% gen_server api.
2929
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2,
@@ -38,6 +38,9 @@ start_link() ->
3838
get_index(DbName, Index) ->
3939
gen_server:call(?MODULE, {get_index, DbName, Index}, infinity).
4040

41+
get_disk_size(DbName, Index) ->
42+
gen_server:call(?MODULE, {get_disk_size, DbName, Index}, infinity).
43+
4144
% gen_server functions.
4245

4346
init([]) ->
@@ -61,6 +64,11 @@ handle_call({get_index, DbName, #index{sig=Sig}=Index}, From, State) ->
6164
{reply, {ok, ExistingPid}, State}
6265
end;
6366

67+
handle_call({get_disk_size, DbName, #index{sig=Sig}=Index}, From, State) ->
68+
Path = <<DbName/binary,"/",Sig/binary>>,
69+
Reply = clouseau_rpc:disk_size(Path),
70+
{reply, Reply, State};
71+
6472
handle_call({open_ok, DbName, Sig, NewPid}, {OpenerPid, _}, State) ->
6573
link(NewPid),
6674
[{_, WaitList}] = ets:lookup(?BY_SIG, {DbName, Sig}),

src/dreyfus_rpc.erl

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
-import(couch_query_servers, [get_os_process/1, ret_os_process/1, proc_prompt/2]).
2020

2121
% public api.
22-
-export([search/4, group1/4, group2/4, info/3]).
22+
-export([search/4, group1/4, group2/4, info/3, disk_size/3]).
2323

2424
% private callback
2525
-export([call/5, info_int/3]).
@@ -90,6 +90,17 @@ info_int(DbName, DDoc, IndexName) ->
9090
rexi:reply(Error)
9191
end.
9292

93+
disk_size(DbName, DDoc, IndexName) ->
94+
erlang:put(io_priority, {interactive, DbName}),
95+
check_interactive_mode(),
96+
case dreyfus_index:design_doc_to_index(DDoc, IndexName) of
97+
{ok, Index} ->
98+
Result = dreyfus_index_manager:get_disk_size(DbName, Index),
99+
rexi:reply(Result);
100+
Error ->
101+
rexi:reply(Error)
102+
end.
103+
93104
get_or_create_db(DbName, Options) ->
94105
case couch_db:open_int(DbName, Options) of
95106
{not_found, no_db_file} ->

0 commit comments

Comments
 (0)