class XRBP::NodeStore::Backends::NuDB
NuDB
nodestore backend, faciliates accessing XRP Ledger
data in a NuDB
database. This module accommodates for compression used in rippled's NuDB
nodestore backend implementation
@example retrieve data from NuDB
backend
require 'nodestore/backends/nudb' nudb = NodeStore::Backends::NuDB.new '/var/lib/rippled/db/nudb' puts nudb.ledger('B506ADD630CB707044B4BFFCD943C1395966692A13DD618E5BD0978A006B43BD')
Constants
- KEY_SIZE
Attributes
path[R]
Public Class Methods
new(path)
click to toggle source
# File lib/xrbp/nodestore/backends/nudb.rb, line 26 def initialize(path) @path = path create! open 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/nudb.rb, line 36 def [](key) fetched = @store.fetch(key)[0] return nil if fetched.empty? decompress(fetched) 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 NuDB
entries
nudb.each do |iterator| puts "Key/Value: #{iterator.key}/#{iterator.value}" end
@example handling ledgers via event callback
nudb.on(:ledger) do |hash, ledger| puts "Ledger #{hash}" pp ledger end # Any Enumerable method that invokes #each will # have intended effect nudb.to_a
# File lib/xrbp/nodestore/backends/nudb.rb, line 61 def each dat = File.join(path, "nudb.dat") RuDB::each(dat) do |key, val| val = decompress(val) type, obj = infer_type(val) if type emit type, key, obj else emit :unknown, key, val end # 'mock' iterator iterator = OpenStruct.new(:key => key, :value => val) yield iterator end return self end
Private Instance Methods
create!()
click to toggle source
Create database if it does not exist
@private
# File lib/xrbp/nodestore/backends/nudb.rb, line 88 def create! dat = File.join(path, "nudb.dat") key = File.join(path, "nudb.key") log = File.join(path, "nudb.log") RuDB::create :dat_path => dat, :key_path => key, :log_path => log, :app_num => 1, :salt => RuDB::make_salt, :key_size => KEY_SIZE, :block_size => RuDB::block_size(key), :load_factor => 0.5 end
open()
click to toggle source
Open existing database
@private
# File lib/xrbp/nodestore/backends/nudb.rb, line 106 def open dat = File.join(path, "nudb.dat") key = File.join(path, "nudb.key") log = File.join(path, "nudb.log") @store = RuDB::Store.new @store.open(dat, key, log) end