diff options
author | Matthew Sackman <matthew@lshift.net> | 2009-08-19 11:24:54 +0100 |
---|---|---|
committer | Matthew Sackman <matthew@lshift.net> | 2009-08-19 11:24:54 +0100 |
commit | 7188bc964fd65a1eed3d46cdec65195df0371eb2 (patch) | |
tree | 4fd699aa191aae31ce9b7456a0e27f1f20035de9 /src | |
parent | e4862945d91dd5fead85a8db6a48c480a31746ac (diff) | |
download | rabbitmq-server-7188bc964fd65a1eed3d46cdec65195df0371eb2.tar.gz |
New branch for bug 21427
Diffstat (limited to 'src')
-rw-r--r-- | src/rabbit_guid.erl | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/src/rabbit_guid.erl b/src/rabbit_guid.erl index 2be00503..f669b9dc 100644 --- a/src/rabbit_guid.erl +++ b/src/rabbit_guid.erl @@ -42,6 +42,7 @@ terminate/2, code_change/3]). -define(SERVER, ?MODULE). +-define(SERIAL_FILENAME, "rabbit_guid"). -record(state, {serial}). @@ -59,17 +60,24 @@ %%---------------------------------------------------------------------------- start_link() -> - %% The persister can get heavily loaded, and we don't want that to - %% impact guid generation. We therefore keep the serial in a - %% separate process rather than calling rabbit_persister:serial/0 - %% directly in the functions below. gen_server:start_link({local, ?SERVER}, ?MODULE, - [rabbit_persister:serial()], []). + [update_disk_serial()], []). + +update_disk_serial() -> + Filename = filename:join(mnesia:system_info(directory), ?SERIAL_FILENAME), + Serial = case file:read_file(Filename) of + {ok, Content} -> + binary_to_term(Content); + {error, _} -> + rabbit_persister:serial() + end, + ok = file:write_file(Filename, term_to_binary(Serial + 1)), + Serial. %% generate a guid that is monotonically increasing per process. %% %% The id is only unique within a single cluster and as long as the -%% persistent message store hasn't been deleted. +%% serial store hasn't been deleted. guid() -> %% We don't use erlang:now() here because a) it may return %% duplicates when the system clock has been rewound prior to a @@ -77,7 +85,7 @@ guid() -> %% now() to move ahead of the system time), and b) it is really %% slow since it takes a global lock and makes a system call. %% - %% rabbit_persister:serial/0, in combination with self/0 (which + %% 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. |