ergochat / ergo

A modern IRC server (daemon/ircd) written in Go.
https://ergo.chat/
MIT License
2.27k stars 180 forks source link

refactor of channel persistence to use UUIDs #2028

Closed slingamn closed 1 year ago

slingamn commented 1 year ago

This is pretty complicated and touches a lot of things, so I'm interested in reviews, maybe from @ajaspers or @progval ?

The core idea here is to refactor persistence to eventually support datastores other than buntdb. There are two problems:

  1. We don't want typical chat operations to block on the datastore (this is mostly implemented already, with the asynchronous persistence / markDirty stuff, but there are some cases where we would still block, particularly for accounts where every login currently incurs a read from the datastore)
  2. We don't want to require nontrivial consistency guarantees from the datastore

The new approach is best illustrated by the new, weak datastore API:

https://github.com/slingamn/ergo/blob/7ce06362764ee35629521eacc1fdee5405370efd/irc/datastore/datastore.go

which exposes key-value pairs. Each key has a UUID and is associated with a "table". There are four operations:

  1. Read everything from a table. This is used at ircd startup to read all persisted data. The source of truth then becomes the in-memory datastructures, with asynchronous persistence back to the datastore
  2. Set a key, with an optional TTL that will be respected by the datastore
  3. Delete a key
  4. Read a single key (this is used for some edge cases, like schema changes)

This branch refactors channels and channel purge records to use the new API.