krestenkrab/fractal_btree — Issue #5: Crash in fractal_btree_writer (function_clause)
Author: jlouis
Created: 2012-01-07 11:53:14+00:00
State: open

Our deletion test exposes a crash in `fractal_btree_writer`, the error is the following:

= ERROR REPORT==== 7-Jan-2012::12:40:55 ===
** Generic server fractal_btree_drv terminating
** Last message in was stop
** When Server state == {state,{dict,1,16,16,8,80,48,
{[],[],[],[],[],[],[],[],[],[],[],[],[],
[],[],[]},
{{[],[],[],[],
[["Btree_8"|<0.54.0>]],
[],[],[],[],[],[],[],[],[],[],[]}}}}
** Reason for termination ==
** {{function_clause,
[{fractal_btree_writer,handle_cast,
[{add,<<"b">>,deleted},
{state,
{file_descriptor,prim_file,{#Port<0.1324>,11}},
0,undefined,undefined,[],"Btree_8/nursery.data",<<>>}],
[{file,"src/fractal_btree_writer.erl"},{line,72}]},
{gen_server,handle_msg,5,[{file,"gen_server.erl"},{line,597}]},
{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,227}]}]},
{gen_server,call,[<0.54.0>,close]}}
** exception error: bad argument
in function dict:update/3
called as dict:update("Btree_8",#Fun,
{dict,0,16,16,8,80,48,
{[],[],[],[],[],[],[],[],[],[],[],[],[],
[],[],[]},
{{[],[],[],[],[],[],[],[],[],[],[],[],[],
[],[],[]}}})
in call from fractal_btree_tests:next_state/3 (test/fractal_btree_tests.erl, line 83)
in call from proper_statem:is_valid/4 (src/proper_statem.erl, line 768)
in call from proper_types:satisfies/2 (src/proper_types.erl, line 486)
in call from proper_types:'-satisfies_all/2-lc$^0/1-0-'/2 (src/proper_types.erl, line 495)
in call from proper_types:satisfies_all/2 (src/proper_types.erl, line 495)
in call from proper_shrink:'-shrink/3-fun-0-'/2 (src/proper_shrink.erl, line 70)
in call from proper_arith:partition_tr/7 (src/proper_arith.erl, line 164)

The reason for this crash is a tight function in `..._writer`: see https://github.com/krestenkrab/fractal_btree/blob/master/src/fractal_btree_writer.erl#L72 where we restrict to a binary only.

My guess is that when a key is promoted from the nursery as the atom `deleted` it then hits the writer and the writer doesn't know how to handle this kind of key. But I am not sure.