ibessonov commented on a change in pull request #208:
URL: https://github.com/apache/ignite-3/pull/208#discussion_r672056431



##########
File path: 
modules/configuration/src/main/java/org/apache/ignite/internal/configuration/util/ConfigurationUtil.java
##########
@@ -277,101 +277,73 @@ else if (val instanceof Map)
                     }
                 }
             }
-        }
-
-        var src = new InnerConfigurationSource(prefixMap);
-
-        src.descend(node);
-    }
-
-    /**
-     * Convert a traversable tree to a map of qualified keys to values.
-     *
-     * @param curRoot Current root tree.
-     * @param updates Tree with updates.
-     * @return Map of changes.
-     */
-    public static Map<String, Serializable> nodeToFlatMap(
-        SuperRoot curRoot,
-        SuperRoot updates
-    ) {
-        Map<String, Serializable> values = new HashMap<>();
 
-        updates.traverseChildren(new KeysTrackingConfigurationVisitor<>() {
-            /** Write nulls instead of actual values. Makes sense for 
deletions from named lists. */
-            private boolean writeNulls;
-
-            /** {@inheritDoc} */
-            @Override public Map<String, Serializable> doVisitLeafNode(String 
key, Serializable val) {
-                if (val != null)
-                    values.put(currentKey(), writeNulls ? null : val);
+            /**
+             * Specific implementation of {@link 
#descend(ConstructableTreeNode)} that descends into named list node and
+             * sets a proper ordering to named list elements.
+             *
+             * @param node Named list node under construction.
+             */
+            private void descendToNamedListNode(NamedListNode<?> node) {
+                // This list must be mutable and RandomAccess.
+                var orderedKeys = new 
ArrayList<>(((NamedListView<?>)node).namedListKeys());
 
-                return values;
-            }
+                for (Map.Entry<String, ?> entry : map.entrySet()) {
+                    String key = entry.getKey();
+                    Object val = entry.getValue();
 
-            /** {@inheritDoc} */
-            @Override public Map<String, Serializable> doVisitInnerNode(String 
key, InnerNode node) {
-                if (node == null)
-                    return null;
+                    assert val == null || val instanceof Map || val instanceof 
Serializable;
 
-                node.traverseChildren(this);
+                    if (val == null) {
+                        // Given that this particular method is applied to 
modify existing trees rather than
+                        // creating new trees, a "hack" is required in this 
place. "construct" is designed to create
+                        // "change" objects, thus it would just nullify named 
list element instead of deleting it.
+                        node.forceDelete(key);
+                    }
+                    else if (val instanceof Map) {
+                        // For every named list entry modification we must 
take its index into account.
+                        // We do this by modifying "orderedKeys" when index is 
explicitly passed.
+                        Object idxObj = ((Map<?, 
?>)val).get(NamedListNode.ORDER_IDX);
 
-                return values;
-            }
+                        if (idxObj != null) {
+                            assert idxObj instanceof Integer : val;
 
-            /** {@inheritDoc} */
-            @Override public <N extends InnerNode> Map<String, Serializable> 
doVisitNamedListNode(String key, NamedListNode<N> node) {
-                for (String namedListKey : node.namedListKeys()) {
-                    N namedElement = node.get(namedListKey);
-
-                    withTracking(namedListKey, true, false, () -> {
-                        if (namedElement == null)
-                            visitDeletedNamedListElement();
-                        else
-                            namedElement.traverseChildren(this);
-
-                        return null;
-                    });
-                }
+                            int idx = (Integer)idxObj;
 
-                return values;
-            }
+                            if (idx >= orderedKeys.size()) {
+                                // Updates can come in arbitrary order. This 
means that array may be too small
+                                // during batch creation. In this case we have 
to insert enough nulls before
+                                // invoking "add" method for actual key.
+                                orderedKeys.ensureCapacity(idx + 1);
 
-            /**
-             * Here we must list all joined keys belonging to deleted element. 
The only way to do it is to traverse
-             * cached configuration tree and write {@code null} into all 
values.
-             */
-            private void visitDeletedNamedListElement() {
-                // It must be impossible to delete something inside of the 
element that we're currently deleting.
-                assert !writeNulls;
+                                while (idx != orderedKeys.size())
+                                    orderedKeys.add(null);
 
-                Object originalNamedElement = null;
+                                orderedKeys.add(idx, key);
+                            }
+                            else
+                                orderedKeys.set(idx, key);
+                        }
 
-                List<String> currentPath = currentPath();
+                        node.construct(key, new 
InnerConfigurationSource((Map<String, ?>)val));
+                    }
+                    else {
+                        assert val instanceof Serializable;
 
-                try {
-                    // This code can in fact be better optimized for deletion 
scenario,
-                    // but there's no point in doing that, since the operation 
is so rare and it will
-                    // complicate code even more.
-                    originalNamedElement = find(currentPath, curRoot);
-                }
-                catch (KeyNotFoundException ignore) {
-                    // May happen, not a big deal. This means that element 
never existed in the first place.
+                        node.construct(key, new 
LeafConfigurationSource((Serializable)val));

Review comment:
       Private values are not yet implemented. I suppose that they will have 
all the same guarantees




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to