From 7d46fc40f08857d38368886a269a0ba086aa5065 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Sat, 24 Apr 2010 13:11:25 +0100 Subject: change guids to fixed-size binaries This change was cherry-picked from the bug21673 branch and brings 'default' closer to that branch. --- include/rabbit.hrl | 2 +- src/rabbit_guid.erl | 12 +++++------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/include/rabbit.hrl b/include/rabbit.hrl index 552aec67..a4abc1ff 100644 --- a/include/rabbit.hrl +++ b/include/rabbit.hrl @@ -87,7 +87,7 @@ -type(file_path() :: string()). %% this is really an abstract type, but dialyzer does not support them --type(guid() :: any()). +-type(guid() :: binary()). -type(txn() :: guid()). -type(pkey() :: guid()). -type(r(Kind) :: diff --git a/src/rabbit_guid.erl b/src/rabbit_guid.erl index 2fa531a7..2d632d9d 100644 --- a/src/rabbit_guid.erl +++ b/src/rabbit_guid.erl @@ -78,7 +78,7 @@ update_disk_serial() -> end, Serial. -%% generate a guid that is monotonically increasing per process. +%% generate a GUID. %% %% The id is only unique within a single cluster and as long as the %% serial store hasn't been deleted. @@ -92,20 +92,18 @@ guid() -> %% A persisted serial number, in combination with self/0 (which %% includes the node name) uniquely identifies a process in space %% and time. We combine that with a process-local counter to give - %% us a GUID that is monotonically increasing per process. + %% us a GUID. G = case get(guid) of undefined -> {{gen_server:call(?SERVER, serial, infinity), self()}, 0}; {S, I} -> {S, I+1} end, put(guid, G), - G. + erlang:md5(term_to_binary(G)). -%% generate a readable string representation of a guid. Note that any -%% monotonicity of the guid is not preserved in the encoding. +%% generate a readable string representation of a GUID. string_guid(Prefix) -> - Prefix ++ "-" ++ base64:encode_to_string( - erlang:md5(term_to_binary(guid()))). + Prefix ++ "-" ++ base64:encode_to_string(guid()). binstring_guid(Prefix) -> list_to_binary(string_guid(Prefix)). -- cgit v1.2.1