Commits

Anonymous committed 12db020 Merge

merge

Comments (0)

Files changed (10)

 expires_in_seconds(_Key, ReqData, Context) ->
     {proplists:get_value(expiry_seconds, BucketProps, 600), ReqData, Context}.
 
-%% @spec check_write({container|item, riak_object:binary_key()},
+%% @spec check_write({container|item, riak_object:key()},
 %%                   jiak_object(), webmachine:wrq(), jiak_context()) ->
 %%         {{ok, jiak_object()}|{error, term()},
 %%          webmachine:wrq(), jiak_context()}
 expires_in_seconds(_Key, ReqData, Context) ->
     {600, ReqData, Context}.
 
-%% @spec check_write({container|item, riak_object:binary_key()},
+%% @spec check_write({container|item, riak_object:key()},
 %%                   jiak_object(), webmachine:wrq(), jiak_context()) ->
 %%         {{ok, jiak_object()}|{error, term()},
 %%          webmachine:wrq(), jiak_context()}
 -export([diff/2, undefined/0]).
 -export([test_roundtrip_vclock/0]).
 
-%% @type jiak_key()=riak_object:binary_key().
 
-%% @spec new(riak_object:bucket(), jiak_key()) -> jiak_object()
+%% @spec new(riak_object:bucket(), riak_object:key()) -> jiak_object()
 %% @doc produces an empty jiak object
 %% @equiv new(B, K, {struct, []}, [])
 new(B, K) -> new(B, K, {struct, []}, []).
 
-%% @spec new(riak_object:bucket(), jiak_key(), mochijson2()) -> jiak_object()
+%% @spec new(riak_object:bucket(),riak_object:key(),mochijson2())->jiak_object()
 %% @doc produces a new jiak object with no links
 %% @equiv new(B, K, O, [])
 new(B, K, O) -> new(B, K, O, []).
 
-%% @spec new(riak_object:bucket(), jiak_key(), mochijson2(), 
+%% @spec new(riak_object:bucket(), riak_object:key(), mochijson2(), 
 %%           [link()]) -> jiak_object()
 %% @doc produces empty jiak object, a mochijson2 structure that
 %%      would encode to the JSON structure:
     Links = links(JiakObject),
     set_links(JiakObject, [ L || L <- Links, L /= RemLink]).
 
-%% @spec remove_link(jiak_object, riak_object:bucket(), jiak_key(), term()) 
+%% @spec remove_link(jiak_object, riak_object:bucket(), riak_object:key(), term()) 
 %%         -> jiak_object()
 %% @equiv remove_link(JiakObject, [Bucket, Key, Tag])
 remove_link(JiakObject, Bucket, Key, Tag) ->

src/jiak_resource.erl

 
 -include_lib("webmachine/include/webmachine.hrl").
 
-%% @type key() = container|riak_object:binary_key()
+%% @type key() = container|schema|riak_object:key()
 
 %% @spec init(proplist()) -> {ok, context()}
 %% @doc Initialize this webmachine resource.  This function will

src/riak_bucketkeys.erl

 handle_call(_,_,State) -> {reply,no_call_support,State}.
 
 handle_cast({OpType,Bucket,Key},State=#state{ops=Ops}) ->
-    BucketFrag = lists:flatten(
-                   io_lib:format("~s-~b", 
-                                 [Bucket, 
-                                  erlang:phash2(Key) rem ?NFRAGS])),
+    BucketFrag = list_to_binary(
+                   lists:flatten(
+                     io_lib:format("~s-~b", 
+                                   [Bucket, 
+                                    erlang:phash2(Key) rem ?NFRAGS]))),
     NewState = ensure_ring(State),
     OpList = case dict:find(BucketFrag, Ops) of
         error ->   [{OpType,Key}];
 
 %% @private 
 all_frags(Bucket) when is_atom(Bucket) ->
-    [atom_to_list(Bucket) ++ "-" ++ X || X <- [integer_to_list(I) || 
-                                               I <- lists:seq(0, ?NFRAGS-1)]].
+    [list_to_binary(F) || F <- [atom_to_list(Bucket) ++ "-" ++ X || X <- [integer_to_list(I) || I <- lists:seq(0, ?NFRAGS-1)]]].
 %% @private
 ensure_ring(State=#state{ring=undefined}) ->
     riak_ring_manager:subscribe(self()),
 %% @type riak_object().  Opaque container for Riak objects.
 -record(r_object, {
           bucket :: atom(),
-          key :: string()|binary(),
+          key :: binary(),
           contents :: [#r_content{}],
           vclock :: [vclock:vclock()],
           updatemetadata=dict:store(clean, true, dict:new()) :: dict(),
           updatevalue :: term()
          }).
 
-%% @type binary_key()=binary().
-%% @type string_key()=string().
-%% @type key()=binary_key()|string_key().
+-define(MAX_KEY_SIZE, 65536).
+
+%% @type key()=binary().
 %% @type bucket()=atom().
 %% @type value()=term().
 
 
 object_test() ->
     B = buckets_are_atoms,
-    K = "keys are strings",
+    K = <<"keys are binaries">>,
     V = <<"values are anything">>,
     O = riak_object:new(B,K,V),
     B = riak_object:bucket(O),
     O3 = riak_object:syntactic_merge(O,O3,node_does_not_matter_here),
     {O,O3}.    
 
+largekey_test() ->
+    TooLargeKey = <<0:(65537*8)>>,
+    try
+        riak_object:new(a, TooLargeKey, <<>>)
+    catch throw:{error, key_too_large} ->
+            ok
+    end.
+            
+
+
 %% @spec new(Bucket::bucket(), Key::key(), Value::value()) -> riak_object()
 %% @doc Constructor for new riak objects.
-new(B, K, V) when is_atom(B), (is_list(K) orelse is_binary(K)) ->
-    Contents = [#r_content{metadata=dict:new(), value=V}],
-    #r_object{bucket=B, key=K, contents=Contents, vclock=vclock:fresh()}.
+new(B, K, V) when is_atom(B), is_binary(K) ->
+    case size(K) > ?MAX_KEY_SIZE of
+        true ->
+            throw({error,key_too_large});
+        false ->
+            Contents = [#r_content{metadata=dict:new(), value=V}],
+            #r_object{bucket=B,key=K,contents=Contents,vclock=vclock:fresh()}
+    end.
 
 %% @spec equal(riak_object(), riak_object()) -> true | false
 %% @doc Deep (expensive) comparison of Riak objects.
 #  Join riak cluster <clustername> using erlcookie <cookie>
 #  via the node listening at <ip>:<port>
 #  and dump the entire cluster's contents to <dumpfilename>
+if [ $# -le 5 ]; then
+    echo Usage: 1>&2
+    echo "    `basename $0` <clustername> <cookie> <ip in ring> " 1>&2
+    echo "                  <doorbell port> <filename to save dump to>" 1>&2
+    exit 1
+fi
 . riak-env.sh
 erl -noshell -pa deps/*/ebin -pa ebin -name backup_dumper -run riak_backup dump_config $1 $2 -run riak start -run riak_backup do_dump $3 $4 $5 -run init stop

start-backup-restore.sh

 #  Join riak cluster <clustername> using erlcookie <cookie>
 #  via the node listening at <ip>:<port>
 #  and overwrite cluster data with that contained in <dumpfilename>
+if [ $# -le 5 ]; then
+    echo Usage: 1>&2
+    echo "    `basename $0` <clustername> <cookie> <ip in ring> " 1>&2
+    echo "                  <doorbell port> <filename to restore from>" 1>&2
+    exit 1
+fi
 . riak-env.sh
 erl -noshell -pa deps/*/ebin -pa ebin -name backup_restore -run riak_backup restore_config $1 $2 -run riak start -run riak_backup do_restore $3 $4 $2 $5 -run init stop
 
 #  Join riak cluster <clustername> using erlcookie <cookie>
 #  via the node listening at <ip>:<port>
 #  and register a riak event handler
+if [ $# -le 7 ]; then
+    echo Usage: 1>&2
+    echo "    `basename $0` <clustername> <cookie> <ip in ring> " 1>&2
+    echo "                  <doorbell port> <nodename> <event module name>" 1>&2
+    echo "                  <event module args>" 1>&2
+    exit 1
+fi
 . riak-env.sh
 erl -noshell -pa deps/*/ebin -pa ebin -name $5 -run riak_eventer eventer_config $1 $2 -run riak start -run riak_eventer do_eventer $3 $4 $6 $7
 #!/usr/bin/env bash
 # start-join <configfile> <ip> <port>
 # join an existing riak ring via a node known to be listening on ip:port
+if [ $# -le 3 ]; then
+    echo Usage: 1>&2
+    echo "    `basename $0` <config file> <ip of node in ring> <doorbell port>" 1>&2
+    exit 1
+fi
 . riak-env.sh
 NODENAME=$(erl -noshell -pa ebin -eval "error_logger:tty(false), riak_app:read_config(\"$1\"), io:format(\"~p~n\",[riak:get_app_env(riak_nodename)])" -run init stop)
 RHOSTNAME=$(erl -noshell -pa ebin -eval "error_logger:tty(false), riak_app:read_config(\"$1\"), io:format(\"~s~n\",[riak:get_app_env(riak_hostname)])" -run init stop)