Blame erlang-riak_core-0004-Revert-Copy-in-mochiglobal-as-riak_core_mochiglobal.patch

2771c49
From: Peter Lemenkov <lemenkov@gmail.com>
2771c49
Date: Sat, 23 Apr 2016 12:02:49 +0300
2771c49
Subject: [PATCH] Revert "Copy in mochiglobal as riak_core_mochiglobal."
2771c49
2771c49
This reverts commit 13f894a05ad2b8e4a461e4685e8f9f044e58ae9b.
2771c49
2771c49
diff --git a/src/riak_core_dtrace.erl b/src/riak_core_dtrace.erl
e64238e
index 3b7208fa..faaef31e 100644
2771c49
--- a/src/riak_core_dtrace.erl
2771c49
+++ b/src/riak_core_dtrace.erl
2771c49
@@ -146,26 +146,26 @@ timeit0(ArgList) ->
2771c49
     end.
2771c49
 
2771c49
 timeit_mg(ArgList) ->
2771c49
-    case riak_core_mochiglobal:get(?MAGIC) of
2771c49
+    case mochiglobal:get(?MAGIC) of
2771c49
         undefined ->
2771c49
             case application:get_env(riak_core, dtrace_support) of
2771c49
                 {ok, true} ->
2771c49
                     case string:to_float(erlang:system_info(version)) of
2771c49
                         {5.8, _} ->
2771c49
                             %% R14B04
2771c49
-                            riak_core_mochiglobal:put(?MAGIC, dtrace),
2771c49
+                            mochiglobal:put(?MAGIC, dtrace),
2771c49
                             timeit_mg(ArgList);
2771c49
                         {Num, _} when Num > 5.8 ->
2771c49
                             %% R15B or higher, though dyntrace option
2771c49
                             %% was first available in R15B01.
2771c49
-                            riak_core_mochiglobal:put(?MAGIC, dyntrace),
2771c49
+                            mochiglobal:put(?MAGIC, dyntrace),
2771c49
                             timeit_mg(ArgList);
2771c49
                         _ ->
2771c49
-                            riak_core_mochiglobal:put(?MAGIC, unsupported),
2771c49
+                            mochiglobal:put(?MAGIC, unsupported),
2771c49
                             false
2771c49
                     end;
2771c49
                 _ ->
2771c49
-                    riak_core_mochiglobal:put(?MAGIC, unsupported),
2771c49
+                    mochiglobal:put(?MAGIC, unsupported),
2771c49
                     false
2771c49
             end;
2771c49
         dyntrace ->
2771c49
@@ -192,7 +192,7 @@ timeit_naive_test() ->
2771c49
 -define(REPS, 225000).
2771c49
 
2771c49
 timeit_mochiglobal_test() ->
2771c49
-    riak_core_mochiglobal:delete(?MAGIC),
2771c49
+    mochiglobal:delete(?MAGIC),
2771c49
     Reps = lists:seq(1, ?REPS),
2771c49
     test_common("timeit_mochiglobal",
2771c49
                 fun() ->
2771c49
@@ -201,7 +201,7 @@ timeit_mochiglobal_test() ->
2771c49
                         [unused, {timer:now_diff(os:timestamp(), Start), unused}]
2771c49
                 end,
2771c49
                 ?REPS),
2771c49
-    riak_core_mochiglobal:delete(?MAGIC).
2771c49
+    mochiglobal:delete(?MAGIC).
2771c49
 
2771c49
 timeit_best_off_test() ->
2771c49
     timeit_best_common("timeit_best OFF (fastest)", false).
2771c49
diff --git a/src/riak_core_mochiglobal.erl b/src/riak_core_mochiglobal.erl
2771c49
deleted file mode 100644
e64238e
index c7fde002..00000000
2771c49
--- a/src/riak_core_mochiglobal.erl
2771c49
+++ /dev/null
2771c49
@@ -1,107 +0,0 @@
2771c49
-%% @author Bob Ippolito <bob@mochimedia.com>
2771c49
-%% @copyright 2010 Mochi Media, Inc.
2771c49
-%% @doc Abuse module constant pools as a "read-only shared heap" (since erts 5.6)
2771c49
-%%      [1].
2771c49
--module(riak_core_mochiglobal).
2771c49
--author("Bob Ippolito <bob@mochimedia.com>").
2771c49
--export([get/1, get/2, put/2, delete/1]).
2771c49
-
2771c49
--spec get(atom()) -> any() | undefined.
2771c49
-%% @equiv get(K, undefined)
2771c49
-get(K) ->
2771c49
-    get(K, undefined).
2771c49
-
2771c49
--spec get(atom(), T) -> any() | T.
2771c49
-%% @doc Get the term for K or return Default.
2771c49
-get(K, Default) ->
2771c49
-    get(K, Default, key_to_module(K)).
2771c49
-
2771c49
-get(_K, Default, Mod) ->
2771c49
-    try Mod:term()
2771c49
-    catch error:undef ->
2771c49
-            Default
2771c49
-    end.
2771c49
-
2771c49
--spec put(atom(), any()) -> ok.
2771c49
-%% @doc Store term V at K, replaces an existing term if present.
2771c49
-put(K, V) ->
2771c49
-    put(K, V, key_to_module(K)).
2771c49
-
2771c49
-put(_K, V, Mod) ->
2771c49
-    Bin = compile(Mod, V),
2771c49
-    code:purge(Mod),
2771c49
-    {module, Mod} = code:load_binary(Mod, atom_to_list(Mod) ++ ".erl", Bin),
2771c49
-    ok.
2771c49
-
2771c49
--spec delete(atom()) -> boolean().
2771c49
-%% @doc Delete term stored at K, no-op if non-existent.
2771c49
-delete(K) ->
2771c49
-    delete(K, key_to_module(K)).
2771c49
-
2771c49
-delete(_K, Mod) ->
2771c49
-    code:purge(Mod),
2771c49
-    code:delete(Mod).
2771c49
-
2771c49
--spec key_to_module(atom()) -> atom().
2771c49
-key_to_module(K) ->
2771c49
-    list_to_atom("mochiglobal:" ++ atom_to_list(K)).
2771c49
-
2771c49
--spec compile(atom(), any()) -> binary().
2771c49
-compile(Module, T) ->
2771c49
-    {ok, Module, Bin} = compile:forms(forms(Module, T),
2771c49
-                                      [verbose, report_errors]),
2771c49
-    Bin.
2771c49
-
2771c49
--spec forms(atom(), any()) -> [erl_syntax:syntaxTree()].
2771c49
-forms(Module, T) ->
2771c49
-    [erl_syntax:revert(X) || X <- term_to_abstract(Module, term, T)].
2771c49
-
2771c49
--spec term_to_abstract(atom(), atom(), any()) -> [erl_syntax:syntaxTree()].
2771c49
-term_to_abstract(Module, Getter, T) ->
2771c49
-    [%% -module(Module).
2771c49
-     erl_syntax:attribute(
2771c49
-       erl_syntax:atom(module),
2771c49
-       [erl_syntax:atom(Module)]),
2771c49
-     %% -export([Getter/0]).
2771c49
-     erl_syntax:attribute(
2771c49
-       erl_syntax:atom(export),
2771c49
-       [erl_syntax:list(
2771c49
-         [erl_syntax:arity_qualifier(
2771c49
-            erl_syntax:atom(Getter),
2771c49
-            erl_syntax:integer(0))])]),
2771c49
-     %% Getter() -> T.
2771c49
-     erl_syntax:function(
2771c49
-       erl_syntax:atom(Getter),
2771c49
-       [erl_syntax:clause([], none, [erl_syntax:abstract(T)])])].
2771c49
-
2771c49
-%%
2771c49
-%% Tests
2771c49
-%%
2771c49
--ifdef(TEST).
2771c49
--include_lib("eunit/include/eunit.hrl").
2771c49
-get_put_delete_test() ->
2771c49
-    K = '$$test$$mochiglobal',
2771c49
-    delete(K),
2771c49
-    ?assertEqual(
2771c49
-       bar,
2771c49
-       get(K, bar)),
2771c49
-    try
2771c49
-        ?MODULE:put(K, baz),
2771c49
-        ?assertEqual(
2771c49
-           baz,
2771c49
-           get(K, bar)),
2771c49
-        ?MODULE:put(K, wibble),
2771c49
-        ?assertEqual(
2771c49
-           wibble,
2771c49
-           ?MODULE:get(K))
2771c49
-    after
2771c49
-        delete(K)
2771c49
-    end,
2771c49
-    ?assertEqual(
2771c49
-       bar,
2771c49
-       get(K, bar)),
2771c49
-    ?assertEqual(
2771c49
-       undefined,
2771c49
-       ?MODULE:get(K)),
2771c49
-    ok.
2771c49
--endif.
2771c49
diff --git a/src/riak_core_ring_manager.erl b/src/riak_core_ring_manager.erl
e64238e
index 0f15b49d..0c83d8bc 100644
2771c49
--- a/src/riak_core_ring_manager.erl
2771c49
+++ b/src/riak_core_ring_manager.erl
e64238e
@@ -127,7 +127,7 @@ start_link(test) ->
2771c49
 
2771c49
 %% @spec get_my_ring() -> {ok, riak_core_ring:riak_core_ring()} | {error, Reason}
2771c49
 get_my_ring() ->
2771c49
-    Ring = case riak_core_mochiglobal:get(?RING_KEY) of
2771c49
+    Ring = case mochiglobal:get(?RING_KEY) of
2771c49
                ets ->
2771c49
                    case ets:lookup(?ETS, ring) of
2771c49
                        [{_, RingETS}] ->
e64238e
@@ -546,13 +546,13 @@ cleanup_ets(test) ->
2771c49
 reset_ring_id() ->
2771c49
     %% Maintain ring id epoch using mochiglobal to ensure ring id remains
2771c49
     %% monotonic even if the riak_core_ring_manager crashes and restarts
2771c49
-    Epoch = case riak_core_mochiglobal:get(riak_ring_id_epoch) of
2771c49
+    Epoch = case mochiglobal:get(riak_ring_id_epoch) of
2771c49
                 undefined ->
2771c49
                     0;
2771c49
                 Value ->
2771c49
                     Value
2771c49
             end,
2771c49
-    riak_core_mochiglobal:put(riak_ring_id_epoch, Epoch + 1),
2771c49
+    mochiglobal:put(riak_ring_id_epoch, Epoch + 1),
2771c49
     {Epoch + 1, 0}.
2771c49
 
2771c49
 %% Set the ring in mochiglobal/ETS.  Exported during unit testing
e64238e
@@ -614,17 +614,17 @@ set_ring_global(Ring) ->
2771c49
                {chashbin, CHBin} | BucketMeta2],
2771c49
     ets:insert(?ETS, Actions),
2771c49
     ets:match_delete(?ETS, {{bucket, '_'}, undefined}),
2771c49
-    case riak_core_mochiglobal:get(?RING_KEY) of
2771c49
+    case mochiglobal:get(?RING_KEY) of
2771c49
         ets ->
2771c49
             ok;
2771c49
         _ ->
2771c49
-            riak_core_mochiglobal:put(?RING_KEY, ets)
2771c49
+            mochiglobal:put(?RING_KEY, ets)
2771c49
     end,
2771c49
     ok.
2771c49
 
2771c49
 promote_ring() ->
2771c49
     {ok, Ring} = get_my_ring(),
2771c49
-    riak_core_mochiglobal:put(?RING_KEY, Ring).
2771c49
+    mochiglobal:put(?RING_KEY, Ring).
2771c49
 
2771c49
 %% Persist a new ring file, set the global value and notify any listeners
2771c49
 prune_write_notify_ring(Ring, State) ->
e64238e
@@ -675,7 +675,7 @@ set_ring_global_test() ->
2771c49
     Ring = riak_core_ring:fresh(),
2771c49
     set_ring_global(Ring),
2771c49
     promote_ring(),
2771c49
-    ?assert(riak_core_ring:nearly_equal(Ring, riak_core_mochiglobal:get(?RING_KEY))),
2771c49
+    ?assert(riak_core_ring:nearly_equal(Ring, mochiglobal:get(?RING_KEY))),
2771c49
     cleanup_ets(test).
2771c49
 
2771c49
 set_my_ring_test() ->