2727% % application API
2828-export ([start /2 ,
2929 stop /1 ,
30- sanity_check /2 ,
31- check_bucket_props /2 ,
3230 atoms_for_check_bucket_props /0 ]).
3331
3432-include (" riak_cs.hrl" ).
@@ -57,14 +55,11 @@ stop(_State) ->
5755sanity_check (true , {ok , true }) ->
5856 riak_cs_sup :start_link ();
5957sanity_check (false , _ ) ->
60- _ = lager :error (" You must update your Riak CS app.config . Please see the"
58+ _ = lager :error (" You must update your Riak CS riak-cs.conf . Please see the"
6159 " release notes for more information on updating you"
6260 " configuration." ),
6361 {error , bad_config };
6462sanity_check (true , {ok , false }) ->
65- _ = lager :error (" Invalid Riak bucket properties detected. Please "
66- " verify that allow_mult is set to true for all "
67- " buckets." ),
6863 {error , invalid_bucket_props };
6964sanity_check (true , {error , Reason }) ->
7065 _ = lager :error (" Could not verify bucket properties. Error was"
@@ -83,15 +78,28 @@ get_env_response_to_bool(_) ->
8378
8479-spec check_bucket_props () -> {ok , boolean ()} | {error , term ()}.
8580check_bucket_props () ->
86- Buckets = [? USER_BUCKET ,
87- ? ACCESS_BUCKET ,
88- ? STORAGE_BUCKET ,
89- ? BUCKETS_BUCKET ],
9081 {ok , MasterPbc } = riak_connection (),
9182 try
92- Results = [check_bucket_props (Bucket , MasterPbc ) ||
93- Bucket <- Buckets ],
94- lists :foldl (fun promote_errors /2 , {ok , true }, Results )
83+ case riakc_pb_socket :get_bucket_type (MasterPbc , <<" default" >>) of
84+ {ok , DefaultProps } ->
85+ _ = lager :info (" Checking default bucket props..." , []),
86+ _ = lager :debug (" default bucket props: ~p " , [DefaultProps ]),
87+ CheckResult = [check_prop (Property , DefaultProps )
88+ || Property <- [{dvv_enabled , true , false },
89+ {allow_mult , true , true },
90+ {last_write_wins , false , true }]],
91+ case CheckResult of
92+ [true , true , true ] ->
93+ _ = lager :debug (" Default bucket type was"
94+ " already configured correctly." ),
95+ {ok , true };
96+ _ ->
97+ _ = lager :error (" Default bucket type is not properly configured" ),
98+ {ok , false }
99+ end ;
100+ {error , _ } = E ->
101+ E
102+ end
95103 after
96104 riakc_pb_socket :stop (MasterPbc )
97105 end .
@@ -101,42 +109,26 @@ atoms_for_check_bucket_props() ->
101109 [riak_core_util , chash_std_keyfun ,
102110 riak_kv_wm_link_walker , mapreduce_linkfun ].
103111
104- promote_errors (_Elem , {error , _Reason }= E ) ->
105- E ;
106- promote_errors ({error , _Reason }= E , _Acc ) ->
107- E ;
108- promote_errors ({ok , false }= F , _Acc ) ->
109- F ;
110- promote_errors ({ok , true }, Acc ) ->
111- Acc .
112-
113- -spec check_bucket_props (binary (), pid ()) -> {ok , boolean ()} | {error , term ()}.
114- check_bucket_props (Bucket , MasterPbc ) ->
115- case catch riakc_pb_socket :get_bucket (MasterPbc , Bucket ) of
116- {ok , Props } ->
117- maybe_warn_dvv_enabled (lists :keyfind (dvv_enabled , 1 , Props )),
118- case lists :keyfind (allow_mult , 1 , Props ) of
119- {allow_mult , true } ->
120- _ = lager :debug (" ~s bucket was"
121- " already configured correctly." ,
122- [Bucket ]),
123- {ok , true };
124- _ ->
125- _ = lager :warning (" ~p is misconfigured" , [Bucket ]),
126- {ok , false }
127- end ;
128- {error , Reason }= E ->
129- _ = lager :warning (
130- " Unable to verify ~s bucket settings (~p )." ,
131- [Bucket , Reason ]),
132- E
112+ -spec check_prop ({atom (), boolean (), boolean ()}, proplists :proplist ()) -> boolean ().
113+ check_prop ({Key , ShouldBe , IsMust }, Props ) ->
114+ case lists :keyfind (Key , 1 , Props ) of
115+ {Key , ShouldBe } ->
116+ true ;
117+ {Key , Current } when not IsMust ->
118+ _ = lager :warning (" ~p is strongly recommended to be ~p (currently ~p )" ,
119+ [Key , ShouldBe , Current ]),
120+ true ;
121+ false ->
122+ _ = lager :warning (" ~p is strongly recommended to be ~p (currently undefined)" ,
123+ [Key , ShouldBe ]),
124+ true ;
125+ _ when IsMust ->
126+ _ = lager :error (" Invalid Riak bucket properties detected. Please "
127+ " verify that riak.conf has `buckets.default.~p = ~p `." ,
128+ [Key , ShouldBe ]),
129+ false
133130 end .
134131
135- maybe_warn_dvv_enabled ({dvv_enabled , false }) ->
136- _ = lager :warning (" DVV is disabled. Please check configuration" );
137- maybe_warn_dvv_enabled (_ ) ->
138- ok .
139-
140132riak_connection () ->
141133 {Host , Port } = riak_cs_config :riak_host_port (),
142134 Timeout = case application :get_env (riak_cs , riakc_connect_timeout ) of
0 commit comments