diff options
| author | Matthew Sackman <matthew@lshift.net> | 2009-09-02 16:34:24 +0100 |
|---|---|---|
| committer | Matthew Sackman <matthew@lshift.net> | 2009-09-02 16:34:24 +0100 |
| commit | 198349ed4d2f06f98ba0bda1e05e183548b3e52b (patch) | |
| tree | d31d79ae37fd75962fc1ee980b277376b9313673 | |
| parent | f0daa43f6f09711186e3cd21ba6c74d6f2e2926f (diff) | |
| download | rabbitmq-server-git-198349ed4d2f06f98ba0bda1e05e183548b3e52b.tar.gz | |
factor out sublist and disjoint tests
| -rw-r--r-- | src/rabbit_disk_queue.erl | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/src/rabbit_disk_queue.erl b/src/rabbit_disk_queue.erl index a5c60250b5..ad7c8df13e 100644 --- a/src/rabbit_disk_queue.erl +++ b/src/rabbit_disk_queue.erl @@ -1811,7 +1811,7 @@ recover_crashed_compactions1(Files, TmpFile) -> %% back to before any of the files in the tmp file and copy %% them over again TmpPath = form_filename(TmpFile), - case lists:all(fun (MsgId) -> lists:member(MsgId, MsgIds) end, MsgIdsTmp) of + case is_sublist(MsgIdsTmp, MsgIds) of true -> %% we're in case 1, 2 or 3 above. Just delete the tmp file %% note this also catches the case when the tmp file %% is empty @@ -1843,9 +1843,7 @@ recover_crashed_compactions1(Files, TmpFile) -> lists:reverse(UncorruptedMessages1)), %% we should have that none of the messages in the prefix %% are in the tmp file - true = lists:all(fun (MsgId) -> - not (lists:member(MsgId, MsgIdsTmp)) - end, MsgIds1), + true = is_disjoint(MsgIds1, MsgIdsTmp), %% must open with read flag, otherwise will stomp over contents {ok, MainHdl} = open_file(NonTmpRelatedFile, ?WRITE_MODE ++ [read]), %% Wipe out any rubbish at the end of the file. Remember @@ -1867,14 +1865,18 @@ recover_crashed_compactions1(Files, TmpFile) -> {ok, _MainMessages, MsgIdsMain} = scan_file_for_valid_messages_msg_ids(NonTmpRelatedFile), %% check that everything in MsgIds1 is in MsgIdsMain - true = lists:all(fun (MsgId) -> lists:member(MsgId, MsgIdsMain) end, - MsgIds1), + true = is_sublist(MsgIds1, MsgIdsMain), %% check that everything in MsgIdsTmp is in MsgIdsMain - true = lists:all(fun (MsgId) -> lists:member(MsgId, MsgIdsMain) end, - MsgIdsTmp) + true = is_sublist(MsgIdsTmp, MsgIdsMain) end, ok. +is_sublist(SmallerList, BiggerList) -> + lists:all(fun (Item) -> lists:member(Item, BiggerList) end, SmallerList). + +is_disjoint(SmallerList, BiggerList) -> + lists:all(fun (Item) -> not lists:member(Item, BiggerList) end, SmallerList). + %% Takes the list in *ascending* order (i.e. eldest message %% first). This is the opposite of what scan_file_for_valid_messages %% produces. The list of msgs that is produced is youngest first. |
