boss_db:find for Riak

323 views
Skip to first unread message

Jason Jackson

unread,
May 28, 2012, 4:55:47 AM5/28/12
to ChicagoBoss
Is find for Riak still having issues, or should find for this adapter
be working as expected now? I have verified that search is working as
expected on my Riak cluster, but boss_db:find always seems to return
an empty set. A short example seen here:

MODEL:

-module(greeting, [Id, GreetingText]).
-compile(export_all).


CONSOLE:

(examples@boss01)2> boss_db:find(greeting,
[]).
[{greeting,"greeting-HwKnJLSbw7garGqOkbe3KlgiuxB",
"Boss says Hello!"},
{greeting,"greeting-R8OlBuFM7eYuyiAYsLloDIJs8oX",
"Try again"}]
(examples@boss01)3> boss_db:find(greeting, [{greeting_text, 'equals',
"Try again"}]).
[]


From the docs, it seems that this should be working. Any thoughts on
what I'm missing?

Thanks!




Evan Miller

unread,
May 28, 2012, 10:56:34 AM5/28/12
to chica...@googlegroups.com
Hi Jason,

Alas I am still waiting for my knight in shining armor to find the bug
in the Riak adapter. It is hiding somewhere in these 269 lines of
code:

https://github.com/evanmiller/boss_db/blob/master/src/db_adapters/boss_db_adapter_riak.erl
--
Evan Miller
http://www.evanmiller.org/

Ruben

unread,
May 28, 2012, 3:49:08 PM5/28/12
to chica...@googlegroups.com
Hi Evan,

I did some modification a couple of months before.

I haven't time to re-checked attached file . 
It is name boss_db_adapter_rgo.erl  :
a) Move to boss_db_adapter_riak.erl
b) Change  "-module(boss_db_adapter_rgo)."  to  "-module(boss_db_adapter_riak)."

I only modify some lines in the code that are comented as % RGO

I hope it can help the group to use riak

Cheers,
-Rubén



El dilluns 28 de maig de 2012 16:56:34 UTC+2, Evan Miller va escriure:
boss_db_adapter_rgo.erl

Evan Miller

unread,
May 28, 2012, 6:24:56 PM5/28/12
to chica...@googlegroups.com
Thanks, Rubén. Looks like there are a few changes in there -- I went
ahead and pushed the one that looks likely to fix the search problem.

https://github.com/evanmiller/boss_db/commit/1718e9dba25b631c46cd6085089e314d50db0350

Anyone who has a Riak installation is encouraged to try it out and let
me know if it works.

Evan

RGG

unread,
May 28, 2012, 6:34:17 PM5/28/12
to chica...@googlegroups.com, chica...@googlegroups.com
Yes. Please check it .
I haven't used it during last month.

If it is working well I will make a proposal about using secondary indexes with riak adapter.

Cheers,
-Rubén





El 29/05/2012, a les 0:24, Evan Miller <emmi...@gmail.com> va escriure:

Jason Jackson

unread,
May 30, 2012, 2:26:13 AM5/30/12
to ChicagoBoss
Hey folks,

I tested this and I am seeing the same result. Spent some time
looking through the code trying to figure whats going on, but I'm not
really seeing it yet.

(examples@boss01)1> boss_db:find(greeting, []).
[{greeting,"greeting-HwKnJLSbw7garGqOkbe3KlgiuxB",
"Boss says Hello!"},
{greeting,"greeting-R8OlBuFM7eYuyiAYsLloDIJs8oX",
"Try again"}]
(examples@boss01)2>
(examples@boss01)2> boss_db:find(greeting, [{greeting_text, 'equals',
"Try again"}]).
[]
(examples@boss01)3>




On May 29, 5:34 am, RGG <muuch...@gmail.com> wrote:
> Yes. Please check it .
> I haven't used it during last month.
>
> If it is working well I will make a proposal about using secondary indexes with riak adapter.
>
> Cheers,
> -Rubén
>
> El 29/05/2012, a les 0:24, Evan Miller <emmil...@gmail.com> va escriure:
>
>
>
>
>
>
>
> > Thanks, Rubén. Looks like there are a few changes in there -- I went
> > ahead and pushed the one that looks likely to fix the search problem.
>
> >https://github.com/evanmiller/boss_db/commit/1718e9dba25b631c46cd6085...
>
> > Anyone who has a Riak installation is encouraged to try it out and let
> > me know if it works.
>
> > Evan
>
> > On Mon, May 28, 2012 at 2:49 PM, Ruben <muuch...@gmail.com> wrote:
> >> Hi Evan,
>
> >> I did some modification a couple of months before.
>
> >> I haven't time to re-checked attached file .
> >> It is name boss_db_adapter_rgo.erl  :
> >> a) Move to boss_db_adapter_riak.erl
> >> b) Change  "-module(boss_db_adapter_rgo)."  to
> >>  "-module(boss_db_adapter_riak)."
>
> >> I only modify some lines in the code that are comented as % RGO
>
> >> I hope it can help the group to use riak
>
> >> Cheers,
> >> -Rubén
>
> >> El dilluns 28 de maig de 2012 16:56:34 UTC+2, Evan Miller va escriure:
>
> >>> Hi Jason,
>
> >>> Alas I am still waiting for my knight in shining armor to find the bug
> >>> in the Riak adapter. It is hiding somewhere in these 269 lines of
> >>> code:
>
> >>>https://github.com/evanmiller/boss_db/blob/master/src/db_adapters/bos...
>
> >>> On Mon, May 28, 2012 at 3:55 AM, Jason Jackson <jasonjack...@gmail.com>

Ruben

unread,
May 30, 2012, 2:59:37 PM5/30/12
to chica...@googlegroups.com
Hi ,

Sorry , sorry ...

I forgot to say Evan about couple of lines that I modified. So Evan did not include this in the final code althought they were in the file a sent him last day.

boss_db_adapter_riak.erl

 should have this code 

save_record(Conn, Record) ->
    Type = element(1, Record),
    Bucket = list_to_binary(type_to_bucket_name(Type)),
    PropList = [{K, V} || {K, V} <- Record:attributes(), K =/= id],
    Key = case Record:id() of
        id ->
            % TODO: The next release of Riak will support server-side ID
            %       generating. Get rid of unique_id_62/0.
            unique_id_62();
        DefinedId when is_list(DefinedId) ->
            [_ | Tail] = string:tokens(DefinedId, "-"),
            string:join(Tail, "-")
    end,
    BinKey = list_to_binary(Key),
    BinVal = term_to_binary(PropList),
    ok = case riakc_pb_socket:get(Conn, Bucket, BinKey) of
        {ok, O} ->
            %%O2 = riakc_obj:update_value(O, BinVal), 
    O2 = riakc_obj:update_value(O, PropList), %RGO   <-----------------------------------------
            riakc_pb_socket:put(Conn, O2);
        {error, _} ->
            %%O = riakc_obj:new(Bucket, BinKey, BinVal),
   O = riakc_obj:new(Bucket, BinKey, PropList,<<"application/x-erlang-term">>), %RGO  <----------------------
            riakc_pb_socket:put(Conn, O)
    end,
    {ok, Record:set(id, lists:concat([Type, "-", Key]))}.


Look at %RGO comments.

Otherwise I did not remember to include that in riak should activate search only once. 

So you must do:
bin/search-cmd install greetings  ( THE 'S' is important . If you put in model <name> you should put <names>)

You should find a bucket called  "_rsid_greetings"

We could plan an automatic search activation from CB but at this point this is the solution

Cheers,
-Rubén




El dilluns 28 de maig de 2012 10:55:47 UTC+2, Jason Jackson va escriure:

Evan Miller

unread,
May 30, 2012, 3:27:10 PM5/30/12
to chica...@googlegroups.com

Ruben Gonzalez

unread,
May 31, 2012, 5:58:23 AM5/31/12
to chica...@googlegroups.com
For me is working well.

Is it working for you Jason?

Thanks Evan !

-RG

2012/5/30 Evan Miller <emmi...@gmail.com>

Hafthorr

unread,
May 31, 2012, 12:58:14 PM5/31/12
to chica...@googlegroups.com
Hi Everyone,

Interesting enough for me it does not :(

Worst thing is, that going Riak search documentation i did catch the application/x-erlang content type issue, but even with that fixed ... seems search is not working for me.

Riak 1.1.2
CB/boss_db directly from github.

(fderp@macpro)21> boss_db:find(greeting, []).                              
[{greeting,"greeting-HSaqaI1GByEoopumxh8upMkVMPk","b"},
 {greeting,"greeting-RFsdfYnUGMK2OKI5URhY3OjDRCQ","c"},
 {greeting,"greeting-WnWZlJKRWIleYKOZKnfsDNNQQZB","a"},
 {greeting,"greeting-nIGBTbVUBiIXnHGZCmsy5wKIfX","a b c d "}]
(fderp@macpro)22> boss_db:find(greeting, [{greeting_text, 'equals', "b"}]).
[]

i did double check the riak buckets and it seems that the search is indexing them

_rsid_greetings
&
greetings


Can anyone who got it working try do this from riak directory (with value that you have in)?

bin/search-cmd search greetings "greeting_text:a"

Cheers

ps. sorry for barging in, trying to learn erlang/riak/cb at the same time :)

RGG

unread,
May 31, 2012, 3:06:57 PM5/31/12
to chica...@googlegroups.com, chica...@googlegroups.com

Hi ,

Have you activated riak search in etc/app.config in riak cluster ?

https://github.com/basho/riak_search
{riak_search, [ {enabled, true}, ]},

Remember that previous insertions in riak have not been indexed and won't be listed.

Add new buckets after enabling search.

Cheers,
-R

El 31/05/2012, a les 18:58, Hafthorr <de...@fractal-dimension.com> va escriure:

Hafthorr

unread,
May 31, 2012, 3:16:31 PM5/31/12
to chica...@googlegroups.com
Hi Ruben,

   Yes search is active (confirmed on config files, and riak control).

Also hook is in place, and riak creates new keys in _rsid_greetings.

seems I'm missing something obvious :)

cheers
Denis

Evan Miller

unread,
May 31, 2012, 3:24:20 PM5/31/12
to chica...@googlegroups.com
Thanks, Ruben. I've updated the README with this info:

https://github.com/evanmiller/ChicagoBoss/blob/master/README_DATABASE#L70

Jason Jackson

unread,
Jun 1, 2012, 3:29:05 AM6/1/12
to ChicagoBoss
Also not working for me.. Guess Denis and I are in the same camp.
The greeting example this thread started with is still returning an
empty set for me, not sure what I might be missing...

Jason



On May 31, 2:24 pm, Evan Miller <emmil...@gmail.com> wrote:
> Thanks, Ruben. I've updated the README with this info:
>
> https://github.com/evanmiller/ChicagoBoss/blob/master/README_DATABASE...
> >> 2012/5/30 Evan Miller <emmil...@gmail.com>
>
> >>> Ok... try these on for size
>
> >>>https://github.com/evanmiller/boss_db/commit/7785715aac456c9239aa46d0...
>
> >>>https://github.com/evanmiller/ChicagoBoss/commit/975df5ec7a761bb72284...

Denis Nuja

unread,
Jun 1, 2012, 10:35:28 AM6/1/12
to chica...@googlegroups.com
From my research (with a limited knowledge about these systems), it
seems that riak is not indexing properly the erlang term thats being
inserted by CB.

I tried on the same riak cluster to insert a JSON, and search properly
indexed it and was able to search thru it.

--
Denis

Ben G.

unread,
Jun 1, 2012, 5:12:22 PM6/1/12
to chica...@googlegroups.com
That "feels" like something in the conversion to binary


Ruben Gonzalez

unread,
Jun 1, 2012, 5:46:19 PM6/1/12
to chica...@googlegroups.com
Hello ,

Maybe I loosing something.

I build this model greeting.erl:

-module (greeting,[Id,GreetingText]).

-compile (export_all).


I build a controller :


greeting ('GET',[])->

error_logger:info_msg ("TEST:"),

Grt=greeting:new("greeting-hello1",<<"Test">>),

Grt:save(),

Grt1=greeting:new("greeting-hello2",<<"Empty">>),

Grt1:save(),

Grt2=greeting:new("greeting-hello3",<<"Test">>),

Grt2:save(),

error_logger:info_msg ("saved"),

Query =[{greeting_text,'equals',"Test"}],

Rawterms=boss_db:find (greeting,Query),

error_logger:info_msg ("Found--->"),

T2=io_lib:format("Res = ~p",[Rawterms]),

error_logger:info_msg (lists:flatten(T2)),

{json,[]}.


I did cmd-search install and so on.

When I access to this controller I get this result in CB console:

=INFO REPORT==== 1-Jun-2012::23:41:32 ===

TEST:

=INFO REPORT==== 1-Jun-2012::23:41:32 ===

saved

=INFO REPORT==== 1-Jun-2012::23:41:32 ===

Found--->

=INFO REPORT==== 1-Jun-2012::23:41:32 ===

Res = [{greeting,"greeting-hello1",<<"Test">>},

       {greeting,"greeting-hello3",<<"Test">>}]

=INFO REPORT==== 1-Jun-2012::23:41:32 ===

GET /db/greeting [xperiences] 200 241ms

---------------------------------

I don't know if this is a right test  

Thanks for feedback.


Cheers,

-Rubén

Jason Jackson

unread,
Jun 9, 2012, 3:53:50 AM6/9/12
to ChicagoBoss
Hey folks,

Sorry for the late follow up, haven't had time to dig back in on this
for a bit..

So, I've stepped through all of the above and verified that search is
active, and have added data to new buckets after enabling search. All
of the wiring between CB and Riak seems fine, but search still isn't
working. Ruben's comment that it is working for him really has me
wondering what I'm missing, because I'm just not seeing it.

I put together a step by step of what I'm doing to see if anyone sees
my mistake or has any ideas:

http://pastie.org/4054996

This is just the simple greeting model that this thread started with.
Very much appreciate if anyone can point me in a direction...

Thanks!







On Jun 2, 6:46 am, Ruben Gonzalez <muuch...@gmail.com> wrote:
> Hello ,
>
> Maybe I loosing something.
>
> I build this model greeting.erl:
>
> -module (greeting,[Id,GreetingText]).
>
> -compile (export_all).
>
> I build a controller :
>
> *greeting ('GET',[])->*
>
> * error_logger:info_msg ("TEST:"), *
>
> * Grt=greeting:new("greeting-hello1",<<"Test">>),*
>
> * Grt:save(), *
>
> * Grt1=greeting:new("greeting-hello2",<<"Empty">>),*
>
> * Grt1:save(), *
>
> * Grt2=greeting:new("greeting-hello3",<<"Test">>),*
>
> * Grt2:save(), *
>
> * error_logger:info_msg ("saved"), *
>
> * Query =[{greeting_text,'equals',"Test"}], *
>
> * Rawterms=boss_db:find (greeting,Query),*
>
> * error_logger:info_msg ("Found--->"), *
>
> * T2=io_lib:format("Res = ~p",[Rawterms]),*
>
> * error_logger:info_msg (lists:flatten(T2)),*
>
> * {json,[]}.*
Reply all
Reply to author
Forward
0 new messages