Make data stored in ModificationCache eligible for GC earlier 48/8348/2
authorMarek Gradzki <mgradzki@cisco.com>
Fri, 8 Sep 2017 06:16:55 +0000 (08:16 +0200)
committerJan Srnicek <jsrnicek@cisco.com>
Wed, 13 Sep 2017 08:08:10 +0000 (08:08 +0000)
ModificationCache might store huge amount of data.
After DOs are retreved from readers it is not used anymore.

Change-Id: I66d57047212fed02321c416af3608c4998315ce7
Signed-off-by: Marek Gradzki <mgradzki@cisco.com>
infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/ReadableDataTreeDelegator.java

index a7ad88c..7c46b4c 100644 (file)
@@ -131,9 +131,11 @@ public final class ReadableDataTreeDelegator implements ReadableDataManager {
         checkNotNull(path, "Invalid instance identifier %s. Cannot create BA equivalent.", yangInstanceIdentifier);
         LOG.debug("OperationalDataTree.readNode(), path={}", path);
 
-        final Optional<? extends DataObject> dataObject;
+        final Optional<? extends DataObject> dataObject = readerRegistry.read(path, ctx);
+
+        // Modification cache should not be used after DOs are read, so we can clear it now to reduce peak footprint.
+        ctx.getModificationCache().close();
 
-        dataObject = readerRegistry.read(path, ctx);
         if (dataObject.isPresent()) {
             final NormalizedNode<?, ?> value = toNormalizedNodeFunction(path).apply(dataObject.get());
             return Optional.<NormalizedNode<?, ?>>fromNullable(value);
@@ -152,6 +154,10 @@ public final class ReadableDataTreeDelegator implements ReadableDataManager {
         final Multimap<InstanceIdentifier<? extends DataObject>, ? extends DataObject> dataObjects =
                 readerRegistry.readAll(ctx);
 
+        // Modification cache should not be used after DOs are read, so we can clear it now to reduce peak footprint.
+        // Even greater reduction can be achieved with HONEYCOMB-361.
+        ctx.getModificationCache().close();
+
         for (final InstanceIdentifier<? extends DataObject> instanceIdentifier : dataObjects.keySet()) {
             final YangInstanceIdentifier rootElementId = serializer.toYangInstanceIdentifier(instanceIdentifier);
             final NormalizedNode<?, ?> node =