diff options
author | Noah Shaw <noahshaw11@yahoo.com> | 2022-07-12 16:08:17 -0500 |
---|---|---|
committer | Nick Vatamaniuc <nickva@users.noreply.github.com> | 2022-07-14 18:10:47 -0400 |
commit | 76dd66f409ef4b34f9cc809228e0c7d1e6a50554 (patch) | |
tree | 43dec7ca0954a646a0c4a3ce11028d4bd63b0303 | |
parent | 02c0c75c2378cb03bc20964fd97dc3718e5f0134 (diff) | |
download | couchdb-76dd66f409ef4b34f9cc809228e0c7d1e6a50554.tar.gz |
Remove view compaction jobs recovery
-rw-r--r-- | src/couch/test/eunit/couch_bt_engine_compactor_tests.erl | 31 | ||||
-rw-r--r-- | src/smoosh/src/smoosh_channel.erl | 15 | ||||
-rw-r--r-- | src/smoosh/src/smoosh_utils.erl | 8 | ||||
-rw-r--r-- | src/smoosh/test/smoosh_tests.erl | 40 |
4 files changed, 56 insertions, 38 deletions
diff --git a/src/couch/test/eunit/couch_bt_engine_compactor_tests.erl b/src/couch/test/eunit/couch_bt_engine_compactor_tests.erl index 73428b0a9..39d9ba3b7 100644 --- a/src/couch/test/eunit/couch_bt_engine_compactor_tests.erl +++ b/src/couch/test/eunit/couch_bt_engine_compactor_tests.erl @@ -29,7 +29,7 @@ teardown(DbName) when is_binary(DbName) -> couch_server:delete(DbName, [?ADMIN_CTX]), ok. -compaction_resume_test_() -> +basic_compaction_test_() -> { setup, fun test_util:start_couch/0, @@ -60,6 +60,25 @@ compaction_resume(DbName) -> check_db_validity(DbName) end). +is_compacting_works(DbName) -> + ?_test(begin + check_db_validity(DbName), + meck:new(couch_emsort, [passthrough]), + ok = wait_in_emsort_bind(self()), + {_Pid, Ref} = spawn_monitor(fun() -> compact_db(DbName) end), + receive + {in_emsort_bind, From} -> + % When emsort:open(Fd) is called the files should + % have been created already + ?assert(couch_db:is_compacting(DbName)), + From ! {please_continue, self()} + end, + receive + {'DOWN', Ref, _, _, _} -> ok + end, + meck:unload(couch_emsort) + end). + check_db_validity(DbName) -> couch_util:with_db(DbName, fun(Db) -> ?assertEqual({ok, 3}, couch_db:get_doc_count(Db)), @@ -122,3 +141,13 @@ wait_db_compact_done(DbName, N) -> timer:sleep(?DELAY), wait_db_compact_done(DbName, N - 1) end. + +wait_in_emsort_bind(WaitingPid) when is_pid(WaitingPid) -> + meck:expect(couch_emsort, open, fun(Fd) -> + WaitingPid ! {in_emsort_bind, self()}, + receive + {please_continue, WaitingPid} -> + ok + end, + meck:passthrough([Fd]) + end). diff --git a/src/smoosh/src/smoosh_channel.erl b/src/smoosh/src/smoosh_channel.erl index 952f4fd50..04b748649 100644 --- a/src/smoosh/src/smoosh_channel.erl +++ b/src/smoosh/src/smoosh_channel.erl @@ -17,7 +17,7 @@ % public api. -export([start_link/1, close/1, suspend/1, resume/1, activate/1, get_status/1]). --export([enqueue/3, last_updated/2, flush/1, is_key/2, is_activated/1, persist/1]). +-export([enqueue/3, last_updated/2, flush/1, is_key/2, is_activated/1]). % gen_server api. -export([ @@ -37,6 +37,7 @@ -else. -define(START_DELAY_IN_MSEC, 0). -define(ACTIVATE_DELAY_IN_MSEC, 0). +-export([persist/1]). -endif. % records. @@ -94,6 +95,7 @@ is_key(ServerRef, Key) -> is_activated(ServerRef) -> gen_server:call(ServerRef, is_activated). +% Only exported to force persistence in tests persist(ServerRef) -> gen_server:call(ServerRef, persist). @@ -103,8 +105,15 @@ init(Name) -> erlang:send_after(60 * 1000, self(), check_window), process_flag(trap_exit, true), Waiting = smoosh_priority_queue:new(Name), - State = #state{name = Name, waiting = Waiting, paused = true, activated = false}, - erlang:send_after(?START_DELAY_IN_MSEC, self(), start_recovery), + State = + case smoosh_utils:is_view_channel(Name) of + true -> + schedule_unpause(), + #state{name = Name, waiting = Waiting, paused = true, activated = true}; + false -> + erlang:send_after(?START_DELAY_IN_MSEC, self(), start_recovery), + #state{name = Name, waiting = Waiting, paused = true, activated = false} + end, {ok, State}. handle_call({last_updated, Object}, _From, State) -> diff --git a/src/smoosh/src/smoosh_utils.erl b/src/smoosh/src/smoosh_utils.erl index c48e73149..1942aebf4 100644 --- a/src/smoosh/src/smoosh_utils.erl +++ b/src/smoosh/src/smoosh_utils.erl @@ -14,7 +14,7 @@ -include_lib("couch/include/couch_db.hrl"). -export([get/2, get/3, split/1, stringify/1, ignore_db/1]). --export([in_allowed_window/1, write_to_file/3]). +-export([in_allowed_window/1, is_view_channel/1, write_to_file/3]). -export([log_level/2]). get(Channel, Key) -> @@ -59,6 +59,12 @@ in_allowed_window(From, To) -> ({HH, MM} >= From) orelse ({HH, MM} < To) end. +is_view_channel(ChannelName) -> + ViewChannels = smoosh_utils:split( + config:get("smoosh", "view_channels", "upgrade_views,ratio_views,slack_views") + ), + lists:member(ChannelName, ViewChannels). + file_delete(Path) -> case file:delete(Path) of % When deleting a state file, we do not care if it does not exist. diff --git a/src/smoosh/test/smoosh_tests.erl b/src/smoosh/test/smoosh_tests.erl index 1d0a6efbb..453a99d15 100644 --- a/src/smoosh/test/smoosh_tests.erl +++ b/src/smoosh/test/smoosh_tests.erl @@ -59,8 +59,7 @@ persistence_tests() -> channels_tests() -> Tests = [ - fun should_enqueue/2, - fun should_start_compact/2 + fun should_enqueue/2 ], { "Various channels tests", @@ -97,17 +96,6 @@ should_persist_queue(ChannelType, DbName) -> ok end). -should_start_compact(ChannelType, DbName) -> - ?_test(begin - {ok, ChannelPid} = smoosh_server:get_channel(ChannelType), - ok = grow_db_file(DbName, 3000), - smoosh_channel:resume(ChannelPid), - ok = wait_compact(ChannelType), - ?assertEqual(true, couch_db:is_compacting(DbName)), - application:start(smoosh), - ok - end). - grow_db_file(DbName, SizeInKb) -> {ok, Db} = couch_db:open_int(DbName, [?ADMIN_CTX]), Data = b64url:encode(crypto:strong_rand_bytes(SizeInKb * 1024)), @@ -122,30 +110,16 @@ is_enqueued(ChannelType, DbName) -> smoosh_channel:is_key(ChannelPid, DbName). wait_enqueue(ChannelType, DbName) -> - test_util:wait(fun() -> - case is_enqueued(ChannelType, DbName) of - false -> - wait; - true -> - ok - end - end). - -wait_compact(ChannelType) -> - {ok, ChannelPid} = smoosh_server:get_channel(ChannelType), test_util:wait( fun() -> - {ok, Status} = smoosh_channel:get_status(ChannelPid), - {active, Active} = lists:keyfind(active, 1, Status), - case Active of - 1 -> - application:stop(smoosh), - ok; - _ -> - wait + case is_enqueued(ChannelType, DbName) of + false -> + wait; + true -> + ok end end, - 10000 + 15000 ). channel_queue(ChannelType) -> |