You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by da...@apache.org on 2008/04/20 20:17:23 UTC

svn commit: r649948 - in /incubator/couchdb/trunk/src/couchdb: couch_db.erl couch_db.hrl couch_erl_driver.c couch_file.erl couch_httpd.erl couch_log.erl couch_query_servers.erl couch_rep.erl couch_server_sup.erl couch_util.erl couch_view.erl

Author: damien
Date: Sun Apr 20 11:17:15 2008
New Revision: 649948

URL: http://svn.apache.org/viewvc?rev=649948&view=rev
Log:
Added proper UUID generation and changed the details of how way debug logging is done to now use a more effcient macro instead of a function call.

Modified:
    incubator/couchdb/trunk/src/couchdb/couch_db.erl
    incubator/couchdb/trunk/src/couchdb/couch_db.hrl
    incubator/couchdb/trunk/src/couchdb/couch_erl_driver.c
    incubator/couchdb/trunk/src/couchdb/couch_file.erl
    incubator/couchdb/trunk/src/couchdb/couch_httpd.erl
    incubator/couchdb/trunk/src/couchdb/couch_log.erl
    incubator/couchdb/trunk/src/couchdb/couch_query_servers.erl
    incubator/couchdb/trunk/src/couchdb/couch_rep.erl
    incubator/couchdb/trunk/src/couchdb/couch_server_sup.erl
    incubator/couchdb/trunk/src/couchdb/couch_util.erl
    incubator/couchdb/trunk/src/couchdb/couch_view.erl

Modified: incubator/couchdb/trunk/src/couchdb/couch_db.erl
URL: http://svn.apache.org/viewvc/incubator/couchdb/trunk/src/couchdb/couch_db.erl?rev=649948&r1=649947&r2=649948&view=diff
==============================================================================
--- incubator/couchdb/trunk/src/couchdb/couch_db.erl (original)
+++ incubator/couchdb/trunk/src/couchdb/couch_db.erl Sun Apr 20 11:17:15 2008
@@ -68,7 +68,7 @@
         % crashed during the file switch.
         case couch_file:open(Filepath ++ ".compact") of
         {ok, Fd0} ->
-            couch_log:info("Found ~s~s compaction file, using as primary storage.", [Filepath, ".compact"]),
+            ?LOG_INFO("Found ~s~s compaction file, using as primary storage.", [Filepath, ".compact"]),
             ok = file:rename(Filepath ++ ".compact", Filepath),
             Fd0;
         {error, enoent} ->
@@ -85,7 +85,7 @@
         % We successfully opened the db, delete old storage files if around
         case file:delete(Filepath ++ ".old") of
         ok ->
-            couch_log:info("Deleted old storage file ~s~s", [Filepath, ".old"]);
+            ?LOG_INFO("Deleted old storage file ~s~s", [Filepath, ".old"]);
         {error, enoent} ->
             ok  % normal result
         end;
@@ -461,7 +461,7 @@
     {ok, State}.
 
 handle_info(Msg, Db) ->
-    couch_log:error("Bad message received for db ~s: ~p", [Db#db.name, Msg]),
+    ?LOG_ERROR("Bad message received for db ~s: ~p", [Db#db.name, Msg]),
     exit({error, Msg}).
 
 
@@ -508,7 +508,7 @@
     compact ->
         case Db#db.compactor_pid of
         nil ->
-            couch_log:info("Starting compaction for db \"~s\"", [Name]),
+            ?LOG_INFO("Starting compaction for db \"~s\"", [Name]),
             Pid = spawn_link(couch_db, start_copy_compact_int, [Db, true]),
             Db2 = Db#db{compactor_pid=Pid},
             ok = gen_server:call(MainPid, {db_updated, Db2}),
@@ -523,7 +523,7 @@
                 init_db(Name, CompactFilepath, NewFd, NewHeader),
         case Db#db.update_seq == NewSeq of
         true ->
-            couch_log:debug("CouchDB swapping files ~s and ~s.", [Filepath, CompactFilepath]),
+            ?LOG_DEBUG("CouchDB swapping files ~s and ~s.", [Filepath, CompactFilepath]),
             ok = file:rename(Filepath, Filepath ++ ".old"),
             ok = file:rename(CompactFilepath, Filepath),
             
@@ -544,10 +544,10 @@
                 end),
                 
             ok = gen_server:call(MainPid, {db_updated, NewDb2}),
-            couch_log:info("Compaction for db ~p completed.", [Name]),
+            ?LOG_INFO("Compaction for db ~p completed.", [Name]),
             update_loop(NewDb2#db{compactor_pid=nil});
         false ->
-            couch_log:info("Compaction file still behind main file "
+            ?LOG_INFO("Compaction file still behind main file "
                 "(update seq=~p. compact update seq=~p). Retrying.",
                 [Db#db.update_seq, NewSeq]),
             Pid = spawn_link(couch_db, start_copy_compact_int, [Db, false]),
@@ -555,7 +555,7 @@
             update_loop(Db2)
         end;
     Else ->
-        couch_log:error("Unknown message received in db ~s:~p", [Db#db.name, Else]),
+        ?LOG_ERROR("Unknown message received in db ~s:~p", [Db#db.name, Else]),
         exit({error, Else})
     end.
 
@@ -701,7 +701,7 @@
                 _ ->
                     % BinFd must not equal our Fd. This can happen when a database
                     % is being updated during a compaction
-                    couch_log:debug("File where the attachments are written has changed. Possibly retrying."),
+                    ?LOG_DEBUG("File where the attachments are written has changed. Possibly retrying.", []),
                     throw(retry)
                 end,
                 {ok, NewSummaryPointer} = couch_stream:write_term(Db#db.summary_stream, {Doc#doc.body, Bins}),
@@ -876,6 +876,7 @@
     if Header == Header2 ->
         Db; % unchanged. nothing to do
     true ->
+        %ok = couch_file:sync(Fd),
         ok = couch_file:write_header(Fd, <<$g, $m, $k, 0>>, Header2),
         Db#db{header = Header2}
     end.
@@ -941,10 +942,10 @@
 
 start_copy_compact_int(#db{name=Name,filepath=Filepath}=Db, CopyLocal) ->
     CompactFile = Filepath ++ ".compact",
-    couch_log:debug("Compaction process spawned for db \"~s\"", [Name]),
+    ?LOG_DEBUG("Compaction process spawned for db \"~s\"", [Name]),
     case couch_file:open(CompactFile) of
     {ok, Fd} ->
-        couch_log:debug("Found existing compaction file for db \"~s\"", [Name]),
+        ?LOG_DEBUG("Found existing compaction file for db \"~s\"", [Name]),
         {ok, Header} = couch_file:read_header(Fd, <<$g, $m, $k, 0>>);
     {error, enoent} -> %
         {ok, Fd} = couch_file:open(CompactFile, [create]),

Modified: incubator/couchdb/trunk/src/couchdb/couch_db.hrl
URL: http://svn.apache.org/viewvc/incubator/couchdb/trunk/src/couchdb/couch_db.hrl?rev=649948&r1=649947&r2=649948&view=diff
==============================================================================
--- incubator/couchdb/trunk/src/couchdb/couch_db.hrl (original)
+++ incubator/couchdb/trunk/src/couchdb/couch_db.hrl Sun Apr 20 11:17:15 2008
@@ -15,6 +15,21 @@
 -define(DESIGN_DOC_PREFIX, "_design/").
 
 -define(DEFAULT_ATTACHMENT_CONTENT_TYPE, "application/octet-stream").
+        
+-define(LOG_DEBUG(Format, Args),
+    case couch_log:debug_on() of
+        true -> error_logger:info_report(couch_debug, {Format, Args});
+        false -> ok
+    end).
+
+-define(LOG_INFO(Format, Args),
+    case couch_log:info_on() of
+        true -> error_logger:info_report(couch_info, {Format, Args});
+        false -> ok
+    end).
+
+-define(LOG_ERROR(Format, Args),
+    error_logger:info_report(couch_error, {Format, Args})).
 
 -record(doc_info,
     {
@@ -53,4 +68,3 @@
     % couch_db:open_doc(Db, Id, Options).
     meta = []
     }).
-    

Modified: incubator/couchdb/trunk/src/couchdb/couch_erl_driver.c
URL: http://svn.apache.org/viewvc/incubator/couchdb/trunk/src/couchdb/couch_erl_driver.c?rev=649948&r1=649947&r2=649948&view=diff
==============================================================================
--- incubator/couchdb/trunk/src/couchdb/couch_erl_driver.c (original)
+++ incubator/couchdb/trunk/src/couchdb/couch_erl_driver.c Sun Apr 20 11:17:15 2008
@@ -23,6 +23,7 @@
 #ifndef WIN32
 #include <string.h> // for memcpy
 #endif
+#include <uuid/uuid.h>
 
 typedef struct {
     ErlDrvPort port;
@@ -92,51 +93,65 @@
 {
     #define COLLATE 0
     #define COLLATE_NO_CASE 1
+    #define UUID 2
 
     couch_drv_data* pData = (couch_drv_data*)drv_data;
+    switch(command) {
+    case UUID:
+        {
+        uuid_t uuid;
+        uuid_generate(uuid);
+        return return_control_result(&uuid, sizeof(uuid), rbuf, rlen);
+        }
+    
+    case COLLATE:
+    case COLLATE_NO_CASE:
+        {
+        UErrorCode status = U_ZERO_ERROR;
+        int collResult;
+        char response;
+        UCharIterator iterA;
+        UCharIterator iterB;
+        int32_t length;
+
+        // 2 strings are in the buffer, consecutively
+        // The strings begin first with a 32 bit integer byte length, then the actual
+        // string bytes follow.
+
+        // first 32bits are the length
+        memcpy(&length, pBuf, sizeof(length));
+        pBuf += sizeof(length);
+
+        // point the iterator at it.
+        uiter_setUTF8(&iterA, pBuf, length);
+
+        pBuf += length; // now on to string b
+
+        // first 32bits are the length
+        memcpy(&length, pBuf, sizeof(length));
+        pBuf += sizeof(length);
+
+        // point the iterator at it.
+        uiter_setUTF8(&iterB, pBuf, length);
+
+        if (command == COLLATE)
+          collResult = ucol_strcollIter(pData->coll, &iterA, &iterB, &status);
+        else if (command == COLLATE_NO_CASE)
+          collResult = ucol_strcollIter(pData->collNoCase, &iterA, &iterB, &status);
+
+        if (collResult < 0)
+          response = 0; //lt
+        else if (collResult > 0)
+          response = 1; //gt
+        else
+          response = 2; //eq
 
-    UErrorCode status = U_ZERO_ERROR;
-    int collResult;
-    char response;
-    UCharIterator iterA;
-    UCharIterator iterB;
-    int32_t length;
-
-    // 2 strings are in the buffer, consecutively
-    // The strings begin first with a 32 bit integer byte length, then the actual
-    // string bytes follow.
-
-    // first 32bits are the length
-    memcpy(&length, pBuf, sizeof(length));
-    pBuf += sizeof(length);
-
-    // point the iterator at it.
-    uiter_setUTF8(&iterA, pBuf, length);
-
-    pBuf += length; // now on to string b
-
-    // first 32bits are the length
-    memcpy(&length, pBuf, sizeof(length));
-    pBuf += sizeof(length);
-
-    // point the iterator at it.
-    uiter_setUTF8(&iterB, pBuf, length);
-
-    if (command == COLLATE)
-        collResult = ucol_strcollIter(pData->coll, &iterA, &iterB, &status);
-    else if (command == COLLATE_NO_CASE)
-        collResult = ucol_strcollIter(pData->collNoCase, &iterA, &iterB, &status);
-    else
+        return return_control_result(&response, sizeof(response), rbuf, rlen);
+        }
+      
+    default:
         return -1;
-
-    if (collResult < 0)
-        response = 0; //lt
-    else if (collResult > 0)
-        response = 1; //gt
-    else
-        response = 2; //eq
-
-    return return_control_result(&response, sizeof(response), rbuf, rlen);
+    }
 }
 
 ErlDrvEntry couch_driver_entry = {

Modified: incubator/couchdb/trunk/src/couchdb/couch_file.erl
URL: http://svn.apache.org/viewvc/incubator/couchdb/trunk/src/couchdb/couch_file.erl?rev=649948&r1=649947&r2=649948&view=diff
==============================================================================
--- incubator/couchdb/trunk/src/couchdb/couch_file.erl (original)
+++ incubator/couchdb/trunk/src/couchdb/couch_file.erl Sun Apr 20 11:17:15 2008
@@ -13,6 +13,8 @@
 -module(couch_file).
 -behaviour(gen_server).
 
+-include("couch_db.hrl").
+
 -define(HEADER_SIZE, 2048). % size of each segment of the doubly written header
 
 -export([open/1, open/2, close/1, pread/3, pwrite/3, expand/2, bytes/1, sync/1]).
@@ -178,12 +180,12 @@
             false ->
                 % To get here we must have two different header versions with signatures intact.
                 % It's weird but possible (a commit failure right at the 2k boundary). Log it and take the first.
-                couch_log:info("Header version differences.~nPrimary Header: ~p~nSecondary Header: ~p", [Header1, Header2]),
+                ?LOG_INFO("Header version differences.~nPrimary Header: ~p~nSecondary Header: ~p", [Header1, Header2]),
                 {ok, Header1}
             end;
         {error, Error} ->
             % error reading second header. It's ok, but log it.
-            couch_log:info("Secondary header corruption (error: ~p). Using primary header.", [Error]),
+            ?LOG_INFO("Secondary header corruption (error: ~p). Using primary header.", [Error]),
             {ok, Header1}
         end;
     {error, Error} ->
@@ -191,7 +193,7 @@
         case extract_header(Prefix, Bin2) of
         {ok, Header2} ->
             % log corrupt primary header. It's ok since the secondary is still good.
-            couch_log:info("Primary header corruption (error: ~p). Using secondary header.", [Error]),
+            ?LOG_INFO("Primary header corruption (error: ~p). Using secondary header.", [Error]),
             {ok, Header2};
         _ ->
             % error reading secondary header too

Modified: incubator/couchdb/trunk/src/couchdb/couch_httpd.erl
URL: http://svn.apache.org/viewvc/incubator/couchdb/trunk/src/couchdb/couch_httpd.erl?rev=649948&r1=649947&r2=649948&view=diff
==============================================================================
--- incubator/couchdb/trunk/src/couchdb/couch_httpd.erl (original)
+++ incubator/couchdb/trunk/src/couchdb/couch_httpd.erl Sun Apr 20 11:17:15 2008
@@ -57,11 +57,11 @@
     % removed, but URL quoting left intact
     {Path, _, _} = mochiweb_util:urlsplit_path(Req:get(raw_path)),
 
-    couch_log:debug("Version:     ~p", [Req:get(version)]),
-    couch_log:debug("Method:      ~p", [Method]),
-    couch_log:debug("Request URI: ~p", [Path]),
-    couch_log:debug("Headers: ~p", [mochiweb_headers:to_list(Req:get(headers))]),
-
+    ?LOG_DEBUG("Version:     ~p", [Req:get(version)]),
+    ?LOG_DEBUG("Method:      ~p", [Method]),
+    ?LOG_DEBUG("Request URI: ~p", [Path]),
+    ?LOG_DEBUG("Headers: ~p", [mochiweb_headers:to_list(Req:get(headers))]),
+    
     {ok, Resp} = case catch(handle_request(Req, DocumentRoot, Method, Path)) of
         {ok, Resp0} ->
             {ok, Resp0};
@@ -69,13 +69,19 @@
             send_error(Req, Error)
     end,
 
-    couch_log:info("~s - - ~p ~B", [
+    ?LOG_INFO("~s - - ~p ~B", [
         Req:get(peer),
         atom_to_list(Req:get(method)) ++ " " ++ Path,
         Resp:get(code)
     ]).
 
 handle_request(Req, DocumentRoot, Method, Path) ->
+    Start = erlang:now(),
+    X = handle_request0(Req, DocumentRoot, Method, Path),
+    io:format("now_diff:~p~n", [timer:now_diff(erlang:now(), Start)]),
+    X.
+    
+handle_request0(Req, DocumentRoot, Method, Path) ->
     case Path of
         "/" ->
             handle_welcome_request(Req, Method);
@@ -431,7 +437,7 @@
                 JsonDoc = couch_doc:to_json_obj(Doc, Options),
                 AdditionalHeaders =
                     case Doc#doc.meta of
-                    [] -> [{"Etag", Etag}]; % output etag when we have no meta
+                    [] -> [{"XEtag", Etag}]; % output etag when we have no meta
                     _ -> []
                     end,
                 send_json(Req, 200, AdditionalHeaders, JsonDoc);
@@ -498,7 +504,7 @@
     Doc = couch_doc:from_json_obj(Json),
 
     {ok, NewRev} = couch_db:update_doc(Db, Doc#doc{id=DocId, revs=Revs}, []),
-    send_json(Req, 201, [{"Etag", "\"" ++ NewRev ++ "\""}], {obj, [
+    send_json(Req, 201, [{"XEtag", "\"" ++ NewRev ++ "\""}], {obj, [
         {ok, true},
         {id, DocId},
         {rev, NewRev}
@@ -791,12 +797,12 @@
 send_error(Req, {method_not_allowed, Methods}) ->
     {ok, Req:respond({405, [{"Allow", Methods}], <<>>})};
 send_error(Req, {modified, Etag}) ->
-    {ok, Req:respond({412, [{"Etag", Etag}], <<>>})};
+    {ok, Req:respond({412, [{"XEtag", Etag}], <<>>})};
 send_error(Req, {not_modified, Etag}) ->
-    {ok, Req:respond({304, [{"Etag", Etag}], <<>>})};
+    {ok, Req:respond({304, [{"XEtag", Etag}], <<>>})};
 send_error(Req, Error) ->
     {Code, Json} = error_to_json(Error),
-    couch_log:info("HTTP Error (code ~w): ~p", [Code, Error]),
+    ?LOG_INFO("HTTP Error (code ~w): ~p", [Code, Error]),
     send_error(Req, Code, Json).
 
 send_error(Req, Code, Json) ->

Modified: incubator/couchdb/trunk/src/couchdb/couch_log.erl
URL: http://svn.apache.org/viewvc/incubator/couchdb/trunk/src/couchdb/couch_log.erl?rev=649948&r1=649947&r2=649948&view=diff
==============================================================================
--- incubator/couchdb/trunk/src/couchdb/couch_log.erl (original)
+++ incubator/couchdb/trunk/src/couchdb/couch_log.erl Sun Apr 20 11:17:15 2008
@@ -14,7 +14,7 @@
 -behaviour(gen_event).
 
 -export([start_link/2,stop/0]).
--export([error/1,error/2,info/1,info/2,debug/1,debug/2,get_level/0,get_level_integer/0, set_level/1]).
+-export([debug_on/0,info_on/0,get_level/0,get_level_integer/0, set_level/1]).
 -export([init/1, handle_event/2, terminate/2, code_change/3, handle_info/2, handle_call/2]).
 
 -define(LEVEL_ERROR, 3).
@@ -44,33 +44,11 @@
     {ok, Fd} = file:open(Filename, [append]),
     {ok, {Fd, level_integer(Level)}}.
 
-error(Msg) ->
-    error("~s", [Msg]).
+debug_on() ->
+    get_level_integer() =< ?LEVEL_DEBUG.
 
-error(Format, Args) ->
-    error_logger:error_report(couch_error, {Format, Args}).
-
-info(Msg) ->
-    info("~s", [Msg]).
-
-info(Format, Args) ->
-    case get_level_integer() =< ?LEVEL_INFO of
-    true ->
-        error_logger:info_report(couch_info, {Format, Args});
-    false ->
-        ok
-    end.
-
-debug(Msg) ->
-    debug("~s", [Msg]).
-
-debug(Format, Args) ->
-    case get_level_integer() =< ?LEVEL_DEBUG of
-    true ->
-        error_logger:info_report(couch_debug, {Format, Args});
-    false ->
-        ok
-    end.
+info_on() ->
+    get_level_integer() =< ?LEVEL_INFO.
 
 set_level(LevelAtom) ->
     set_level_integer(level_integer(LevelAtom)).

Modified: incubator/couchdb/trunk/src/couchdb/couch_query_servers.erl
URL: http://svn.apache.org/viewvc/incubator/couchdb/trunk/src/couchdb/couch_query_servers.erl?rev=649948&r1=649947&r2=649948&view=diff
==============================================================================
--- incubator/couchdb/trunk/src/couchdb/couch_query_servers.erl (original)
+++ incubator/couchdb/trunk/src/couchdb/couch_query_servers.erl Sun Apr 20 11:17:15 2008
@@ -53,7 +53,7 @@
     case cjson:decode(readline(Port)) of
     {obj, [{"log", Msg}]} when is_list(Msg) ->
         % we got a message to log. Log it and continue
-        couch_log:info("Query Server Log Message: ~s", [Msg]),
+        ?LOG_INFO("Query Server Log Message: ~s", [Msg]),
         read_json(Port);
     Else ->
         Else
@@ -75,7 +75,7 @@
         link(Port0),
         Port0;
     {empty, Cmd} ->
-        couch_log:info("Spawning new ~s instance.", [Lang]),
+        ?LOG_INFO("Spawning new ~s instance.", [Lang]),
         open_port({spawn, Cmd}, [stream,
                                     {line, 1000},
                                     exit_status,
@@ -170,11 +170,11 @@
     {value, {Lang, _}} ->
         case Status of
         0 -> ok;
-        _ -> couch_log:error("Abnormal shutdown of ~s query server process (exit_status: ~w).", [Lang, Status])
+        _ -> ?LOG_ERROR("Abnormal shutdown of ~s query server process (exit_status: ~w).", [Lang, Status])
         end,
         {noreply, {QueryServerList,  lists:keydelete(Port, 2, LangPorts)}};
     _ ->
-        couch_log:error("Unknown linked port/process crash: ~p", [Port])
+        ?LOG_ERROR("Unknown linked port/process crash: ~p", [Port])
     end;
 handle_info(_Whatever, {Cmd, Ports}) ->
     {noreply, {Cmd, Ports}}.

Modified: incubator/couchdb/trunk/src/couchdb/couch_rep.erl
URL: http://svn.apache.org/viewvc/incubator/couchdb/trunk/src/couchdb/couch_rep.erl?rev=649948&r1=649947&r2=649948&view=diff
==============================================================================
--- incubator/couchdb/trunk/src/couchdb/couch_rep.erl (original)
+++ incubator/couchdb/trunk/src/couchdb/couch_rep.erl Sun Apr 20 11:17:15 2008
@@ -151,9 +151,9 @@
     do_http_request(Url, Action, []).
 
 do_http_request(Url, Action, JsonBody) ->
-    couch_log:debug("couch_rep HTTP client request:"),
-    couch_log:debug("\tAction: ~p", [Action]),
-    couch_log:debug("\tUrl: ~p", [Url]),
+    ?LOG_DEBUG("couch_rep HTTP client request:", []),
+    ?LOG_DEBUG("\tAction: ~p", [Action]),
+    ?LOG_DEBUG("\tUrl: ~p", [Url]),
 
     % ensure that the inets application is running
     case application:start(inets) of

Modified: incubator/couchdb/trunk/src/couchdb/couch_server_sup.erl
URL: http://svn.apache.org/viewvc/incubator/couchdb/trunk/src/couchdb/couch_server_sup.erl?rev=649948&r1=649947&r2=649948&view=diff
==============================================================================
--- incubator/couchdb/trunk/src/couchdb/couch_server_sup.erl (original)
+++ incubator/couchdb/trunk/src/couchdb/couch_server_sup.erl Sun Apr 20 11:17:15 2008
@@ -17,6 +17,8 @@
 
 -export([start_link/1,stop/0]).
 
+-include("couch_db.hrl").
+
 %% supervisor callbacks
 -export([init/1]).
 
@@ -169,7 +171,7 @@
             UpdateNotifierExes,
             FtSearchQueryServer,
             [lists:flatten(io_lib:format("\t~s=~s~n", [Lang, QueryExe])) || {Lang, QueryExe} <- QueryServers]]),
-    couch_log:debug("~s", [ConfigInfo]),
+    ?LOG_DEBUG("~s", [ConfigInfo]),
 
     case StartResult of
     {ok,_} ->

Modified: incubator/couchdb/trunk/src/couchdb/couch_util.erl
URL: http://svn.apache.org/viewvc/incubator/couchdb/trunk/src/couchdb/couch_util.erl?rev=649948&r1=649947&r2=649948&view=diff
==============================================================================
--- incubator/couchdb/trunk/src/couchdb/couch_util.erl (original)
+++ incubator/couchdb/trunk/src/couchdb/couch_util.erl Sun Apr 20 11:17:15 2008
@@ -40,11 +40,25 @@
 
 
 new_uuid() ->
-    gen_server:call(couch_util, new_uuid).
+    to_hex(erlang:port_control(drv_port(), 2, <<>>)).
+
+to_hex([]) ->
+    [];
+to_hex([H|T]) ->
+    Digit1 = H div 16,
+    Digit2 = H rem 16,
+    [to_digit(Digit1), to_digit(Digit2) | to_hex(T)].
+
+to_digit(N) when N < 10 ->
+    $0 + N;
+to_digit(N) ->
+    $a + N-10.
+    
 
 % returns a random integer
 rand32() ->
-    gen_server:call(couch_util, rand32).
+    [A,B,C,D|_] = erlang:port_control(drv_port(), 2, <<>>),
+    (A bsl 24) + (B bsl 16) + (C bsl 8) + D.
 
 % given a pathname "../foo/bar/" it gives back the fully qualified
 % absolute pathname.
@@ -190,8 +204,6 @@
 terminate(_Reason, _Server) ->
     ok.
 
-handle_call(new_uuid, _From, Server) ->
-    {reply, new_uuid_int(), Server};
 handle_call(rand32, _From, Server) ->
     {reply, rand32_int(), Server}.
 
@@ -205,14 +217,6 @@
     {noreply, State}.
 
 
-new_uuid_int() ->
-    % eventually make this a C callout for a real guid (collisions are far less likely
-    % when using a proper generation function). For now we just fake it.
-    Num1 = random:uniform(16#FFFFFFFF + 1) - 1,
-    Num2 = random:uniform(16#FFFFFFFF + 1) - 1,
-    Num3 = random:uniform(16#FFFFFFFF + 1) - 1,
-    Num4 = random:uniform(16#FFFFFFFF + 1) - 1,
-    lists:flatten(io_lib:format("~8.16.0B~8.16.0B~8.16.0B~8.16.0B", [Num1, Num2, Num3, Num4])).
 
 
 

Modified: incubator/couchdb/trunk/src/couchdb/couch_view.erl
URL: http://svn.apache.org/viewvc/incubator/couchdb/trunk/src/couchdb/couch_view.erl?rev=649948&r1=649947&r2=649948&view=diff
==============================================================================
--- incubator/couchdb/trunk/src/couchdb/couch_view.erl (original)
+++ incubator/couchdb/trunk/src/couchdb/couch_view.erl Sun Apr 20 11:17:15 2008
@@ -141,7 +141,7 @@
         [{_, Fd, Count}] ->
             ok
         end,
-        couch_log:debug("Spawning new temp update process for db ~s.", [DbName]),
+        ?LOG_DEBUG("Spawning new temp update process for db ~s.", [DbName]),
         NewPid = spawn_link(couch_view, start_temp_update_loop, [DbName, Fd, Lang, Query]),
         true = ets:insert(couch_views_temp_fd_by_db, {DbName, Fd, Count + 1}),
         add_to_ets(NewPid, DbName, Name),
@@ -154,7 +154,7 @@
     Pid = 
     case ets:lookup(couch_views_by_name, {DbName, GroupId}) of
     [] ->
-        couch_log:debug("Spawning new update process for view group ~s in database ~s.", [GroupId, DbName]),
+        ?LOG_DEBUG("Spawning new update process for view group ~s in database ~s.", [GroupId, DbName]),
         NewPid = spawn_link(couch_view, start_update_loop, [Root, DbName, GroupId]),
         add_to_ets(NewPid, DbName, GroupId),
         NewPid;
@@ -168,7 +168,7 @@
     Names = ets:lookup(couch_views_by_db, DbName),
     lists:foreach(
         fun({_DbName, GroupId}) ->
-            couch_log:debug("Killing update process for view group ~s. in database ~s.", [GroupId, DbName]),
+            ?LOG_DEBUG("Killing update process for view group ~s. in database ~s.", [GroupId, DbName]),
             [{_, Pid}] = ets:lookup(couch_views_by_name, {DbName, GroupId}),
             exit(Pid, kill),
             receive {'EXIT', Pid, _} ->
@@ -184,7 +184,7 @@
 handle_info({'EXIT', FromPid, Reason}, #server{root_dir=RootDir}=Server) ->
     case ets:lookup(couch_views_by_updater, FromPid) of
     [] -> % non-updater linked process must have died, we propagate the error
-        couch_log:error("Exit on non-updater process: ~p", [Reason]),
+        ?LOG_ERROR("Exit on non-updater process: ~p", [Reason]),
         exit(Reason);
     [{_, {DbName, "_temp_" ++ _ = GroupId}}] ->
         delete_from_ets(FromPid, DbName, GroupId),
@@ -202,7 +202,7 @@
     end,
     {noreply, Server};
 handle_info(Msg, _Server) ->
-    couch_log:error("Bad message received for view module: ~p", [Msg]),
+    ?LOG_ERROR("Bad message received for view module: ~p", [Msg]),
     exit({error, Msg}).
     
 add_to_ets(Pid, DbName, GroupId) ->
@@ -294,7 +294,7 @@
     {Pid, get_updated} ->
         [Pid | get_notify_pids()];
     Else ->
-        couch_log:error("Unexpected message in view updater: ~p", [Else]),
+        ?LOG_ERROR("Unexpected message in view updater: ~p", [Else]),
         exit({error, Else})
     after Wait ->
         exit(wait_timeout)