Class: SlateDb::Reader
- Inherits:
-
Object
- Object
- SlateDb::Reader
- Defined in:
- lib/slatedb/reader.rb
Class Method Summary collapse
-
.open(path, url: nil, checkpoint_id: nil, follow_latest: nil, manifest_poll_interval: nil, checkpoint_lifetime: nil, max_memtable_bytes: nil, cache_root: nil, max_open_file_handles: nil, merge_operator: nil) {|reader| ... } ⇒ Reader
Open a read-only reader at the given path.
Instance Method Summary collapse
-
#get(key, durability_filter: nil, dirty: nil, cache_blocks: nil) ⇒ String?
Get a value by key.
-
#scan(start_key, end_key = nil, durability_filter: nil, dirty: nil, read_ahead_bytes: nil, cache_blocks: nil, max_fetch_tasks: nil) ⇒ Iterator
Scan a range of keys.
-
#scan_prefix(prefix, durability_filter: nil, dirty: nil, read_ahead_bytes: nil, cache_blocks: nil, max_fetch_tasks: nil, from: nil, to: nil) ⇒ Iterator
Scan all keys with a given prefix.
Class Method Details
.open(path, url: nil, checkpoint_id: nil, follow_latest: nil, manifest_poll_interval: nil, checkpoint_lifetime: nil, max_memtable_bytes: nil, cache_root: nil, max_open_file_handles: nil, merge_operator: nil) {|reader| ... } ⇒ Reader
Open a read-only reader at the given path.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/slatedb/reader.rb', line 53 def open(path, url: nil, checkpoint_id: nil, follow_latest: nil, manifest_poll_interval: nil, checkpoint_lifetime: nil, max_memtable_bytes: nil, cache_root: nil, max_open_file_handles: nil, merge_operator: nil) opts = {} opts[:follow_latest] = follow_latest unless follow_latest.nil? opts[:manifest_poll_interval] = manifest_poll_interval if manifest_poll_interval opts[:checkpoint_lifetime] = checkpoint_lifetime if checkpoint_lifetime opts[:max_memtable_bytes] = max_memtable_bytes if max_memtable_bytes opts[:cache_root] = cache_root if cache_root opts[:max_open_file_handles] = max_open_file_handles if max_open_file_handles opts[:merge_operator] = merge_operator.to_s if merge_operator reader = _open(path, url, checkpoint_id, opts) if block_given? begin yield reader ensure begin reader.close rescue StandardError nil end end else reader end end |
Instance Method Details
#get(key, durability_filter: nil, dirty: nil, cache_blocks: nil) ⇒ String?
Get a value by key.
92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/slatedb/reader.rb', line 92 def get(key, durability_filter: nil, dirty: nil, cache_blocks: nil) opts = {} opts[:durability_filter] = durability_filter.to_s if durability_filter opts[:dirty] = dirty unless dirty.nil? opts[:cache_blocks] = cache_blocks unless cache_blocks.nil? if opts.empty? _get(key) else (key, opts) end end |
#scan(start_key, end_key = nil, durability_filter: nil, dirty: nil, read_ahead_bytes: nil, cache_blocks: nil, max_fetch_tasks: nil) ⇒ Iterator
Scan a range of keys.
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/slatedb/reader.rb', line 111 def scan(start_key, end_key = nil, durability_filter: nil, dirty: nil, read_ahead_bytes: nil, cache_blocks: nil, max_fetch_tasks: nil, &) opts = {} opts[:durability_filter] = durability_filter.to_s if durability_filter opts[:dirty] = dirty unless dirty.nil? opts[:read_ahead_bytes] = read_ahead_bytes if read_ahead_bytes opts[:cache_blocks] = cache_blocks unless cache_blocks.nil? opts[:max_fetch_tasks] = max_fetch_tasks if max_fetch_tasks iter = if opts.empty? _scan(start_key, end_key) else (start_key, end_key, opts) end if block_given? iter.each(&) else iter end end |
#scan_prefix(prefix, durability_filter: nil, dirty: nil, read_ahead_bytes: nil, cache_blocks: nil, max_fetch_tasks: nil, from: nil, to: nil) ⇒ Iterator
Scan all keys with a given prefix.
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/slatedb/reader.rb', line 148 def scan_prefix(prefix, durability_filter: nil, dirty: nil, read_ahead_bytes: nil, cache_blocks: nil, max_fetch_tasks: nil, from: nil, to: nil, &) opts = { durability_filter: durability_filter&.to_s, dirty: dirty, read_ahead_bytes: read_ahead_bytes, cache_blocks: cache_blocks, max_fetch_tasks: max_fetch_tasks, subrange_from: from, subrange_to: to }.compact iter = if opts.empty? _scan_prefix(prefix) else (prefix, opts) end if block_given? iter.each(&) else iter end end |