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 04:45:39 UTC
svn commit: r1818879 - in /jackrabbit/oak/trunk/oak-run/src:
main/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/
test/java/org/apache/jackrabbit/oak/index/
Author: chetanm
Date: Thu Dec 21 04:45:39 2017
New Revision: 1818879
URL: http://svn.apache.org/viewvc?rev=1818879&view=rev
Log:
OAK-7103 - Enable compression by default on DocumentStoreIndexer logic
Modified:
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/FlatFileNodeStoreBuilder.java
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/NodeStateEntrySorter.java
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/StoreAndSortStrategy.java
jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/index/DocumentStoreIndexerIT.java
Modified: jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/FlatFileNodeStoreBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/FlatFileNodeStoreBuilder.java?rev=1818879&r1=1818878&r2=1818879&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/FlatFileNodeStoreBuilder.java (original)
+++ jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/FlatFileNodeStoreBuilder.java Thu Dec 21 04:45:39 2017
@@ -33,7 +33,7 @@ import org.slf4j.LoggerFactory;
import static com.google.common.collect.Iterables.size;
public class FlatFileNodeStoreBuilder {
- private static final String OAK_INDEXER_USE_ZIP = "oak.indexer.useZip";
+ public static final String OAK_INDEXER_USE_ZIP = "oak.indexer.useZip";
private static final String OAK_INDEXER_SORTED_FILE_PATH = "oak.indexer.sortedFilePath";
private final Logger log = LoggerFactory.getLogger(getClass());
private final Iterable<NodeStateEntry> nodeStates;
@@ -44,7 +44,7 @@ public class FlatFileNodeStoreBuilder {
private NodeStateEntryWriter entryWriter;
private long entryCount = 0;
- private boolean useZip = Boolean.getBoolean(OAK_INDEXER_USE_ZIP);
+ private boolean useZip = Boolean.valueOf(System.getProperty(OAK_INDEXER_USE_ZIP, "true"));
public FlatFileNodeStoreBuilder(Iterable<NodeStateEntry> nodeStates, File workDir) {
this.nodeStates = nodeStates;
@@ -66,7 +66,7 @@ public class FlatFileNodeStoreBuilder {
comparator = new PathElementComparator(preferredPathElements);
entryWriter = new NodeStateEntryWriter(blobStore);
FlatFileStore store = new FlatFileStore(createdSortedStoreFile(), new NodeStateEntryReader(blobStore),
- size(preferredPathElements), false);
+ size(preferredPathElements), useZip);
if (entryCount > 0) {
store.setEntryCount(entryCount);
}
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=1818879&r1=1818878&r2=1818879&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 04:45:39 2017
@@ -19,6 +19,8 @@
package org.apache.jackrabbit.oak.index.indexer.document.flatfile;
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
@@ -38,6 +40,8 @@ import static com.google.common.collect.
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 {
@@ -51,6 +55,7 @@ public class NodeStateEntrySorter {
private boolean useZip;
private boolean deleteOriginal;
private long maxMemory = ONE_GB * 5;
+ private long actualFileSize;
public NodeStateEntrySorter(Comparator<Iterable<String>> pathComparator, File nodeStateFile, File workDir) {
this(pathComparator, nodeStateFile, workDir, getSortedFileName(nodeStateFile));
@@ -75,6 +80,11 @@ public class NodeStateEntrySorter {
this.maxMemory = maxMemoryInGb * ONE_GB;
}
+ public void setActualFileSize(long actualFileSize) {
+ this.actualFileSize = actualFileSize;
+ }
+
+
public void sort() throws IOException {
long estimatedMemory = estimateAvailableMemory();
long memory = Math.min(estimatedMemory, maxMemory);
@@ -85,18 +95,7 @@ public class NodeStateEntrySorter {
Function<String, NodeStateEntryHolder> func1 = (line) -> line == null ? null : new NodeStateEntryHolder(line, pathComparator);
Function<NodeStateEntryHolder, String> func2 = holder -> holder == null ? null : holder.getLine();
- List<File> sortedFiles = ExternalSort.sortInBatch(nodeStateFile,
- comparator, //Comparator to use
- DEFAULTMAXTEMPFILES,
- memory,
- charset, //charset
- workDir, //temp directory where intermediate files are created
- true,
- 0,
- useZip,
- func2,
- func1
- );
+ List<File> sortedFiles = sortInBatch(memory, comparator, func1, func2);
log.info("Batch sorting done in {} with {} files of size {} to merge", w, sortedFiles.size(),
humanReadableByteCount(sizeOf(sortedFiles)));
@@ -108,22 +107,63 @@ public class NodeStateEntrySorter {
Stopwatch w2 = Stopwatch.createStarted();
- ExternalSort.mergeSortedFiles(sortedFiles,
- sortedFile,
- comparator,
- charset,
- true,
- false,
- useZip,
- func2,
- func1
-
- );
+ mergeSortedFiles(comparator, func1, func2, sortedFiles);
log.info("Merging of sorted files completed in {}", w2);
log.info("Sorting completed in {}", w);
}
+ private void mergeSortedFiles(Comparator<NodeStateEntryHolder> comparator, Function<String, NodeStateEntryHolder> func1,
+ Function<NodeStateEntryHolder, String> func2, List<File> sortedFiles) throws IOException {
+ try(BufferedWriter writer = createWriter(sortedFile, useZip)) {
+ ExternalSort.mergeSortedFiles(sortedFiles,
+ writer,
+ comparator,
+ charset,
+ true, //distinct
+ useZip, //useZip
+ func2,
+ func1
+
+ );
+ }
+ }
+
+ private List<File> sortInBatch(long memory, Comparator<NodeStateEntryHolder> comparator,
+ Function<String, NodeStateEntryHolder> func1,
+ Function<NodeStateEntryHolder, String> func2) throws IOException {
+ if (useZip) {
+ try (BufferedReader reader = createReader(nodeStateFile, useZip)) {
+ return ExternalSort.sortInBatch(reader,
+ actualFileSize,
+ comparator, //Comparator to use
+ DEFAULTMAXTEMPFILES,
+ memory,
+ charset, //charset
+ workDir, //temp directory where intermediate files are created
+ true, //distinct
+ 0,
+ useZip, //useZip
+ func2,
+ func1
+ );
+ }
+ } else {
+ return ExternalSort.sortInBatch(nodeStateFile,
+ comparator, //Comparator to use
+ DEFAULTMAXTEMPFILES,
+ memory,
+ charset, //charset
+ workDir, //temp directory where intermediate files are created
+ true,
+ 0,
+ useZip,
+ func2,
+ func1
+ );
+ }
+ }
+
public File getSortedFile() {
return sortedFile;
}
Modified: jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/StoreAndSortStrategy.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/StoreAndSortStrategy.java?rev=1818879&r1=1818878&r2=1818879&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/StoreAndSortStrategy.java (original)
+++ jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/StoreAndSortStrategy.java Thu Dec 21 04:45:39 2017
@@ -25,12 +25,12 @@ import java.io.IOException;
import com.google.common.base.Stopwatch;
import org.apache.commons.io.FileUtils;
-import org.apache.jackrabbit.oak.commons.IOUtils;
import org.apache.jackrabbit.oak.index.indexer.document.NodeStateEntry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static com.google.common.base.StandardSystemProperty.LINE_SEPARATOR;
+import static org.apache.jackrabbit.oak.commons.IOUtils.humanReadableByteCount;
class StoreAndSortStrategy {
private static final String OAK_INDEXER_DELETE_ORIGINAL = "oak.indexer.deleteOriginal";
@@ -45,6 +45,7 @@ class StoreAndSortStrategy {
private long entryCount;
private boolean deleteOriginal = Boolean.parseBoolean(System.getProperty(OAK_INDEXER_DELETE_ORIGINAL, "true"));
private int maxMemory = Integer.getInteger(OAK_INDEXER_MAX_SORT_MEMORY_IN_GB, 3);
+ private long textSize;
public StoreAndSortStrategy(Iterable<NodeStateEntry> nodeStates, PathElementComparator comparator,
@@ -57,7 +58,7 @@ class StoreAndSortStrategy {
}
public File createSortedStoreFile() throws IOException {
- File storeFile = writeToStore(storeDir, "store.json");
+ File storeFile = writeToStore(storeDir, getStoreFileName());
return sortStoreFile(storeFile);
}
@@ -76,6 +77,7 @@ class StoreAndSortStrategy {
sorter.setUseZip(compressionEnabled);
sorter.setMaxMemoryInGB(maxMemory);
sorter.setDeleteOriginal(deleteOriginal);
+ sorter.setActualFileSize(textSize);
sorter.sort();
return sorter.getSortedFile();
}
@@ -84,14 +86,16 @@ class StoreAndSortStrategy {
entryCount = 0;
File file = new File(dir, fileName);
Stopwatch sw = Stopwatch.createStarted();
- try (BufferedWriter w = FlatFileStoreUtils.createWriter(file, false)) {
+ try (BufferedWriter w = FlatFileStoreUtils.createWriter(file, compressionEnabled)) {
for (NodeStateEntry e : nodeStates) {
String line = entryWriter.toString(e);
w.append(line).append(LINE_SEPARATOR.value());
+ textSize += line.length() + LINE_SEPARATOR.value().length();
entryCount++;
}
}
- log.info("Dumped {} nodestates in json format in {} ({})",entryCount, sw, IOUtils.humanReadableByteCount(file.length()));
+ String sizeStr = compressionEnabled ? String.format("compressed/%s actual size", humanReadableByteCount(textSize)) : "";
+ log.info("Dumped {} nodestates in json format in {} ({} {})",entryCount, sw, humanReadableByteCount(file.length()), sizeStr);
return file;
}
@@ -99,4 +103,8 @@ class StoreAndSortStrategy {
log.info("Delete original dump from traversal : {} ({})", deleteOriginal, OAK_INDEXER_DELETE_ORIGINAL);
log.info("Max heap memory (GB) to be used for merge sort : {} ({})", maxMemory, OAK_INDEXER_MAX_SORT_MEMORY_IN_GB);
}
+
+ private String getStoreFileName() {
+ return compressionEnabled ? "store.json.zip" : "store.json";
+ }
}
Modified: jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/index/DocumentStoreIndexerIT.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/index/DocumentStoreIndexerIT.java?rev=1818879&r1=1818878&r2=1818879&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/index/DocumentStoreIndexerIT.java (original)
+++ jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/index/DocumentStoreIndexerIT.java Thu Dec 21 04:45:39 2017
@@ -34,6 +34,7 @@ import org.apache.jackrabbit.oak.index.i
import org.apache.jackrabbit.oak.index.indexer.document.DocumentStoreIndexer;
import org.apache.jackrabbit.oak.index.indexer.document.NodeStateEntry;
import org.apache.jackrabbit.oak.index.indexer.document.NodeStateIndexer;
+import org.apache.jackrabbit.oak.index.indexer.document.flatfile.FlatFileNodeStoreBuilder;
import org.apache.jackrabbit.oak.plugins.document.Collection;
import org.apache.jackrabbit.oak.plugins.document.DocumentMKBuilderProvider;
import org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore;
@@ -128,6 +129,13 @@ public class DocumentStoreIndexerIT exte
}
@Test
+ public void indexMongoRepo_WithCompressionDisabled() throws Exception{
+ System.setProperty(FlatFileNodeStoreBuilder.OAK_INDEXER_USE_ZIP, "false");
+ indexMongoRepo();
+ System.clearProperty(FlatFileNodeStoreBuilder.OAK_INDEXER_USE_ZIP);
+ }
+
+ @Test
public void bundling() throws Exception{
DocumentNodeStoreBuilder<?> docBuilder = builderProvider.newBuilder().setMongoDB(getConnection().getDB());
DocumentNodeStore store = docBuilder.build();