Skip to content

fetch callback needs documented requirements #53

Open
@vinniefalco

Description

@vinniefalco

The documentation needs to be explicit about the restrictions and limitations of what can be performed in the fetch callback:

From
https://www.reddit.com/r/cpp/comments/60px64/nudb_100_released_a_keyvalue_database_for_ssds/dfaj3z7/

db.insert(the_key, ...);
db.fetch(the_key, [&](void const* buffer, std::size_t size) {
    unexpectedly_slow_operation();
    // wow that really took a long time
    //
    // did you know that we're still holding the internal rwlock?
    //
    // it's "never held during disk reads and writes"
    // but our request was fetched from the write queue,
    // which is probed by every reader and writer in order to
    // maintain consistency
    //
    // now guess who is currently waiting to get exclusive access...
    // ...it's the background worker!
    //
    // Q: are other readers still able to acquire the rwlock?
    // A: of course not, we don't want writer starvation :)
    //
    // TL;DR: a reader can block the whole system forever ... :D
    db.fetch(some_other_key, [&](...) { /* let's deadlock */ });                
}, ...);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions