Skip to content

Commit

Permalink
Revert "Revert "MB-54268 Conditionally pass '--disable-bucket-config'""
Browse files Browse the repository at this point in the history
This reverts commit b3c7658.

Reason for revert: dependent cbimport change has been merged

Change-Id: Ib5310507c9883625a73209a5b4853478eb69473e
Reviewed-on: https://review.couchbase.org/c/ns_server/+/182955
Well-Formed: Build Bot <build@couchbase.com>
Tested-by: Build Bot <build@couchbase.com>
Reviewed-by: Bryan McCoid <bryan.mccoid@couchbase.com>
  • Loading branch information
stevewatanabe committed Nov 30, 2022
1 parent f3bd879 commit 6c8a294
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 22 deletions.
20 changes: 11 additions & 9 deletions src/menelaus_web_samples.erl
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ handle_get(Req) ->
-spec none_use_couchdb(Samples :: [{binary(), binary()}]) -> boolean().
none_use_couchdb(Samples) ->
lists:all(
fun ({Sample, _Bucket}) ->
fun ({Sample, _Bucket, _BucketState}) ->
samples_without_couchdb(binary_to_list(Sample))
end, Samples).

Expand All @@ -52,9 +52,9 @@ samples_without_couchdb(Name) when is_list(Name) ->
build_samples_input_list(Samples) ->
lists:foldl(
fun ({[{<<"sample">>, Sample},{<<"bucket">>, Bucket}]}, AccIn) ->
[{Sample, Bucket} | AccIn];
[{Sample, Bucket, bucket_must_exist} | AccIn];
(Sample, AccIn) ->
[{Sample, Sample} | AccIn]
[{Sample, Sample, bucket_must_not_exist} | AccIn]
end, [], Samples).

%% There are two types of input to this request. The classic/original input
Expand Down Expand Up @@ -143,14 +143,16 @@ try_decode(Body) ->
end.

start_loading_samples(Req, Samples) ->
lists:foreach(fun ({Sample, Bucket}) ->
lists:foreach(fun ({Sample, Bucket, BucketState}) ->
start_loading_sample(Req, binary_to_list(Sample),
binary_to_list(Bucket))
binary_to_list(Bucket),
BucketState)
end, Samples).

start_loading_sample(Req, Sample, Bucket) ->
start_loading_sample(Req, Sample, Bucket, BucketState) ->
case samples_loader_tasks:start_loading_sample(Sample, Bucket,
?SAMPLE_BUCKET_QUOTA_MB) of
?SAMPLE_BUCKET_QUOTA_MB,
BucketState) of
ok ->
ns_audit:start_loading_sample(Req, Bucket);
already_started ->
Expand Down Expand Up @@ -217,7 +219,7 @@ check_sample_exists(Sample) ->
check_valid_samples(Samples) ->
Errors =
lists:foldl(
fun ({Sample, Sample}, AccIn) ->
fun ({Sample, Sample, bucket_must_not_exist}, AccIn) ->
%% Classic case where data is loaded into non-existent
%% bucket with the same name as the sample data.
RV =
Expand All @@ -230,7 +232,7 @@ check_valid_samples(Samples) ->
check_sample_exists(Sample)
end,
[RV | AccIn];
({Sample, Bucket}, AccIn) ->
({Sample, Bucket, bucket_must_exist}, AccIn) ->
%% Newer case where the bucket must already exist.
RV =
case ns_bucket:name_conflict(binary_to_list(Bucket)) of
Expand Down
32 changes: 19 additions & 13 deletions src/samples_loader_tasks.erl
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
-export([init/1, handle_call/3, handle_cast/2,
handle_info/2, terminate/2, code_change/3]).

-export([start_loading_sample/3, get_tasks/1]).
-export([start_loading_sample/4, get_tasks/1]).

-export([perform_loading_task/3]).
-export([perform_loading_task/4]).

start_loading_sample(Sample, Bucket, Quota) ->
gen_server:call(?MODULE, {start_loading_sample, Sample, Bucket, Quota},
infinity).
start_loading_sample(Sample, Bucket, Quota, BucketState) ->
gen_server:call(?MODULE, {start_loading_sample, Sample, Bucket, Quota,
BucketState}, infinity).

get_tasks(Timeout) ->
gen_server:call(?MODULE, get_tasks, Timeout).
Expand All @@ -40,11 +40,11 @@ init([]) ->
erlang:process_flag(trap_exit, true),
{ok, #state{}}.

handle_call({start_loading_sample, Sample, Bucket, Quota}, _From,
handle_call({start_loading_sample, Sample, Bucket, Quota, BucketState}, _From,
#state{tasks = Tasks} = State) ->
case lists:keyfind(Bucket, 1, Tasks) of
false ->
Pid = start_new_loading_task(Sample, Bucket, Quota),
Pid = start_new_loading_task(Sample, Bucket, Quota, BucketState),
ns_heart:force_beat(),
NewState = State#state{tasks = [{Bucket, Pid} | Tasks]},
{reply, ok, maybe_pass_token(NewState)};
Expand Down Expand Up @@ -109,10 +109,11 @@ maybe_pass_token(#state{token_pid = undefined,
maybe_pass_token(State) ->
State.

start_new_loading_task(Sample, Bucket, Quota) ->
proc_lib:spawn_link(?MODULE, perform_loading_task, [Sample, Bucket, Quota]).
start_new_loading_task(Sample, Bucket, Quota, BucketState) ->
proc_lib:spawn_link(?MODULE, perform_loading_task,
[Sample, Bucket, Quota, BucketState]).

perform_loading_task(Sample, Bucket, Quota) ->
perform_loading_task(Sample, Bucket, Quota, BucketState) ->
receive
allowed_to_go -> ok
end,
Expand All @@ -139,13 +140,18 @@ perform_loading_task(Sample, Bucket, Quota) ->
Args = ["json",
"--bucket", Bucket,
"--format", "sample",
"--bucket-quota", integer_to_list(Quota),
"--bucket-replicas", integer_to_list(NumReplicas),
"--threads", "2",
"--verbose",
"--dataset", "file://" ++ filename:join([BinDir, "..",
"samples", Sample ++ ".zip"])] ++
ClusterOpts,
ClusterOpts ++
case BucketState of
bucket_must_exist ->
["--disable-bucket-config"];
bucket_must_not_exist ->
["--bucket-quota", integer_to_list(Quota),
"--bucket-replicas", integer_to_list(NumReplicas)]
end,

Env = [{"CB_USERNAME", "@ns_server"},
{"CB_PASSWORD", ns_config_auth:get_password(special)} |
Expand Down

0 comments on commit 6c8a294

Please sign in to comment.