You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by ch...@apache.org on 2017/12/21 05:02:48 UTC

svn commit: r1818881 - in /jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile: NodeStateEntryHolder.java NodeStateEntrySorter.java

Author: chetanm
Date: Thu Dec 21 05:02:48 2017
New Revision: 1818881

URL: http://svn.apache.org/viewvc?rev=1818881&view=rev
Log:
OAK-7102 - Refactor DocumentIndexer logic to enable different sort approaches

Move out the holder class and remove reference to comparator

Added:
    jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/NodeStateEntryHolder.java   (with props)
Modified:
    jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/NodeStateEntrySorter.java

Added: jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/NodeStateEntryHolder.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/NodeStateEntryHolder.java?rev=1818881&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/NodeStateEntryHolder.java (added)
+++ jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/NodeStateEntryHolder.java Thu Dec 21 05:02:48 2017
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.jackrabbit.oak.index.indexer.document.flatfile;
+
+import java.util.List;
+
+import static com.google.common.collect.ImmutableList.copyOf;
+import static org.apache.jackrabbit.oak.commons.PathUtils.elements;
+import static org.apache.jackrabbit.oak.index.indexer.document.flatfile.NodeStateEntryWriter.getPath;
+
+class NodeStateEntryHolder {
+    final String line;
+    final List<String> pathElements;
+
+    public NodeStateEntryHolder(String line) {
+        this.line = line;
+        this.pathElements = copyOf(elements(getPath(line)));
+    }
+}

Propchange: jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/NodeStateEntryHolder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/NodeStateEntrySorter.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/NodeStateEntrySorter.java?rev=1818881&r1=1818880&r2=1818881&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/NodeStateEntrySorter.java (original)
+++ jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/NodeStateEntrySorter.java Thu Dec 21 05:02:48 2017
@@ -36,13 +36,10 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import static com.google.common.base.Charsets.UTF_8;
-import static com.google.common.collect.ImmutableList.copyOf;
 import static org.apache.commons.io.FileUtils.ONE_GB;
 import static org.apache.jackrabbit.oak.commons.IOUtils.humanReadableByteCount;
-import static org.apache.jackrabbit.oak.commons.PathUtils.elements;
 import static org.apache.jackrabbit.oak.index.indexer.document.flatfile.FlatFileStoreUtils.createReader;
 import static org.apache.jackrabbit.oak.index.indexer.document.flatfile.FlatFileStoreUtils.createWriter;
-import static org.apache.jackrabbit.oak.index.indexer.document.flatfile.NodeStateEntryWriter.getPath;
 
 public class NodeStateEntrySorter {
     private final Logger log = LoggerFactory.getLogger(getClass());
@@ -91,9 +88,9 @@ public class NodeStateEntrySorter {
         log.info("Sorting with memory {} (estimated {})", humanReadableByteCount(memory), humanReadableByteCount(estimatedMemory));
         Stopwatch w = Stopwatch.createStarted();
 
-        Comparator<NodeStateEntryHolder> comparator = Comparator.naturalOrder();
-        Function<String, NodeStateEntryHolder> func1 = (line) -> line == null ? null : new NodeStateEntryHolder(line, pathComparator);
-        Function<NodeStateEntryHolder, String> func2 = holder -> holder == null ? null : holder.getLine();
+        Comparator<NodeStateEntryHolder> comparator = (e1, e2) -> pathComparator.compare(e1.pathElements, e2.pathElements);
+        Function<String, NodeStateEntryHolder> func1 = (line) -> line == null ? null : new NodeStateEntryHolder(line);
+        Function<NodeStateEntryHolder, String> func2 = holder -> holder == null ? null : holder.line;
 
         List<File> sortedFiles = sortInBatch(memory, comparator, func1, func2);
 
@@ -194,25 +191,4 @@ public class NodeStateEntrySorter {
         return presFreeMemory;
     }
 
-    static class NodeStateEntryHolder implements Comparable<NodeStateEntryHolder> {
-        final String line;
-        final List<String> pathElements;
-        final Comparator<Iterable<String>> comparator;
-
-        public NodeStateEntryHolder(String line, Comparator<Iterable<String>> comparator) {
-            this.line = line;
-            this.comparator = comparator;
-            this.pathElements = copyOf(elements(getPath(line)));
-        }
-
-        public String getLine() {
-            return line;
-        }
-
-        @Override
-        public int compareTo(NodeStateEntryHolder o) {
-            return comparator.compare(this.pathElements, o.pathElements);
-        }
-    }
-
 }