tidwall / buntdb

BuntDB is an embeddable, in-memory key/value database for Go with custom indexing and geospatial support
MIT License
4.57k stars 289 forks source link

Key not found error even when the key is present in the corresponding file #41

Closed apratheek closed 6 years ago

apratheek commented 6 years ago

Hi, is there any reason why a stored key-value pair is not found even though the key is present in the DB file? My use case is as follows:

  1. A server writing key-value pairs to this file
  2. Go tests updating the file

Any help would be appreciated. Thanks.

tidwall commented 6 years ago

The only reason would be if the key was later deleted using BuntDB. The DB file is an append only log. The key can be present more than once. First as a Set and later as a Delete.

apratheek commented 6 years ago

Hi, thanks for the response. I've checked. Seems like there's a race condition between the two instances of the opened file. What happens when one would open 2 connections to the same db store (persisting on disk) and update the file? Would both the connections see the same data or would there be a lag where the other connection would return a Not Found error?

tidwall commented 6 years ago

A buntdb file is designed to be opened one at a time. Multiple instances reading to the same file will likely result in stale data, and multiple writes will risk corruption.

apratheek commented 6 years ago

Thanks for pointing that out!