Details
Description
Current SessionManager will only clean the session in a timely triggered GC mechanism, and the default timeout is 1hr, which means the session metadata will be in memory for 1hr, this is OK without recovery enabled.
But with session recovery enabled, stored session data will also only be cleaned out after timeout, this will unnecessarily prolong the metadata persisted in the external storage. If Livy server is failed in this time period, though session is already inactive, recovered Livy server will recover and mark as inactive again, and the TTL will again set to 1hr. To the extreme, if Livy server always failed with this time period, the persisted metadata will never have a chance to clean up.
So we should aggressively clean the metadata once session is stopped.