Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

gfsIndexes/0,1 for setting up the proper gfs collection indexes,bugfi…

…x for md5 command
  • Loading branch information...
commit 454c929a53fac15a0ed97ca85a3a889b13dc7195 1 parent 19cd670
@SergejJurecko authored
Showing with 24 additions and 6 deletions.
  1. +1 −1  erlmongo.hrl
  2. +7 −2 mongoapi.erl
  3. +16 −3 mongodb.erl
View
2  erlmongo.hrl
@@ -17,7 +17,7 @@
record_info(fields, gfs_file),
record_info(fields, gfs_chunk)}).
--record(gfs_state,{pool,proc, db, file, collection, length = 0, mode,
+-record(gfs_state,{pool,proc, db, file, collection, coll_name, length = 0, mode,
nchunk = 0, flush_limit = 1048576, closed = false}).
-export([rec2prop/2, prop2rec/4]).
View
9 mongoapi.erl
@@ -454,6 +454,11 @@ setProfilingLevel(L) when is_integer(L) ->
getProfilingLevel() ->
runCmd([{"profile", -1}]).
+gfsIndexes() ->
+ gfsIndexes(<<"fd">>).
+gfsIndexes(Collection) ->
+ ensureIndex(<<Collection/binary,".chunks">>,[{<<"files_id">>,1},{<<"n">>,1}]),
+ ensureIndex(<<Collection/binary,".files">>,[{<<"filename">>,1}]).
gfsNew(Filename) ->
gfsNew(<<"fd">>, Filename, []).
@@ -464,7 +469,7 @@ gfsNew([_|_] = Collection, Filename, Opts) ->
gfsNew(<<_/binary>> = Collection, Filename, Opts) ->
mongodb:startgfs(gfsopts(Opts,#gfs_state{pool = Pool,file = #gfs_file{filename = Filename, length = 0, chunkSize = 262144,
docid = {oid,mongodb:create_id()}, uploadDate = now()},
- collection = name(Collection), db = DB, mode = write})).
+ collection = name(Collection), coll_name = Collection, db = DB, mode = write})).
gfsopts([{meta, Rec}|T], S) ->
gfsopts(T, S#gfs_state{file = (S#gfs_state.file)#gfs_file{metadata = Rec}});
@@ -510,7 +515,7 @@ gfsOpen(Collection, R) ->
gfsOpen(Collection,DR)
end;
_ ->
- mongodb:startgfs(#gfs_state{pool = Pool,file = R, collection = name(Collection), db = DB, mode = read})
+ mongodb:startgfs(#gfs_state{pool = Pool,file = R, coll_name = Collection, collection = name(Collection), db = DB, mode = read})
end.
gfsRead(PID, N) ->
View
19 mongodb.erl
@@ -519,6 +519,7 @@ gfs_proc(#gfs_state{mode = write} = P, Buf) ->
<<FlushBin:FlSize/binary,Rem/binary>> = Buf,
gfs_proc(gfsflush(P, FlushBin, <<>>),Rem);
{close} ->
+ io:format("closing~n"),
gfsflush(P#gfs_state{closed = true}, Buf, <<>>);
{'EXIT',_,_} ->
self() ! {close},
@@ -618,7 +619,15 @@ gfsflush(P, Bin, Out) ->
exec_insert(P#gfs_state.pool,<<(P#gfs_state.collection)/binary, ".chunks">>, #insert{documents = Out}),
case P#gfs_state.closed of
true ->
- [{<<"md5">>, MD5}|_] = exec_cmd(P#gfs_state.pool,P#gfs_state.db, [{<<"filemd5">>, FileID},{<<"root">>, P#gfs_state.collection}]);
+ MD5Cmd = exec_cmd(P#gfs_state.pool,P#gfs_state.db, [{<<"filemd5">>, FileID},{<<"root">>, P#gfs_state.coll_name}]),
+ case proplists:get_value(<<"md5">>,MD5Cmd) of
+ undefined ->
+ io:format("Md5 cmd failed ~p", [MD5Cmd]),
+ MD5 = undefined,
+ ok;
+ MD5 ->
+ ok
+ end;
false ->
MD5 = undefined
end,
@@ -905,8 +914,10 @@ gen_prop_keyname([{[_|_] = KeyName, KeyVal}|T], Bin) ->
gen_prop_keyname([{list_to_binary(KeyName), KeyVal}|T], Bin);
gen_prop_keyname([{KeyName, KeyVal}|T], Bin) ->
case is_integer(KeyVal) of
- true ->
+ true when T == [] ->
Add = <<(list_to_binary(integer_to_list(KeyVal)))/binary>>;
+ true ->
+ Add = <<(list_to_binary(integer_to_list(KeyVal)))/binary,"_">>;
false ->
Add = <<>>
end,
@@ -927,8 +938,10 @@ gen_keyname([{KeyIndex, KeyVal}|Keys], [Field|Fields], KeyIndex, Name) ->
true
end,
case is_integer(KeyVal) of
- true ->
+ true when Keys == [] ->
Add = <<(list_to_binary(integer_to_list(KeyVal)))/binary>>;
+ true ->
+ Add = <<(list_to_binary(integer_to_list(KeyVal)))/binary,"_">>;
false ->
Add = <<>>
end,
Please sign in to comment.
Something went wrong with that request. Please try again.