Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Has LevelDB a max-length limit for keys?

Tags:

nosql

leveldb

Has LevelDB keys a limit for the key length?

I want to save data with url's as key. so this urls can be very very long i.g. http://veryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryloooooooooooooooong-url.com

like image 978
tiefenb Avatar asked Jun 17 '13 08:06

tiefenb


People also ask

How does LevelDB store data?

LevelDB is an on-disk key-value store where the keys and values are both arbitrary blobs of data. Each LevelDB database occupies a folder on the file system. The folder will contain some combination of files named “CURRENT”, “LOCK”, “LOG”, “LOG. old” and files named “MANIFEST-######”, “######.


2 Answers

There is no key length limit in LevelDB. Keys are arbitrary byte arrays of any length. You can use a long url like you've provided in your question.

They mention here that the keys are byte arrays... https://code.google.com/p/leveldb/

As a test, I inserted some documents with keys that were a million characters long. It worked just fine.

like image 181
Brandon Joyce Avatar answered Oct 11 '22 23:10

Brandon Joyce


There is no theoretical limit to the key length, but the DB might not be very efficient with long keys and short records. There is an index at the top of the SST files that contains the keys and the offsets into the file, and the keys in these index blocks are binary chopped to locate rows.

Just a thought - you might want to do some sanitisation on the URLs before using them as raw keys. e.g., canonicalise the domain name and case of the protocol, canonicalise the order of the query params, etc.

like image 38
gub Avatar answered Oct 12 '22 00:10

gub