If the node is drained, the StorageService#drain method is called, which triggers shutdown of mutation stage, messaging service, compaction, batchlog etc. In the end of this process, the node is moved to DRAINED status with the process still running.
When JVM is shutdown, the JVM shutdown hooks are ran, which are subscribed during the server initialisation: Runtime.getRuntime().addShutdownHook(drainOnShutdown); here.
I noticed this behaviour while reviewing
CASSANDRA-12461, as if we'd like add custom pre and post-shutdown hooks, most likely it makes sense to run them once (or user might expect such behaviour).
Is this behaviour correct? Should we run whole shutdown process twice or just once in "drain" and no-op during JVM shutdown?