lets/doc/lets.md
Joseph Wayne Norton e3c129b105 Add support to use async thread pool for driver backend
Enhance driver implementation to optionally use Erlang's asynchronous
driver thread pool for all LevelDB operations with the intention to
avoid blocking of Erlang's scheduler threads.
2011-11-06 23:42:47 +09:00

18 KiB

#Module lets#

##Data Types##

###db_opts()##

db_opts() = {db, [{path, [file:filename()](file.md#type-filename)} | create_if_missing | {create_if_missing, boolean()} | error_if_exists | {error_if_exists, boolean()} | paranoid_checks | {paranoid_checks, boolean()} | {write_buffer_size, pos_integer()} | {max_open_files, pos_integer()} | {block_cache_size, pos_integer()} | {block_size, pos_integer()} | {block_restart_interval, pos_integer()}]}

###db_read_opts()##

db_read_opts() = {db_read, [verify_checksums | {verify_checksums, boolean()} | fill_cache | {fill_cache, boolean()}]}

###db_write_opts()##

db_write_opts() = {db_write, [sync | {sync, boolean()}]}

###ets_opt()##

ets_opt() = set | ordered_set | named_table | {key_pos, pos_integer()} | public | protected | private | compressed | async

###impl_opt()##

impl_opt() = drv | nif | ets

###key()##

key() = binary()

###object()##

object() = term()

###opts()##

opts() = [[ets_opt()](#type-ets_opt) | [impl_opt()](#type-impl_opt) | [db_opts()](#type-db_opts) | [db_read_opts()](#type-db_read_opts) | [db_write_opts()](#type-db_write_opts)]

###tab()##

abstract datatype: tab()

##Function Index##

delete/1

Deletes the entire table Tab.

.
delete/2

Deletes all objects with the key Key from the table Tab.

.
delete_all_objects/1

Delete all objects in the table Tab. The operation is guaranteed to be atomic and isolated. This function only applies to the ets implementation.

.
destroy/2

Destroy the contents of the specified table. This function only applies to driver and nif implementations.

.
first/1

Returns the first key Key in the table Tab. If the table is empty, $end_of_table will be returned.

.
info/2

Returns information about the table Tab as a list of {Item, Value} tuples.

Valid +Item+ options are:
  • owner

  • name

  • named_table only the ets implementation

  • type

  • keypos

  • protection

  • compressed

  • async only the drv implementation

  • memory only the ets implementation

  • size only the ets implementation

.
insert/2

Inserts the object or all of the objects in the list ObjectOrObjects into the table Tab.

.
insert_new/2

This function works exactly like insert/2, with the exception that instead of overwriting objects with the same key, it simply returns false. This function only applies to the ets implementation.

.
lookup/2

Returns a list of all objects with the key Key in the table Tab.

.
new/2

Creates a new table and returns a table identifier which can be used in subsequent operations. The table identifier can be sent to other processes so that a table can be shared between different processes within a node.

Valid LETS properties for +Options+ are:
  • set The table is a set table - one key, one object, no order among objects. This is the default table type.

  • ordered_set The table is an ordered_set table - one key, one object, ordered in Erlang term order, which is the order implied by the < and > operators.

  • named_table If this option is present, the name Name is associated with the table identifier. only the ets implementation

  • {key_pos,pos_integer()} Specfies which element in the stored tuples should be used as key. By default, it is the first element, i.e. Pos=1.

  • public Any process may read or write to the table.

  • protected The owner process can read and write to the table. Other processes can only read the table. This is the default setting for the access rights.

  • private Only the owner process can read or write to the table.

  • compressed If this option is present, the table data will be stored in a compressed format.

  • async If this option is present, the emulator's async thread pool will be used when accessing the table data. only the drv implementation

  • drv If this option is present, the table data will be stored with LevelDB backend via an Erlang Driver. This is the default setting for the table implementation.

  • nif If this option is present, the table data will be stored with LevelDB backend via an Erlang NIF.

  • ets If this option is present, the table data will be stored with ETS as the backend.

  • {db, [db_opts()]} LevelDB database options.

  • {db_read, [db_read_opts()]} LevelDB read options.

  • {db_write, [db_write_opts()]} LevelDB write options.

    Valid LevelDB database properties for +db_opts()+ are:
  • {path, file:filename()} Open the database with the specified path. The default is Name.

  • create_if_missing | {create_if_missing, boolean()} If true, the database will be created if it is missing. The default is false.

  • error_if_exists | {error_if_exists, boolean()} If true, an error is raised if the database already exists. The default is false.

  • paranoid_checks | {paranoid_checks, boolean()} If true, the implementation will do aggressive checking of the data it is processing and will stop early if it detects any errors. The default is false.

  • {write_buffer_size, pos_integer()} The default is 4MB.

  • {max_open_files, pos_integer()} The default is 1000.

  • {block_cache_size, pos_integer()} The default is 8MB.

  • {block_size, pos_integer()} The default is 4K.

  • {block_restart_interval, pos_integer()} The default is 16.

    Valid LevelDB read properties for +db_read_opts()+ are:
  • verify_checksums | {verify_checksums, boolean()} If true, all data read from underlying storage will be verified against corresponding checksums. The default is false.

  • fill_cache | {fill_cache, boolean()} If true, the data read should be cached in memory. The default is true.

    Valid LevelDB write properties for +db_write_opts()+ are:
  • sync | {sync, boolean()} If true, the write will be flushed from the operating system buffer cache before the write is considered complete. The default is false.

.
next/2

Returns the next key Key2, following the key Key1 in the table Tab. If there is no next key, $end_of_table is returned.

.
repair/2

If a table cannot be opened, you may attempt to call this method to resurrect as much of the contents of the table as possible. Some data may be lost, so be careful when calling this function on a table that contains important information. This function only applies to driver and nif implementations.

.
tab2list/1

Returns a list of all objects in the table Tab. The operation is not guaranteed to be atomic and isolated.

.

##Function Details##

###delete/1##

delete(Tab::[tab()](#type-tab)) -> true



Deletes the entire table Tab.

See also: ets:delete/1.

###delete/2##

delete(Tab::[tab()](#type-tab), Key::[key()](#type-key)) -> true



Deletes all objects with the key Key from the table Tab.

See also: ets:delete/2.

###delete_all_objects/1##

delete_all_objects(Tab::[tab()](#type-tab)) -> true



Delete all objects in the table Tab. The operation is guaranteed to be atomic and isolated. This function only applies to the ets implementation.

See also: ets:delete_all_objects/1.

###destroy/2##

destroy(Name::atom(), Options::[opts()](#type-opts)) -> true



Destroy the contents of the specified table. This function only applies to driver and nif implementations.

###first/1##

first(Tab::[tab()](#type-tab)) -> [key()](#type-key) | '$end_of_table'



Returns the first key Key in the table Tab. If the table is empty, $end_of_table will be returned.

See also: ets:first/1.

###info/2##

info(Tab::[tab()](#type-tab), Item::atom()) -> term()



Returns information about the table Tab as a list of {Item, Value} tuples.

Valid +Item+ options are:
  • owner

  • name

  • named_table only the ets implementation

  • type

  • keypos

  • protection

  • compressed

  • async only the drv implementation

  • memory only the ets implementation

  • size only the ets implementation

See also: ets:info/2.

###insert/2##

insert(Tab::[tab()](#type-tab), ObjectOrObjects::[object()](#type-object) | [[object()](#type-object)]) -> true



Inserts the object or all of the objects in the list ObjectOrObjects into the table Tab.

See also: ets:insert/2.

###insert_new/2##

insert_new(Tab::[tab()](#type-tab), ObjectOrObjects::[object()](#type-object) | [[object()](#type-object)]) -> true



This function works exactly like insert/2, with the exception that instead of overwriting objects with the same key, it simply returns false. This function only applies to the ets implementation.

See also: ets:insert_new/2.

###lookup/2##

lookup(Tab::[tab()](#type-tab), Key::[key()](#type-key)) -> [[object()](#type-object)]



Returns a list of all objects with the key Key in the table Tab.

See also: ets:lookup/2.

###new/2##

new(Name::atom(), Options::[opts()](#type-opts)) -> [tab()](#type-tab)



Creates a new table and returns a table identifier which can be used in subsequent operations. The table identifier can be sent to other processes so that a table can be shared between different processes within a node.

Valid LETS properties for +Options+ are:
  • set The table is a set table - one key, one object, no order among objects. This is the default table type.

  • ordered_set The table is an ordered_set table - one key, one object, ordered in Erlang term order, which is the order implied by the < and > operators.

  • named_table If this option is present, the name Name is associated with the table identifier. only the ets implementation

  • {key_pos,pos_integer()} Specfies which element in the stored tuples should be used as key. By default, it is the first element, i.e. Pos=1.

  • public Any process may read or write to the table.

  • protected The owner process can read and write to the table. Other processes can only read the table. This is the default setting for the access rights.

  • private Only the owner process can read or write to the table.

  • compressed If this option is present, the table data will be stored in a compressed format.

  • async If this option is present, the emulator's async thread pool will be used when accessing the table data. only the drv implementation

  • drv If this option is present, the table data will be stored with LevelDB backend via an Erlang Driver. This is the default setting for the table implementation.

  • nif If this option is present, the table data will be stored with LevelDB backend via an Erlang NIF.

  • ets If this option is present, the table data will be stored with ETS as the backend.

  • {db, [db_opts()]} LevelDB database options.

  • {db_read, [db_read_opts()]} LevelDB read options.

  • {db_write, [db_write_opts()]} LevelDB write options.

    Valid LevelDB database properties for +db_opts()+ are:
  • {path, file:filename()} Open the database with the specified path. The default is Name.

  • create_if_missing | {create_if_missing, boolean()} If true, the database will be created if it is missing. The default is false.

  • error_if_exists | {error_if_exists, boolean()} If true, an error is raised if the database already exists. The default is false.

  • paranoid_checks | {paranoid_checks, boolean()} If true, the implementation will do aggressive checking of the data it is processing and will stop early if it detects any errors. The default is false.

  • {write_buffer_size, pos_integer()} The default is 4MB.

  • {max_open_files, pos_integer()} The default is 1000.

  • {block_cache_size, pos_integer()} The default is 8MB.

  • {block_size, pos_integer()} The default is 4K.

  • {block_restart_interval, pos_integer()} The default is 16.

    Valid LevelDB read properties for +db_read_opts()+ are:
  • verify_checksums | {verify_checksums, boolean()} If true, all data read from underlying storage will be verified against corresponding checksums. The default is false.

  • fill_cache | {fill_cache, boolean()} If true, the data read should be cached in memory. The default is true.

    Valid LevelDB write properties for +db_write_opts()+ are:
  • sync | {sync, boolean()} If true, the write will be flushed from the operating system buffer cache before the write is considered complete. The default is false.

See also: ets:new/2.

###next/2##

next(Tab::[tab()](#type-tab), Key::[key()](#type-key)) -> [key()](#type-key) | '$end_of_table'



Returns the next key Key2, following the key Key1 in the table Tab. If there is no next key, $end_of_table is returned.

See also: ets:next/2.

###repair/2##

repair(Name::atom(), Options::[opts()](#type-opts)) -> true



If a table cannot be opened, you may attempt to call this method to resurrect as much of the contents of the table as possible. Some data may be lost, so be careful when calling this function on a table that contains important information. This function only applies to driver and nif implementations.

###tab2list/1##

tab2list(Tab::[tab()](#type-tab)) -> [[object()](#type-object)]



Returns a list of all objects in the table Tab. The operation is not guaranteed to be atomic and isolated.

See also: ets:tab2list/1.