From 99fb1bee74fdbb92d7eae837a0bcf643384badf1 Mon Sep 17 00:00:00 2001 From: Kresten Krab Thorup Date: Sun, 22 Apr 2012 23:36:42 +0200 Subject: [PATCH] When opening a level, enforce just enough merge When re-opening a Hanoi data store, we need to reestablish the invariant that there is always room to inject a data file at the top level. In a worst case scenario, every level has all of A, B, and C; and thus needs to merge A+B -> X fully in order to accommodate what the parent will inject. 2*BTREE_SIZE(Level) >= sizeof(A+B) --- src/hanoi.erl | 2 ++ src/hanoi_level.erl | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/hanoi.erl b/src/hanoi.erl index 5259b2a..70ab835 100644 --- a/src/hanoi.erl +++ b/src/hanoi.erl @@ -222,6 +222,8 @@ open_levels(Dir) -> undefined, lists:seq(MaxLevel, MinLevel, -1)), + ok = hanoi_level:incremental_merge(TopLevel, 2*?BTREE_SIZE(MaxLevel)), + {ok, TopLevel}. parse_level(FileName) -> diff --git a/src/hanoi_level.erl b/src/hanoi_level.erl index a563e40..b214555 100644 --- a/src/hanoi_level.erl +++ b/src/hanoi_level.erl @@ -59,7 +59,6 @@ open(Dir,Level,Next) when Level>0 -> process_flag(trap_exit,true), initialize(#state{dir=Dir,level=Level,next=Next}) end), - incremental_merge(PID, 2*?BTREE_SIZE(?TOP_LEVEL)), {ok, PID}. lookup(Ref, Key) ->