Author: rgodfrey Date: Sat Oct 15 21:21:37 2016 New Revision: 1765110 URL: http://svn.apache.org/viewvc?rev=1765110&view=rev Log: QPID-7460 : Improve Json config store performance
Modified: qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/configuration/store/StoreConfigurationChangeListener.java qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/store/JsonFileConfigStore.java qpid/java/trunk/broker-core/src/test/java/org/apache/qpid/server/configuration/store/StoreConfigurationChangeListenerTest.java Modified: qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/configuration/store/StoreConfigurationChangeListener.java URL: http://svn.apache.org/viewvc/qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/configuration/store/StoreConfigurationChangeListener.java?rev=1765110&r1=1765109&r2=1765110&view=diff ============================================================================== --- qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/configuration/store/StoreConfigurationChangeListener.java (original) +++ qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/configuration/store/StoreConfigurationChangeListener.java Sat Oct 15 21:21:37 2016 @@ -24,6 +24,7 @@ import java.util.Collection; import org.apache.qpid.server.model.ConfigurationChangeListener; import org.apache.qpid.server.model.ConfiguredObject; +import org.apache.qpid.server.model.Model; import org.apache.qpid.server.model.State; import org.apache.qpid.server.store.DurableConfigurationStore; @@ -58,18 +59,24 @@ public class StoreConfigurationChangeLis { if(object.isDurable() && child.isDurable()) { - child.addChangeListener(this); - _store.update(true, child.asObjectRecord()); + Model model = child.getModel(); + Collection<Class<? extends ConfiguredObject>> parentTypes = + model.getParentTypes(child.getCategoryClass()); + if(parentTypes.size() == 1 || parentTypes.iterator().next().equals(object.getCategoryClass())) + { + child.addChangeListener(this); + _store.update(true, child.asObjectRecord()); - Class<? extends ConfiguredObject> categoryClass = child.getCategoryClass(); - Collection<Class<? extends ConfiguredObject>> childTypes = - child.getModel().getChildTypes(categoryClass); + Class<? extends ConfiguredObject> categoryClass = child.getCategoryClass(); + Collection<Class<? extends ConfiguredObject>> childTypes = + model.getChildTypes(categoryClass); - for (Class<? extends ConfiguredObject> childClass : childTypes) - { - for (ConfiguredObject<?> grandchild : child.getChildren(childClass)) + for (Class<? extends ConfiguredObject> childClass : childTypes) { - childAdded(child, grandchild); + for (ConfiguredObject<?> grandchild : child.getChildren(childClass)) + { + childAdded(child, grandchild); + } } } } Modified: qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/store/JsonFileConfigStore.java URL: http://svn.apache.org/viewvc/qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/store/JsonFileConfigStore.java?rev=1765110&r1=1765109&r2=1765110&view=diff ============================================================================== --- qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/store/JsonFileConfigStore.java (original) +++ qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/store/JsonFileConfigStore.java Sat Oct 15 21:21:37 2016 @@ -33,6 +33,9 @@ import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.SortedSet; +import java.util.TreeMap; +import java.util.TreeSet; import java.util.UUID; import com.fasterxml.jackson.databind.ObjectMapper; @@ -298,13 +301,59 @@ public class JsonFileConfigStore extends } else { - data = build(_rootClass, rootId); + data = build(_rootClass, rootId, createChildMap()); } save(data); } - private Map<String, Object> build(final Class<? extends ConfiguredObject> type, final UUID id) + private HashMap<UUID, Map<String, SortedSet<ConfiguredObjectRecord>>> createChildMap() + { + Model model = _parent.getModel(); + HashMap<UUID, Map<String, SortedSet<ConfiguredObjectRecord>>> map = new HashMap<>(); + + for(ConfiguredObjectRecord record : _objectsById.values()) + { + int parentCount = record.getParents().size(); + if (parentCount == 0) + { + continue; + } + Collection<Class<? extends ConfiguredObject>> parentTypes = + model.getParentTypes(_classNameMapping.get(record.getType())); + if (parentTypes != null && !parentTypes.isEmpty()) + { + + final Class<? extends ConfiguredObject> primaryParentCategory = + parentTypes.iterator().next(); + + String parentCategoryName = primaryParentCategory.getSimpleName(); + + UUID parentId = record.getParents().get(parentCategoryName); + + if (parentId != null) + { + Map<String, SortedSet<ConfiguredObjectRecord>> childMap = map.get(parentId); + if (childMap == null) + { + childMap = new TreeMap<>(); + map.put(parentId, childMap); + } + SortedSet<ConfiguredObjectRecord> children = childMap.get(record.getType()); + if (children == null) + { + children = new TreeSet<>(CONFIGURED_OBJECT_RECORD_COMPARATOR); + childMap.put(record.getType(), children); + } + children.add(record); + } + } + } + return map; + } + + private Map<String, Object> build(final Class<? extends ConfiguredObject> type, final UUID id, + Map<UUID, Map<String, SortedSet<ConfiguredObjectRecord>>> childMap) { ConfiguredObjectRecord record = _objectsById.get(id); Map<String,Object> map = new LinkedHashMap<String, Object>(); @@ -332,41 +381,24 @@ public class JsonFileConfigStore extends Collections.sort(childClasses, CATEGORY_CLASS_COMPARATOR); - for(Class<? extends ConfiguredObject> childClass : childClasses) + final Map<String, SortedSet<ConfiguredObjectRecord>> allChildren = childMap.get(id); + if(allChildren != null && !allChildren.isEmpty()) { - // only add if this is the "first" parent - if(_parent.getModel().getParentTypes(childClass).iterator().next() == type) + for(Map.Entry<String, SortedSet<ConfiguredObjectRecord>> entry : allChildren.entrySet()) { - String singularName = childClass.getSimpleName().toLowerCase(); + String singularName = entry.getKey().toLowerCase(); String attrName = singularName + (singularName.endsWith("s") ? "es" : "s"); - List<UUID> childIds = _idsByType.get(childClass.getSimpleName()); - if(childIds != null) - { - List<Map<String,Object>> entities = new ArrayList<Map<String, Object>>(); - List<ConfiguredObjectRecord> sortedChildren = new ArrayList<>(); - for(UUID childId : childIds) - { - ConfiguredObjectRecord childRecord = _objectsById.get(childId); - - final UUID parent = childRecord.getParents().get(type.getSimpleName()); - String parentId = parent.toString(); - if(id.toString().equals(parentId)) - { - sortedChildren.add(childRecord); - } - } + final SortedSet<ConfiguredObjectRecord> sortedChildren = entry.getValue(); + List<Map<String,Object>> entities = new ArrayList<Map<String, Object>>(); - Collections.sort(sortedChildren, CONFIGURED_OBJECT_RECORD_COMPARATOR); - - for(ConfiguredObjectRecord childRecord : sortedChildren) - { - entities.add(build(childClass, childRecord.getId())); - } + for(ConfiguredObjectRecord childRecord : sortedChildren) + { + entities.add(build(_classNameMapping.get(entry.getKey()), childRecord.getId(), childMap)); + } - if(!entities.isEmpty()) - { - map.put(attrName,entities); - } + if(!entities.isEmpty()) + { + map.put(attrName,entities); } } } Modified: qpid/java/trunk/broker-core/src/test/java/org/apache/qpid/server/configuration/store/StoreConfigurationChangeListenerTest.java URL: http://svn.apache.org/viewvc/qpid/java/trunk/broker-core/src/test/java/org/apache/qpid/server/configuration/store/StoreConfigurationChangeListenerTest.java?rev=1765110&r1=1765109&r2=1765110&view=diff ============================================================================== --- qpid/java/trunk/broker-core/src/test/java/org/apache/qpid/server/configuration/store/StoreConfigurationChangeListenerTest.java (original) +++ qpid/java/trunk/broker-core/src/test/java/org/apache/qpid/server/configuration/store/StoreConfigurationChangeListenerTest.java Sat Oct 15 21:21:37 2016 @@ -75,6 +75,7 @@ public class StoreConfigurationChangeLis when(child.getCategoryClass()).thenReturn(VirtualHost.class); Model model = mock(Model.class); when(model.getChildTypes(any(Class.class))).thenReturn(Collections.<Class<? extends ConfiguredObject>>emptyList()); + when(model.getParentTypes(eq(VirtualHost.class))).thenReturn(Collections.<Class<? extends ConfiguredObject>>singleton(Broker.class)); when(child.getModel()).thenReturn(model); when(child.isDurable()).thenReturn(true); _listener.childAdded(broker, child); --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@qpid.apache.org For additional commands, e-mail: commits-h...@qpid.apache.org