Return-Path: X-Original-To: apmail-jackrabbit-oak-commits-archive@minotaur.apache.org Delivered-To: apmail-jackrabbit-oak-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 60885E909 for ; Tue, 8 Jan 2013 09:51:59 +0000 (UTC) Received: (qmail 54096 invoked by uid 500); 8 Jan 2013 09:51:59 -0000 Delivered-To: apmail-jackrabbit-oak-commits-archive@jackrabbit.apache.org Received: (qmail 54045 invoked by uid 500); 8 Jan 2013 09:51:58 -0000 Mailing-List: contact oak-commits-help@jackrabbit.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: oak-dev@jackrabbit.apache.org Delivered-To: mailing list oak-commits@jackrabbit.apache.org Received: (qmail 54005 invoked by uid 99); 8 Jan 2013 09:51:57 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 08 Jan 2013 09:51:57 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 08 Jan 2013 09:51:54 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id D0D9023888E7; Tue, 8 Jan 2013 09:51:33 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1430194 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2: Property2IndexLookup.java strategy/ContentMirrorStoreStrategy.java strategy/IndexStoreStrategy.java Date: Tue, 08 Jan 2013 09:51:33 -0000 To: oak-commits@jackrabbit.apache.org From: thomasm@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130108095133.D0D9023888E7@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: thomasm Date: Tue Jan 8 09:51:33 2013 New Revision: 1430194 URL: http://svn.apache.org/viewvc?rev=1430194&view=rev Log: OAK-537 Property2Index: assume the index exists Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/Property2IndexLookup.java jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/strategy/ContentMirrorStoreStrategy.java jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/strategy/IndexStoreStrategy.java Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/Property2IndexLookup.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/Property2IndexLookup.java?rev=1430194&r1=1430193&r2=1430194&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/Property2IndexLookup.java (original) +++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/Property2IndexLookup.java Tue Jan 8 09:51:33 2013 @@ -81,7 +81,7 @@ public class Property2IndexLookup { NodeState node = root; Iterator it = PathUtils.elements(path).iterator(); while (true) { - if (getIndexDefinitionNode(node, name) != null) { + if (getIndexDataNode(node, name) != null) { return true; } if (!it.hasNext()) { @@ -114,12 +114,11 @@ public class Property2IndexLookup { * @return the set of matched paths */ public Set find(String name, PropertyValue value) { - NodeState state = getIndexDefinitionNode(root, name); - if (state == null || state.getChildNode(":index") == null) { + NodeState state = getIndexDataNode(root, name); + if (state == null) { throw new IllegalArgumentException("No index for " + name); } Set paths = Sets.newHashSet(); - state = state.getChildNode(":index"); if (value == null) { paths.addAll(store.find(state, null)); } else { @@ -131,11 +130,10 @@ public class Property2IndexLookup { public double getCost(String name, PropertyValue value) { // TODO the cost method is currently reading all the data - // is not supposed to do that, it is only supposed to estimate - NodeState state = getIndexDefinitionNode(root, name); - if (state == null || state.getChildNode(":index") == null) { + NodeState state = getIndexDataNode(root, name); + if (state == null) { return Double.POSITIVE_INFINITY; } - state = state.getChildNode(":index"); double cost; if (value == null) { cost = store.count(state, null); @@ -146,14 +144,15 @@ public class Property2IndexLookup { } /** - * Get the node with the index definition node for the given property. + * Get the node with the index data for the given property, if there is an + * applicable index with data. * * @param name the property name - * @return the node where the index definition is stored, or null if no - * index definition node was found + * @return the node where the index data is stored, or null if no index + * definition or index data node was found */ @Nullable - private static NodeState getIndexDefinitionNode(NodeState node, String name) { + private static NodeState getIndexDataNode(NodeState node, String name) { NodeState state = node.getChildNode(INDEX_DEFINITIONS_NAME); if (state != null) { for (ChildNodeEntry entry : state.getChildNodeEntries()) { @@ -165,7 +164,11 @@ public class Property2IndexLookup { if (names != null) { for (int i = 0; i < names.count(); i++) { if (name.equals(names.getValue(Type.STRING, i))) { - return entry.getNodeState(); + NodeState indexDef = entry.getNodeState(); + NodeState index = indexDef.getChildNode(":index"); + if (index != null) { + return index; + } } } } Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/strategy/ContentMirrorStoreStrategy.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/strategy/ContentMirrorStoreStrategy.java?rev=1430194&r1=1430193&r2=1430194&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/strategy/ContentMirrorStoreStrategy.java (original) +++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/strategy/ContentMirrorStoreStrategy.java Tue Jan 8 09:51:33 2013 @@ -123,9 +123,6 @@ public class ContentMirrorStoreStrategy } static int countMatchingLeaves(NodeState state) { - if (state == null) { - return 0; - } int count = 0; if (state.getProperty("match") != null) { count++; @@ -140,11 +137,8 @@ public class ContentMirrorStoreStrategy public Set find(NodeState index, Iterable values) { Set paths = new HashSet(); if (values == null) { - if (index != null) { - // We have an entry for this value, so use it - for (ChildNodeEntry child : index.getChildNodeEntries()) { - getMatchingPaths(child.getNodeState(), "", paths); - } + for (ChildNodeEntry child : index.getChildNodeEntries()) { + getMatchingPaths(child.getNodeState(), "", paths); } } else { for (String p : values) { @@ -178,7 +172,10 @@ public class ContentMirrorStoreStrategy count += countMatchingLeaves(index); } else { for (String p : values) { - count += countMatchingLeaves(index.getChildNode(p)); + NodeState s = index.getChildNode(p); + if (s != null) { + count += countMatchingLeaves(s); + } } } return count; Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/strategy/IndexStoreStrategy.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/strategy/IndexStoreStrategy.java?rev=1430194&r1=1430193&r2=1430194&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/strategy/IndexStoreStrategy.java (original) +++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/strategy/IndexStoreStrategy.java Tue Jan 8 09:51:33 2013 @@ -55,7 +55,7 @@ public interface IndexStoreStrategy { /** * Search for a given set of values * - * @param index index node + * @param index index node (may not be null) * @param values values to look for (null to check for property existence) * @return the set of paths corresponding to the given values */ @@ -65,7 +65,7 @@ public interface IndexStoreStrategy { * Count the occurrence of a given set of values. Used in calculating the * cost of an index. * - * @param index the index node + * @param index the index node (may not be null) * @param values values to look for (null to check for property existence) * @return the aggregated count of occurrences for each provided value */