Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Abstracting away underlying storage #138

Open
ccleve opened this issue Feb 17, 2022 · 6 comments
Open

Abstracting away underlying storage #138

ccleve opened this issue Feb 17, 2022 · 6 comments

Comments

@ccleve
Copy link

ccleve commented Feb 17, 2022

The MapBuilder will accept a struct that implements io::Write. This is cool, it means that the fst can be written anywhere.

Is it possible for Map::new() to accept a struct that implements io:Read instead of &[u8]? What would it take to make that happen?

My need is this: I will have a very large fst, possible larger than available memory. It will be stored in a file that, under the hood, is broken into pages, and the pages are in a cache. If the fst needs to access a part of memory, I'll have to fetch it on the fly from the page cache.

In practice, this will be reasonably fast if most pages are in memory, and it should degrade gracefully if they're not. But I would need a layer of abstraction to do it.

@BurntSushi
Copy link
Owner

Nope. Random access is pretty baked into the implementation. Even in theory, I don't know how it would be implemented with just an io::Read. You would at least also need an io::Seek.

You haven't explained, AFAIK, why the obvious solution of memory maps doesn't work for you. It's even mentioned in the docs for precisely your use case: traversing large FSTs that don't fit into memory.

@BurntSushi
Copy link
Owner

In theory, an abstraction could be introduced that gave more control how bytes are fetched. It would just need to be stronger than io::Read.

I'm not sure I personally have the bandwidth to maintain or even review the patches necessary to achieve such a feat though unfortunately.

@ccleve
Copy link
Author

ccleve commented Feb 17, 2022

I'd like to store the data in native Postgres page files. I'm creating an new type of Postgres index that would use an fst. Unfortunately, pages have page headers, and I can't get around that problem. So even if I could mmap the file directly, I'd still have parts of the file that were inaccessible.

@BurntSushi
Copy link
Owner

Yeah you should have lead with that. :P Otherwise the XY problem is at work here by asking for io::Read.

In any case, your best bet is to fork and patch it yourself. It likely won't be too easy. The current code is pretty tightly coupled to &[u8]. But it will probably be easier than starting from scratch completely.

@ellenhp
Copy link

ellenhp commented Jun 7, 2022

I found this: https://github.com/phiresky/tantivy-fst
Which is used here: quickwit-oss/tantivy#1067
Demo: https://demo.phiresky.xyz/tmp-ytccrzsovkcjoylr/dist/index.html

I'm forking it to see if it will accomplish what I need, but I thought I would also leave it here in case it might help others.

@claudius108
Copy link

claudius108 commented Jun 8, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants