ets docから、単一オブジェクトへのすべての更新は、アトミックかつ分離されていることが保証されます。これは、1 つのオブジェクトに対する更新操作が成功するか失敗するかのどちらかであり、何の影響もなく (原子性)、更新の中間結果が他のプロセスから見えない (分離) ことを意味します。
次のコードでは、2 つのテーブルを 1 つにラップしました
私の質問:
これはErlangの一般的なパターンですか?
挿入と更新の場合、それはアトミックで分離されていますか?
-module(example_store)。-export([init/0, insert/1, update/1]).
init() -> ets:new(store, [public, named_table, {read_concurrency, true}, {write_concurrency, true}]),
データ = ets:new(store_data, [public, named_table, {read_concurrency, true}, {write_concurrency, true}]),
Info = ets:new(store_info, [public,ordered_set, named_table, {read_concurrency, true}, {write_concurrency, true}]), ets:insert(store, {store, Data, Info}). %% insert data insert({Key, Value, Info}) -> {store, Data_tb, Info_tb} = ets:lookup(store, store), ets:insert(Data_tb, {Key, Value}), ets:insert(Info_tb, {Info, Key}), ok. %% update data update({Key, Value, Info, Info_old}) -> {store, Data_tb, Info_tb} = ets:lookup(store, store), ets:insert(Data_tb, {Key, Value}), ets:delete(Info_tb, {Info_old,Key}), ets:insert(Info_tb, {Info, Key}), ok.
@Derek
Brown の Update_1、ラップされたテーブルは保証できず、insert/1
分離update/1
することもできません。
Q3 : 絶縁することは可能ですか? (Gen_server を除く)