Class: XRBP::NodeStore::Backends::RocksDB

Inherits:
DB
  • Object
show all
Defined in:
lib/xrbp/nodestore/backends/rocksdb.rb

Overview

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

Examples:

retrieve data from RocksDB backend

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

Constant Summary collapse

MAX_OPEN_FILES =

cap max open files for performance

2000

Instance Method Summary collapse

Methods inherited from DB

#account, #inner_node, #ledger, #ledger_entry, #tx

Constructor Details

#initialize(path) ⇒ RocksDB

Returns a new instance of RocksDB.



18
19
20
21
22
# 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

Instance Method Details

#[](key) ⇒ String

Retrieve database value for the specified key

Parameters:

  • key (String)

    binary key to lookup

Returns:

  • (String)

    binary value



28
29
30
# File 'lib/xrbp/nodestore/backends/rocksdb.rb', line 28

def [](key)
  @db[key]
end

#eachObject

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

Examples:

iterating over RocksDB entries

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

handling account via event callback

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

# Any Enumerable method that invokes #each will
# have intended effect
rocksdb.to_a


51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# 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