Fixing OrientDB on NixOS after server ran out of storage

Our nexus server ran out of storage. This led to me running into the following error:

Error during transaction commit
	DB name="component"
	at com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage.makeRollback(OAbstractPaginatedStorage.java:2858)
...
	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:883)
	at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:1034)
	at java.lang.Thread.run(Thread.java:750)
Caused by: java.lang.NullPointerException: null

As I have learned, this can cause OrientDB to get corrupted. If you are not running NixOS/running nexus in docker you can take a look here:
https://gist.github.com/micalbrecht/212d37865fbc24afc6d8b1aab621dea6

Backup DB

Before doing anything, backup your nexus data, especially everything in <nexus-dir>/db

Open nexus-orient-console

find /nix -name "nexus-orient-console.jar"

If you installed nexus via the official package, you will find at least one .jar. Make sure you have java available (at the time of writing this java8 was required):

nix-shell -p jdk8

Open the console:

java -jar /nix/<path-you-found-before>/nexus-orient-console.jar

Repair Database

CONNECT PLOCAL:/your/path/to/nexus/dir/db/component admin admin
REBUILD INDEX *
REPAIR DATABASE --fix-graph
REPAIR DATABASE --fix-links
REPAIR DATABASE --fix-ridbags
REPAIR DATABASE --fix-bonsai
DISCONNECT

Fix permissions

In my case I performed the steps above as root, which caused some files in <nexus-dir>/db/component to now be owned by root. Fix this using

chown -R nexus:nexus <nexus-dir>/db/component

Restart Nexus

systemctl restart nexus