lmdb-js icon indicating copy to clipboard operation
lmdb-js copied to clipboard

Cache behavior

Open anywhichway opened this issue 2 years ago • 8 comments

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"));

anywhichway avatar May 29 '23 00:05 anywhichway

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

kriszyp avatar May 29 '23 04:05 kriszyp

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

anywhichway avatar May 29 '23 15:05 anywhichway

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 avatar May 30 '23 02:05 anywhichway

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 avatar May 30 '23 03:05 anywhichway

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"));
   }
})

anywhichway avatar May 30 '23 16:05 anywhichway

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

kriszyp avatar May 30 '23 16:05 kriszyp

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 avatar May 30 '23 19:05 anywhichway

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

anywhichway avatar May 30 '23 22:05 anywhichway