2016-09-07 50 views
0

我有兩個在集羣中運行的erlang MNESIA節點。如何在mnesia碎片上分發記錄?

我已經通過以下屬性創建了表。

mnesia:create_table(vmq_offline_store,[ 
       {frag_properties,[ 
        {node_pool,[node()|nodes()]}, 
        {hash_module,verneDB_frag_hash}, 
        {n_fragments,8}, 
        {n_disc_only_copies,length([node()|nodes()])}] 
       }, 
       {index,[]},{type, bag}, 
       {attributes,record_info(fields,vmq_offline_store)}]). 

我可以看到在兩個erlang節點上創建的所有8個片段。

之後,我使用來自外部節點的RPC調用將50000條記錄插入表中。這些50000條記錄僅插入到vmq_offline_store中。沒有分發所有的片段。

vmq_offline_store: with 50000 records occupying 2096701142 bytes on disc 
vmq_offline_store_frag2: with 0  records occupying 5464  bytes on disc 
vmq_offline_store_frag3: with 0  records occupying 5464  bytes on disc 
vmq_offline_store_frag4: with 0  records occupying 5464  bytes on disc 
vmq_offline_store_frag5: with 0  records occupying 5464  bytes on disc 
vmq_offline_store_frag6: with 0  records occupying 5464  bytes on disc 
vmq_offline_store_frag7: with 0  records occupying 5464  bytes on disc 
vmq_offline_store_frag8: with 0  records occupying 5464  bytes on disc 

你能幫我解釋一下如何在碎片上分配記錄嗎?

回答

0

創建具有分段屬性的Mnesia表是不夠的。每個表操作都必須明確指定分段表的「訪問模塊」,mnesia_frag。這是通過調用函數mnesia:activity/4來完成的,而不是調用mnesia:transaction/1或使用髒操作。

例如,這樣的代碼:

​​

變爲:

Fun = fun() -> ... end, 
Result = mnesia:activity(transaction, Fun, [], mnesia_frag), 

(請注意,在mnesia:activity發出錯誤信號,而不是返回{aborted, Reason}的錯誤)

對於髒操作,代碼像這樣:

mnesia:dirty_write(MyRecord) 

變爲:

mnesia:activity(sync_dirty, mnesia, write, [MyRecord], mnesia_frag) 

或者:

mnesia:activity(sync_dirty, fun() -> mnesia:write(MyRecord) end, [], 
       mnesia_frag) 

即,從未使用mnesia:dirty_*功能;在髒活動中使用「裸」的。