Issue #9 resolved

Insert after add_pool fails

created an issue

I have trouble starting the system trying the latest revision (changeset: 91:9fc3c1e25caf, Wed Jun 23 17:35:43 2010 +0400).

Doing an insert (or any command) after add_pool fails with error:

{{{ {{badmatch,undefined},[{emongo,sequence,2}... }}}

I did a quick look and it seems that emongo_pool state is still //active=false// when emongo_pool's// handle_call(?pid(RequestCount), _From, #pool{active=true}=State)// is called. This causes the pattern match to fail and branch



handle_call(_Request, _From, State) -> {reply, undefined, State}. }}}

to be called. This returns the undefined, I think.

It seems that the connection is not up yet when add_pool returns.






test(Database) -> application:start(emongo), emongo:add_pool(pool1, "localhost", 27017, Database, 1), ok = emongo:insert(pool1, "emongotest", [{test, "foo"}]), emongo:delete(pool1, "emongotest"). }}}

{{{ erlc -o ebin/ t/new_emongo.erl erl -pa ./ebin -eval "new_emongo:test(\"bugtest\")" -s init stop -noshell }}}

Comments (6)

  1. Dmitry Belyaev repo owner
    • changed status to open

    As I can see, setting initial value of #pool{..., active = true, ...} (in emongo_pool) is safe cause do_open_connections will make it false if no connection will be established.

    Thanks for the bug, I'll update the module tommorow.

  2. kisyad reporter

    Changing the initial value to true seems to help and my test cases pass.

    Insert and update api seems to have changed to return an integer value instead of 'ok'. Don't know if that's intentional or not. If it's intentional, could the return value be tagged. {ok, Integer} for example.

  3. Dmitry Belyaev repo owner

    In fact, both update and insert operations have no result at all. They are executed asynchronously and we only know that we have sent them. So, you shouldn't check it's result.

    Values that are returned from insert or update are now incremented ids of theirs requests. I gonna change this behavior if it's misleading.

  4. Dmitry Belyaev repo owner

    By the way, if you add more workers and make bigger insert you may get interesting effect: sometimes delete will happen before insert.

    test(Database) ->
            emongo:add_pool(pool1, "localhost", 27016, Database, 10),
            ok = emongo:insert(pool1, "emongotest", [[{i, I}] || I <- lists:seq(1, 100000)]),
            ok = emongo:delete(pool1, "emongotest"),
            Data = length(emongo:find_all(pool1, "emongotest")),
            io:format("Data: ~p~n", [Data]),

    If you want to be sure in what happens after what then you need sequences =)

    test2(Database) ->
            emongo:add_pool(pool1, "localhost", 27016, Database, 10),
            Data = emongo:sequence(pool1,
                    emongo:insert_seq("emongotest", [[{i, I}] || I <- lists:seq(1, 100000)],
                            emongo:delete_seq("emongotest", [],
                                    emongo:find_all_seq("emongotest", [], [])))),
            io:format("Data: ~p~n", [Data]),
  5. Log in to comment