class Tkrzw::AsyncDBM

Asynchronous database manager adapter. This class is a wrapper of DBM for asynchronous operations. A task queue with a thread pool is used inside. Every method except for the constructor and the destructor is run by a thread in the thread pool and the result is set in the future oject of the return value. The caller can ignore the future object if it is not necessary. The Destruct method waits for all tasks to be done. Therefore, the destructor should be called before the database is closed.

Public Class Methods

new(dbm, num_worker_threads) click to toggle source

Sets up the task queue.

  • @param dbm A database object which has been opened.

  • @param num_worker_threads: The number of threads in the internal thread pool.

# File tkrzw.rb, line 884
def initialize(dbm, num_worker_threads)
  # (native code)
end

Public Instance Methods

append(key, value, delim="") click to toggle source

Appends data at the end of a record of a key.

  • @param key The key of the record.

  • @param value The value to append.

  • @param delim The delimiter to put after the existing record.

  • @return The future for the result status.

If there's no existing record, the value is set without the delimiter.

# File tkrzw.rb, line 957
def append(key, value, delim="")
  # (native code)
end
append_multi(delim="", **records) click to toggle source

Appends data to multiple records of the keyword arguments.

  • @param delim The delimiter to put after the existing record.

  • @param records Records to append.

  • @return The future for the result status.

# File tkrzw.rb, line 965
def append_multi(delim="", **records)
  # (native code)
end
clear() click to toggle source

Removes all records.

  • @return The future for the result status.

# File tkrzw.rb, line 1024
def clear()
  # (native code)
end
compare_exchange(key, expected, desired) click to toggle source

Compares the value of a record and exchanges if the condition meets.

  • @param key The key of the record.

  • @param expected The expected value. If it is nil, no existing record is expected. If it is DBM::ANY_DATA, an existing record with any value is expacted.

  • @param desired The desired value. If it is nil, the record is to be removed. If it is DBM::ANY_DATA, no update is done.

  • @return The future for the result status. If the condition doesn't meet, INFEASIBLE_ERROR is set.

# File tkrzw.rb, line 974
def compare_exchange(key, expected, desired)
  # (native code)
end
compare_exchange_multi(expected, desired) click to toggle source

Compares the values of records and exchanges if the condition meets.

  • @param expected An array of pairs of the record keys and their expected values. If the value is nil, no existing record is expected. If the value is DBM::ANY_DATA, an existing record with any value is expacted.

  • @param desired An array of pairs of the record keys and their desired values. If the value is nil, the record is to be removed.

  • @return The future for the result status. If the condition doesn't meet, INFEASIBLE_ERROR is set.

# File tkrzw.rb, line 992
def compare_exchange_multi(expected, desired)
  # (native code)
end
copy_file_data(dest_path, sync_hard=false) click to toggle source

Copies the content of the database file to another file.

  • @param dest_path A path to the destination file.

  • @param sync_hard True to do physical synchronization with the hardware.

  • @return The future for the result status.

# File tkrzw.rb, line 1049
def copy_file_data(dest_path, sync_hard=false)
  # (native code)
end
destruct() click to toggle source

Destructs the asynchronous database adapter. This method waits for all tasks to be done.

# File tkrzw.rb, line 902
def destruct()
  # (native code)
end
export(dest_dbm) click to toggle source

Exports all records to another database.

  • @param dest_dbm The destination database. The lefetime of the database object must last until the task finishes.

  • @return The future for the result status.

# File tkrzw.rb, line 1056
def export(dest_dbm)
  # (native code)
end
export_to_flat_records(dest_file) click to toggle source

Exports all records of a database to a flat record file.

  • @param dest_file The file object to write records in. The lefetime of the file object must last until the task finishes.

  • @return The future for the result status.

A flat record file contains a sequence of binary records without any high level structure so it is useful as a intermediate file for data migration.

# File tkrzw.rb, line 1064
def export_to_flat_records(dest_file)
  # (native code)
end
get(key) click to toggle source

Gets the value of a record of a key.

  • @param key The key of the record.

  • @return The future for the result status and the value of the matching record.

# File tkrzw.rb, line 909
def get(key)
  # (native code)
end
get_multi(*keys) click to toggle source

Gets the values of multiple records of keys.

  • @param keys The keys of records to retrieve.

  • @return The future for the result status and a map of retrieved records. Keys which don't match existing records are ignored.

# File tkrzw.rb, line 916
def get_multi(*keys)
  # (native code)
end
import_from_flat_records(src_file) click to toggle source

Imports records to a database from a flat record file.

  • @param src_file The file object to read records from. The lefetime of the file object must last until the task finishes.

  • @return The future for the result status.

# File tkrzw.rb, line 1071
def import_from_flat_records(src_file)
  # (native code)
end
increment(key, inc=1, init=0) click to toggle source

Increments the numeric value of a record.

  • @param key The key of the record.

  • @param inc The incremental value. If it is Utility::INT64MIN, the current value is not changed and a new record is not created.

  • @param init The initial value.

  • @return The future for the result status and the current value.

The record value is stored as an 8-byte big-endian integer. Negative is also supported.

# File tkrzw.rb, line 984
def increment(key, inc=1, init=0)
  # (native code)
end
inspect() click to toggle source

Returns a string representation of the object.

  • @return The string representation of the object.

# File tkrzw.rb, line 896
def inspect()
  # (native code)
end
pop_first(status=nil) click to toggle source

Gets the first record and removes it.

  • @return An array of the result status, the key, and the value of the first record.

# File tkrzw.rb, line 1009
def pop_first(status=nil)
  # (native code)
end
push_last(value, wtime=nil) click to toggle source

Adds a record with a key of the current timestamp.

  • @param value The value of the record.

  • @param wtime The current wall time used to generate the key. If it is nil, the system clock is used.

  • @return The future for the result status.

The key is generated as an 8-bite big-endian binary string of the timestamp. If there is an existing record matching the generated key, the key is regenerated and the attempt is repeated until it succeeds.

# File tkrzw.rb, line 1018
def push_last(value, wtime=nil)
  # (native code)
end
rebuild(**params) click to toggle source

Rebuilds the entire database.

  • @param params Optional keyword parameters.

  • @return The future for the result status.

The parameters work in the same way as with DBM#rebuild.

# File tkrzw.rb, line 1032
def rebuild(**params)
  # (native code)
end
rekey(old_key, new_key, overwrite=true, copying=false) click to toggle source

Changes the key of a record.

  • @param old_key The old key of the record.

  • @param new_key The new key of the record.

  • @param overwrite Whether to overwrite the existing record of the new key.

  • @param copying Whether to retain the record of the old key.

  • @return The future for the result status. If there's no matching record to the old key, NOT_FOUND_ERROR is set. If the overwrite flag is false and there is an existing record of the new key, DUPLICATION ERROR is set.

This method is done atomically. The other threads observe that the record has either the old key or the new key. No intermediate states are observed.

# File tkrzw.rb, line 1003
def rekey(old_key, new_key, overwrite=true, copying=false)
  # (native code)
end
remove(key) click to toggle source

Removes a record of a key.

  • @param key The key of the record.

  • @return The future for the result status. If there's no matching record, NOT_FOUND_ERROR is set.

# File tkrzw.rb, line 940
def remove(key)
  # (native code)
end
remove_multi(*keys) click to toggle source

Removes records of keys.

  • @param keys The keys of the records.

  • @return The future for the result status. If there are missing records, NOT_FOUND_ERROR is set.

# File tkrzw.rb, line 947
def remove_multi(*keys)
  # (native code)
end
set(key, value, overwrite=true) click to toggle source

Sets a record of a key and a value.

  • @param key The key of the record.

  • @param value The value of the record.

  • @param overwrite Whether to overwrite the existing value. It can be omitted and then false is set.

  • @return The future for the result status. If overwriting is abandoned, DUPLICATION_ERROR is set.

# File tkrzw.rb, line 925
def set(key, value, overwrite=true)
  # (native code)
end
set_multi(overwrite=true, **records) click to toggle source

Sets multiple records of the keyword arguments.

  • @param overwrite Whether to overwrite the existing value if there's a record with the same key. If true, the existing value is overwritten by the new value. If false, the operation is given up and an error status is returned.

  • @param records Records to store.

  • @return The future for the result status. If there are records avoiding overwriting, DUPLICATION_ERROR is set.

# File tkrzw.rb, line 933
def set_multi(overwrite=true, **records)
  # (native code)
end
synchronize(hard, **params) click to toggle source

Synchronizes the content of the database to the file system.

  • @param hard True to do physical synchronization with the hardware or false to do only logical synchronization with the file system.

  • @param params Optional keyword parameters.

  • @return The future for the result status.

The parameters work in the same way as with DBM#synchronize.

# File tkrzw.rb, line 1041
def synchronize(hard, **params)
  # (native code)
end
to_s() click to toggle source

Returns a string representation of the content.

  • @return The string representation of the content.

# File tkrzw.rb, line 890
def to_s()
  # (native code)
end