Stickynotes demo

Bryan Fink bryan at basho.com
Fri Sep 25 08:50:26 EDT 2009


On Fri, Sep 25, 2009 at 1:44 AM, Dan Reverri <reverri at gmail.com> wrote:
> I am having trouble getting the Stickynotes demo to operate with just Riak.
...
> However, if I do not start the Stickynotes webmachine application the script
> fails:
> 1. start Riak:
> ./debug-fresh.sh demo/stickynotes/riak-config.erlenv
> 2. Run the following python script:
> http://pastie.org/630014
> jiak.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>')
>
> If the script is accessing the database directly (port 8098) why would it
> require the webmachine application to run for it to work?

Hi, Dan.  The difference in behavior has to do with some
initialization that the stickynotes webmachine app does when it starts
up.  Take a look at the function setup_buckets near the bottom of
stickynotes_sup.erl.  The calls:

    C:set_bucket(<<"notes">>, [{bucket_mod, notes},{allow_mult, true}]),
    C:set_bucket(<<"groups">>, [{bucket_mod, groups},{allow_mult, true}]);

set up the schema for the notes and groups bucket (in this case, the
schemas are defined by the erlang modules 'notes' and 'groups').

Without a schema setting, riak's http interface doesn't know how to
check the validity of the objects being stored.  So, it's saying "503
[Schema] Unavailable".

The solution is to make a couple of calls to set_bucket_schema with
your JiakClient before doing anything else:

    # setup buckets
    JC.set_bucket_schema("groups", ["name"])
    JC.set_bucket_schema("notes", ["text","x","y","z","color"])

Unfortunately, the riak's http interface doesn't yet support setting
the 'bucket_mod' schema param, so while the two lines above will cause
your script not to raise exceptions, they won't engage the automatic
backlinking behavior you'd otherwise see.  (So your last print
statement will say "links: []" instead of "links: [['notes', ...,
'note']]".)

Luckily, because it's just one-time initialization stuff, the
webmachine app doesn't have to continue running while you execute your
python script.  Start stickynotes once, then shut it down, and as long
as you don't reset your riak cluster, the schema settings (full
bucket_mod-backlinking-enabled here) will stay active.  If you use
debug-restart.sh instead of debug-fresh.sh, you won't lose that bucket
schema setting across riak restarts.

-Bryan




More information about the riak-users mailing list