Granola-Team / mina-indexer

The Mina Indexer is a re-imagined version of the software collectively called the "Mina archive node."
Apache License 2.0
18 stars 10 forks source link

Problem: can't find process using a given indexer database #1169

Closed robinbb closed 2 months ago

robinbb commented 2 months ago

Given a particular mina-indexer database directory, a sysadmin would like to know which process is using the database. A mina-indexer process might also like to know if the database directory is in use by another running process. This is because it is impossible (unsupported) for more than one Indexer to use a given database directory at a time. Without this, it is impossible to safely re-use a database directory that exists when starting a mina-indexer server. Since it takes hours to re-create a database directory from logs, this is a major problem.

robinbb commented 2 months ago

A solution to this problem, for example, would be to write a PID file to the database directory whenever a server is starting. Before doing that, the server should consult the database directory to see if there is already a PID file there. If there is, and the process with that PID is still running, then the server cannot start. If there is no such process (faulty shutdown by the prior Indexer), or if there is no PID file, then it is safe for the starting Indexer server to use the database. (Be careful of race conditions. Use links.)

This solution has the advantage that the PID file can be used by sysadmins and outside tooling to know the same thing that the Indexer knows - which process is using that database directory. This would be useful if, for example, the sysadmin/tool is considering deleting the database directory. If there is a PID, and the associated process is live, then it is not safe to delete.