node-leveldb icon indicating copy to clipboard operation
node-leveldb copied to clipboard

iterator should be a stream

Open max-mapper opened this issue 13 years ago • 11 comments

right now with iterator.forRange there is no way to know when the iterator has finished. ideally creating an iterator return a readable Stream

max-mapper avatar Jun 12 '12 00:06 max-mapper

in the meantime i am using this workaround

function getLast(cb) {
  db.iterator(function(err, iterator) {
    if (err) return cb(err)
    iterator.last(function(err) {
      if (err) return cb(err)
      iterator.current(function(err, key, val) {
        cb(err, key)
      })
    })
  })
}

then i can use the returned value as the end parameter in forRange

max-mapper avatar Jun 12 '12 00:06 max-mapper

I have further improved upon the above design here: https://github.com/maxogden/plumbdb/commit/0cf5212673242413ac4a4b27858a70cd23e915c8

essentially I am using the seek, current and next functions on Iterator wrapped in a readable Stream

max-mapper avatar Jun 17 '12 22:06 max-mapper

I am not opposed to this but do not have much time right now. If anyone wants to take a stab at it that would great.

my8bird avatar Jun 23 '12 12:06 my8bird

@maxogden Does the patch supplied resolve your issue? It seems like a different approach to a common problem.

my8bird avatar Jul 09 '12 14:07 my8bird

the above patch makes this library more usable but this issue should stay open as a stream would be a more ideal API

max-mapper avatar Jul 09 '12 17:07 max-mapper

So you mean write wrapper that iterates on your behalf and emits data events (ie a stream?). Iterating over key-values in leveldb is FAST. Imagine iterating over every key in a very large database, without back pressure I bet something would break. Run out of ram because there's too many events in the queue? Or perhaps the overhead from crossing the V8->C++ boundary would just grind your app to a screeching halt.

I can understand the desire for a stream interface, it sounds like it make more sense as helper module for people who understand that you shouldn't iterate over a large set with it. This module should match the leveldb C++ interface as much as possible IMHO.

gflarity avatar Jul 25 '12 15:07 gflarity

streams support backpressure. I get that it should match the c++ interface but it's a node binding and streams are part of node core

max-mapper avatar Aug 12 '12 01:08 max-mapper

@maxogden, I like your suggestion of exposing a stream. I may take a stab at this. Stay tuned.

carter-thaxton avatar Mar 07 '13 20:03 carter-thaxton

:+1:

mikepb avatar Mar 07 '13 20:03 mikepb

Fwiw I've been happy with the stream implementation in rvagg/levelup

Sent from my iPhone

On Mar 7, 2013, at 12:18 PM, Michael Phan-Ba [email protected] wrote:

— Reply to this email directly or view it on GitHub.

max-mapper avatar Mar 07 '13 20:03 max-mapper

Wow, rvagg/levelup looks like it's really matured, and has a nice little ecosystem. Last I looked, there wasn't an "obvious" winner among the leveldb drivers. @maxogden, in your opinion, is there any reason to resurrect this node-leveldb project, or have you been satisfied with levelup? No need to reinvent the wheel.

carter-thaxton avatar Mar 08 '13 20:03 carter-thaxton