Permalink
Browse files

implemented db.col.drop, started adopting insert1.js test

  • Loading branch information...
1 parent 30b4342 commit 2efd2d299acad3c955102f843e59ccef1f759abd @pavlobaron committed Apr 30, 2012
Showing with 26 additions and 13 deletions.
  1. +16 −8 src/riak_mongo_message.erl
  2. +7 −4 src/riak_mongo_protocol.erl
  3. +3 −1 test/test.sh
View
@@ -30,8 +30,9 @@
-include("riak_mongo_state.hrl").
-include_lib("bson/include/bson_binary.hrl").
--define(CMD,<<"$cmd">>).
--define(ADM,<<"admin">>).
+-define(CMD, <<"$cmd">>).
+-define(ADM, <<"admin">>).
+-define(DROP, <<"drop">>).
%%
%% loop over messages
@@ -65,9 +66,9 @@ process_messages(A1,A2) ->
process_message(#mongo_query{ db=DataBase, coll=?CMD,
selector=Selector}, State) ->
- {struct, [{Command,_}|Options]} = Selector,
+ {struct, [{Command, Collection}|Options]} = Selector,
- case db_command(DataBase, Command, Options, State) of
+ case db_command(DataBase, Command, Collection, Options, State) of
{ok, Reply, State2} ->
{reply, #mongo_reply{ documents=[ {struct, Reply} ]} , State2}
end
@@ -119,20 +120,27 @@ you(#worker_state{sock=Sock}) ->
{ok, {{A, B, C, D}, P}} = inet:peername(Sock), %IPv6???
io_lib:format("~p.~p.~p.~p:~p", [A, B, C, D, P]).
-db_command(?ADM, <<"whatsmyuri">>, _Options, State) ->
+db_command(?ADM, <<"whatsmyuri">>, _Collection, _Options, State) ->
{ok, [{you, {utf8, you(State)}}, {ok, 1}], State};
-db_command(?ADM, <<"replSetGetStatus">>, _Options, State) ->
+db_command(?ADM, <<"replSetGetStatus">>, _Collection, _Options, State) ->
_IsForShell = proplists:is_defined(forShell, _Options),
{ok, [{ok, false}], State};
-db_command(_DataBase, <<"getlasterror">>, _Options, State) ->
+db_command(_DataBase, <<"getlasterror">>, _Collection, _Options, State) ->
case State#worker_state.lastError of
[] ->
{ok, [{ok,true}], State#worker_state{lastError=[]}};
MSG ->
{ok, [{err, io:format("~p", MSG)}], State#worker_state{lastError=[]}}
end;
-db_command(DataBase, Command, _Options, State) ->
+db_command(DataBase, ?DROP, Collection, _Options, State) ->
+ NewState = riak_mongo_riak:delete(#mongo_delete{singleremove=false, selector={},
+ dbcoll=riak_mongo_protocol:join_dbcoll({DataBase, Collection})},
+ State),
+ {ok, [{ok,true}], NewState};
+
+db_command(DataBase, Command, Collection, _Options, State) ->
+ error_logger:info_msg("unhandled command: ~p, ~p:~p~n", [Command, DataBase, Collection]),
{ok, [{err, <<"unknown command: db=", DataBase, ", cmd=", Command/binary>>}, {ok, false}], State}.
@@ -22,7 +22,7 @@
-module(riak_mongo_protocol).
-export([decode_wire/1, decode_packet/1, encode_packet/1]).
--export([split_dbcoll/1]).
+-export([split_dbcoll/1, join_dbcoll/1]).
-include_lib ("bson/include/bson_binary.hrl").
-include_lib ("riak_mongo_protocol.hrl").
@@ -143,9 +143,12 @@ decode_packet(<< ?HDR(_,OP), _/binary >> = All) ->
split_dbcoll(Bin) ->
- {Pos, _Len} = binary:match (Bin, <<$.>>),
- <<DB :Pos /binary, $.:8, Coll /binary>> = Bin,
- {DB, Coll}.
+ {Pos, _Len} = binary:match (Bin, <<$.>>),
+ <<DB :Pos /binary, $.:8, Coll /binary>> = Bin,
+ {DB, Coll}.
+
+join_dbcoll({Db, Col}) ->
+ <<Db/binary, ":", Col/binary>>.
encode_packet(#mongo_reply{
request_id=RequestId,
View
@@ -3,12 +3,14 @@
if test -z $1
then
JS=""
+ DB="riak"
else
cd mongo
git update
JS=$1
+ DB=""
cd jstests
fi
echo "running script? $JS"
-mongo --verbose -port 32323 collection $JS
+mongo --verbose -port 32323 $DB $JS

0 comments on commit 2efd2d2

Please sign in to comment.