lucaong / cubdb

Elixir embedded key/value database
Apache License 2.0
556 stars 23 forks source link

Simplify and improve reader logic using snapshotting #48

Closed lucaong closed 2 years ago

lucaong commented 2 years ago

Before, read operations were executed on a Task spawned by the GenServer server process, to enable concurrency. This required monitoring reader tasks, and updating the bookkeeping information to prevent clean up of files that are still referenced by some reader.

Now, read operations are executed by the GenServer client process, after obtaining a snapshot (or on the given snapshot). This enables concurrency without the need of reader tasks, and simplifies the whole flow. Bookkeeping is perfomed by the snapshot logic, so no additional process or monitor is necessary.

For the user, nothing changes, apart from one single breaking change: the select function does not support anymore passing a :timeout option. While this is considered a breaking change, now the select happens on the client process, so the user has complete control and can enforce timeouts or stop the process, without the need of a specific option to shutdown the internal reader Task.