diff options
author | Matthias Radestock <matthias@lshift.net> | 2010-04-24 13:11:25 +0100 |
---|---|---|
committer | Matthias Radestock <matthias@lshift.net> | 2010-04-24 13:11:25 +0100 |
commit | 7d46fc40f08857d38368886a269a0ba086aa5065 (patch) | |
tree | b6c5ce77441fcc8cdf469722ca537c9e9f6190ca | |
parent | b278252edfd4f5f0819fdaa33470187732776411 (diff) | |
download | rabbitmq-server-bug22647.tar.gz |
change guids to fixed-size binariesbug22647
This change was cherry-picked from the bug21673 branch and brings
'default' closer to that branch.
-rw-r--r-- | include/rabbit.hrl | 2 | ||||
-rw-r--r-- | 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)). |