Giter Club home page Giter Club logo

Comments (5)

athre0z avatar athre0z commented on June 3, 2024 1

Hmm, yeah. The C++ Next method is annotated with a REQUIRES: Valid() comment. Valid() is indeed returning false here, so calling Next is not permitted:

https://github.com/facebook/rocksdb/blob/d7567d5eee5a0210376ce25475ae95b88b0a9c14/include/rocksdb/iterator.h#L67-L70

I suppose the problem here might simply be that in a C++ API it is typically considered to be perfectly acceptable for something to segfault if a user disregards such requirements whereas in Rust it would be considered unsound for a function that isn't marked as unsafe.

I suspect that the Rust interface for the raw iterator might have to be changed to automatically perform valid calls before next and prev. Alternatively the next and prev functions could be marked as unsafe. It looks like a similar check is already in place in key and value. Will probably eat a bit of CPU cycles for no good reason to also do it in next/prev, though not sure whether it'd be significant.

from rust-rocksdb.

Congyuwang avatar Congyuwang commented on June 3, 2024

Atomic loading a null 0x0 address? Looks like a rocksdb bug. Does this occur if testing with c++ rocksdb of the same version?

from rust-rocksdb.

aleksuss avatar aleksuss commented on June 3, 2024

@athre0z good catch 👍🏻

from rust-rocksdb.

aleksuss avatar aleksuss commented on June 3, 2024

In cpp I've got the same result:

#include <rocksdb/db.h>

using namespace rocksdb;

int main() {
    DB *db = nullptr;
    Options options;

    options.create_if_missing = true;

    auto status = DB::Open(options, "/tmp/dddd", &db);
    assert(status.ok());

    auto iter = db->NewIterator(ReadOptions());
    iter->Next();


    return 0;
}

Result:

Current executable set to 'с++/cmake-build-debug/cpp-playground' (arm64).
(lldb) r
Process 9702 launched: 'с++/cmake-build-debug/cpp-playground' (arm64)
Process 9702 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
    frame #0: 0x00000001010246fc librocksdb.8.dylib`rocksdb::(anonymous namespace)::SkipListRep::Iterator::Next() + 4
librocksdb.8.dylib`rocksdb::(anonymous namespace)::SkipListRep::Iterator::Next:
->  0x1010246fc <+4>:  ldapr  x8, [x8]
    0x101024700 <+8>:  str    x8, [x0, #0x10]
    0x101024704 <+12>: ret    

librocksdb.8.dylib`rocksdb::(anonymous namespace)::SkipListRep::Iterator::~Iterator:
    0x101024708 <+0>:  stp    x20, x19, [sp, #-0x20]!
Target 0: (cpp-playground) stopped.
(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
  * frame #0: 0x00000001010246fc librocksdb.8.dylib`rocksdb::(anonymous namespace)::SkipListRep::Iterator::Next() + 4
    frame #1: 0x0000000100f5b6d0 librocksdb.8.dylib`rocksdb::MemTableIterator::Next() + 64
    frame #2: 0x0000000100f5b718 librocksdb.8.dylib`rocksdb::MemTableIterator::NextAndGetResult(rocksdb::IterateResult*) + 36
    frame #3: 0x0000000100f1f034 librocksdb.8.dylib`rocksdb::DBIter::Next() + 308
    frame #4: 0x00000001000054b4 cpp-playground`main at main.cpp:27:11
    frame #5: 0x000000018cf7d058 dyld`start + 2224

from rust-rocksdb.

Congyuwang avatar Congyuwang commented on June 3, 2024

Valid call seems very cheap, just returning a flag:

https://github.com/facebook/rocksdb/blob/543191f2eacadf14e3aa6ff9a08f85a8ad82da95/db/db_iter.h#L144

from rust-rocksdb.

Related Issues (20)

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.