[erlang-questions] Replicating a distributed database

Håkan Mattsson hakan@REDACTED
Tue Dec 8 08:22:41 CET 2009


On Tue, Dec 8, 2009 at 12:09 AM, adam <aduston@REDACTED> wrote:
> It's interesting: I can't find an answer to this question anywhere. We
> have a table that has fragments evenly distributed between nodes A and
> B. We want to replicate these fragments to nodes C and D, which are on
> separate machines. I believe that the Mnesia API provides no way of
> accomplishing this without unseemly workarounds. Am I wrong?
>
> If I start an Mnesia cluster on nodes A, B, C, and D, then as soon as
> I create a fragmented table, Mnesia distributes the fragments evenly
> between nodes A, B, C, and D, so there's a lot of work required with
> add_table_copy to get the fragments in the right place. It appears
> that mnesia ignores the disc_only_copies option when creating a
> fragmented table, only paying attention to n_disc_only_copies in the
> frag_properties option, so I believe there's no nice way to order
> mnesia to put fragments on nodes A and B only.
>
> I can start an Mnesia cluster on nodes A and B, create the fragmented
> tables, then add nodes C and D and use add_table_copy. This appears to
> give correct results but is kind of an ugly solution.
>
> Am I missing some obvious way to accomplish this?

Yes, use the node_pool option. It defaults to all nodes in the schema, but you
can use it to control which nodes that initially will be used for the fragmented
table.

For example, this will create a table with 100 fragments distributed
over the nodes
a and b regardless of how many nodes that are known in the schema:

mnesia:create_table(f, [{frag_properties, [{n_fragments, 100},
{n_disc_copies, 2},

{node_pool, [a@REDACTED, b@REDACTED]}]}]).

Take a look at the Mnesia info before and after the call below.

/Håkan
---
Håkan Mattsson (0705-199 251)

(a@REDACTED)10> mnesia:info().
---> Processes holding locks <---
---> Processes waiting for locks <---
---> Participant transactions <---
---> Coordinator transactions <---
---> Uncertain transactions <---
---> Active tables <---
schema         : with 1        records occupying 432      words of mem
===> System info in version "4.4.12", debug level = none <===
opt_disc. Directory "/home/hakan/Mnesia.a@REDACTED" is used.
use fallback at restart = false
running db nodes   = [d@REDACTED,b@REDACTED,c@REDACTED,a@REDACTED]
stopped db nodes   = []
master node tables = []
remote             = []
ram_copies         = []
disc_copies        = [schema]
disc_only_copies   = []
[{a@REDACTED,disc_copies},
 {b@REDACTED,disc_copies},
 {c@REDACTED,disc_copies},
 {d@REDACTED,disc_copies}] = [schema]
2 transactions committed, 0 aborted, 0 restarted, 0 logged to disc
0 held locks, 0 in queue; 0 local transactions, 0 remote
0 transactions waits for other nodes: []
ok
(a@REDACTED)12> mnesia:create_table(f, [{frag_properties, [{n_fragments,
100}, {n_disc_copies, 2}, {node_pool, [a@REDACTED, b@REDACTED]}]}]).
{atomic,ok}
(a@REDACTED)13> mnesia:info(). ---> Processes holding locks <---
---> Processes waiting for locks <---
---> Participant transactions <---
---> Coordinator transactions <---
---> Uncertain transactions <---
---> Active tables <---
f              : with 0        records occupying 316      words of mem
f_frag2        : with 0        records occupying 316      words of mem
f_frag3        : with 0        records occupying 316      words of mem
f_frag4        : with 0        records occupying 316      words of mem
f_frag5        : with 0        records occupying 316      words of mem
f_frag6        : with 0        records occupying 316      words of mem
f_frag7        : with 0        records occupying 316      words of mem
f_frag8        : with 0        records occupying 316      words of mem
f_frag9        : with 0        records occupying 316      words of mem
f_frag10       : with 0        records occupying 316      words of mem
f_frag11       : with 0        records occupying 316      words of mem
f_frag12       : with 0        records occupying 316      words of mem
f_frag13       : with 0        records occupying 316      words of mem
f_frag14       : with 0        records occupying 316      words of mem
f_frag15       : with 0        records occupying 316      words of mem
f_frag16       : with 0        records occupying 316      words of mem
f_frag17       : with 0        records occupying 316      words of mem
f_frag18       : with 0        records occupying 316      words of mem
f_frag19       : with 0        records occupying 316      words of mem
f_frag20       : with 0        records occupying 316      words of mem
f_frag21       : with 0        records occupying 316      words of mem
f_frag22       : with 0        records occupying 316      words of mem
f_frag23       : with 0        records occupying 316      words of mem
f_frag24       : with 0        records occupying 316      words of mem
f_frag25       : with 0        records occupying 316      words of mem
f_frag26       : with 0        records occupying 316      words of mem
f_frag27       : with 0        records occupying 316      words of mem
f_frag28       : with 0        records occupying 316      words of mem
f_frag29       : with 0        records occupying 316      words of mem
f_frag30       : with 0        records occupying 316      words of mem
f_frag31       : with 0        records occupying 316      words of mem
f_frag32       : with 0        records occupying 316      words of mem
f_frag33       : with 0        records occupying 316      words of mem
f_frag34       : with 0        records occupying 316      words of mem
f_frag35       : with 0        records occupying 316      words of mem
f_frag36       : with 0        records occupying 316      words of mem
f_frag37       : with 0        records occupying 316      words of mem
f_frag38       : with 0        records occupying 316      words of mem
f_frag39       : with 0        records occupying 316      words of mem
f_frag40       : with 0        records occupying 316      words of mem
f_frag41       : with 0        records occupying 316      words of mem
f_frag42       : with 0        records occupying 316      words of mem
f_frag43       : with 0        records occupying 316      words of mem
f_frag44       : with 0        records occupying 316      words of mem
f_frag45       : with 0        records occupying 316      words of mem
f_frag46       : with 0        records occupying 316      words of mem
f_frag47       : with 0        records occupying 316      words of mem
f_frag48       : with 0        records occupying 316      words of mem
f_frag49       : with 0        records occupying 316      words of mem
f_frag50       : with 0        records occupying 316      words of mem
f_frag51       : with 0        records occupying 316      words of mem
f_frag52       : with 0        records occupying 316      words of mem
f_frag53       : with 0        records occupying 316      words of mem
f_frag54       : with 0        records occupying 316      words of mem
f_frag55       : with 0        records occupying 316      words of mem
f_frag56       : with 0        records occupying 316      words of mem
f_frag57       : with 0        records occupying 316      words of mem
f_frag58       : with 0        records occupying 316      words of mem
f_frag59       : with 0        records occupying 316      words of mem
f_frag60       : with 0        records occupying 316      words of mem
f_frag61       : with 0        records occupying 316      words of mem
f_frag62       : with 0        records occupying 316      words of mem
f_frag63       : with 0        records occupying 316      words of mem
f_frag64       : with 0        records occupying 316      words of mem
f_frag65       : with 0        records occupying 316      words of mem
f_frag66       : with 0        records occupying 316      words of mem
f_frag67       : with 0        records occupying 316      words of mem
f_frag68       : with 0        records occupying 316      words of mem
f_frag69       : with 0        records occupying 316      words of mem
f_frag70       : with 0        records occupying 316      words of mem
f_frag71       : with 0        records occupying 316      words of mem
f_frag72       : with 0        records occupying 316      words of mem
f_frag73       : with 0        records occupying 316      words of mem
f_frag74       : with 0        records occupying 316      words of mem
f_frag75       : with 0        records occupying 316      words of mem
f_frag76       : with 0        records occupying 316      words of mem
f_frag77       : with 0        records occupying 316      words of mem
f_frag78       : with 0        records occupying 316      words of mem
f_frag79       : with 0        records occupying 316      words of mem
f_frag80       : with 0        records occupying 316      words of mem
f_frag81       : with 0        records occupying 316      words of mem
f_frag82       : with 0        records occupying 316      words of mem
f_frag83       : with 0        records occupying 316      words of mem
f_frag84       : with 0        records occupying 316      words of mem
f_frag85       : with 0        records occupying 316      words of mem
f_frag86       : with 0        records occupying 316      words of mem
f_frag87       : with 0        records occupying 316      words of mem
f_frag88       : with 0        records occupying 316      words of mem
f_frag89       : with 0        records occupying 316      words of mem
f_frag90       : with 0        records occupying 316      words of mem
f_frag91       : with 0        records occupying 316      words of mem
f_frag92       : with 0        records occupying 316      words of mem
f_frag93       : with 0        records occupying 316      words of mem
f_frag94       : with 0        records occupying 316      words of mem
f_frag95       : with 0        records occupying 316      words of mem
f_frag96       : with 0        records occupying 316      words of mem
f_frag97       : with 0        records occupying 316      words of mem
f_frag98       : with 0        records occupying 316      words of mem
f_frag99       : with 0        records occupying 316      words of mem
f_frag100      : with 0        records occupying 316      words of mem
schema         : with 101      records occupying 12167    words of mem
===> System info in version "4.4.12", debug level = none <===
opt_disc. Directory "/home/hakan/Mnesia.a@REDACTED" is used.
use fallback at restart = false
running db nodes   = [d@REDACTED,b@REDACTED,c@REDACTED,a@REDACTED]
stopped db nodes   = []
master node tables = []
remote             = []
ram_copies         = []
disc_copies        = [f,f_frag10,f_frag100,f_frag11,f_frag12,f_frag13,
                      f_frag14,f_frag15,f_frag16,f_frag17,f_frag18,f_frag19,
                      f_frag2,f_frag20,f_frag21,f_frag22,f_frag23,f_frag24,
                      f_frag25,f_frag26,f_frag27,f_frag28,f_frag29,f_frag3,
                      f_frag30,f_frag31,f_frag32,f_frag33,f_frag34,f_frag35,
                      f_frag36,f_frag37,f_frag38,f_frag39,f_frag4,f_frag40,
                      f_frag41,f_frag42,f_frag43,f_frag44,f_frag45,f_frag46,
                      f_frag47,f_frag48,f_frag49,f_frag5,f_frag50,f_frag51,
                      f_frag52,f_frag53,f_frag54,f_frag55,f_frag56,f_frag57,
                      f_frag58,f_frag59,f_frag6,f_frag60,f_frag61,f_frag62,
                      f_frag63,f_frag64,f_frag65,f_frag66,f_frag67,f_frag68,
                      f_frag69,f_frag7,f_frag70,f_frag71,f_frag72,f_frag73,
                      f_frag74,f_frag75,f_frag76,f_frag77,f_frag78,f_frag79,
                      f_frag8,f_frag80,f_frag81,f_frag82,f_frag83,f_frag84,
                      f_frag85,f_frag86,f_frag87,f_frag88,f_frag89,f_frag9,
                      f_frag90,f_frag91,f_frag92,f_frag93,f_frag94,f_frag95,
                      f_frag96,f_frag97,f_frag98,f_frag99,schema]
disc_only_copies   = []
[{a@REDACTED,disc_copies},{b@REDACTED,disc_copies}] = [f_frag100,f_frag99,f_frag98,
                                                 f_frag97,f_frag96,f_frag95,
                                                 f_frag94,f_frag93,f_frag92,
                                                 f_frag91,f_frag90,f_frag89,
                                                 f_frag88,f_frag87,f_frag86,
                                                 f_frag85,f_frag84,f_frag83,
                                                 f_frag82,f_frag81,f_frag80,
                                                 f_frag79,f_frag78,f_frag77,
                                                 f_frag76,f_frag75,f_frag74,
                                                 f_frag73,f_frag72,f_frag71,
                                                 f_frag70,f_frag69,f_frag68,
                                                 f_frag67,f_frag66,f_frag65,
                                                 f_frag64,f_frag63,f_frag62,
                                                 f_frag61,f_frag60,f_frag59,
                                                 f_frag58,f_frag57,f_frag56,
                                                 f_frag55,f_frag54,f_frag53,
                                                 f_frag52,f_frag51,f_frag50,
                                                 f_frag49,f_frag48,f_frag47,
                                                 f_frag46,f_frag45,f_frag44,
                                                 f_frag43,f_frag42,f_frag41,
                                                 f_frag40,f_frag39,f_frag38,
                                                 f_frag37,f_frag36,f_frag35,
                                                 f_frag34,f_frag33,f_frag32,
                                                 f_frag31,f_frag30,f_frag29,
                                                 f_frag28,f_frag27,f_frag26,
                                                 f_frag25,f_frag24,f_frag23,
                                                 f_frag22,f_frag21,f_frag20,
                                                 f_frag19,f_frag18,f_frag17,
                                                 f_frag16,f_frag15,f_frag14,
                                                 f_frag13,f_frag12,f_frag11,
                                                 f_frag10,f_frag9,f_frag8,
                                                 f_frag7,f_frag6,f_frag5,
                                                 f_frag4,f_frag3,f_frag2,f]
[{a@REDACTED,disc_copies},
 {b@REDACTED,disc_copies},
 {c@REDACTED,disc_copies},
 {d@REDACTED,disc_copies}] = [schema]
3 transactions committed, 1 aborted, 0 restarted, 1 logged to disc
0 held locks, 0 in queue; 0 local transactions, 0 remote
0 transactions waits for other nodes: []
ok
(a@REDACTED)14>


More information about the erlang-questions mailing list