kriszyp / lmdb-js

Simple, efficient, ultra-fast, scalable data store wrapper for LMDB
Other
479 stars 39 forks source link

Cache behavior #237

Open anywhichway opened 1 year ago

anywhichway commented 1 year ago

I would expect value to be 1 below because it would be reloaded. This does not seem to be the case.

await db.put(1,1); db.cache.delete(1); const value = db.get(1); if(value!==1) console.log(new Error("Value is not 1"));

kriszyp commented 1 year ago

I think I need a little more context, this code snippet works fine for me (returns 1).

anywhichway commented 1 year ago

Hmmmm ... returns undefined for me. I will try to reproduce in an isolated manner.

anywhichway commented 1 year ago

Looks like this was a case of another piece of code having side effects once caching was turned on. It had no side effects with caching off. Eliminated side effect. Eliminated issue. Sorry to have bothered you.

anywhichway commented 1 year ago

Further info ... this situation only occurs under very high load, i.e. using benchtest. The value gets into the cache but the awaits on put never resolve. And, put is being called indirectly by my code, e.g. put.call(this,key,value).

I have walked into the source an commitPromise in write.js is the promise that is not resolving and does not seem to be throwing either.

I have reopened since I can reproduce now, even with the side-effects that were in my code removed. I am working on a standalone Benchtest file.

anywhichway commented 1 year ago

Definitively a side effect of using Benchtest:

This works:

await db.put(1,1);
 if(db.cache.has(key)) { // succeeds
      db.cache.delete(1);
     const value = db.get(1); // returns undefined
     if(key!==1) console.log(new Error("Key is not 1"));
   }

This does not:

suite.add("put primitive",async () => {
    await db.put(1,1);
   if(db.cache.has(key)) { // succeeds
      db.cache.delete(1);
     const value = db.get(1); // returns undefined
     if(key!==1) console.log(new Error("Key is not 1"));
   }
})
kriszyp commented 1 year ago

Would I do something like import { suite } from 'benchtest'; to test this?

anywhichway commented 1 year ago

I will create a Git repository you can use.

On Tue, May 30, 2023, 9:25 AM Kris Zyp @.***> wrote:

Would I do something like import { suite } from 'benchtest'; to test this?

— Reply to this email directly, view it on GitHub https://github.com/kriszyp/lmdb-js/issues/237#issuecomment-1568728616, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABF2US2X6LBIN5VCXBNR6XTXIYNQDANCNFSM6AAAAAAYSFKCRE . You are receiving this because you modified the open/close state.Message ID: @.***>

anywhichway commented 1 year ago

@kriszyp see repository https://github.com/anywhichway/lmdb-issues