module FDB

Documentation for this API can be found at apple.github.io/foundationdb/api-ruby.html

Documentation for this API can be found at apple.github.io/foundationdb/api-ruby.html

Documentation for this API can be found at apple.github.io/foundationdb/api-ruby.html

Documentation for this API can be found at apple.github.io/foundationdb/api-ruby.html

Public Class Methods

api_version(version) click to toggle source
# File lib/fdb.rb, line 38
def self.api_version(version)
  header_version = 520
  if self.is_api_version_selected?()
    if @@chosen_version != version
      raise "FDB API already loaded at version #{@@chosen_version}."
    end
    return
  end

  if version < 14
    raise "FDB API versions before 14 are not supported"
  end

  if version > header_version
    raise "Latest known FDB API version is #{header_version}"
  end

  @@chosen_version = version

  require_relative 'fdbimpl'

  err = FDBC.fdb_select_api_version_impl(version, header_version)
  if err.nonzero?
    if err == 2203
      max_supported_version = FDBC.fdb_get_max_api_version()
      if header_version > max_supported_version
        raise "This version of the FoundationDB Ruby binding is not supported by the installed FoundationDB C library. The binding requires a library that supports API version #{header_version}, but the installed library supports a maximum version of #{max_supported_version}."

      else
        raise "API version #{version} is not supported by the installed FoundationDB C library."
      end
    end
    raise "FoundationDB API version error"
  end

  require_relative 'fdbtuple'
  require_relative 'fdbdirectory'
  if version > 22
    require_relative 'fdblocality'
  end

  return
end
cb_mutex() click to toggle source
# File lib/fdbimpl.rb, line 140
def self.cb_mutex
  @@cb_mutex
end
create_cluster(cluster=nil) click to toggle source
# File lib/fdbimpl.rb, line 506
def self.create_cluster(cluster=nil)
  f = FDBC.fdb_create_cluster(cluster)
  cpointer = FFI::MemoryPointer.new :pointer
  FDBC.check_error FDBC.fdb_future_block_until_ready(f)
  FDBC.check_error FDBC.fdb_future_get_cluster(f, cpointer)
  Cluster.new cpointer.get_pointer(0)
end
directory() click to toggle source
# File lib/fdbdirectory.rb, line 496
def self.directory 
  @@directory
end
ffi_callbacks() click to toggle source
# File lib/fdbimpl.rb, line 155
def self.ffi_callbacks
  @@ffi_callbacks
end
get_api_version() click to toggle source
# File lib/fdb.rb, line 31
def self.get_api_version()
  if self.is_api_version_selected?()
    return @@chosen_version
  else
    raise "FDB API version not selected"
  end
end
init() click to toggle source
# File lib/fdbimpl.rb, line 215
def self.init()
  @@network_thread_monitor.synchronize do
    if !@@network_thread.nil?
      raise Error.new(2000)
    end

    begin
      @@network_thread = Thread.new do
        @@network_thread_monitor.synchronize do
          # Don't start running until init releases this
        end
        # puts "Starting FDB network"
        begin
          FDBC.check_error FDBC.fdb_run_network
        rescue Error => e
          $stderr.puts "Unhandled error in FoundationDB network thread: #{e.to_s}"
        end
      end

      FDBC.check_error FDBC.fdb_setup_network
    rescue
      @@network_thread.kill
      @@network_thread = nil
      raise
    end
  end

  nil
end
is_api_version_selected?() click to toggle source
# File lib/fdb.rb, line 28
def self.is_api_version_selected?()
  @@chosen_version >= 0
end
key_to_bytes(k) click to toggle source
# File lib/fdbimpl.rb, line 182
def self.key_to_bytes(k)
  if k.respond_to? 'as_foundationdb_key'
    k.as_foundationdb_key
  else
    k
  end
end
open( cluster_file = nil, database_name = "DB" ) click to toggle source
# File lib/fdbimpl.rb, line 261
def self.open( cluster_file = nil, database_name = "DB" )
  @@network_thread_monitor.synchronize do
    if ! @@network_thread
      init
    end
  end

  @@cache_lock.synchronize do
    if ! @@open_clusters.has_key? cluster_file
      @@open_clusters[cluster_file] = create_cluster( cluster_file )
    end

    if ! @@open_databases.has_key? [cluster_file, database_name]
      @@open_databases[[cluster_file, database_name]] = @@open_clusters[cluster_file].open_database(database_name)
    end

    @@open_databases[[cluster_file, database_name]]
  end
end
options() click to toggle source
# File lib/fdbimpl.rb, line 208
def FDB.options
  @@options
end
stop() click to toggle source
# File lib/fdbimpl.rb, line 245
def self.stop()
  FDBC.check_error FDBC.fdb_stop_network
end
strinc(key) click to toggle source
# File lib/fdbimpl.rb, line 198
def self.strinc(key)
        key = key.gsub(/\xff*\z/, '')
        raise ArgumentError, 'Key must contain at least one byte not equal to 0xFF.' if key.length == 0

        key[0..-2] + (key[-1].ord + 1).chr
end
value_to_bytes(v) click to toggle source
# File lib/fdbimpl.rb, line 190
def self.value_to_bytes(v)
  if v.respond_to? 'as_foundationdb_value'
    v.as_foundationdb_value
  else
    v
  end
end