[erlang-questions] Fragmented mnesia table: access to local fragment

Paul Mineiro paul-trapexit@REDACTED
Wed Jan 30 19:04:33 CET 2008


Sebastien,

I have done things of this flavor.  What I did was:

1. Find out the number of fragments from mnesia.

----------
num_fragments (Tablename) ->
  { value, { n_fragments, N } } =
    lists:keysearch (n_fragments,
                     1,
                     mnesia:table_info (Tablename, frag_properties)),
  N.
----------

2. Construct the fragment table names.

----------
frag_table_name (Tab, 1) ->
  Tab;
frag_table_name (Tab, N) ->
  list_to_atom (atom_to_list (Tab) ++ "_frag" ++ integer_to_list (N)).
----------

3. Find out if a fragment is local.

----------
is_local (TableName) ->
  lists:member (node (), mnesia:table_info (TableName, disc_copies)) orelse
  lists:member (node (), mnesia:table_info (TableName, disc_only_copies)) orelse
  lists:member (node (), mnesia:table_info (TableName, ram_copies)).
----------

You can put all this together in a list comprehension:

----------
local_fragments (TableName) ->
  [ F || N <- lists:seq (1, num_fragments (TableName)),
         F <- [ frag_table_name (TableName, N) ],
         is_local (F) ].
----------

Once you have the list of local fragments, do what you will on each of them,
but *without* using the mnesia_frag access context.

-- p

On Wed, 30 Jan 2008, [ISO-8859-1] sébastien BECUWE wrote:

> Hi,
>
> I would like to access only on local data. Is there a way to do that ?
> I have configured a fragmented table on  a cluster and each  node has
> two fragment.  I would  to create a process which check data integrity
> and for improving  performance  i will prefer to do it on each node and
> only on  local fragment.
>
> Can anyone help me ?
>
> Thanks,
>
> Sébastien BECUWE.
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>

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

  -- Robert Noyce



More information about the erlang-questions mailing list