sequinstream / sequin

Stream data out of your Postgres database.
https://sequinstream.com
MIT License
444 stars 12 forks source link

Add Redis-based mutex and mutexed supervisor #229

Closed acco closed 1 month ago

acco commented 1 month ago

This pull request introduces a distributed mutex implementation using Redis for Sequin. The changes include:

  1. A new Sequin.Mutex module that provides functions to acquire, touch, and release mutexes using Redis.

  2. A Sequin.MutexOwner GenStateMachine that manages mutex acquisition and maintenance, with callbacks for successful acquisition.

  3. A Sequin.MutexedSupervisor that ensures only one instance of child processes is running at a time across distributed nodes.

The implementation uses Redix for Redis communication and includes error handling for Redis connection issues. The MutexOwner periodically touches the mutex to maintain ownership and crashes if the mutex is unexpectedly lost.

The MutexedSupervisor uses a one-for-all strategy, ensuring that if the MutexOwner loses its mutex, all child processes are shut down as well.

Additionally, the gen_state_machine dependency has been added to the project's mix file to support the new GenStateMachine implementation.

acco commented 1 month ago

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @acco and the rest of your teammates on Graphite Graphite