Coder Social home page Coder Social logo

bdb's People

Contributors

braydonf avatar chjj avatar nodech avatar pinheadmz avatar theanmolsharma avatar tynes avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bdb's Issues

Thread safety of `WriteBatch` object not synchronized

There is a memory safety issue when making batch database calls.

Details:

Within a single process, the same leveldb::DB object may be safely shared by multiple concurrent threads. (...) However other objects (like Iterator and WriteBatch) may require external synchronization. If two threads share such an object, they must protect access to it using their own locking protocol. (...)

https://github.com/google/leveldb/blob/master/doc/index.md#concurrency

The bindings (./src/bindings.cc) methods batch_init, batch_put, batch_del, batch_write and batch_clear all share access to the WriteBatch object. The batch_write method will share the object with another thread in BatchWriteWorker. It's possible that batch_put, batch_del and batch_clear can unsafely modify the WriteBatch object that is shared with the other thread.

Reproduce:

Call batch_put, batch_del or batch_clear after a call to batch_write and before the batch_write worker thread is complete.

Some of the possible errors:

  • Segmentation fault
  • Abort trap 6
  • Corruption: unknown WriteBatch tag
  • Corruption: bad WriteBatch Put
  • Corruption: WriteBatch has wrong count

BufferMap

I was experimenting with buffer maps as well, I also looked into bdb to get BufferMap not convert buffers at all (Similar to std::map) because of the js memory overhead when working with strings (fortunately I don't need huge keys), I ran several benchmarks today after seeing
bcoin-org/bcoin/issues/533

Is there any reason to use rbt for memdb ?

@chjj

Drop support for the strings

Leveldown had support for string encoding for keys and values, but bdb depends and strictly uses buffers for everything. So we can drop support for strings and simplify the codebase. (no need for converting functions etc.)

Range skips zero in iterator.

DB Layout for key:

  e: bdb.key('e', ['uint32']),

Range Usage:

    return db.range({
      gte: layout.e.min(),
      lte: layout.e.max(),
      parse: key => layout.e.parse(key)
    });

If there's 0 written in that field, iterator.parse skips that value.
Issue comes from here: https://github.com/bcoin-org/bdb/blob/master/lib/db.js#L1162

We need some convention, what you need to return from parser to skip that value.

E.g. null or undefined.

It will probably skip zero string and other falsy values )))

@chjj

I can just return buffers and parse on my own. but still I think we need some convention when to skip in iterator.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.