Are ETS Bulk Operations Atomic?

In particular, :ets.tab2list

and :ets.file2tab

. Are these snapshot functions in table state or can other operations interleave read and write while these functions are running?

+3


source to share


1 answer


Based on the documentation here :

Functions that overlap within a table, such as select

and match

, give the same guarantee as safe_fixtable

.

Where

[...] The function safe_fixtable

can be used to ensure that a sequence of first / 1 and subsequent / 2 calls traverses the table without error and that every existing object in the table is visited exactly once, even if another (or the same) process simultaneously deletes or inserts objects into the table.

And specifically related to your question:

Nothing else is guaranteed; in particular, objects that are inserted or deleted during such a traversal may be visited once or not at all.




EDIT

ets:tab2list/1

calls ets:match_object/2

, which is an inline function (BIF) implemented in C. The implementation here uses BIF ets_select2

, which is the implementation for ets:select/2

.

ets:file2tab

ends the call load_table/3

it just uses ets:insert/2

.

The code ets:tab2file/3

in ets.erl

uses ets:select/3

to get the first chunk and then ets:select/1

to get the remaining chunks in the table.

+2


source







All Articles