Experience with python schema setting

Jay Doane jay.s.doane at gmail.com
Thu Oct 15 17:53:14 EDT 2009


On Oct 15, 2009, at 2:27 PM, Dhananjay Nene wrote:

> I think I found the answers for the parameters and their values via  
> the documentation with the Java Client - but still not sure if set  
> schema is mandatory.

Yes, I believe it is.  There must be a schema present for each  
bucket.  It can either be created via an erlang module (as in  
jiak_example.erl), or dynamically via set_bucket_schema.

In any case, I get the same errors you get when I forget to do so :)

What I wonder is if/when we will have the ability to set other bucket  
properties from the jiak clients, or if I'm missing something?

Cheers,
Jay

>
> Dhananjay Nene wrote:
>>
>> Note: My questions are at the very end of this mail.
>>
>> According to the documentation the URI for setting the schema is as  
>> follows :
>>
>> PUT /jiak/Bucket
>>
>> Set the schema for Bucket according to the request body.
>>
>> However I couldn't find the reference to how the body of the POST  
>> to that URI should be constructed. When I try to insert a few  
>> records using the python client using the following code, I get a  
>> 503 error
>>
>> Code:
>>
>>     JC = JiakClient("127.0.0.1",8098)
>>     JO = JiakObject("jiak_example", "doctestkey")
>>     JO = JiakObject("jiak_example", "doctestkey")
>>     JO.object["foo"] = 2
>>     JC.store(JO)
>>
>> Error:
>> Traceback (most recent call last):
>>   File "jiak.py", line 183, in <module>
>>     JC.store(JO)
>>   File "jiak.py", line 101, in store
>>     {"Content-Type": "application/json"}))
>>   File "jiak.py", line 71, in _expect
>>     raise JiakException(Resp.status, Resp.reason, Resp.read())
>> __main__.JiakException: (503, 'Service Unavailable',  
>> '<html><head><title>503 Service Unavailable</title></ 
>> head><body><h1>Service Unavailable</h1>The server is currently  
>> unable to handle the request due to a temporary overloading or  
>> maintenance of the server.<br><P><HR><ADDRESS>mochiweb+webmachine  
>> web server</ADDRESS></body></html>')
>>
>> Since this seems to be a problem with setting the default schema  
>> (not entirely sure of that , I explicitly invoked set_bucket schema  
>> as follows )
>>
>> Code :
>>
>>     JC = JiakClient("127.0.0.1",8098)
>>     JC.set_bucket_schema("jiak_example",None)
>>     JO = JiakObject("jiak_example", "doctestkey")
>>     JO = JiakObject("jiak_example", "doctestkey")
>>     JO.object["foo"] = 2
>>     JC.store(JO)
>>
>> In return, I get the following error :
>>
>> Error :
>>
>> Traceback (most recent call last):
>>   File "jiak.py", line 183, in <module>
>>     JC.store(JO)
>>   File "jiak.py", line 101, in store
>>     {"Content-Type": "application/json"}))
>>   File "jiak.py", line 71, in _expect
>>     raise JiakException(Resp.status, Resp.reason, Resp.read())
>> __main__.JiakException: (500, 'Internal Server Error',  
>> '<html><head><title>500 Internal Server Error</title></ 
>> head><body><h1>Internal Server Error</h1>The server encountered an  
>> error while processing this request:<br><pre>{badarg,[{lists,member, 
>> [<<"foo">>,null]},\n         {jiak_resource,\'-check_write_mask/2-lc 
>> $^0/1-0-\',2},\n         {jiak_resource,check_write_mask,2}, 
>> \n         {jiak_resource,object_forbidden,2},\n          
>> {webmachine_resource,resource_call,3},\n          
>> {webmachine_resource,do,3},\n          
>> {webmachine_decision_core,resource_call,1},\n          
>> {webmachine_decision_core,decision,1}]}</ 
>> pre><P><HR><ADDRESS>mochiweb+webmachine web server</ADDRESS></ 
>> body></html>')
>>
>> There's clearly some issue most likely with the second argument I  
>> pass to set_bucket_schema. However couldn't find any specific  
>> reference to what these parameters should be (allowed_fields,  
>> write_mask, read_mask etc.)
>>
>> So I further modified it to pass an empty list
>>
>> Code :
>>
>>     JC = JiakClient("127.0.0.1",8098)
>>     JC.set_bucket_schema("jiak_example",[])
>>     JO = JiakObject("jiak_example", "doctestkey")
>>     JO.object["foo"] = 2
>>     JC.store(JO)
>>
>> Error :
>>
>> Traceback (most recent call last):
>>   File "jiak.py", line 182, in <module>
>>     JC.store(JO)
>>   File "jiak.py", line 101, in store
>>     {"Content-Type": "application/json"}))
>>   File "jiak.py", line 71, in _expect
>>     raise JiakException(Resp.status, Resp.reason, Resp.read())
>> __main__.JiakException: (403, 'Forbidden', 'Write disallowed, some  
>> of [<<"foo">>] not writable.\n')
>>
>>
>> Finally I explicitly made "foo" an allowed attribute - and all  
>> worked fine.
>>
>> Code :
>>     JC = JiakClient("127.0.0.1",8098)
>>     JC.set_bucket_schema("jiak_example",["foo"])
>>     JO = JiakObject("jiak_example", "doctestkey")
>>     JO.object["foo"] = 2
>>     JC.store(JO)
>>
>> Error : No Error. Seemed to work fine.
>>
>> So - my questions are :
>>
>> (a) Am I on the right track / approach ?
>> (b) Is calling set_bucket_schema mandatory ?
>> (c) How can I find what values should I be setting allowed_fields,  
>> read_mask, write_mask etc.
>>
>>
>>
>
> _______________________________________________
> riak-users mailing list
> riak-users at lists.basho.com
> http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com





More information about the riak-users mailing list