Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #214 from basho/jdb-ring-manager-load

Fix race during start-up that could overwrite existing ring file.
Fix issue #166.
  • Loading branch information...
commit 62af2bc4a8345d30729cd0efd745343edb5b3f5b 2 parents 5404bf8 + 0765c3a
@jtuple jtuple authored
View
22 src/riak_core_app.erl
@@ -77,28 +77,6 @@ start(_StartType, _StartArgs) ->
{ok, Pid} ->
riak_core:register(riak_core, [{stat_mod, riak_core_stat}]),
ok = riak_core_ring_events:add_guarded_handler(riak_core_ring_handler, []),
- %% App is running; search for latest ring file and initialize with it
- riak_core_ring_manager:prune_ringfiles(),
- case riak_core_ring_manager:find_latest_ringfile() of
- {ok, RingFile} ->
- case riak_core_ring_manager:read_ringfile(RingFile) of
- {error, Reason} ->
- lager:critical("Failed to read ring file: ~p",
- [lager:posix_error(Reason)]),
- throw({error, Reason});
- Ring0 ->
- %% Upgrade the ring data structure if necessary.
- Ring = riak_core_ring:upgrade(Ring0),
- riak_core_ring_manager:set_my_ring(Ring)
- end;
- {error, not_found} ->
- riak_core_ring_manager:write_ringfile(),
- lager:warning("No ring file available.");
- {error, Reason} ->
- lager:critical("Failed to load ring file: ~p",
- [lager:posix_error(Reason)]),
- throw({error, Reason})
- end,
%% Register capabilities
riak_core_capability:register({riak_core, vnode_routing},
View
37 src/riak_core_ring_manager.erl
@@ -206,22 +206,35 @@ stop() ->
%% ===================================================================
init([Mode]) ->
- case Mode of
- live ->
- Ring = riak_core_ring:fresh();
- test ->
- Ring = riak_core_ring:fresh(16,node())
- end,
-
- %% Set the ring and send initial notification to local observers that
- %% ring has changed.
- %% Do *not* save the ring to disk here. On startup we deliberately come
- %% up with a ring where the local node owns all partitions so that any
- %% fallback vnodes will be started so they can hand off.
+ Ring = reload_ring(Mode),
set_ring_global(Ring),
riak_core_ring_events:ring_update(Ring),
{ok, #state{mode = Mode, raw_ring=Ring}}.
+reload_ring(test) ->
+ riak_core_ring:fresh(16,node());
+reload_ring(live) ->
+ case riak_core_ring_manager:find_latest_ringfile() of
+ {ok, RingFile} ->
+ case riak_core_ring_manager:read_ringfile(RingFile) of
+ {error, Reason} ->
+ lager:critical("Failed to read ring file: ~p",
+ [lager:posix_error(Reason)]),
+ throw({error, Reason});
+ Ring0 ->
+ %% Upgrade the ring data structure if necessary.
+ lager:info("Upgrading legacy ring"),
+ Ring = riak_core_ring:upgrade(Ring0),
+ Ring
+ end;
+ {error, not_found} ->
+ lager:warning("No ring file available."),
+ riak_core_ring:fresh();
+ {error, Reason} ->
+ lager:critical("Failed to load ring file: ~p",
+ [lager:posix_error(Reason)]),
+ throw({error, Reason})
+ end.
handle_call(get_raw_ring, _From, #state{raw_ring=Ring} = State) ->
{reply, {ok, Ring}, State};
View
2  test/bucket_fixup_test.erl
@@ -82,6 +82,8 @@ io:format(user, "BBOT DBG: ~p ~p ~p\n", [?MODULE, ?LINE, Ls2]),
catch(riak_core_ring_manager:stop()),
catch(exit(whereis(riak_core_ring_events), shutdown)),
timer:sleep(1000),
+ riak_core_ring_events:start_link(),
+ riak_core_ring_manager:start_link(test),
application:load(riak_core),
application:set_env(riak_core, bucket_fixups, []),
application:set_env(riak_core, default_bucket_props, []),
Please sign in to comment.
Something went wrong with that request. Please try again.