Namdak Tonpa 6 years ago
parent
commit
3e9e0a9091
3 changed files with 18 additions and 9 deletions
  1. 1 1
      mix.exs
  2. 1 1
      src/kvs.app.src
  3. 16 7
      src/stores/kvs_rocks.erl

+ 1 - 1
mix.exs

@@ -2,7 +2,7 @@ defmodule KVS.Mixfile do
   use Mix.Project
   use Mix.Project
 
 
   def project do
   def project do
-    [app: :kvs, version: "6.7.0", description: "Abstract Chain Database", package: package(), deps: deps()]
+    [app: :kvs, version: "6.7.1", description: "Abstract Chain Database", package: package(), deps: deps()]
   end
   end
 
 
   def application do
   def application do

+ 1 - 1
src/kvs.app.src

@@ -1,6 +1,6 @@
 {application, kvs,
 {application, kvs,
    [{description, "KVS Abstract Chain Database"},
    [{description, "KVS Abstract Chain Database"},
-    {vsn, "6.7.0"},
+    {vsn, "6.7.1"},
     {registered, []},
     {registered, []},
     {applications, [kernel,stdlib,rocksdb]},
     {applications, [kernel,stdlib,rocksdb]},
     {mod, { kvs, []}},
     {mod, { kvs, []}},

+ 16 - 7
src/stores/kvs_rocks.erl

@@ -20,34 +20,43 @@ initialize() -> [ kvs:initialize(kvs_rocks,Module) || Module <- kvs:modules() ].
 ref() -> application:get_env(kvs,rocks_ref,[]).
 ref() -> application:get_env(kvs,rocks_ref,[]).
 index(_,_,_) -> [].
 index(_,_,_) -> [].
 get(Tab, Key) ->
 get(Tab, Key) ->
-    Address = <<(list_to_binary(lists:concat(["/",io_lib:format("~p",[Tab]),"/"])))/binary,(term_to_binary(Key))/binary>>,
+    Address = <<(list_to_binary(lists:concat(["/",format(Tab),"/"])))/binary,(term_to_binary(Key))/binary>>,
+    io:format("KVS.GET.Address: ~s~n",[Address]),
     case rocksdb:get(ref(), Address, []) of
     case rocksdb:get(ref(), Address, []) of
          not_found -> {error,not_found};
          not_found -> {error,not_found};
          {ok,Bin} -> {ok,binary_to_term(Bin,[safe])} end.
          {ok,Bin} -> {ok,binary_to_term(Bin,[safe])} end.
 
 
 put(Records) when is_list(Records) -> lists:map(fun(Record) -> put(Record) end, Records);
 put(Records) when is_list(Records) -> lists:map(fun(Record) -> put(Record) end, Records);
-put(Record) -> rocksdb:put(ref(), <<(list_to_binary(lists:concat(["/",element(1,Record),"/"])))/binary,
-                                    (term_to_binary(element(2,Record)))/binary>>, term_to_binary(Record), [{sync,true}]).
+put(Record) -> 
+    Address = <<(list_to_binary(lists:concat(["/",format(element(1,Record)),"/"])))/binary,
+                         (term_to_binary(element(2,Record)))/binary>>,
+    io:format("KVS.PUT.Address: ~s~n",[Address]),
+    rocksdb:put(ref(), Address, term_to_binary(Record), [{sync,true}]).
+
+format(X) when is_list(X) -> X;
+format(X) when is_atom(X) -> X;
+format(X) -> io_lib:format("~p",[X]).
 
 
 delete(Feed, Id) ->
 delete(Feed, Id) ->
-    Key    = list_to_binary(lists:concat(["/",io_lib:format("~p",[Feed]),"/"])),
+    Key    = list_to_binary(lists:concat(["/",format(Feed),"/"])),
     A      = <<Key/binary,(term_to_binary(Id))/binary>>,
     A      = <<Key/binary,(term_to_binary(Id))/binary>>,
     rocksdb:delete(ref(), A, []).
     rocksdb:delete(ref(), A, []).
 
 
 count(_) -> 0.
 count(_) -> 0.
 all(R) -> {ok,I} = rocksdb:iterator(ref(), []),
 all(R) -> {ok,I} = rocksdb:iterator(ref(), []),
-           Key = list_to_binary(lists:concat(["/",io_lib:format("~p",[R])])),
+           Key = list_to_binary(lists:concat(["/",format(R)])),
            First = rocksdb:iterator_move(I, {seek,Key}),
            First = rocksdb:iterator_move(I, {seek,Key}),
            lists:reverse(next(I,Key,size(Key),First,[],[],-1,0)).
            lists:reverse(next(I,Key,size(Key),First,[],[],-1,0)).
 
 
 next(_,_,_,_,_,T,N,C) when C == N -> T;
 next(_,_,_,_,_,T,N,C) when C == N -> T;
 next(I,Key,S,{ok,A,X},_,T,N,C) -> next(I,Key,S,A,X,T,N,C);
 next(I,Key,S,{ok,A,X},_,T,N,C) -> next(I,Key,S,A,X,T,N,C);
 next(_,___,_,{error,_},_,T,_,_) -> T;
 next(_,___,_,{error,_},_,T,_,_) -> T;
-next(I,Key,S,A,X,T,N,C) ->
+next(I,Key,S,A,X,T,N,C) when size(A) > S ->
      case binary:part(A,0,S) of Key ->
      case binary:part(A,0,S) of Key ->
           next(I,Key,S,rocksdb:iterator_move(I, next), [],
           next(I,Key,S,rocksdb:iterator_move(I, next), [],
                        [binary_to_term(X,[safe])|T],N,C+1);
                        [binary_to_term(X,[safe])|T],N,C+1);
-                  _ -> T end.
+                  _ -> T end;
+next(_,_,_,_,_,T,_,_) -> T.
 
 
 seq(_,_) -> integer_to_list(os:system_time()).
 seq(_,_) -> integer_to_list(os:system_time()).
 create_table(_,_) -> [].
 create_table(_,_) -> [].