String type = notification.getType();
if (type.equals(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION))
{
// retrieve the garbage collection notification information
CompositeData cd = (CompositeData) notification.getUserData();
GarbageCollectionNotificationInfo info = GarbageCollectionNotificationInfo.from(cd);
long duration = info.getGcInfo().getDuration();
StringBuilder sb = new StringBuilder();
sb.append(info.getGcName()).append(" GC in ").append(duration).append("ms. ");
long bytes = 0;
List<String> keys = new ArrayList<>(info.getGcInfo().getMemoryUsageBeforeGc().keySet());
Collections.sort(keys);
for (String key : keys)
{
MemoryUsage before = info.getGcInfo().getMemoryUsageBeforeGc().get(key);
MemoryUsage after = info.getGcInfo().getMemoryUsageAfterGc().get(key);
if (after != null && after.getUsed() != before.getUsed())
{
sb.append(key).append(": ").append(before.getUsed());
sb.append(" -> ");
sb.append(after.getUsed());
if (!key.equals(keys.get(keys.size() - 1)))
sb.append("; ");
bytes += before.getUsed() - after.getUsed();
}
}
while (true)
{
State prev = state.get();
if (state.compareAndSet(prev, new State(duration, bytes, prev)))
break;
}
String st = sb.toString();
if (duration > MIN_LOG_DURATION)
logger.info(st);
else if (logger.isDebugEnabled())
logger.debug(st);
if (duration > MIN_LOG_DURATION_TPSTATS)
StatusLogger.log();
// if we just finished a full collection and we're still using a lot of memory, try to reduce the pressure
if (info.getGcName().equals("ConcurrentMarkSweep"))
SSTableDeletingTask.rescheduleFailedTasks();
}
}