Index: oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/util/Date.java =================================================================== --- oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/util/Date.java (revision 1601308) +++ oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/util/Date.java (working copy) @@ -24,6 +24,7 @@ import java.util.Collections; import java.util.List; import java.util.Random; +import java.util.TimeZone; /** * Enumerates some Calendar with math applied for easying tests @@ -88,7 +89,7 @@ private static final List VALUES = Collections.unmodifiableList(Arrays.asList(values())); private static final int SIZE = VALUES.size(); - private static final Random RND = new Random(); + private static final Random RND = new Random(30); /** * return a random Date @@ -100,8 +101,10 @@ } public String toISO_8601_2000() { - return new SimpleDateFormat( - "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").format(getCalendar().getTime()); + SimpleDateFormat format = new SimpleDateFormat( + "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); + format.setTimeZone(TimeZone.getTimeZone("GMT")); + return format.format(getCalendar().getTime()); } } Index: oak-run/src/main/java/org/apache/jackrabbit/oak/scalability/FormatSearcher.java =================================================================== --- oak-run/src/main/java/org/apache/jackrabbit/oak/scalability/FormatSearcher.java (revision 1601308) +++ oak-run/src/main/java/org/apache/jackrabbit/oak/scalability/FormatSearcher.java (working copy) @@ -23,6 +23,7 @@ import javax.jcr.query.QueryManager; import org.apache.jackrabbit.oak.benchmark.util.MimeType; +import org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants; import org.apache.jackrabbit.oak.scalability.ScalabilityAbstractSuite.ExecutionContext; /** @@ -33,15 +34,15 @@ @SuppressWarnings("deprecation") @Override protected Query getQuery(QueryManager qm, ExecutionContext context) throws RepositoryException { - StringBuilder statement = new StringBuilder("/jcr:content/"); + StringBuilder statement = new StringBuilder("/jcr:root/"); - statement.append(((String) context.getMap().get("ROOT_NODE_NAME"))).append("//element(*, ") + statement.append(((String) context.getMap().get(ScalabilityBlobSearchSuite.CTX_ROOT_NODE_NAME_PROP))).append("//element(*, ") .append(context.getMap().get(ScalabilityBlobSearchSuite.CTX_FILE_NODE_TYPE_PROP)).append(")"); statement.append("[(("); // adding all the possible mime-types in an OR fashion for (MimeType mt : MimeType.values()) { - statement.append("@").append(ScalabilityBlobSearchSuite.FORMAT_PROP).append(" = '") + statement.append("jcr:content/@").append(NodeTypeConstants.JCR_MIMETYPE).append(" = '") .append(mt.getValue()).append("' or "); } Index: oak-run/src/main/java/org/apache/jackrabbit/oak/scalability/LastModifiedSearcher.java =================================================================== --- oak-run/src/main/java/org/apache/jackrabbit/oak/scalability/LastModifiedSearcher.java (revision 1601308) +++ oak-run/src/main/java/org/apache/jackrabbit/oak/scalability/LastModifiedSearcher.java (working copy) @@ -23,6 +23,7 @@ import javax.jcr.query.QueryManager; import org.apache.jackrabbit.oak.benchmark.util.Date; +import org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants; import org.apache.jackrabbit.oak.scalability.ScalabilityAbstractSuite.ExecutionContext; /** @@ -42,7 +43,7 @@ final String path = (String) context.getMap().get(ScalabilityBlobSearchSuite.CTX_ROOT_NODE_NAME_PROP); final String statement = "/jcr:root/" + path + "//element(*, " + context.getMap().get(ScalabilityBlobSearchSuite.CTX_FILE_NODE_TYPE_PROP) - + ")[(@jcr:lastModified >= xs:dateTime('" + + ")[(jcr:content/@jcr:lastModified >= xs:dateTime('" + timeframe.toISO_8601_2000() + "'))]"; LOG.debug("LastModifiedSearcher: {}", statement); Index: oak-run/src/main/java/org/apache/jackrabbit/oak/scalability/ScalabilityAbstractSuite.java =================================================================== --- oak-run/src/main/java/org/apache/jackrabbit/oak/scalability/ScalabilityAbstractSuite.java (revision 1601308) +++ oak-run/src/main/java/org/apache/jackrabbit/oak/scalability/ScalabilityAbstractSuite.java (working copy) @@ -207,7 +207,12 @@ * * @throws Exception */ - protected void beforeSuite() throws Exception {} + protected void beforeSuite() throws Exception { + // Start the profiler. Giving a chance to overriding classes to call it at a different stage + if (PROFILE) { + context.startProfiler(); + } + } /** * Prepares this performance benchmark. @@ -227,9 +232,6 @@ beforeSuite(); - if (PROFILE) { - context.startProfiler(); - } } /** @@ -496,9 +498,7 @@ } public void startProfiler() { - if (PROFILE) { profiler = new Profiler().startCollecting(); - } } public void stopProfiler() { Index: oak-run/src/main/java/org/apache/jackrabbit/oak/scalability/ScalabilityBlobSearchSuite.java =================================================================== --- oak-run/src/main/java/org/apache/jackrabbit/oak/scalability/ScalabilityBlobSearchSuite.java (revision 1601308) +++ oak-run/src/main/java/org/apache/jackrabbit/oak/scalability/ScalabilityBlobSearchSuite.java (working copy) @@ -21,7 +21,6 @@ import static com.google.common.collect.Lists.newArrayList; import static com.google.common.collect.Lists.newArrayListWithCapacity; -import java.util.Calendar; import java.util.List; import java.util.Random; @@ -37,6 +36,11 @@ import javax.jcr.lock.LockException; import javax.jcr.nodetype.ConstraintViolationException; import javax.jcr.nodetype.NodeType; +import javax.jcr.nodetype.NodeTypeDefinition; +import javax.jcr.nodetype.NodeTypeManager; +import javax.jcr.nodetype.NodeTypeTemplate; +import javax.jcr.nodetype.PropertyDefinitionTemplate; +import javax.jcr.version.OnParentVersionAction; import javax.jcr.version.VersionException; import org.apache.commons.io.output.NullOutputStream; @@ -52,6 +56,7 @@ import org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexEditorProvider; import org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexProvider; import org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneInitializerHelper; +import org.apache.jackrabbit.oak.plugins.index.property.OrderedIndex; import org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider; import org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants; import org.apache.jackrabbit.oak.spi.commit.Observer; @@ -94,6 +99,14 @@ */ private static final int MAX_ASSETS_PER_LEVEL = Integer.getInteger("maxAssets", 500); + /** + * Controls if the index definitions are to be created. + */ + private static final boolean INDEX = Boolean.getBoolean("index"); + /** + * Controls if a customType is to be created + */ + private static final boolean CUSTOM_TYPE = Boolean.getBoolean("customType"); public static final String CTX_SEARCH_PATHS_PROP = "searchPaths"; public static final String CTX_ROOT_NODE_NAME_PROP = "rootNodeName"; @@ -104,7 +117,7 @@ private static final String CUSTOM_REF_PROP = "references"; - public static final String FORMAT_PROP = "format"; + private static final String CUSTOM_NODE_TYPE = "Asset"; protected static final String ROOT_NODE_NAME = "LongevitySearchAssets" + TEST_ID; @@ -114,6 +127,7 @@ private List searchPaths; private List readPaths; + private String nodeType; private final Boolean storageEnabled; @@ -137,9 +151,17 @@ root.addNode(ROOT_NODE_NAME); // defining indexes - createIndexDefinition(root, FORMAT_PROP, PropertyIndexEditorProvider.TYPE, - new String[] { FORMAT_PROP }, false); + if (INDEX) { + createIndexDefinition(root, NodeTypeConstants.JCR_MIMETYPE, + PropertyIndexEditorProvider.TYPE, + new String[] {NodeTypeConstants.JCR_MIMETYPE}, false); + createIndexDefinition(root, NodeTypeConstants.JCR_LASTMODIFIED, OrderedIndex.TYPE, + new String[] {NodeTypeConstants.JCR_LASTMODIFIED}, false); + } + if (CUSTOM_TYPE) { + setNodeType(createCustomNodeType(session)); + } session.save(); } @@ -171,6 +193,32 @@ return indexDef; } + @SuppressWarnings("unchecked") + private static String createCustomNodeType(Session session) + throws RepositoryException { + NodeTypeManager ntm = session.getWorkspace().getNodeTypeManager(); + NodeTypeDefinition ntd = ntm.getNodeType(NodeTypeConstants.NT_FILE); + NodeTypeTemplate ntt = ntm.createNodeTypeTemplate(ntd); + ntt.setOrderableChildNodes(false); + ntt.setName(CUSTOM_NODE_TYPE); + ntt.getPropertyDefinitionTemplates().add( + createCustomPropertyDefTemplate(ntm, CUSTOM_PATH_PROP)); + ntt.getPropertyDefinitionTemplates().add( + createCustomPropertyDefTemplate(ntm, CUSTOM_REF_PROP)); + ntm.registerNodeType(ntt, true); + return ntt.getName(); + } + private static PropertyDefinitionTemplate createCustomPropertyDefTemplate(NodeTypeManager ntm, + String prop) throws RepositoryException { + PropertyDefinitionTemplate pdt = ntm.createPropertyDefinitionTemplate(); + pdt.setName(prop); + pdt.setOnParentVersion(OnParentVersionAction.IGNORE); + pdt.setRequiredType(PropertyType.STRING); + pdt.setValueConstraints(null); + pdt.setDefaultValues(null); + pdt.setFullTextSearchable(true); + return pdt; + } /** * Executes before each test run */ @@ -233,7 +281,11 @@ } @Override - protected void executeBenchmark(final ScalabilityBenchmark benchmark, final ExecutionContext context) throws Exception { + protected void executeBenchmark(final ScalabilityBenchmark benchmark, + final ExecutionContext context) throws Exception { + if (PROFILE) { + context.startProfiler(); + } //Execute the benchmark with the number threads configured List threads = newArrayListWithCapacity(SEARCHERS); for (int idx = 0; idx < SEARCHERS;idx++) { @@ -258,6 +310,7 @@ e.printStackTrace(); } } + context.stopProfiler(); } @Override @@ -302,7 +355,13 @@ searchPaths.add(path); } } + public String getNodeType() { + return nodeType; + } + protected void setNodeType(String nodeType) { + this.nodeType = nodeType; + } private class Reader implements Runnable { private final Session session = loginWriter(); @@ -379,18 +438,13 @@ private Node putFile(String fileNamePrefix, String parentDir) throws RepositoryException, UnsupportedRepositoryOperationException, ValueFormatException, VersionException, LockException, ConstraintViolationException { - String type = getType(); - Node filepath = JcrUtils.getOrAddNode(parent, parentDir, type); + Node filepath = JcrUtils.getOrAddNode(parent, parentDir, getParentType()); Node file = JcrUtils.getOrAddNode(filepath, (fileNamePrefix + "File" + counter++), - type); + getType()); - // adding a custom format/mime-type for later querying. - file.setProperty(FORMAT_PROP, MimeType.randomMimeType().getValue()); - // adding a last modified for later querying - file.setProperty(Property.JCR_LAST_MODIFIED, Date.randomDate().getCalendar()); Binary binary = parent.getSession().getValueFactory().createBinary( @@ -399,8 +453,8 @@ Node content = JcrUtils.getOrAddNode(file, Node.JCR_CONTENT, NodeType.NT_RESOURCE); - content.setProperty(Property.JCR_MIMETYPE, "application/octet-stream"); - content.setProperty(Property.JCR_LAST_MODIFIED, Calendar.getInstance()); + content.setProperty(Property.JCR_MIMETYPE, MimeType.randomMimeType().getValue()); + content.setProperty(Property.JCR_LAST_MODIFIED, Date.randomDate().getCalendar()); content.setProperty(Property.JCR_DATA, binary); file.setProperty(CUSTOM_PATH_PROP, file.getPath()); @@ -414,10 +468,33 @@ return file; } - private String getType() throws RepositoryException { + /** + * Gets the node type of the parent. + * + * @return the parent type + * @throws RepositoryException the repository exception + */ + protected String getParentType() throws RepositoryException { String type = NodeTypeConstants.NT_UNSTRUCTURED; + if (parent.getSession().getWorkspace().getNodeTypeManager().hasNodeType( + NodeTypeConstants.NT_OAK_UNSTRUCTURED)) { + type = NodeTypeConstants.NT_OAK_UNSTRUCTURED; + } + return type; + } + + /** + * Order of precedence is customNodeType, oak:Unstructured, nt:unstructured + * + * @return + * @throws RepositoryException + */ + protected String getType() throws RepositoryException { + String type = NodeTypeConstants.NT_UNSTRUCTURED; if (!context.getMap().containsKey(CTX_FILE_NODE_TYPE_PROP)) { - if (parent.getSession().getWorkspace().getNodeTypeManager().hasNodeType( + if (getNodeType() != null) { + type = getNodeType(); + } else if (parent.getSession().getWorkspace().getNodeTypeManager().hasNodeType( NodeTypeConstants.NT_OAK_UNSTRUCTURED)) { type = NodeTypeConstants.NT_OAK_UNSTRUCTURED; } Index: oak-run/src/main/java/org/apache/jackrabbit/oak/scalability/ScalabilityRunner.java =================================================================== --- oak-run/src/main/java/org/apache/jackrabbit/oak/scalability/ScalabilityRunner.java (revision 1601308) +++ oak-run/src/main/java/org/apache/jackrabbit/oak/scalability/ScalabilityRunner.java (working copy) @@ -18,8 +18,10 @@ */ package org.apache.jackrabbit.oak.scalability; +import static java.util.Arrays.asList; import java.io.File; import java.io.PrintStream; +import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; @@ -144,11 +146,11 @@ Map> argmap = Maps.newHashMap(); // Split the args to get suites and benchmarks (i.e. suite:benchmark1,benchmark2) for(String arg : argset) { - String[] tokens = arg.split(":"); - if (tokens.length > 1) { - argmap.put(tokens[0], Splitter.on(",").trimResults().splitToList(tokens[1])); + List tokens = Splitter.on(":").limit(2).splitToList(arg); + if (tokens.size() > 1) { + argmap.put(tokens.get(0), Splitter.on(",").trimResults().splitToList(tokens.get(1))); } else { - argmap.put(tokens[0], null); + argmap.put(tokens.get(0), null); } argset.remove(arg); } @@ -159,9 +161,11 @@ List benchmarks = argmap.get(suite.toString()); // Only keep requested benchmarks if (benchmarks != null) { - for (ScalabilityBenchmark availableBenchmark : suite.getBenchmarks().values()) { - if (!benchmarks.contains(availableBenchmark.toString())) { - suite.removeBenchmark(availableBenchmark.toString()); + Iterator iter = suite.getBenchmarks().keySet().iterator(); + for (;iter.hasNext();) { + String availBenchmark = iter.next(); + if (!benchmarks.contains(availBenchmark)) { + iter.remove(); } } }