noahshaw11 commented on a change in pull request #3766:
URL: https://github.com/apache/couchdb/pull/3766#discussion_r733182102



##########
File path: src/smoosh/src/smoosh_priority_queue.erl
##########
@@ -12,32 +12,70 @@
 
 -module(smoosh_priority_queue).
 
--export([new/0, last_updated/2, is_key/2, in/4, in/5, out/1, size/1, info/1]).
+-export([new/1]).
+
+-export([open/1, last_updated/2, is_key/2, in/4, in/5, out/1, size/1, info/1]).
+
+-export([flush/1]).
+
+-export([from_list/2, to_list/1]).
+
+-export([file_name/1, write_to_file/1]).
+
+-define(VSN, 1).
 
 -record(priority_queue, {
-    dict=dict:new(),
-    tree=gb_trees:empty()
+    name,
+    map,
+    tree
 }).
 
-new() ->
-    #priority_queue{}.
+new(Name) ->
+    #priority_queue{name=Name, map=maps:new(), tree=gb_trees:empty()}.
+
+open(#priority_queue{name=Name} = Q) ->
+    case do_open(file_name(Q)) of
+        {ok, Terms} ->
+            Tree = maps:fold(fun(Key, {TreeKey, Value}, TreeAcc) ->
+                gb_trees:enter(TreeKey, {Key, Value}, TreeAcc)
+            end, gb_trees:empty(), Terms),
+            Q1 = #priority_queue{name=Name, map=Terms, tree=Tree},
+            write_to_file(Q1),

Review comment:
       This is something I would like to discuss. The issue I am thinking about 
is the bloat of `.queue` files on the file system. 
[Here](https://github.com/apache/couchdb/pull/3766/files/3aa3b7f743ba8cbf460d431e6f2cfa8a0963b9ed#diff-e1a750216ea14302008b3dfa1bbdec43a968fcb06939d6b91b1404fd37273091R146)
 I am deleting the file even on successful reads. I could leave the file on a 
successful read, but if an error is found and returned from `do_open/1` then I 
would only `write_to_file/1` then. What do you think?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to