Erlang: how to spawn a node and link it to a mnesia table

55 views Asked by At

I have to implement tuple spaces using mnesia in a distibuted and cuncurrent environment. The interface provides these functions:

  • new(name): creates a new TS (a new mnesia table) named with name
  • in(TS, Pattern): returns a tuple matching the pattern in the TS and deletes it from the TS. It blocks if there is no tuple matching
  • rd(TS, Pattern)r: eturns a tuple matching the pattern in the TS, but the tuple remains in the TS. It blocks if there is no tuple matching
  • out(TS, Tuple): puts the tuple Tuple in the TS
  • in(TS, Pattern, Timeout): ss in(TS, Pattern) but returns after Timetout returns {ok,Tuple} or {err, timeout}
  • rd(TS, Pattern, Timeout): as rd(TS,Pattern) but return after Timout returns {ok,Tuple} or {err, timeout}
  • addNode(TS, Node): adds the Node to the TS, so Node can access to all the tuples of TS
  • removeNode(TS,Node): removes a node from the TS
  • nodes(TS): tells the nodes on which the TS is visible/replicated

I have no idea (at all) on how how to implement the addNode. Is it possible to use something like this?

register(node_name,spawn_link(fun()-> mnesia:add_table_copy(tab_name, node_name, disc_copies) end)
0

There are 0 answers