Giter Site home page Giter Site logo

Comments (20)

MeirionHughes avatar MeirionHughes commented on July 4, 2024 1

okaydoky I'll test if that fixes my unit-test locally then do the pr.

from subleveldown.

MeirionHughes avatar MeirionHughes commented on July 4, 2024 1

fixed - still failing. I've also made sure that my local version of level-codec with your suggested change (Level/codec@master...MeirionHughes:master) is defiantly being loaded.

... anyway I can use charwise and keep all my keys as strings for now.

from subleveldown.

MeirionHughes avatar MeirionHughes commented on July 4, 2024

No issue if I switch to charwise - so I suspect the mix of string + buffer and its screwing with the ! delimiter checking.

from subleveldown.

vweevers avatar vweevers commented on July 4, 2024

You're likely hitting a known issue with memdown, when mixing buffers and strings in the same db, see Level/level-ttl#68 (comment) (different context, same underlying issue). Might be fixable by reverting Level/codec#23.

from subleveldown.

vweevers avatar vweevers commented on July 4, 2024

To confirm it's that, could you try replacing memdown with leveldown?

from subleveldown.

MeirionHughes avatar MeirionHughes commented on July 4, 2024

Yes - leveldown works.

from subleveldown.

vweevers avatar vweevers commented on July 4, 2024

Great. So, reverting Level/codec#23 should fix this, the level-ttl issue and a multileveldown issue (Level/community#71). I can't think of any reasons not to revert it. Feel up to making a PR?

from subleveldown.

MeirionHughes avatar MeirionHughes commented on July 4, 2024

So, you want to revert #23, which was a revert itself?

from subleveldown.

vweevers avatar vweevers commented on July 4, 2024

Yes :)

from subleveldown.

MeirionHughes avatar MeirionHughes commented on July 4, 2024

okay I've cherry-picked the original commit and resolved the linting errors: https://github.com/MeirionHughes/codec/commit/9f6686a390b96200a93103e6672d96569a388a2a

doesn't seem to fix it unfortunately.

I yarn link and yarn link level-codec locally, and added a console.log during the export just to make sure it was being used.

from subleveldown.

MeirionHughes avatar MeirionHughes commented on July 4, 2024

I'll see if I can make a basic failing test on here

from subleveldown.

MeirionHughes avatar MeirionHughes commented on July 4, 2024

Okay I've managed to get it to trigger the race condition. At least for me and its consistent: https://github.com/Level/subleveldown/compare/tests/buffer-race-issue

it very odd because you can change subdb(db, 'logs') to subdb(db, 'AAAA') and it works...

from subleveldown.

vweevers avatar vweevers commented on July 4, 2024

{ keyEncoding: 'buffer' } should be { keyEncoding: 'binary' }

from subleveldown.

vweevers avatar vweevers commented on July 4, 2024

I had a closer look. Thanks for providing a clean subleveldown test! The problem is that memdown, when comparing two keys, and one key is a buffer while the other key is a string, does not compare them bytewise. Essentially it compares buf[index] to str[index].

from subleveldown.

vweevers avatar vweevers commented on July 4, 2024

We have a few options:

  1. Support comparing buffers to strings in memdown (bringing its behavior closer to leveldown) (but it's not compatible with IDB-style sort order, which sorts by type first and then content - i.e. string data is never equal to binary data) (bytewise is also IDB-style but sorts string and binary the other way around...)
  2. Have memdown sort by type, then content
  3. Have subleveldown always use buffers internally

I hate encodings right now :)

from subleveldown.

vweevers avatar vweevers commented on July 4, 2024

I think I prefer 2. Because although it is not the same behavior as leveldown, it is the least surprising and it's fairly reasonable to expect a consumer to be consistent in their usage of key/value types - i.e. don't mix buffers and strings in the same (sub)db.

@ralphtheninja WDYT?

Edit: I forgot I already wrote code for 2! To deal with other surprising cases, all arising from the fact that memdown does not compare by type. For example it considers 'a' and 0 to be equal (because JavaScript attempts to convert the left- and right-hand sides of greater-than and less-than operators to numbers, unless both sides are strings. In the case of 'a' and 0, 'a' becomes NaN, which is never greater or less than a number.)

from subleveldown.

MeirionHughes avatar MeirionHughes commented on July 4, 2024

Thanks for investigating, on a Sunday no-less! - Perhaps no.1 via an option so that it behaves just like leveldown? Non-breaking, but allows memdown to behave like leveldown during unit tests. I guess if you're code for no.2 already solves it then that is the way to go.

from subleveldown.

vweevers avatar vweevers commented on July 4, 2024

Perhaps no.1 via an option so that it behaves just like leveldown?

Although it's easy to add a comparator option to memdown to make it sort however you want, IMO the default behavior should cover common use cases like these, and not require configuration.

Somewhere this week, I'll try to clean up and push the code that I have. It will make memdown sort the same as IDB and level-js, and almost the same as bytewise.

Side note: are you using memdown purely to speed up tests? You might like level-test which defaults to leveldown in node, but is quite fast because it uses temporary directories without cleaning them up (leaving that to the OS).

from subleveldown.

vweevers avatar vweevers commented on July 4, 2024

Opened a PR for level-codec (Level/codec#51, thanks!); memdown discussion is to be continued in Level/memdown#186.

Keeping this open though, as a reminder to test everything together once ready.

from subleveldown.

vweevers avatar vweevers commented on July 4, 2024

Fixed in [email protected].

from subleveldown.

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.