basho / riak

Riak is a decentralized datastore from Basho Technologies.
http://docs.basho.com
Apache License 2.0
3.92k stars 534 forks source link

Bucket Types usage changed/broken in KV 3.0.1 #1043

Closed Bob-The-Marauder closed 3 years ago

Bob-The-Marauder commented 3 years ago

Expected behaviour - bucket type created, prompted to activate new type. Actual behaviour:

[root@localhost ~]# riak admin bucket-type create n_val_of_2 '{"props":{"n_val":2}}'
Cannot create bucket type n_val_of_2: invalid json

[root@localhost ~]# riak admin bucket-type create user_account_bucket '`cat /tmp/props.json`'
RPC to 'riak@127.0.0.1' failed: {'EXIT',
                                 {function_clause,
                                  [{riak_kv_console,bucket_type_create,
                                    [["user_account_bucket","{","\"props\":",
                                      "{","\"precommit\":",
                                      "[\"syntax_check\"],","\"postcommit\":",
                                      "[\"welcome_email\",",
                                      "\"update_registry\"]","}","}"]],
                                    [{file,
                                      "/root/riak/rel/pkg/out/BUILD/riak-3.0.1/_build/default/lib/riak_kv/src/riak_kv_console.erl"},
                                     {line,499}]},
                                   {rpc,'-handle_call_call/6-fun-0-',5,
                                    [{file,"rpc.erl"},{line,197}]}]}}

The props.json file is owned by the riak user and is as follows:

{
  "props": {
    "precommit": ["syntax_check"],
    "postcommit": ["welcome_email", "update_registry"]
  }
}

The inline example is copied from https://www.tiot.jp/riak-docs/riak/kv/2.2.6/using/reference/bucket-types/#bucket-types-and-the-allow-mult-setting and the props.json file used is copied directly from https://www.tiot.jp/riak-docs/riak/kv/2.2.6/using/reference/bucket-types/#bucket-type-example

Attempting to create a bucket type with no special properties i.e. riak-admin bucket-type create namespace_bucket '{"props":{}}' also returns "invalid json".

I have tried with both the Yokozuna and non-Yokozuna packages for KV 3.0.1. I also tried with a devrel and got a different path for riak_kv_console.erl in the error that was specific to my devrel build.

Manual experimentation with the json format for the inline example either results in "invalid json" or the same error as when trying to create from a json file.

Non-bucket type creation seems to work fine e.g. taking the curl example from https://www.tiot.jp/riak-docs/riak/kv/2.2.6/developing/usage/creating-objects/#write-parameters gives:

[root@localhost ~]# curl -XPUT -H "Content-Type: text/plain" -d "vroom" http://localhost:8098/buckets/dodge/keys/viper?w=3

[root@localhost ~]# curl http://localhost:8098/buckets/dodge/keys/viper
vroom
martinsumner commented 3 years ago

These console commands all get handled by relx (having previously been under the guise of nodetool). Whatever was handling json inputs no longer works in relx.

All the tests attach to the node to set bucket types, so this should still work via riak remote_console:

(riak@127.0.0.1)1> riak_core_bucket_type:create(<<"maps">>, [{datatype, map}]).
(riak@127.0.0.1)2> riak_core_bucket_type:activate(<<"maps">>).

This is the best workaround for the moment. I don't know what's going to be involved in fixing the way relx scripts work to get all the old console commands going again.

martincox commented 3 years ago

I have a fix for this. I'll create a PR shortly.

martincox commented 3 years ago

1044 fixes this.

martinsumner commented 3 years ago

https://github.com/basho/riak_kv/pull/1781 resolves the issue when no props are passed - a type is created with empty props

Bob-The-Marauder commented 3 years ago

Fixed in Riak KV 3.0.2. Default bucket type behaviour updated to match 2.x.x from Riak KV 3.0.3