class XRBP::NodeStore::Backends::RocksDB

RocksDB nodestore backend, faciliates accessing XRP Ledger data in a RocksDB database.

@example retrieve data from RocksDB backend

require 'nodestore/backends/rocksdb'
rocksdb = NodeStore::Backends::RocksDB.new '/var/lib/rippled/db/rocksdb'
puts rocksdb.ledger('B506ADD630CB707044B4BFFCD943C1395966692A13DD618E5BD0978A006B43BD')

Constants

MAX_OPEN_FILES

cap max open files for performance

Public Class Methods

new(path) click to toggle source
# File lib/xrbp/nodestore/backends/rocksdb.rb, line 18
def initialize(path)
  @db = ::RocksDB::DB.new path,
          {:readonly => true,
     :max_open_files => MAX_OPEN_FILES}
end

Public Instance Methods

[](key) click to toggle source

Retrieve database value for the specified key

@param key [String] binary key to lookup @return [String] binary value

# File lib/xrbp/nodestore/backends/rocksdb.rb, line 28
def [](key)
  @db[key]
end
each() { |iterator| ... } click to toggle source

Iterate over each database key/value pair, invoking callback. During iteration will emit signals specific to the DB types being parsed

@example iterating over RocksDB entries

rocksdb.each do |iterator|
  puts "Key/Value: #{iterator.key}/#{iterator.value}"
end

@example handling account via event callback

rocksdb.on(:account) do |hash, account|
  puts "Account #{hash}"
  pp account
end

# Any Enumerable method that invokes #each will
# have intended effect
rocksdb.to_a
# File lib/xrbp/nodestore/backends/rocksdb.rb, line 51
def each
  iterator = @db.new_iterator
  iterator.seek_to_first

  while(iterator.valid)
    type, obj = infer_type(iterator.value)

    if type
      emit type, iterator.key, obj
    else
      emit :unknown, iterator.key,
                     iterator.value
    end

    yield iterator
    iterator.next
  end

  iterator.close
  return self
end