1

How do you get xodus to completely shut down and release resources?

Closing all environments that are open does not stop the shared threads, nor release (sometimes massive) amounts of data in the cache.

For example, right now, I have a supposedly stopped xodus environment, but I still have jetbrains.exodus.core.dataStructures.ConcurrentLongObjectCache$CacheEntry (and its related byte[] objects) using 8 GB of RAM, which I want reclaimed...

--followup--

The following code is what I found necessary to release the cached memory, mostly held in static objects by xodus:

    Field tailPages = Class.forName("jetbrains.exodus.log.SharedLogCache").getSuperclass().getDeclaredField("TAIL_PAGES_CACHE");
    tailPages.setAccessible(true);
    Object concurrentLongObjectCache = tailPages.get(null);  //static field
    Method clear = Class.forName("jetbrains.exodus.core.dataStructures.ConcurrentLongObjectCache").getMethod("clear");
    clear.invoke(concurrentLongObjectCache);

    Log.invalidateSharedCache();
    SharedOpenFilesCache.invalidate();

The following call will stop most of the threads:

ThreadJobProcessorPool.getProcessors().forEach(jobProcessor -> jobProcessor.finish());

I've found, I can safely restart xodus after calling any/all of the above.

If you want to stop all of the threads, do this:

    Field spawner = ThreadJobProcessorPool.class.getDeclaredField("SPAWNER");
    spawner.setAccessible(true);
    Object threadJobSpawner = spawner.get(null); //static field
    threadJobSpawner.getClass().getMethod("finish").invoke(threadJobSpawner);

However, I've found that xodus does not properly restart after doing that - there is something off with the way the SPAWNER tries to restart itself, which I haven't looked into.

user2163960
  • 1,871
  • 19
  • 22

1 Answers1

0

Currently, there is no an appropriate way to completely unload Xodus.

Speaking of RAM, you can reclaim memory used by cached data by calling public static method jetbrains.exodus.log.Log.invalidateSharedCache(). Please make sure that all Environments are closed at that moment, otherwise an OutOfMemoryError would be very likely to happen.

As for background threads, there is no a workaround to finish them. Please follow the feature request: https://youtrack.jetbrains.com/issue/XD-729.

Vyacheslav Lukianov
  • 1,913
  • 8
  • 12
  • I've discovered that ThreadJobProcessorPool.getProcessors().forEach(jobProcessor -> jobProcessor.finish()); seems to work to stop the threads (though I haven't checked to see if it leaves things in a state where I could restart it again) The invalidateSharedCache doesn't seem to be releasing the memory I'm seeing held, I'll look closer at what is holding it. – user2163960 Jun 11 '18 at 14:50