Skip to content

Instantly share code, notes, and snippets.

@shino
Last active August 29, 2015 14:16
Show Gist options
  • Save shino/9f5621681e17beea0128 to your computer and use it in GitHub Desktop.
Save shino/9f5621681e17beea0128 to your computer and use it in GitHub Desktop.
Dirty patch for Riak CS to work with Erlang/OTP 17.4
diff --git a/include/riak_cs.hrl b/include/riak_cs.hrl
index 8e0296f..d293b45 100644
--- a/include/riak_cs.hrl
+++ b/include/riak_cs.hrl
@@ -504,3 +504,11 @@
-define(OBJECT_BUCKET_PREFIX, <<"0o:">>). % Version # = 0
-define(BLOCK_BUCKET_PREFIX, <<"0b:">>). % Version # = 0
+
+-ifdef(namespaced_types).
+-type mochiweb_headers() :: gb_trees:tree().
+-type robj_md() :: dict:dict().
+-else.
+-type mochiweb_headers() :: gb_tree().
+-type robj_md() :: dict().
+-endif.
diff --git a/rebar.config b/rebar.config
index ba783f7..f686c18 100644
--- a/rebar.config
+++ b/rebar.config
@@ -1,6 +1,6 @@
{sub_dirs, ["rel"]}.
-{require_otp_vsn, "R16"}.
+{require_otp_vsn, "R16|17"}.
{cover_enabled, true}.
@@ -9,7 +9,10 @@
{lib_dirs, ["deps", "apps"]}.
-{erl_opts, [debug_info, warnings_as_errors, {parse_transform, lager_transform}]}.
+{erl_opts, [debug_info,
+ warnings_as_errors,
+ {parse_transform, lager_transform},
+ {platform_define, "^[0-9]+", namespaced_types}]}.
{xref_checks, []}.
{xref_queries,
@@ -48,10 +51,9 @@
{eper, ".*", {git, "git://github.com/basho/eper.git", "0.78"}},
{druuid, ".*", {git, "git://github.com/kellymclaughlin/druuid.git", {tag, "0.2"}}},
{velvet, "1.3.*", {git, "git://github.com/basho/velvet", "4bb0fd664ff065c4082ca8dd2e0683e920537d15"}},
- {poolboy, "0.8.*", {git, "git://github.com/basho/poolboy", "0.8.1p2"}},
+ {poolboy, "0.8.*", {git, "git://github.com/basho/poolboy", {branch, "develop"}}},
{folsom, ".*", {git, "git://github.com/boundary/folsom", {tag, "0.8.2"}}},
{cluster_info, ".*", {git, "git://github.com/basho/cluster_info", {tag, "2.0.0"}}},
- {xmerl, ".*", {git, "git://github.com/shino/xmerl", "b35bcb05abaf27f183cfc3d85d8bffdde0f59325"}},
{erlcloud, ".*", {git, "git://github.com/basho/erlcloud.git", {tag, "0.4.5"}}},
{rebar_lock_deps_plugin, ".*", {git, "git://github.com/seth/rebar_lock_deps_plugin.git", {tag, "3.1.0"}}}
]}.
diff --git a/rebar.config.script b/rebar.config.script
index a570cf3..7d4da3f 100644
--- a/rebar.config.script
+++ b/rebar.config.script
@@ -1,16 +1,11 @@
+HashDefine = [{d,new_hash}],
HashMacroAdded =
- case erlang:system_info(otp_release) < "R16" of
- true ->
- CONFIG;
- false ->
- HashDefine = [{d,new_hash}],
case lists:keysearch(erl_opts, 1, CONFIG) of
{value, {erl_opts, Opts}} ->
lists:keyreplace(erl_opts,1,CONFIG,{erl_opts,Opts++HashDefine});
false ->
CONFIG ++ [{erl_opts, HashDefine}]
- end
- end,
+ end,
{IsEE, Package} = case os:getenv("RIAK_CS_EE_DEPS") of
false -> {false, "riak-cs"};
diff --git a/src/riak_cs_get_fsm.erl b/src/riak_cs_get_fsm.erl
index 980577b..52bb417 100644
--- a/src/riak_cs_get_fsm.erl
+++ b/src/riak_cs_get_fsm.erl
@@ -67,6 +67,12 @@
-type block_name() :: {binary(), integer()}.
+-ifdef(namespaced_types).
+-type block_queue() :: queue:queue().
+-else.
+-type block_queue() :: queue().
+-endif.
+
-record(state, {from :: {pid(), reference()},
riak_client :: riak_client(),
mani_fsm_pid :: pid(),
@@ -78,7 +84,7 @@
got_blocks=orddict:new() :: orddict:orddict(),
manifest :: term(),
blocks_order :: [block_name()],
- blocks_intransit=queue:new() :: queue(),
+ blocks_intransit=queue:new() :: block_queue(),
test=false :: boolean(),
total_blocks :: pos_integer(),
num_sent=0 :: non_neg_integer(),
diff --git a/src/riak_cs_list_objects_ets_cache.erl b/src/riak_cs_list_objects_ets_cache.erl
index da1808d..b91ed48 100644
--- a/src/riak_cs_list_objects_ets_cache.erl
+++ b/src/riak_cs_list_objects_ets_cache.erl
@@ -52,9 +52,15 @@
-define(DICTMODULE, dict).
+-ifdef(namespaced_types).
+-type dictionary() :: dict:dict().
+-else.
+-type dictionary() :: dict().
+-endif.
+
-record(state, {tid :: ets:tid(),
- monitor_to_timer = ?DICTMODULE:new() :: ?DICTMODULE(),
- key_to_monitor = ?DICTMODULE:new() :: ?DICTMODULE()}).
+ monitor_to_timer = ?DICTMODULE:new() :: dictionary(),
+ key_to_monitor = ?DICTMODULE:new() :: dictionary()}).
-type state() :: #state{}.
-type cache_lookup_result() :: {true, [binary()]} | false.
@@ -257,7 +263,7 @@ handle_down(MonitorRef, State=#state{monitor_to_timer=MonToTimer}) ->
NewMonToTimer = remove_timer(MonitorRef, MonToTimer),
State#state{monitor_to_timer=NewMonToTimer}.
--spec remove_monitor(binary(), ?DICTMODULE()) -> ?DICTMODULE().
+-spec remove_monitor(binary(), dictionary()) -> dictionary().
remove_monitor(ExpiredKey, KeyToMon) ->
RefResult = safe_fetch(ExpiredKey, KeyToMon),
case RefResult of
@@ -268,7 +274,7 @@ remove_monitor(ExpiredKey, KeyToMon) ->
end,
?DICTMODULE:erase(ExpiredKey, KeyToMon).
--spec remove_timer(reference(), ?DICTMODULE()) -> ?DICTMODULE().
+-spec remove_timer(reference(), dictionary()) -> dictionary().
remove_timer(MonitorRef, MonToTimer) ->
RefResult = safe_fetch(MonitorRef, MonToTimer),
_ = case RefResult of
@@ -281,7 +287,7 @@ remove_timer(MonitorRef, MonToTimer) ->
end,
?DICTMODULE:erase(MonitorRef, MonToTimer).
--spec safe_fetch(Key :: term(), Dict :: ?DICTMODULE()) ->
+-spec safe_fetch(Key :: term(), Dict :: dictionary()) ->
{ok, term()} | {error, term()}.
safe_fetch(Key, Dict) ->
try
diff --git a/src/riak_cs_oos_rewrite.erl b/src/riak_cs_oos_rewrite.erl
index d0ce41a..bb71729 100644
--- a/src/riak_cs_oos_rewrite.erl
+++ b/src/riak_cs_oos_rewrite.erl
@@ -34,8 +34,8 @@
-endif.
%% @doc Function to rewrite headers prior to processing by webmachine.
--spec rewrite(atom(), atom(), {integer(), integer()}, gb_tree(), string()) ->
- {gb_tree(), string()}.
+-spec rewrite(atom(), atom(), {integer(), integer()}, mochiweb_headers(), string()) ->
+ {mochiweb_headers(), string()}.
rewrite(Method, _Scheme, _Vsn, Headers, RawPath) ->
riak_cs_dtrace:dt_wm_entry(?MODULE, <<"rewrite">>),
{Path, QueryString, _} = mochiweb_util:urlsplit_path(RawPath),
@@ -63,7 +63,7 @@ parse_path(Path) ->
{ApiVsn, Account, "/" ++ string:join(RestPath, "/")}.
%% @doc Add headers for the raw path, the API version, and the account.
--spec rewrite_headers(gb_tree(), string(), string(), string()) -> gb_tree().
+-spec rewrite_headers(mochiweb_headers(), string(), string(), string()) -> mochiweb_headers().
rewrite_headers(Headers, RawPath, ApiVsn, Account) ->
UpdHdrs0 = mochiweb_headers:default(?RCS_REWRITE_HEADER, RawPath, Headers),
UpdHdrs1 = mochiweb_headers:enter(?OOS_API_VSN_HEADER, ApiVsn, UpdHdrs0),
diff --git a/src/riak_cs_s3_rewrite.erl b/src/riak_cs_s3_rewrite.erl
index d2f8b44..d228c00 100644
--- a/src/riak_cs_s3_rewrite.erl
+++ b/src/riak_cs_s3_rewrite.erl
@@ -61,8 +61,8 @@
-type subresources() :: [subresource()].
%% @doc Function to rewrite headers prior to processing by webmachine.
--spec rewrite(atom(), atom(), {integer(), integer()}, gb_tree(), string()) ->
- {gb_tree(), string()}.
+-spec rewrite(atom(), atom(), {integer(), integer()}, mochiweb_headers(), string()) ->
+ {mochiweb_headers(), string()}.
rewrite(Method, _Scheme, _Vsn, Headers, Url) ->
riak_cs_dtrace:dt_wm_entry(?MODULE, <<"rewrite">>),
{Path, QueryString, _} = mochiweb_util:urlsplit_path(Url),
@@ -86,8 +86,8 @@ raw_url(RD) ->
{Path, mochiweb_util:parse_qs(QS)}
end.
--spec rewrite_path_and_headers(atom(), gb_tree(), string(), string(), string()) ->
- {gb_tree(), string()}.
+-spec rewrite_path_and_headers(atom(), mochiweb_headers(), string(), string(), string()) ->
+ {mochiweb_headers(), string()}.
rewrite_path_and_headers(Method, Headers, Url, Path, QueryString) ->
Host = mochiweb_headers:get_value("host", Headers),
HostBucket = bucket_from_host(Host),
diff --git a/src/riak_cs_s3_rewrite_legacy.erl b/src/riak_cs_s3_rewrite_legacy.erl
index 824e045..e239e77 100644
--- a/src/riak_cs_s3_rewrite_legacy.erl
+++ b/src/riak_cs_s3_rewrite_legacy.erl
@@ -22,9 +22,11 @@
-export([rewrite/5]).
+-include("riak_cs.hrl").
+
%% @doc Function to rewrite headers prior to processing by webmachine.
--spec rewrite(atom(), atom(), {integer(), integer()}, gb_tree(), string()) ->
- {gb_tree(), string()}.
+-spec rewrite(atom(), atom(), {integer(), integer()}, mochiweb_headers(), string()) ->
+ {mochiweb_headers(), string()}.
rewrite(Method, _Scheme, _Vsn, Headers, Url) ->
riak_cs_dtrace:dt_wm_entry(?MODULE, <<"rewrite">>),
%% Unquote the path to accomodate some naughty client libs (looking
diff --git a/src/riak_cs_utils.erl b/src/riak_cs_utils.erl
index ac7b1aa..c668aad 100644
--- a/src/riak_cs_utils.erl
+++ b/src/riak_cs_utils.erl
@@ -335,7 +335,7 @@ handle_active_manifests({error, no_active_manifest}) ->
{error, notfound}.
%% @doc Determine if a set of contents of a riak object has a tombstone.
--spec has_tombstone({dict(), binary()}) -> boolean().
+-spec has_tombstone({robj_md(), binary()}) -> boolean().
has_tombstone({_, <<>>}) ->
true;
has_tombstone({MD, _V}) ->
diff --git a/src/twop_set.erl b/src/twop_set.erl
index 1a6a2ae..38e7ad8 100644
--- a/src/twop_set.erl
+++ b/src/twop_set.erl
@@ -53,7 +53,13 @@
resolve/1
]).
--type twop_set() :: {set(), set()}.
+-ifdef(namespaced_types).
+-type stdlib_set() :: sets:set().
+-else.
+-type stdlib_set() :: set().
+-endif.
+
+-type twop_set() :: {stdlib_set(), stdlib_set()}.
-export_type([twop_set/0]).
%%%===================================================================
deps/bear
deps/cluster_info
deps/cuttlefish
deps/druuid
deps/eper
deps/erlcloud
deps/folsom
deps/getopt
deps/goldrush
deps/ibrowse
deps/lager
deps/lager_syslog
deps/meck
deps/mochiweb
deps/neotoma
deps/node_package
deps/poolboy
deps/protobuffs
deps/rebar_lock_deps_plugin
deps/riak_cs_multibag
diff --git a/rebar.config b/rebar.config
index 790518e..2b520e1 100644
--- a/rebar.config
+++ b/rebar.config
@@ -1,4 +1,4 @@
-{require_otp_vsn, "R15|R16"}.
+{require_otp_vsn, "R15|R16|17"}.
{cover_enabled, true}.
deps/riak_pb
deps/riak_repl_pb_api
deps/riakc
deps/syslog
deps/velvet
diff --git a/rebar.config b/rebar.config
index 9a03432..49fd94b 100644
--- a/rebar.config
+++ b/rebar.config
@@ -1,4 +1,4 @@
-{require_otp_vsn, "R14B0[234]|R15|R16"}.
+{require_otp_vsn, "R14B0[234]|R15|R16|17"}.
{cover_enabled, true}.
diff --git a/rebar.config.script b/rebar.config.script
index 58f42a8..ff08011 100644
--- a/rebar.config.script
+++ b/rebar.config.script
@@ -1,12 +1,7 @@
-case erlang:system_info(otp_release) < "R16" of
- true ->
- CONFIG;
- false ->
HashDefine = [{d,new_hash}],
case lists:keysearch(erl_opts, 1, CONFIG) of
{value, {erl_opts, Opts}} ->
lists:keyreplace(erl_opts,1,CONFIG,{erl_opts,Opts++HashDefine});
false ->
CONFIG ++ [{erl_opts, HashDefine}]
- end
-end.
+ end.
deps/webmachine
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment