You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by no...@apache.org on 2016/09/07 09:57:21 UTC

[33/50] [abbrv] lucene-solr:apiv2: SOLR-9452: JsonRecordReader should not deep copy document before handler.handle()

SOLR-9452: JsonRecordReader should not deep copy document before handler.handle()


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/f0f92d87
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/f0f92d87
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/f0f92d87

Branch: refs/heads/apiv2
Commit: f0f92d875ecab8a9acc01e959b852faf99a41e8e
Parents: 26262f4
Author: Shalin Shekhar Mangar <sh...@apache.org>
Authored: Wed Aug 31 18:12:02 2016 +0530
Committer: Shalin Shekhar Mangar <sh...@apache.org>
Committed: Wed Aug 31 18:12:02 2016 +0530

----------------------------------------------------------------------
 solr/CHANGES.txt                                |  2 ++
 .../solr/common/util/JsonRecordReader.java      | 25 ++++----------------
 2 files changed, 6 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/f0f92d87/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index f33138d..cc90e6e 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -103,6 +103,8 @@ Optimizations
 * SOLR-9447: Do not clone SolrInputDocument if update processor chain does not contain custom processors.
   (shalin)
 
+* SOLR-9452: JsonRecordReader should not deep copy document before handler.handle(). (noble, shalin)
+
 Other Changes
 ----------------------
 

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/f0f92d87/solr/solrj/src/java/org/apache/solr/common/util/JsonRecordReader.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/common/util/JsonRecordReader.java b/solr/solrj/src/java/org/apache/solr/common/util/JsonRecordReader.java
index 2025197..782c25d 100644
--- a/solr/solrj/src/java/org/apache/solr/common/util/JsonRecordReader.java
+++ b/solr/solrj/src/java/org/apache/solr/common/util/JsonRecordReader.java
@@ -119,9 +119,8 @@ public class JsonRecordReader {
    */
   public List<Map<String, Object>> getAllRecords(Reader r) throws IOException {
     final List<Map<String, Object>> results = new ArrayList<>();
-    streamRecords(r, (record, path) -> {
-      results.add(record);
-    });
+    // Deep copy is required here because the stream might hold on to the map
+    streamRecords(r, (record, path) -> results.add(Utils.getDeepCopy(record, 2)));
     return results;
   }
 
@@ -279,23 +278,6 @@ public class JsonRecordReader {
       return n;
     }
 
-    /**
-     * Copies a supplied Map to a new Map which is returned. Used to copy a
-     * records values. If a fields value is a List then they have to be
-     * deep-copied for thread safety
-     */
-    private static Map<String, Object> getDeepCopy(Map<String, Object> values) {
-      Map<String, Object> result = new LinkedHashMap<>();
-      for (Map.Entry<String, Object> entry : values.entrySet()) {
-        if (entry.getValue() instanceof List) {
-          result.put(entry.getKey(), new ArrayList((List) entry.getValue()));
-        } else {
-          result.put(entry.getKey(), entry.getValue());
-        }
-      }
-      return result;
-    }
-
     private void parse(JSONParser parser,
                        Handler handler,
                        Map<String, Object> values) throws IOException {
@@ -394,7 +376,7 @@ public class JsonRecordReader {
           int event = parser.nextEvent();
           if (event == OBJECT_END) {
             if (isRecord()) {
-              handler.handle(getDeepCopy(values), splitPath);
+              handler.handle(values, splitPath);
             }
             return;
           }
@@ -456,6 +438,7 @@ public class JsonRecordReader {
     }
 
     private void addChildDoc2ParentDoc(Map<String, Object> record, Map<String, Object> values) {
+      record =  Utils.getDeepCopy(record, 2);
       Object oldVal = values.get(null);
       if (oldVal == null) {
         values.put(null, record);