kriszyp / lmdb-js

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

String does not fit in target buffer #219

Open morteza102030 opened 1 year ago

morteza102030 commented 1 year ago

sometimes when db.get(String) i receive this error

Unhandled Rejection at: Promise Promise {

RangeError: String does not fit in target buffer at LMDBStore.writeKey (/root/m/node_modules/ordered-binary/dist/index.cjs:76:11) at LMDBStore.getBinaryFast (/root/m/node_modules/lmdb/dist/index.cjs:1386:58) at LMDBStore.get (/root/m/node_modules/lmdb/dist/index.cjs:1573:22) at module.exports (/root/m/handlers/lookHandler.js:467:27) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) }
kriszyp commented 1 year ago

What size of strings are you trying to use? By default, the maximum key size is 1978 bytes. Curious if this is an issue with strings that should be handled, or poor error reporting for larger strings that should be rejected.

morteza102030 commented 1 year ago

my string is random 1 to 4000 characters

kriszyp commented 1 year ago

I will look into improving that error, but those strings will be too large to use as keys with the default setting. However, I believe you should be able use 4000 character strings (as long as they one-byte UTF8, not more than 4026 bytes) if you set the pageSize to 8192 (requires recreating the database).