Skip to content
This repository has been archived by the owner on Dec 2, 2024. It is now read-only.

fails with level-ttl #66

Closed
jfromaniello opened this issue Mar 15, 2017 · 8 comments
Closed

fails with level-ttl #66

jfromaniello opened this issue Mar 15, 2017 · 8 comments
Labels
bug Something isn't working more information needed Further information is requested

Comments

@jfromaniello
Copy link

I am not sure if this is an issue with level-ttl or memdown, but I can't get this to work:

const level  = require('levelup');
const ttl = require('level-ttl');
const memdown = require('memdown');

var db = level({db: memdown});
db.put('foo', 'bar');
db.get('foo', (err, data) => console.log(data));
//prints bar

const aday = 24 * 60 * 60 * 1000;
var ttldb = ttl(db, { checkFrequency: aday });
ttldb.put('foo', 'bar', { ttl: aday })
ttldb.get('foo', (err, data) => console.log(data));
//prints undefined

It works if I use leveldown.

@calvinmetcalf
Copy link
Contributor

what about running ttldb.get('foo', (err, data) => console.log(err, data));

@jfromaniello
Copy link
Author

It is a NotFoundError , either through ttldb.get or with db.get

@calvinmetcalf
Copy link
Contributor

calvinmetcalf commented Mar 16, 2017 via email

@calvinmetcalf
Copy link
Contributor

wait I know ttldb.put('foo', 'bar', { ttl: aday }) you're not waiting for the callback here, I'm frankly surprised it works in leveldown.

@yonjah
Copy link

yonjah commented Aug 21, 2017

@calvinmetcalf you should ignore the minor issues in the example code and see that this is an actual bug in memdown/level-ttl integration.

the issue is that memdown is using ltgt compare which assumes all values are from the same type and will produce inconsistent result when with mixed values of buffers and strings and since level-ttl uses Buffer keys it will break if other code uses string keys ( I assume leveldown doesn't care about this mixed value issues since it probably converts all keys to buffers when doing the js to cpp shift but I haven't dug into it too much)

@jfromaniello as a work around you can convert your keys to Buffers the following code seems to work -

const ttldb = ttl(db, { checkFrequency: aday });
const key = Buffer.from('foo');
ttldb.put(key, 'bar', { ttl: aday }, (err) => {
	err && console.log(err);
	ttldb.get(key, (err, data) => console.log(data));
})

@jfromaniello
Copy link
Author

@yonjah Thank you very much and sorry for the delay on my response... I missed the notification for your response.

By doing this the TTL module seems to work, but I break another part of my code where I was doing something like this:

    const readStream = type.db.createReadStream({
      gte: prefix,
      lte: `${prefix}~`,
    });

If I do this I don't get any result, I tried converting these to Buffers, but I don't get any result back.. Any ideas how can I get that working?

@yonjah
Copy link

yonjah commented Jan 19, 2018

@jfromaniello sorry I don't have a lot of experience with levelDB.
I was only looking at this issue since I was considering using limitd.
I can try diving back into it when I'll have some spare time but I'm not sure when it will be

@vweevers vweevers added bug Something isn't working more information needed Further information is requested labels Jan 1, 2019
@vweevers
Copy link
Member

This is likely Level/level-ttl#68 or more specifically Level/level-ttl#68 (comment).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working more information needed Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants