[erlang-bugs] mnesia-4.3.5 select continuation problem

Paul Mineiro <>
Sun Dec 9 05:33:04 CET 2007


mnesia:select/4 and mnesia:select/1 are failing with ordered set tables
and a tuple key pattern.  a little module demonstrating the effect is
attached, the output (on my machine) is:

-------
21> c (selectbug), selectbug:showbug ().
{a,'$1'} set: {atomic,'$end_of_table'}
{a,'$1'} ordered_set: {'EXIT',
                          {{badmatch,
                               {aborted,
                                   {badarg,
                                       [ram_copies,
                                        {bug,{a,b},{a,'$1'},1,<<>>,[],0,0},
                                        [{{'_',{a,'$1'},'_'},[],['$1']}]]}}},
                           [{selectbug,selector,2},
                            {selectbug,'-showbug/0-fun-0-',1},
                            {lists,foreach,2},
                            {erl_eval,do_apply,5},
                            {shell,exprs,6},
                            {shell,eval_loop,3}]}}
{a,'$1'} bag: {atomic,'$end_of_table'}
'$1' set: {atomic,'$end_of_table'}
'$1' ordered_set: {atomic,'$end_of_table'}
'$1' bag: {atomic,'$end_of_table'}
ok
-------

looking at things, it looks like ets:repair_continuation/2 is expecting
a list in the 3rd element of the first argument.  i put an io:format on
the { badrpc, Reason } clause of mnesia:do_dirty_rpc/5 to print out the
reason:

-------
{'EXIT',{function_clause,[{ets,repair_continuation,
                               [{bug,{a,b},{a,'$1'},1,<<>>,[],0,0},
                                [{{'_',{a,'$1'},'_'},[],['$1']}]]},
                          {mnesia_lib,db_select_cont,3},
                          {rpc,local_call,3},
                          {mnesia,do_dirty_rpc,5},
                          {mnesia,select_cont,3},
                          {mnesia_tm,apply_fun,3},
                          {mnesia_tm,execute_transaction,5},
                          {selectbug,selector,2}]}}
------

the 3rd element is a tuple here.

poking around i can see that the ets:select/3 call from
mnesia_lib:db_select_init/4 is actually returning a continuation whose 3rd
argument is not a list.  this is now a BIF so i feel a bit stuck at this
point.  since it's a BIF here's some extra info:

------
% erl -s erlang halt
Erlang (BEAM) emulator version 5.5.5 [source] [async-threads:0] [kernel-poll:false]

% dpkg -s erlang-otp
Package: erlang-otp
Status: install ok installed
Priority: optional
Section: languages
Installed-Size: 139084
Maintainer: None <>
Architecture: darwin-i386
Source: erlang-otp
Version: 11b-5-1
Depends: libncurses5-shlibs, unixodbc2-shlibs | unixodbc2-nox-shlibs, darwin (>= 8-1)
Description: General-purpose programming language
 Erlang is a general-purpose programming language and runtime environment.
 Erlang has built-in support for concurrency, distribution and fault
 tolerance. Erlang is used in several large telecommunication systems
 from Ericsson.  The most popular implementation of Erlang is available as
 open source from the open source erlang site.
 .
 Web site: http://www.erlang.org/
 .
 Maintainer: None <>
BuildDependsOnly: Undefined

% uname -a
Darwin paul-mineiros-computer.local 8.9.3 Darwin Kernel Version 8.9.3: Fri Apr 27 14:50:07 PDT 2007; root:xnu-792.19.5~2/RELEASE_I386 i386 i386

------

thanks,

-- p

Optimism is an essential ingredient of innovation. How else can the
individual favor change over security?

  -- Robert Noyce
-------------- next part --------------
-module (selectbug).
-export ([ showbug/0 ]).

showbug () ->
  mnesia:start (),
  lists:foreach 
    (fun ({ KeyPat, Type }) -> 
       io:format ("~p ~p: ~p~n", 
                  [ KeyPat, Type, catch selector (KeyPat, Type) ]) 
     end,
     [ { X, Y } || X <- [ { a, '$1' }, '$1' ],
                   Y <- [ set, ordered_set, bag ] ]).

selector (KeyPattern, Type) ->
  { atomic, ok } = mnesia:create_table (bug, [ { type, Type } ]),
  ok = mnesia:dirty_write ({ bug, { a, b }, c }),
  try
    { atomic, '$end_of_table' } =
      mnesia:transaction (
        fun () ->
          { _Objects, Cont } = mnesia:select (bug,
                                              [ { { '_', KeyPattern, '_' },
                                                  [],
                                                  [ '$1' ] } ],
                                              1,
                                              read),
          % This causes aborted transaction
          mnesia:select (Cont) 
        end)
  after
    mnesia:delete_table (bug)
  end.


More information about the erlang-bugs mailing list