Skip to content

Running into "Internal error: unexpected root node key" issues #10

Open
@Gozala

Description

@Gozala

Hi Team,

I have being trying to get okra to persist in IDB in browser and sync with remote replica using sync protocol, but seem to run into a problem after bunch of fast writes coming from here

public getRoot(): Node {
const upperBound = { key: KeyValueNodeStore.metadataKey, inclusive: false }
for (const entry of this.entries(null, upperBound, { reverse: true })) {
const node = this.parseEntry(entry)
assert(node.key === null, "Internal error: unexpected root node key", node)
return node
}

Initially I attempted to use okra-idb package from npm but I was running into lot of problems with IDB transactions completing mid writes. As @joeltg have pointed out here #3 that is because IDB completes transaction as soon as you yield to event loop & async generators do exactly that.

To overcome this problem I have effectively rewrote IDB backend and most of the core okra constructs to use generator based task scheduling library which I have being using already to abstract over sync / async interfaces. General idea is that you can author potentially async logic as follows

Task.spawn(function* () {
   const awaited = yield* Task.wait(maybePromise)
   ....
})

In case of IDB I also have wrote task poll that just like Task.wait will suspend execution and resume once passed IDBRequest succeeds or fails. This way I could represent entries / nodes using custom Sequence type which utilized tasks.

Above switch addressed premature IDB transaction completion issues, as task scheduler ensures that continuations take places on IDBRequest events without yielding to event-loop.


Unfortunately I am running into the mentioned invariant mentioned at the beginning of the issue. It appears that after some bunch of writes store ends up in a state where iteration over nodes does return an entry where first key isn't a single byte.

Perhaps more surprising is the fact that DB does actually contain record where with 0xFF key which makes me wonder if iteration order assumed is invalid

image

I realize that at this point, I'm basically working off a fork but any help would be highly appreciated. I also would be very delighted if any of the ideas could be uplifted to this library.

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